From cc21c6933e532ea997468b73af1c21fa271ec6c0 Mon Sep 17 00:00:00 2001 From: John Yenter-Briars Date: Thu, 16 Feb 2023 14:19:21 -0600 Subject: [PATCH 1/3] plz work --- .gitignore | 3 +- .../CalendarSync.Console.csproj | 9 ++- CalendarSync.Console/Program.cs | 74 ++++++++++++++----- .../PublishProfiles/FolderProfile.pubxml | 19 +++++ .../Properties/launchSettings.json | 2 +- 5 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 CalendarSync.Console/Properties/PublishProfiles/FolderProfile.pubxml diff --git a/.gitignore b/.gitignore index ff5b00c..787a09e 100644 --- a/.gitignore +++ b/.gitignore @@ -261,4 +261,5 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc \ No newline at end of file +*.pyc +appsettings.json diff --git a/CalendarSync.Console/CalendarSync.Console.csproj b/CalendarSync.Console/CalendarSync.Console.csproj index 8c22aea..0bb9ba5 100644 --- a/CalendarSync.Console/CalendarSync.Console.csproj +++ b/CalendarSync.Console/CalendarSync.Console.csproj @@ -1,4 +1,4 @@ - + Exe @@ -15,10 +15,17 @@ + + + + Always + + + diff --git a/CalendarSync.Console/Program.cs b/CalendarSync.Console/Program.cs index 20b0314..c29fe82 100644 --- a/CalendarSync.Console/Program.cs +++ b/CalendarSync.Console/Program.cs @@ -1,32 +1,68 @@ using CalendarSync; using CalendarSync.Console; using CommandLine; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Microsoft.Win32.TaskScheduler; -const uint DefaultDaysToSync = 7; +const string DailyTaskName = "SyncCalendar"; +var configuration = new ConfigurationBuilder() + .AddJsonFile("appsettings.json") + .Build(); -Parser.Default.ParseArguments(args) - .WithParsed(async o => - { - var host = Host.CreateDefaultBuilder().Build(); - var logger = host.Services.GetRequiredService>(); - logger.LogInformation("Logging established"); +var host = Host.CreateDefaultBuilder().Build(); +var logger = host.Services.GetRequiredService>(); +logger.LogInformation("Logging established"); - var primaryAccountRefreshToken = o.PrimaryAccountRefreshToken; - var secondaryAccountRefreshToken = o.SecondaryAccountRefreshToken; - var clientId = o.ClientId; - var orgConnectionString = o.OrgConnectionString; +var primaryAccountRefreshToken = configuration["PrimaryAccountRefreshToken"]; +var primaryAccountSubjectPrefix = configuration["PrimaryAccountSubjectPrefix"]; +var secondaryAccountRefreshToken = configuration["PrimaryAccountRefreshToken"]; +var secondaryAccountSubjectPrefix = configuration["SecondaryAccountSubjectPrefix"]; +var clientId = configuration["PrimaryAccountRefreshToken"]; +var orgConnectionString = configuration["PrimaryAccountRefreshToken"]; +var daysToSync = uint.Parse(configuration["DaysToSync"]); - var daysToSync = o.DaysToSync != 0 ? o.DaysToSync : DefaultDaysToSync; +try +{ + using TaskService ts = new TaskService(); + if (ts.GetTask(DailyTaskName) == null) + { + TaskDefinition td = ts.NewTask(); + td.RegistrationInfo.Description = "Every day at 9 am sync calendars"; - var source = new SecondaryAccToPrimaryAccProfile(secondaryAccountRefreshToken, o.SecondaryAccountSubjectPrefix); - var dest = new PrimaryAccToSecondaryAccProfile(primaryAccountRefreshToken, o.PrimaryAccountSubjectPrefix); - var service = new CalendarSyncService(dest, source, logger, clientId, orgConnectionString); - var startTime = DateTime.UtcNow; - var endTime = startTime.AddDays(daysToSync); + DailyTrigger trigger = new() + { + StartBoundary = DateTime.Today + new TimeSpan(10, 45, 0), + DaysInterval = 1 + }; + td.Triggers.Add(trigger); - await service.SyncRangeBidirectionalAsync(startTime.ToString("O"), endTime.ToString("O")); - }); + var dir = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/CalendarSync"; + td.Actions.Add(new ExecAction($"{dir}/CalendarSync.Console.exe", dir, null)); + + ts.RootFolder.RegisterTaskDefinition(DailyTaskName, td); + } + + var source = new SecondaryAccToPrimaryAccProfile(secondaryAccountRefreshToken, secondaryAccountSubjectPrefix); + var dest = new PrimaryAccToSecondaryAccProfile(primaryAccountRefreshToken, primaryAccountSubjectPrefix); + var service = new CalendarSyncService(dest, source, logger, clientId, orgConnectionString); + var startTime = DateTime.UtcNow; + var endTime = startTime.AddDays(daysToSync); + + Console.WriteLine("TESTTTTTT"); + Console.ReadKey(); + + //await service.SyncRangeBidirectionalAsync(startTime.ToString("O"), endTime.ToString("O")); + +} +catch (Exception e) +{ + Console.WriteLine(e.ToString()); +} +finally +{ + Console.ReadKey(); +} diff --git a/CalendarSync.Console/Properties/PublishProfiles/FolderProfile.pubxml b/CalendarSync.Console/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..2ebdb53 --- /dev/null +++ b/CalendarSync.Console/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,19 @@ + + + + + Release + Any CPU + bin\Release\net6.0\publish\win-x86\ + FileSystem + <_TargetId>Folder + net6.0 + win-x86 + true + true + false + true + + \ No newline at end of file diff --git a/CalendarSync.Console/Properties/launchSettings.json b/CalendarSync.Console/Properties/launchSettings.json index aafa395..583794a 100644 --- a/CalendarSync.Console/Properties/launchSettings.json +++ b/CalendarSync.Console/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "CalendarSync.Console": { "commandName": "Project", - "commandLineArgs": "--secondaryAccountRefreshToken idk --primaryAccountRefreshToken test --primaryAccountSubjectPrefix [Root16] --secondaryAccountSubjectPrefix [RSM] --clientId lezfooo --orgConnectionString asgsgs --daysToSync I2" + "commandLineArgs": "--secondaryAccountRefreshToken idk --primaryAccountRefreshToken test --primaryAccountSubjectPrefix [Root16] --secondaryAccountSubjectPrefix [RSM] --clientId lezfooo --orgConnectionString asgsgs --daysToSync 2" } } } \ No newline at end of file From 1bb06437d00621e4c60223d5fe027961560b38b8 Mon Sep 17 00:00:00 2001 From: John Yenter-Briars Date: Thu, 16 Feb 2023 19:49:26 -0600 Subject: [PATCH 2/3] update logging --- .gitignore | 3 ++- CalendarSync.Console/Program.cs | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 787a09e..e9d6a98 100644 --- a/.gitignore +++ b/.gitignore @@ -262,4 +262,5 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ *.pyc -appsettings.json + +appsettings.json \ No newline at end of file diff --git a/CalendarSync.Console/Program.cs b/CalendarSync.Console/Program.cs index c29fe82..f1d0a9d 100644 --- a/CalendarSync.Console/Program.cs +++ b/CalendarSync.Console/Program.cs @@ -14,20 +14,25 @@ var host = Host.CreateDefaultBuilder().Build(); var logger = host.Services.GetRequiredService>(); -logger.LogInformation("Logging established"); +logger.LogInformation(@" + BE NOT AFRAID + Your calendars will begin to sync + DO NOT close this window until you see the final logging message. +"); var primaryAccountRefreshToken = configuration["PrimaryAccountRefreshToken"]; var primaryAccountSubjectPrefix = configuration["PrimaryAccountSubjectPrefix"]; -var secondaryAccountRefreshToken = configuration["PrimaryAccountRefreshToken"]; +var secondaryAccountRefreshToken = configuration["SecondaryAccountRefreshToken "]; var secondaryAccountSubjectPrefix = configuration["SecondaryAccountSubjectPrefix"]; -var clientId = configuration["PrimaryAccountRefreshToken"]; -var orgConnectionString = configuration["PrimaryAccountRefreshToken"]; +var clientId = configuration["ClientId"]; +var orgConnectionString = configuration["OrgConnectionString "]; var daysToSync = uint.Parse(configuration["DaysToSync"]); try { using TaskService ts = new TaskService(); - if (ts.GetTask(DailyTaskName) == null) + var calendarSyncTask = ts.GetTask(DailyTaskName); + if (calendarSyncTask == null) { TaskDefinition td = ts.NewTask(); td.RegistrationInfo.Description = "Every day at 9 am sync calendars"; @@ -52,11 +57,12 @@ var startTime = DateTime.UtcNow; var endTime = startTime.AddDays(daysToSync); - Console.WriteLine("TESTTTTTT"); - Console.ReadKey(); - - //await service.SyncRangeBidirectionalAsync(startTime.ToString("O"), endTime.ToString("O")); + await service.SyncRangeBidirectionalAsync(startTime.ToString("O"), endTime.ToString("O")); + logger.LogInformation(@" + Calendar syncing complete! + Go forth about your day and be productive. + "); } catch (Exception e) { From cac0854b73add20be089baa54d7e64b424ca70b0 Mon Sep 17 00:00:00 2001 From: John Yenter-Briars Date: Thu, 23 Feb 2023 13:49:58 -0600 Subject: [PATCH 3/3] changes --- CalendarSync.Console/Program.cs | 56 +++++++++---------- .../Properties/launchSettings.json | 2 +- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/CalendarSync.Console/Program.cs b/CalendarSync.Console/Program.cs index f1d0a9d..5d44e1b 100644 --- a/CalendarSync.Console/Program.cs +++ b/CalendarSync.Console/Program.cs @@ -9,8 +9,8 @@ const string DailyTaskName = "SyncCalendar"; var configuration = new ConfigurationBuilder() - .AddJsonFile("appsettings.json") - .Build(); + .AddJsonFile("appsettings.json") + .Build(); var host = Host.CreateDefaultBuilder().Build(); var logger = host.Services.GetRequiredService>(); @@ -30,45 +30,41 @@ DO NOT close this window until you see the final logging message. try { - using TaskService ts = new TaskService(); - var calendarSyncTask = ts.GetTask(DailyTaskName); - if (calendarSyncTask == null) - { - TaskDefinition td = ts.NewTask(); - td.RegistrationInfo.Description = "Every day at 9 am sync calendars"; + using TaskService ts = new TaskService(); + var calendarSyncTask = ts.GetTask(DailyTaskName); + if (calendarSyncTask == null) + { + TaskDefinition td = ts.NewTask(); + td.RegistrationInfo.Description = "Every day at 9 am sync calendars"; - DailyTrigger trigger = new() - { - StartBoundary = DateTime.Today + new TimeSpan(10, 45, 0), - DaysInterval = 1 - }; - td.Triggers.Add(trigger); + DailyTrigger trigger = new() + { + StartBoundary = DateTime.Today + new TimeSpan(10, 45, 0), + DaysInterval = 1 + }; + td.Triggers.Add(trigger); - var dir = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/CalendarSync"; + var dir = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/CalendarSync"; - td.Actions.Add(new ExecAction($"{dir}/CalendarSync.Console.exe", dir, null)); + td.Actions.Add(new ExecAction($"{dir}/CalendarSync.Console.exe", dir, null)); - ts.RootFolder.RegisterTaskDefinition(DailyTaskName, td); - } + ts.RootFolder.RegisterTaskDefinition(DailyTaskName, td); + } - var source = new SecondaryAccToPrimaryAccProfile(secondaryAccountRefreshToken, secondaryAccountSubjectPrefix); - var dest = new PrimaryAccToSecondaryAccProfile(primaryAccountRefreshToken, primaryAccountSubjectPrefix); - var service = new CalendarSyncService(dest, source, logger, clientId, orgConnectionString); - var startTime = DateTime.UtcNow; - var endTime = startTime.AddDays(daysToSync); + var source = new SecondaryAccToPrimaryAccProfile(secondaryAccountRefreshToken, secondaryAccountSubjectPrefix); + var dest = new PrimaryAccToSecondaryAccProfile(primaryAccountRefreshToken, primaryAccountSubjectPrefix); + var service = new CalendarSyncService(dest, source, logger, clientId, orgConnectionString); + var startTime = DateTime.UtcNow; + var endTime = startTime.AddDays(daysToSync); - await service.SyncRangeBidirectionalAsync(startTime.ToString("O"), endTime.ToString("O")); + await service.SyncRangeBidirectionalAsync(startTime.ToString("O"), endTime.ToString("O")); - logger.LogInformation(@" + logger.LogInformation(@" Calendar syncing complete! Go forth about your day and be productive. "); } catch (Exception e) { - Console.WriteLine(e.ToString()); -} -finally -{ - Console.ReadKey(); + Console.WriteLine(e.ToString()); } diff --git a/CalendarSync.Console/Properties/launchSettings.json b/CalendarSync.Console/Properties/launchSettings.json index 583794a..0a9bb0a 100644 --- a/CalendarSync.Console/Properties/launchSettings.json +++ b/CalendarSync.Console/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "CalendarSync.Console": { "commandName": "Project", - "commandLineArgs": "--secondaryAccountRefreshToken idk --primaryAccountRefreshToken test --primaryAccountSubjectPrefix [Root16] --secondaryAccountSubjectPrefix [RSM] --clientId lezfooo --orgConnectionString asgsgs --daysToSync 2" + "commandLineArgs": "--secondaryAccountRefreshToken idk --primaryAccountRefreshToken test --primaryAccountSubjectPrefix [primacct] --secondaryAccountSubjectPrefix [secacct] --clientId lezfooo --orgConnectionString asgsgs --daysToSync 2" } } } \ No newline at end of file