Made DefaultConnectionInheritance LoadFrom a generic method to decouple it from the Settings class

This commit is contained in:
David Sparer
2016-08-09 11:02:53 -06:00
parent e5c896cb36
commit 12cd38a047
3 changed files with 7 additions and 68 deletions

View File

@@ -1,5 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using mRemoteNG.Tools;
using System.ComponentModel;

View File

@@ -1,16 +1,13 @@

using System;
using System.Reflection;
namespace mRemoteNG.Connection
{
public class DefaultConnectionInheritance : ConnectionInfoInheritance
{
private static readonly DefaultConnectionInheritance _singletonInstance = new DefaultConnectionInheritance();
private const string SettingNamePrefix = "InhDefault";
public static DefaultConnectionInheritance Instance { get { return _singletonInstance; } }
public static DefaultConnectionInheritance Instance { get; } = new DefaultConnectionInheritance();
private DefaultConnectionInheritance() : base(null)
{
@@ -20,13 +17,14 @@ namespace mRemoteNG.Connection
{ }
public void LoadFromSettings()
public void LoadFrom<TSource>(TSource sourceInstance, Func<string,string> propertyNameMutator = null)
{
if (propertyNameMutator == null) propertyNameMutator = (a) => a;
var inheritanceProperties = GetProperties();
foreach (var property in inheritanceProperties)
{
var propertyFromSettings = typeof(Settings).GetProperty($"{SettingNamePrefix}{property.Name}");
var valueFromSettings = propertyFromSettings.GetValue(Settings.Default, null);
var propertyFromSettings = typeof(TSource).GetProperty(propertyNameMutator(property.Name));
var valueFromSettings = propertyFromSettings.GetValue(sourceInstance, null);
property.SetValue(Instance, valueFromSettings, null);
}
}
@@ -40,63 +38,6 @@ namespace mRemoteNG.Connection
var localValue = property.GetValue(Instance, null);
propertyFromSettings.SetValue(Settings.Default, localValue, null);
}
//Settings.Default.InhDefaultDescription = Description;
//Settings.Default.InhDefaultIcon = Icon;
//Settings.Default.InhDefaultPanel = Panel;
//Settings.Default.InhDefaultUsername = Username;
//Settings.Default.InhDefaultPassword = Password;
//Settings.Default.InhDefaultDomain = Domain;
//Settings.Default.InhDefaultProtocol = Protocol;
//Settings.Default.InhDefaultPort = Port;
//Settings.Default.InhDefaultPuttySession = PuttySession;
//Settings.Default.InhDefaultUseConsoleSession = UseConsoleSession;
//Settings.Default.InhDefaultUseCredSsp = UseCredSsp;
//Settings.Default.InhDefaultRenderingEngine = RenderingEngine;
//Settings.Default.InhDefaultICAEncryptionStrength = ICAEncryptionStrength;
//Settings.Default.InhDefaultRDPAuthenticationLevel = RDPAuthenticationLevel;
//Settings.Default.InhDefaultLoadBalanceInfo = LoadBalanceInfo;
//Settings.Default.InhDefaultResolution = Resolution;
//Settings.Default.InhDefaultAutomaticResize = AutomaticResize;
//Settings.Default.InhDefaultColors = Colors;
//Settings.Default.InhDefaultCacheBitmaps = CacheBitmaps;
//Settings.Default.InhDefaultDisplayWallpaper = DisplayWallpaper;
//Settings.Default.InhDefaultDisplayThemes = DisplayThemes;
//Settings.Default.InhDefaultEnableFontSmoothing = EnableFontSmoothing;
//Settings.Default.InhDefaultEnableDesktopComposition = EnableDesktopComposition;
////
//Settings.Default.InhDefaultRedirectKeys = RedirectKeys;
//Settings.Default.InhDefaultRedirectDiskDrives = RedirectDiskDrives;
//Settings.Default.InhDefaultRedirectPrinters = RedirectPrinters;
//Settings.Default.InhDefaultRedirectPorts = RedirectPorts;
//Settings.Default.InhDefaultRedirectSmartCards = RedirectSmartCards;
//Settings.Default.InhDefaultRedirectSound = RedirectSound;
////
//Settings.Default.InhDefaultPreExtApp = PreExtApp;
//Settings.Default.InhDefaultPostExtApp = PostExtApp;
//Settings.Default.InhDefaultMacAddress = MacAddress;
//Settings.Default.InhDefaultUserField = UserField;
//// VNC inheritance
//Settings.Default.InhDefaultVNCAuthMode = VNCAuthMode;
//Settings.Default.InhDefaultVNCColors = VNCColors;
//Settings.Default.InhDefaultVNCCompression = VNCCompression;
//Settings.Default.InhDefaultVNCEncoding = VNCEncoding;
//Settings.Default.InhDefaultVNCProxyIP = VNCProxyIP;
//Settings.Default.InhDefaultVNCProxyPassword = VNCProxyPassword;
//Settings.Default.InhDefaultVNCProxyPort = VNCProxyPort;
//Settings.Default.InhDefaultVNCProxyType = VNCProxyType;
//Settings.Default.InhDefaultVNCProxyUsername = VNCProxyUsername;
//Settings.Default.InhDefaultVNCSmartSizeMode = VNCSmartSizeMode;
//Settings.Default.InhDefaultVNCViewOnly = VNCViewOnly;
//// Ext. App inheritance
//Settings.Default.InhDefaultExtApp = ExtApp;
//// RDP gateway inheritance
//Settings.Default.InhDefaultRDGatewayUsageMethod = RDGatewayUsageMethod;
//Settings.Default.InhDefaultRDGatewayHostname = RDGatewayHostname;
//Settings.Default.InhDefaultRDGatewayUsername = RDGatewayUsername;
//Settings.Default.InhDefaultRDGatewayPassword = RDGatewayPassword;
//Settings.Default.InhDefaultRDGatewayDomain = RDGatewayDomain;
//Settings.Default.InhDefaultRDGatewayUseConnectionCredentials = RDGatewayUseConnectionCredentials;
}
}
}

View File

@@ -1621,7 +1621,7 @@ namespace mRemoteNG.UI.Window
DefaultPropertiesVisible = false;
DefaultInheritanceVisible = true;
var defaultInheritance = DefaultConnectionInheritance.Instance;
defaultInheritance.LoadFromSettings();
defaultInheritance.LoadFrom<Settings>(Settings.Default, (a)=>"InhDefault"+a);
SetPropertyGridObject(defaultInheritance);
}
}