diff --git a/src/Lithnet.Miiserver.AutoSync/Config/ConfigFile.cs b/src/Lithnet.Miiserver.AutoSync/Config/ConfigFile.cs index 33acff4..75c29a2 100644 --- a/src/Lithnet.Miiserver.AutoSync/Config/ConfigFile.cs +++ b/src/Lithnet.Miiserver.AutoSync/Config/ConfigFile.cs @@ -42,7 +42,7 @@ public static ConfigFile Load(string file) public static void Save(ConfigFile config, string filename) { - //ConfigFile.MarkManagementAgentsAsConfigured(config); + ConfigFile.MarkManagementAgentsAsConfigured(config); Serializer.Save(filename, config); } diff --git a/src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigClient.cs b/src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigClient.cs index adfb73c..a661a22 100644 --- a/src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigClient.cs +++ b/src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigClient.cs @@ -13,11 +13,12 @@ public class ConfigClient : ClientBase, IConfigService public ConfigClient() : base(ConfigServiceConfiguration.NetNamedPipeBinding, ConfigServiceConfiguration.NetNamedPipeEndpointAddress) { - this.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; + // this.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; } public ConfigFile GetConfig() { + ProtectedString.EncryptOnWrite = false; ConfigFile x = this.Channel.GetConfig(); x.ValidateManagementAgents(); return x; @@ -25,6 +26,7 @@ public ConfigFile GetConfig() public void PutConfig(ConfigFile config) { + ProtectedString.EncryptOnWrite = false; this.Channel.PutConfig(config); } diff --git a/src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigService.cs b/src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigService.cs index abe72c3..73b9706 100644 --- a/src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigService.cs +++ b/src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigService.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Lithnet.Logging; +using System.Diagnostics; namespace Lithnet.Miiserver.AutoSync { @@ -52,6 +53,7 @@ public ConfigFile GetConfig() { try { + Trace.WriteLine($"Calling {nameof(GetConfig)} as {Environment.UserName}"); ProtectedString.EncryptOnWrite = false; return Program.CurrentConfig; } @@ -66,6 +68,7 @@ public void PutConfig(ConfigFile config) { try { + Trace.WriteLine($"Calling {nameof(PutConfig)} as {Environment.UserName}"); ProtectedString.EncryptOnWrite = true; ConfigFile.Save(config, RegistrySettings.ConfigurationFile); Program.CurrentConfig = config; @@ -81,6 +84,7 @@ public void Reload() { try { + Trace.WriteLine($"Calling {nameof(Reload)} as {Environment.UserName}"); Program.Reload(); } catch (Exception ex) @@ -94,6 +98,7 @@ public bool IsPendingRestart() { try { + Trace.WriteLine($"Calling {nameof(IsPendingRestart)} as {Environment.UserName}"); return Program.PendingRestart; } catch (Exception ex) diff --git a/src/Lithnet.Miiserver.AutoSync/Program.cs b/src/Lithnet.Miiserver.AutoSync/Program.cs index 0e5bf3b..d58164a 100644 --- a/src/Lithnet.Miiserver.AutoSync/Program.cs +++ b/src/Lithnet.Miiserver.AutoSync/Program.cs @@ -55,9 +55,10 @@ internal static ConfigFile CurrentConfig /// public static void Main(string[] args) { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + bool runService = args != null && args.Contains("/service"); Logger.LogPath = RegistrySettings.LogPath; - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; if (!runService) { @@ -89,7 +90,9 @@ public static void Main(string[] args) private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { + Logger.WriteLine("An unhandled exception has occurred in the service"); Logger.WriteException((Exception)e.ExceptionObject); + Environment.Exit(1); } public static void StartConfigServiceHost() diff --git a/src/Lithnet.Miiserver.Autosync.UI/App.xaml.cs b/src/Lithnet.Miiserver.Autosync.UI/App.xaml.cs index 9b07f3d..82f4766 100644 --- a/src/Lithnet.Miiserver.Autosync.UI/App.xaml.cs +++ b/src/Lithnet.Miiserver.Autosync.UI/App.xaml.cs @@ -31,8 +31,8 @@ public App() // Must be started off the UI-thread Task.Run(() => { - Program.StartConfigServiceHost(); - Program.LoadConfiguration(); + // Program.StartConfigServiceHost(); + // Program.LoadConfiguration(); }).Wait(); } #endif diff --git a/src/Lithnet.Miiserver.Autosync.UI/ViewModels/MAConfigParametersViewModel.cs b/src/Lithnet.Miiserver.Autosync.UI/ViewModels/MAConfigParametersViewModel.cs index 859657a..dee90db 100644 --- a/src/Lithnet.Miiserver.Autosync.UI/ViewModels/MAConfigParametersViewModel.cs +++ b/src/Lithnet.Miiserver.Autosync.UI/ViewModels/MAConfigParametersViewModel.cs @@ -14,6 +14,7 @@ namespace Lithnet.Miiserver.AutoSync.UI.ViewModels public class MAConfigParametersViewModel : ViewModelBase { private List allowedTypes; + private static string nullPlaceholder = "(none)"; public MAConfigParametersViewModel(MAConfigParameters model) : base(model) @@ -73,44 +74,44 @@ public string MAControllerPath public string ScheduledImportRunProfileName { - get => this.Model.ScheduledImportRunProfileName; - set => this.Model.ScheduledImportRunProfileName = value; + get => this.Model.ScheduledImportRunProfileName ?? nullPlaceholder; + set => this.Model.ScheduledImportRunProfileName = value == nullPlaceholder ? null : value; } public string FullSyncRunProfileName { - get => this.Model.FullSyncRunProfileName; - set => this.Model.FullSyncRunProfileName = value; + get => this.Model.FullSyncRunProfileName ?? nullPlaceholder; + set => this.Model.FullSyncRunProfileName = value == nullPlaceholder ? null : value; } public string FullImportRunProfileName { - get => this.Model.FullImportRunProfileName; - set => this.Model.FullImportRunProfileName = value; + get => this.Model.FullImportRunProfileName ?? nullPlaceholder; + set => this.Model.FullImportRunProfileName = value == nullPlaceholder ? null : value; } public string ExportRunProfileName { - get => this.Model.ExportRunProfileName; - set => this.Model.ExportRunProfileName = value; + get => this.Model.ExportRunProfileName ?? nullPlaceholder; + set => this.Model.ExportRunProfileName = value == nullPlaceholder ? null : value; } public string DeltaSyncRunProfileName { - get => this.Model.DeltaSyncRunProfileName; - set => this.Model.DeltaSyncRunProfileName = value; + get => this.Model.DeltaSyncRunProfileName ?? nullPlaceholder; + set => this.Model.DeltaSyncRunProfileName = value == nullPlaceholder ? null : value; } public string DeltaImportRunProfileName { - get => this.Model.DeltaImportRunProfileName; - set => this.Model.DeltaImportRunProfileName = value; + get => this.Model.DeltaImportRunProfileName ?? nullPlaceholder; + set => this.Model.DeltaImportRunProfileName = value == nullPlaceholder ? null : value; } public string ConfirmingImportRunProfileName { - get => this.Model.ConfirmingImportRunProfileName; - set => this.Model.ConfirmingImportRunProfileName = value; + get => this.Model.ConfirmingImportRunProfileName ?? nullPlaceholder; + set => this.Model.ConfirmingImportRunProfileName = value == nullPlaceholder ? null : value; } public bool Disabled @@ -141,7 +142,12 @@ public IEnumerable RunProfileNames { get { - return this.Model.ManagementAgent?.RunProfiles.Select(t => t.Key); + yield return "(none)"; + + foreach(var i in this.Model.ManagementAgent?.RunProfiles) + { + yield return i.Key; + } } } @@ -173,7 +179,7 @@ private void AddTrigger() } catch (Exception ex) { - MessageBox.Show($"An unexpected error occured.\n{ex.Message}", "Unable to create trigger"); + MessageBox.Show($"An unexpected error occurred.\n{ex.Message}", "Unable to create trigger"); Trace.WriteLine(ex); } } diff --git a/src/Lithnet.Miiserver.Autosync.UI/ViewModels/MainWindowViewModel.cs b/src/Lithnet.Miiserver.Autosync.UI/ViewModels/MainWindowViewModel.cs index 374247b..ec1a9a0 100644 --- a/src/Lithnet.Miiserver.Autosync.UI/ViewModels/MainWindowViewModel.cs +++ b/src/Lithnet.Miiserver.Autosync.UI/ViewModels/MainWindowViewModel.cs @@ -228,6 +228,8 @@ private void Import() } this.ViewModelIsDirty = false; + + this.ResetConfigViewModel(); } private void Save() @@ -236,16 +238,13 @@ private void Save() try { + MarkManagementAgentsAsConfigured(); + this.Cursor = Cursors.Wait; ConfigClient c = new ConfigClient(); c.PutConfig(this.ConfigFile.Model); this.ViewModelIsDirty = false; - foreach (MAConfigParametersViewModel p in this.ConfigFile.ManagementAgents) - { - p.IsNew = false; - } - this.AskToRestartService(); } catch (Exception ex) @@ -259,6 +258,14 @@ private void Save() } } + private void MarkManagementAgentsAsConfigured() + { + foreach (MAConfigParametersViewModel p in this.ConfigFile.ManagementAgents) + { + p.IsNew = false; + } + } + private bool CanSave() { return this.ConfigFile != null; @@ -316,6 +323,7 @@ private void Export() { this.Cursor = Cursors.Wait; ProtectedString.EncryptOnWrite = false; + this.MarkManagementAgentsAsConfigured(); AutoSync.ConfigFile.Save(this.ConfigFile.Model, dialog.FileName); this.ViewModelIsDirty = false; } diff --git a/src/Lithnet.Miiserver.Autosync.UI/Windows/MainWindow.xaml b/src/Lithnet.Miiserver.Autosync.UI/Windows/MainWindow.xaml index 2201350..723249b 100644 --- a/src/Lithnet.Miiserver.Autosync.UI/Windows/MainWindow.xaml +++ b/src/Lithnet.Miiserver.Autosync.UI/Windows/MainWindow.xaml @@ -5,6 +5,8 @@ Title="{Binding Path=DisplayName}" Cursor="{Binding Path=Cursor}" Icon="/autosync.ico" + BorderThickness="1" + BorderBrush="{DynamicResource AccentColorBrush}" Height="Auto" Width="Auto">