Пример #1
0
        public void WhenParentAndChildNonDefault_ThenOverlayByReturnsCorrectValues()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var parent = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "black",
                    key,
                    _ => true);
                parent.Value = "red";
                Assert.IsFalse(parent.IsDefault);

                var child = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "black",
                    key,
                    _ => true);
                child.Value = "green";
                Assert.IsFalse(child.IsDefault);

                var effective = parent.OverlayBy(child);
                Assert.AreNotSame(effective, parent);
                Assert.AreNotSame(effective, child);

                Assert.AreEqual("green", effective.Value);
                Assert.AreEqual("red", effective.DefaultValue);
                Assert.IsFalse(effective.IsDefault);
            }
        }
Пример #2
0
        public void WhenParentIsNonDefaultAndChildSetToOriginalDefault_ThenIsDefaultReturnsFalse()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var parent = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "black",
                    key,
                    _ => true);
                parent.Value = "red";
                Assert.IsFalse(parent.IsDefault);

                var intermediate = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "black",
                    key,
                    _ => true);
                Assert.IsTrue(intermediate.IsDefault);

                var child = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "black",
                    key,
                    _ => true);

                var effective = parent
                                .OverlayBy(intermediate)
                                .OverlayBy(child);
                Assert.AreNotSame(effective, parent);
                Assert.AreNotSame(effective, intermediate);
                Assert.AreNotSame(effective, child);

                effective.Value = "black";

                Assert.AreEqual("black", effective.Value);
                Assert.AreEqual("red", effective.DefaultValue);
                Assert.IsFalse(effective.IsDefault);
            }
        }
Пример #3
0
        public void WhenValueIsOfWrongType_ThenSetValueRaisesInvalidCastException()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "blue",
                    key,
                    _ => true);

                Assert.Throws <InvalidCastException>(() => setting.Value = 1);
            }
        }
Пример #4
0
        public void WhenValueDiffersFromDefault_ThenSetValueSucceedsAndSettingIsDirty()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "blue",
                    key,
                    _ => true);

                setting.Value = "yellow";

                Assert.IsFalse(setting.IsDefault);
                Assert.IsTrue(setting.IsDirty);
            }
        }
Пример #5
0
        public void WhenValueAndDefaultAreNull_ThenSetValueSucceedsAndSettingIsNotDirty()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    null,
                    key,
                    _ => true);

                setting.Value = null;

                Assert.IsTrue(setting.IsDefault);
                Assert.IsFalse(setting.IsDirty);
            }
        }
Пример #6
0
        public void WhenSettingIsNonNull_ThenSaveUpdatesRegistry()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "blue",
                    key,
                    _ => true);

                setting.Value = "green";
                setting.Save(key);

                Assert.AreEqual("green", key.GetValue("test"));
            }
        }
Пример #7
0
        public void WhenValueIsNull_ThenSetValueResetsToDefault()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "blue",
                    key,
                    _ => true);

                setting.Value = "blue";
                setting.Value = null;

                Assert.AreEqual("blue", setting.Value);
                Assert.IsTrue(setting.IsDefault);
            }
        }
Пример #8
0
        public void WhenSettingIsNull_ThenSaveResetsRegistry()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                key.SetValue("test", "red");

                var setting = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "blue",
                    key,
                    _ => true);

                setting.Value = null;
                setting.Save(key);

                Assert.IsNull(key.GetValue("test"));
            }
        }
Пример #9
0
        public void WhenRegistryKeyIsNull_ThenFromKeyUsesDefaults()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                var setting = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "blue",
                    null,
                    _ => true);

                Assert.AreEqual("test", setting.Key);
                Assert.AreEqual("title", setting.Title);
                Assert.AreEqual("description", setting.Description);
                Assert.AreEqual("category", setting.Category);
                Assert.AreEqual("blue", setting.Value);
                Assert.IsTrue(setting.IsDefault);
                Assert.IsFalse(setting.IsDirty);
            }
        }
Пример #10
0
        public void WhenRegistryValueExists_ThenFromKeyUsesValue()
        {
            using (var key = this.hkcu.CreateSubKey(TestKeyPath))
            {
                key.SetValue("test", "red");

                var setting = RegistryStringSetting.FromKey(
                    "test",
                    "title",
                    "description",
                    "category",
                    "blue",
                    key,
                    _ => true);

                Assert.AreEqual("test", setting.Key);
                Assert.AreEqual("title", setting.Title);
                Assert.AreEqual("description", setting.Description);
                Assert.AreEqual("category", setting.Category);
                Assert.AreEqual("red", setting.Value);
                Assert.IsFalse(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 _)),
     });
Пример #12
0
        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 _)),
         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))
     });
 }
Пример #15
0
        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));
        }