Пример #1
0
        public void DeleteConfigValue_WithValidSettings_DeletesKey()
        {
            // Arrange
            var keyName         = "dependencyVersion";
            var nugetConfigPath = "NuGet.Config";
            var config          = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <config>
    <add key=""" + keyName + @""" value=""Highest"" />
  </config>
</configuration>";

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);
                var settings = new Settings(mockBaseDirectory);

                // Act
                SettingsUtility.DeleteConfigValue(settings, keyName);

                // Assert
                var content = File.ReadAllText(Path.Combine(mockBaseDirectory, nugetConfigPath));
                content.Should().NotContain(keyName);
            }
        }
Пример #2
0
        /// <summary>
        /// Sets a NuGet user settings property.
        /// </summary>
        /// <param name="property">The name of the settings property to set.</param>
        /// <param name="value">
        /// The value of the settings property.
        /// If null, the settings property will be deleted.
        /// </param>
        public static void Set(string property, string value)
        {
            var settings = ServiceLocator.GetInstance <Configuration.ISettings>();
            var packageRestoreConsent = new PackageRestoreConsent(settings);

            if (string.Equals(property, "PackageRestoreConsentGranted", StringComparison.OrdinalIgnoreCase))
            {
                packageRestoreConsent.IsGrantedInSettings = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
            }
            else if (string.Equals(property, "PackageRestoreIsAutomatic", StringComparison.OrdinalIgnoreCase))
            {
                packageRestoreConsent.IsAutomatic = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
            }
            else
            {
                if (value == null)
                {
                    SettingsUtility.DeleteConfigValue(settings, property);
                }
                else
                {
                    SettingsUtility.SetConfigValue(settings, property, value);
                }
            }
        }
Пример #3
0
        public void DeleteConfigValue_WithNullSettings_Throws()
        {
            var ex = Record.Exception(() => SettingsUtility.DeleteConfigValue(settings: null, key: "randomKey"));

            ex.Should().NotBeNull();
            ex.Should().BeOfType <ArgumentNullException>();
        }
        public static void registerSettings(Form parentForm)
        {
            ProxySettingsForm frmProxy = new ProxySettingsForm
            {
                StartPosition = FormStartPosition.CenterParent
            };

            var settings   = Settings.LoadDefaultSettings("c:\\temp");
            var proxyInfos = SettingsUtility.GetConfigValue(settings, KEY_HTTP_PROXY);

            if (proxyInfos == null)
            {
                proxyInfos = "";
            }

            Match m = Regex.Match(proxyInfos, @"http://(.*)?:(.*)", RegexOptions.IgnoreCase);

            if (m.Success)
            {
                frmProxy.UseCustomProxy = true;

                frmProxy.proxyAddress = m.Groups[1].Value;

                frmProxy.proxyPort = m.Groups[2].Value;
            }
            else
            {
                frmProxy.UseCustomProxy = false;

                frmProxy.proxyAddress = "";

                frmProxy.proxyPort = "";
            }

            if (frmProxy.ShowDialog(parentForm) == DialogResult.OK)
            {
                if (frmProxy.UseCustomProxy)
                {
                    SettingsUtility.SetConfigValue(settings, KEY_HTTP_PROXY, string.Format("http://{0}:{1}", frmProxy.proxyAddress, frmProxy.proxyPort));
                }
                else
                {
                    SettingsUtility.DeleteConfigValue(settings, KEY_HTTP_PROXY);
                    SettingsUtility.DeleteConfigValue(settings, KEY_HTTP_PROXY_USER);
                    SettingsUtility.DeleteConfigValue(settings, KEY_HTTP_PROXY_PASSWORD);
                }
                MessageBox.Show("You need to restart XrmToolbox for changes to take effect");
            }
        }
Пример #5
0
        public override void ExecuteCommand()
        {
            if (Settings == null)
            {
                throw new InvalidOperationException(LocalizedResourceManager.GetString("Error_SettingsIsNull"));
            }

            var getKey = Arguments.FirstOrDefault();

            if (Set.Any())
            {
                foreach (var property in Set)
                {
                    if (string.IsNullOrEmpty(property.Value))
                    {
                        SettingsUtility.DeleteConfigValue(Settings, property.Key);
                    }
                    else
                    {
                        // Hack: Need a nicer way for the user to say encrypt this.
                        var encrypt = HttpPasswordKey.Equals(property.Key, StringComparison.OrdinalIgnoreCase);
                        SettingsUtility.SetConfigValue(Settings, property.Key, property.Value, encrypt);
                    }
                }
            }
            else if (!string.IsNullOrEmpty(getKey))
            {
                var value = SettingsUtility.GetConfigValue(Settings, getKey, isPath: AsPath);
                if (string.IsNullOrEmpty(value))
                {
                    Console.WriteError(LocalizedResourceManager.GetString("ConfigCommandKeyNotFound"), getKey);
                }
                else
                {
                    Console.WriteLine(value);
                }
            }
        }