public void WhenParentAndChildNonDefault_ThenOverlayByReturnsCorrectValues() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var parent = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 10, key, 0, 100); parent.Value = 42; Assert.IsFalse(parent.IsDefault); var child = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 10, key, 0, 100); child.Value = 1; Assert.IsFalse(child.IsDefault); var effective = parent.OverlayBy(child); Assert.AreNotSame(effective, parent); Assert.AreNotSame(effective, child); Assert.AreEqual(1, effective.Value); Assert.AreEqual(42, effective.DefaultValue); Assert.IsFalse(effective.IsDefault); } }
public void WhenParentIsNonDefaultAndChildSetToOriginalDefault_ThenIsDefaultReturnsFalse() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var parent = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 10, key, 0, 100); parent.Value = 42; Assert.IsFalse(parent.IsDefault); var intermediate = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 10, key, 0, 100); Assert.IsTrue(intermediate.IsDefault); var child = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 10, key, 0, 100); var effective = parent .OverlayBy(intermediate) .OverlayBy(child); Assert.AreNotSame(effective, parent); Assert.AreNotSame(effective, intermediate); Assert.AreNotSame(effective, child); effective.Value = 10; Assert.AreEqual(10, effective.Value); Assert.AreEqual(42, effective.DefaultValue); Assert.IsFalse(effective.IsDefault); } }
public void WhenValueIsUnparsable_ThenSetValueRaisesFormatException() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); Assert.Throws <FormatException>(() => setting.Value = "test"); } }
public void WhenValueIsOfWrongType_ThenSetValueRaisesInvalidCastException() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); Assert.Throws <InvalidCastException>(() => setting.Value = false); } }
public void WhenValueIsInvalid_ThenSetValueRaisesArgumentOutOfRangeException() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); Assert.Throws <ArgumentOutOfRangeException>(() => setting.Value = -1); } }
public void WhenValueIsString_ThenSetValueParsesValue() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); setting.Value = "12"; Assert.AreEqual(12, setting.Value); } }
public void WhenValueDiffersFromDefault_ThenSetValueSucceedsAndSettingIsDirty() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); setting.Value = 0; Assert.IsFalse(setting.IsDefault); Assert.IsTrue(setting.IsDirty); } }
public void WhenSettingIsNonNull_ThenSaveUpdatesRegistry() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); setting.Value = 1; setting.Save(key); Assert.AreEqual(1, key.GetValue("test")); } }
public void WhenValueIsNull_ThenSetValueResetsToDefault() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); setting.Value = 1; setting.Value = null; Assert.AreEqual(17, setting.Value); Assert.IsTrue(setting.IsDefault); } }
public void WhenSettingIsNull_ThenSaveResetsRegistry() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { key.SetValue("test", 42); var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); setting.Value = null; setting.Save(key); Assert.IsNull(key.GetValue("test")); } }
public static SshSettings FromKey(RegistryKey registryKey) { return(new SshSettings() { IsPropagateLocaleEnabled = RegistryBoolSetting.FromKey( "IsPropagateLocaleEnabled", "IsPropagateLocaleEnabled", null, null, true, registryKey), PublicKeyValidity = RegistryDwordSetting.FromKey( "PublicKeyValidity", "PublicKeyValidity", "Validity of (OS Login/Metadata) keys in seconds", null, (int)TimeSpan.FromDays(30).TotalSeconds, registryKey, (int)TimeSpan.FromMinutes(1).TotalSeconds, int.MaxValue) }); }
public void WhenRegistryValueDoesNotExist_ThenFromKeyUsesDefaults() { using (var key = this.hkcu.CreateSubKey(TestKeyPath)) { var setting = RegistryDwordSetting.FromKey( "test", "title", "description", "category", 17, key, 0, 100); Assert.AreEqual("test", setting.Key); Assert.AreEqual("title", setting.Title); Assert.AreEqual("description", setting.Description); Assert.AreEqual("category", setting.Category); Assert.AreEqual(17, setting.Value); Assert.IsTrue(setting.IsDefault); Assert.IsFalse(setting.IsDirty); } }
public static ApplicationSettings FromKey(RegistryKey registryKey) { return(new ApplicationSettings() { IsMainWindowMaximized = RegistryBoolSetting.FromKey( "IsMainWindowMaximized", "IsMainWindowMaximized", null, null, false, registryKey), MainWindowHeight = RegistryDwordSetting.FromKey( "MainWindowHeight", "MainWindowHeight", null, null, 0, registryKey, 0, ushort.MaxValue), MainWindowWidth = RegistryDwordSetting.FromKey( "WindowWidth", "WindowWidth", null, null, 0, registryKey, 0, ushort.MaxValue), IsUpdateCheckEnabled = RegistryBoolSetting.FromKey( "IsUpdateCheckEnabled", "IsUpdateCheckEnabled", null, null, true, registryKey), LastUpdateCheck = RegistryQwordSetting.FromKey( "LastUpdateCheck", "LastUpdateCheck", null, null, 0, registryKey, 0, long.MaxValue), IsPreviewFeatureSetEnabled = RegistryBoolSetting.FromKey( "IsPreviewFeatureSetEnabled", "IsPreviewFeatureSetEnabled", null, null, false, registryKey), ProxyUrl = RegistryStringSetting.FromKey( "ProxyUrl", "ProxyUrl", null, null, null, registryKey, url => url == null || Uri.TryCreate(url, UriKind.Absolute, out Uri _)), ProxyPacUrl = RegistryStringSetting.FromKey( "ProxyPacUrl", "ProxyPacUrl", null, null, null, registryKey, url => url == null || Uri.TryCreate(url, UriKind.Absolute, out Uri _)), ProxyUsername = RegistryStringSetting.FromKey( "ProxyUsername", "ProxyUsername", null, null, null, registryKey, _ => true), ProxyPassword = RegistrySecureStringSetting.FromKey( "ProxyPassword", "ProxyPassword", null, null, registryKey, DataProtectionScope.CurrentUser), IsDeviceCertificateAuthenticationEnabled = RegistryBoolSetting.FromKey( "IsDeviceCertificateAuthenticationEnabled", "IsDeviceCertificateAuthenticationEnabled", null, null, false, registryKey), FullScreenDevices = RegistryStringSetting.FromKey( "FullScreenDevices", "FullScreenDevices", null, null, null, registryKey, _ => true), IncludeOperatingSystems = RegistryEnumSetting <OperatingSystems> .FromKey( "IncludeOperatingSystems", "IncludeOperatingSystems", null, null, OperatingSystems.Windows, registryKey) });
public static TerminalSettings FromKey(RegistryKey registryKey) { return(new TerminalSettings() { IsCopyPasteUsingCtrlCAndCtrlVEnabled = RegistryBoolSetting.FromKey( "IsCopyPasteUsingCtrlCAndCtrlVEnabled", "IsCopyPasteUsingCtrlCAndCtrlVEnabled", null, null, true, registryKey), IsSelectAllUsingCtrlAEnabled = RegistryBoolSetting.FromKey( "IsSelectAllUsingCtrlAEnabled", "IsSelectAllUsingCtrlAEnabled", null, null, false, registryKey), IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled = RegistryBoolSetting.FromKey( "IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled", "IsCopyPasteUsingShiftInsertAndCtrlInsertEnabled", null, null, true, registryKey), IsSelectUsingShiftArrrowEnabled = RegistryBoolSetting.FromKey( "IsSelectUsingShiftArrrowEnabled", "IsSelectUsingShiftArrrowEnabled", null, null, true, registryKey), IsQuoteConvertionOnPasteEnabled = RegistryBoolSetting.FromKey( "IsQuoteConvertionOnPasteEnabled", "IsQuoteConvertionOnPasteEnabled", null, null, true, registryKey), IsNavigationUsingControlArrrowEnabled = RegistryBoolSetting.FromKey( "IsNavigationUsingControlArrrowEnabled", "IsNavigationUsingControlArrrowEnabled", null, null, true, registryKey), IsScrollingUsingCtrlUpDownEnabled = RegistryBoolSetting.FromKey( "IsScrollingUsingCtrlUpDownEnabled", "IsScrollingUsingCtrlUpDownEnabled", null, null, true, registryKey), IsScrollingUsingCtrlHomeEndEnabled = RegistryBoolSetting.FromKey( "IsScrollingUsingCtrlHomeEndEnabled", "IsScrollingUsingCtrlHomeEndEnabled", null, null, true, registryKey), FontFamily = RegistryStringSetting.FromKey( "FontFamily", "FontFamily", null, null, TerminalFont.DefaultFontFamily, registryKey, f => f == null || TerminalFont.IsValidFont(f)), FontSizeAsDword = RegistryDwordSetting.FromKey( "FontSize", "FontSize", null, null, DwordFromFontSize(TerminalFont.DefaultSize), registryKey, DwordFromFontSize(TerminalFont.MinimumSize), DwordFromFontSize(TerminalFont.MaximumSize)) }); }
protected void InitializeFromKey(RegistryKey key) { // // RDP Settings. // this.RdpUsername = RegistryStringSetting.FromKey( "Username", "Username", "Windows logon username", Categories.RdpCredentials, null, key, _ => true); this.RdpPassword = RegistrySecureStringSetting.FromKey( "Password", "Password", "Windows logon password", Categories.RdpCredentials, key, DataProtectionScope.CurrentUser); this.RdpDomain = RegistryStringSetting.FromKey( "Domain", "Domain", "Windows logon domain", Categories.RdpCredentials, null, key, _ => true); this.RdpConnectionBar = RegistryEnumSetting <RdpConnectionBarState> .FromKey( "ConnectionBar", "Show connection bar", "Show connection bar in full-screen mode", Categories.RdpDisplay, RdpConnectionBarState._Default, key); this.RdpDesktopSize = RegistryEnumSetting <RdpDesktopSize> .FromKey( "DesktopSize", "Desktop size", "Size of remote desktop", Categories.RdpDisplay, ConnectionSettings.RdpDesktopSize._Default, key); this.RdpAuthenticationLevel = RegistryEnumSetting <RdpAuthenticationLevel> .FromKey( "AuthenticationLevel", "Server authentication", "Require server authentication when connecting", Categories.RdpConnection, ConnectionSettings.RdpAuthenticationLevel._Default, key); this.RdpColorDepth = RegistryEnumSetting <RdpColorDepth> .FromKey( "ColorDepth", "Color depth", "Color depth of remote desktop", Categories.RdpDisplay, ConnectionSettings.RdpColorDepth._Default, key); this.RdpAudioMode = RegistryEnumSetting <RdpAudioMode> .FromKey( "AudioMode", "Audio mode", "Redirect audio when playing on server", Categories.RdpResources, ConnectionSettings.RdpAudioMode._Default, key); this.RdpRedirectClipboard = RegistryEnumSetting <RdpRedirectClipboard> .FromKey( "RedirectClipboard", "Redirect clipboard", "Allow clipboard contents to be shared with remote desktop", Categories.RdpResources, ConnectionSettings.RdpRedirectClipboard._Default, key); this.RdpUserAuthenticationBehavior = RegistryEnumSetting <RdpUserAuthenticationBehavior> .FromKey( "RdpUserAuthenticationBehavior", null, // Hidden. null, // Hidden. null, // Hidden. ConnectionSettings.RdpUserAuthenticationBehavior._Default, key); this.RdpBitmapPersistence = RegistryEnumSetting <RdpBitmapPersistence> .FromKey( "BitmapPersistence", "Bitmap caching", "Use persistent bitmap cache", Categories.RdpResources, ConnectionSettings.RdpBitmapPersistence._Default, key); this.RdpConnectionTimeout = RegistryDwordSetting.FromKey( "ConnectionTimeout", null, // Hidden. null, // Hidden. null, // Hidden. 30, key, 0, 300); this.RdpCredentialGenerationBehavior = RegistryEnumSetting <RdpCredentialGenerationBehavior> .FromKey( "CredentialGenerationBehavior", null, // Hidden. null, // Hidden. null, // Hidden. ConnectionSettings.RdpCredentialGenerationBehavior._Default, key); this.RdpPort = RegistryDwordSetting.FromKey( "RdpPort", "Server port", "Server port", Categories.RdpConnection, 3389, key, 1, ushort.MaxValue); // // SSH Settings. // this.SshPort = RegistryDwordSetting.FromKey( "SshPort", "Server port", "Server port", Categories.SshConnection, 22, key, 1, ushort.MaxValue); this.SshUsername = RegistryStringSetting.FromKey( "SshUsername", "Username", "Preferred Linux username (only applicable if OS Login is disabled)", Categories.SshCredentials, null, key, username => string.IsNullOrEmpty(username) || AuthorizedKey.IsValidUsername(username)); this.SshConnectionTimeout = RegistryDwordSetting.FromKey( "SshConnectionTimeout", null, // Hidden. null, // Hidden. null, // Hidden. 30, key, 0, 300); Debug.Assert(this.Settings.All(s => s != null)); }
public static ApplicationSettings FromKey(RegistryKey registryKey) { return(new ApplicationSettings() { IsMainWindowMaximized = RegistryBoolSetting.FromKey( "IsMainWindowMaximized", "IsMainWindowMaximized", null, null, false, registryKey), MainWindowHeight = RegistryDwordSetting.FromKey( "MainWindowHeight", "MainWindowHeight", null, null, 0, registryKey, 0, ushort.MaxValue), MainWindowWidth = RegistryDwordSetting.FromKey( "WindowWidth", "WindowWidth", null, null, 0, registryKey, 0, ushort.MaxValue), IsUpdateCheckEnabled = RegistryBoolSetting.FromKey( "IsUpdateCheckEnabled", "IsUpdateCheckEnabled", null, null, true, registryKey), LastUpdateCheck = RegistryQwordSetting.FromKey( "LastUpdateCheck", "LastUpdateCheck", null, null, 0, registryKey, 0, long.MaxValue), IsPreviewFeatureSetEnabled = RegistryBoolSetting.FromKey( "IsPreviewFeatureSetEnabled", "IsPreviewFeatureSetEnabled", null, null, false, registryKey), ProxyUrl = RegistryStringSetting.FromKey( "ProxyUrl", "ProxyUrl", null, null, null, registryKey, url => url == null || Uri.TryCreate(url, UriKind.Absolute, out Uri _)), });
protected void InitializeFromKey(RegistryKey key) { this.Username = RegistryStringSetting.FromKey( "Username", "Username", "Windows logon username", "Credentials", null, key, _ => true); this.Password = RegistrySecureStringSetting.FromKey( "Password", "Password", "Windows logon password", "Credentials", key, DataProtectionScope.CurrentUser); this.Domain = RegistryStringSetting.FromKey( "Domain", "Domain", "Windows logon domain", "Credentials", null, key, _ => true); this.ConnectionBar = RegistryEnumSetting <RdpConnectionBarState> .FromKey( "ConnectionBar", "Show connection bar", "Show connection bar in full-screen mode", "Display", RdpConnectionBarState._Default, key); this.DesktopSize = RegistryEnumSetting <RdpDesktopSize> .FromKey( "DesktopSize", "Desktop size", "Size of remote desktop", "Display", RdpDesktopSize._Default, key); this.AuthenticationLevel = RegistryEnumSetting <RdpAuthenticationLevel> .FromKey( "AuthenticationLevel", "Server authentication", "Require server authentication when connecting", "Connection", RdpAuthenticationLevel._Default, key); this.ColorDepth = RegistryEnumSetting <RdpColorDepth> .FromKey( "ColorDepth", "Color depth", "Color depth of remote desktop", "Display", RdpColorDepth._Default, key); this.AudioMode = RegistryEnumSetting <RdpAudioMode> .FromKey( "AudioMode", "Audio mode", "Redirect audio when playing on server", "Local resources", RdpAudioMode._Default, key); this.RedirectClipboard = RegistryEnumSetting <RdpRedirectClipboard> .FromKey( "RedirectClipboard", "Redirect clipboard", "Allow clipboard contents to be shared with remote desktop", "Local resources", RdpRedirectClipboard._Default, key); this.UserAuthenticationBehavior = RegistryEnumSetting <RdpUserAuthenticationBehavior> .FromKey( "RdpUserAuthenticationBehavior", null, // Hidden. null, // Hidden. null, // Hidden. RdpUserAuthenticationBehavior._Default, key); this.BitmapPersistence = RegistryEnumSetting <RdpBitmapPersistence> .FromKey( "BitmapPersistence", "Bitmap caching", "Use persistent bitmap cache", "Performance", RdpBitmapPersistence._Default, key); this.ConnectionTimeout = RegistryDwordSetting.FromKey( "ConnectionTimeout", null, // Hidden. null, // Hidden. null, // Hidden. 30, key, 0, 300); this.CredentialGenerationBehavior = RegistryEnumSetting <RdpCredentialGenerationBehavior> .FromKey( "CredentialGenerationBehavior", null, // Hidden. null, // Hidden. null, // Hidden. RdpCredentialGenerationBehavior._Default, key); this.RdpPort = RegistryDwordSetting.FromKey( "RdpPort", "RDP port", "RDP port", "Connection", 3389, key, 1, ushort.MaxValue); Debug.Assert(this.Settings.All(s => s != null)); }