using System; using Cronos; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace VestalisQuintet.VQCalendarAttention { public class Program { private const string CredentialsFilePath = "../calendartowebhook-fa30e21f081f.json"; private const string CalendarId = "3e39821e10e795b311f93c79490960c3196632a465a794ca32e8a44c50115dde@group.calendar.google.com"; public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); // テストとしてCalendarApiTestを実行する // await CalendarApiTest.GetLatestEventAsync("3e39821e10e795b311f93c79490960c3196632a465a794ca32e8a44c50115dde@group.calendar.google.com", "../calendartowebhook-fa30e21f081f.json"); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { // Cronosで定義したCronジョブサービスを追加 // 翌日の予定を通知する services.AddHostedService<NextDayCalendarAttentionService>(serviceProvider => { // Cron式を設定 (例: 毎日午前9時に実行) //var cronExpression = CronExpression.Parse("0 9 * * *"); // 毎晩21時に実行 var cronExpression = CronExpression.Parse("0 21 * * *"); //var cronExpression = CronExpression.Parse("* * * * *"); // タイムゾーンを東京に設定 var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"); return new NextDayCalendarAttentionService(cronExpression, timeZoneInfo, serviceProvider, CredentialsFilePath, CalendarId); }); }); } }