Skip to content

Commit

Permalink
Fixes an issue where management agents were incorrectly saved as unco…
Browse files Browse the repository at this point in the history
…nfigured

Fixes an issue where importing a config file with a password would fail
Fixes an issue where the UI would not refresh after importing a config file
Fixes an issue where selecting no run profile was not an option
Fixes an issue where the main window has no border
  • Loading branch information
ryannewington committed Aug 7, 2017
1 parent a703182 commit 4eef788
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Lithnet.Miiserver.AutoSync/Config/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ public class ConfigClient : ClientBase<IConfigService>, 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;
}

public void PutConfig(ConfigFile config)
{
ProtectedString.EncryptOnWrite = false;
this.Channel.PutConfig(config);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Lithnet.Miiserver.AutoSync/ConfigService/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using Lithnet.Logging;
using System.Diagnostics;

namespace Lithnet.Miiserver.AutoSync
{
Expand Down Expand Up @@ -52,6 +53,7 @@ public ConfigFile GetConfig()
{
try
{
Trace.WriteLine($"Calling {nameof(GetConfig)} as {Environment.UserName}");
ProtectedString.EncryptOnWrite = false;
return Program.CurrentConfig;
}
Expand All @@ -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;
Expand All @@ -81,6 +84,7 @@ public void Reload()
{
try
{
Trace.WriteLine($"Calling {nameof(Reload)} as {Environment.UserName}");
Program.Reload();
}
catch (Exception ex)
Expand All @@ -94,6 +98,7 @@ public bool IsPendingRestart()
{
try
{
Trace.WriteLine($"Calling {nameof(IsPendingRestart)} as {Environment.UserName}");
return Program.PendingRestart;
}
catch (Exception ex)
Expand Down
5 changes: 4 additions & 1 deletion src/Lithnet.Miiserver.AutoSync/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ internal static ConfigFile CurrentConfig
/// </summary>
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)
{
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/Lithnet.Miiserver.Autosync.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Lithnet.Miiserver.AutoSync.UI.ViewModels
public class MAConfigParametersViewModel : ViewModelBase<MAConfigParameters>
{
private List<Type> allowedTypes;
private static string nullPlaceholder = "(none)";

public MAConfigParametersViewModel(MAConfigParameters model)
: base(model)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -141,7 +142,12 @@ public IEnumerable<string> 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;
}
}
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ private void Import()
}

this.ViewModelIsDirty = false;

this.ResetConfigViewModel();
}

private void Save()
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Lithnet.Miiserver.Autosync.UI/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Title="{Binding Path=DisplayName}"
Cursor="{Binding Path=Cursor}"
Icon="/autosync.ico"
BorderThickness="1"
BorderBrush="{DynamicResource AccentColorBrush}"
Height="Auto"
Width="Auto">

Expand Down

0 comments on commit 4eef788

Please sign in to comment.