static async Task Main(string[] args) { string baseDir = AppDomain.CurrentDomain.BaseDirectory; string configPath = AppDomain.CurrentDomain.BaseDirectory + "settings.json"; if (args.Length > 0) { configPath = args[0]; } Console.WriteLine("Using settings path: " + configPath); if (!File.Exists(configPath)) { Console.WriteLine("Error: Config file cannot be found in the specified path."); Console.ReadLine(); return; } //setup var config = JsonConvert.DeserializeObject <AppSettings>(File.ReadAllText(configPath)); //check/create logs folder if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + Logs.LogFolderName)) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + Logs.LogFolderName); } //services #if DEBUG var logs = Console.Out; //TODO: move to file #else var logs = File.CreateText(baseDir + Logs.LogFolderName + '/' + DateTime.Now.ToString(Logs.LogNameFormat) + Logs.LogFileExtension); #endif var cap = new AppointmentDBContext(config.CAPDBPath); var zoom = new ZoomService(config.ZoomAPIKey, config.ZoomAPISecret); var cache = new MeetingCache(config.CacheFilePath); PhoneService.Init(config.TwilioAccountSID, config.TwilioAuthToken); //main functionality var sync = new MeetingSync(cap, zoom, cache, logs, config); #if DEBUG //test date var syncDate = new DateTime(2021, 5, 31); //sync appointments await sync.SyncAppointments(syncDate, DateTime.MaxValue); #else var syncDate = DateTime.Now.Subtract(DateTime.Now.TimeOfDay); //sync appointments await sync.SyncAppointments(syncDate, DateTime.MaxValue); #endif //save cache cache.RemoveBefore(syncDate.AddDays(-7)); cache.Dispose(); }
static void Main(string[] args) { string baseDir = AppDomain.CurrentDomain.BaseDirectory; string configPath = AppDomain.CurrentDomain.BaseDirectory + "settings.json"; if (args.Length > 0) { configPath = args[0]; } Console.WriteLine("Using settings path: " + configPath); if (!File.Exists(configPath)) { Console.WriteLine("Error: Config file cannot be found in the specified path."); Console.ReadLine(); return; } var config = JsonConvert.DeserializeObject <AppSettings>(File.ReadAllText(configPath)); var reminder = new ZBAppReminder(config); PhoneService.Init(config.TwilioAccountSID, config.TwilioAuthToken); //check create logs folder if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + Logs.LogFolderName)) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + Logs.LogFolderName); } var tomorrow = DateTime.Now.AddDays(1); #if DEBUG tomorrow = new DateTime(2021, 5, 31); reminder.Output = Console.Out; //For testing output to console reminder.CheckSendTextReminders(tomorrow, tomorrow); Console.ReadLine(); #else try { reminder.Output = File.CreateText(baseDir + Logs.LogFolderName + '/' + DateTime.Now.ToString(Logs.LogNameFormat) + Logs.LogFileExtension); reminder.CheckSendTextReminders(tomorrow, tomorrow); } catch (Exception ex) { File.WriteAllText(baseDir + Logs.LogFolderName + @"/Error " + DateTime.Now.ToString(Logs.LogNameFormat) + Logs.LogFileExtension, ex.ToString()); PhoneService.SendMessage(config.ErrorLogPhone, config.TwilioPhone, ex.ToString()); } reminder.Output.Close(); #endif }