Наследование: ConfigurationElementCollection
 public Configurations()
 {
     var fileMap = new ExeConfigurationFileMap();
     fileMap.ExeConfigFilename = ConfigFileName;
     Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
     this.settings = config.AppSettings.Settings;
 }
Пример #2
0
        public void Transform(string inputFilePath, string outputFilePath, KeyValueConfigurationCollection settings)
        {
            var xsltTemplateReader = new XmlTextReader(inputFilePath);
            var emptyDocumentReader = XmlReader.Create(new System.IO.StringReader("<empty />"));

            var writerSettings = new XmlWriterSettings();
            //settings.ConformanceLevel = ConformanceLevel.Fragment;
            writerSettings.Indent = true;

            using (var outputWriter = XmlWriter.Create(outputFilePath, writerSettings))
            {
                var xsltSettings = new XsltSettings();

                XsltArgumentList argumentList = new XsltArgumentList();

                var extensions = new XsltExtensionMethods(settings);

                argumentList.AddExtensionObject("http://core.com/config", extensions);
                argumentList.AddExtensionObject("http://setty.net/config", extensions);

                var transformer = new XslCompiledTransform(true);
                transformer.Load(xsltTemplateReader, xsltSettings, null);
                transformer.Transform(emptyDocumentReader, argumentList, outputWriter);
            }
        }
Пример #3
0
        public FormUpdater(string patcherExecutable, string patcherArguments)
        {
            this.patcherExecutable = patcherExecutable;
            this.patcherArguments = patcherArguments;
            try
            {
                hyperConfigFile = ConfigurationManager.OpenExeConfiguration(patcherExecutable);
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to load " + patcherExecutable + ".config file", "Selfupdater");
                Environment.Exit(0);
            }
            hyperSettings = hyperConfigFile.AppSettings.Settings;
            hyperFolder = new DirectoryInfo(Environment.CurrentDirectory);
            InitializeComponent();
            try
            {
                hyperVersion = Convert.ToUInt32(hyperSettings["hyperVersion"].Value);
                patchesWebPath = new Uri(hyperSettings["patchesWebPath"].Value);
            }
            catch (Exception)
            {
                hyperVersion = 0;
            }

            MessageBox.Show("Updates are going to be installed now.", "Selfupdater");
            InitUpdateProcess();
        }
Пример #4
0
 public ImageAnalyzer()
 {
     configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     confCollection = configManager.AppSettings.Settings;
     string keyId = confCollection["FaceAPIKey"].Value;
     faceDetector = new FaceServiceClient(keyId);
 }
Пример #5
0
        private DefaultEntries() {
            Configuration exeConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
            this.loadedDefaultConfig = exeConfig.AppSettings.Settings;
            Logger.Debug(string.Format("Loading application settings from {0}", exeConfig.FilePath));
            this.Url = "https://";
            this.Name = Environment.UserName;
            this.Binding = null;
            this.CanModifyUrl = true;
            if (this.loadedDefaultConfig["Url"] != null) {
                this.Url = this.loadedDefaultConfig["Url"].Value ?? "https://";
            }

            if (this.loadedDefaultConfig["Name"] != null) {
                this.Name = this.loadedDefaultConfig["Name"].Value ?? Environment.UserName;
            }

            if (this.loadedDefaultConfig["Binding"] != null) {
                this.Binding = this.loadedDefaultConfig["Binding"].Value;
            }

            if (this.loadedDefaultConfig["UrlModificationAllowed"] != null) {
                bool canModify;
                if (Boolean.TryParse(this.loadedDefaultConfig["UrlModificationAllowed"].Value, out canModify)) {
                    this.CanModifyUrl = canModify;
                }
            }
        }
Пример #6
0
        public InitializerConfig(EntityFrameworkSection entityFrameworkSettings, KeyValueConfigurationCollection appSettings)
        {
            DebugCheck.NotNull(entityFrameworkSettings);
            DebugCheck.NotNull(appSettings);

            _entityFrameworkSettings = entityFrameworkSettings;
            _appSettings = appSettings;
        }
Пример #7
0
        //private dynamic MapSettings(KeyValueConfigurationCollection settings)
        //{
        //    var expandoDictionary = new ExpandoObject() as IDictionary<string, Object>;
        //    foreach (var key in settings.AllKeys)
        //        expandoDictionary.Add(key, settings[key].Value);
        //    expandoDictionary.Add("AppSettings", SettingsHelper.GetApplicationSettingsXmlString(settings));
        //    return expandoDictionary as dynamic;
        //}
        private SettingsModel MapSettings(KeyValueConfigurationCollection settings)
        {
            var res = settings.AllKeys.ToDictionary(key => key, key => settings[key].Value);

            res.Add("ApplicationSettings", SettingsHelper.GetApplicationSettingsXmlString(settings));

            return new SettingsModel(res);
        }
Пример #8
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public ConfigAppSettingHelper()
        {
            appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
             if (appConfig != null)
                eles = appConfig.AppSettings.Settings;

             _autoSave = true;
            _sameNameReplace = true;
        }
 private IDictionary<string, string> TranslateForConficius(KeyValueConfigurationCollection settingsDictionary)
 {
     var conficiusAnswers = new Dictionary<string, string>();
     foreach (var setting in settingsDictionary.AllKeys)
     {
         conficiusAnswers.Add(setting, settingsDictionary[setting].Value);
     }
     return conficiusAnswers;
 }
Пример #10
0
		static Settings ()
		{
			try {
				var config = ConfigurationManager.OpenExeConfiguration (System.Reflection.Assembly.GetExecutingAssembly ().Location);
				libConfig = config.AppSettings.Settings;
			} catch {
				exeConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings;
			}
		}
Пример #11
0
 public static PluginConfig FromSettings(KeyValueConfigurationCollection settings)
 {
     var config = new PluginConfig();
     foreach (var key in settings.AllKeys)
     {
         config.Data.Add(new DataItem(key, settings[key].Value));
     }
     return config;
 }
Пример #12
0
        /// <summary>
        /// Clears and then fills the collection with the key/value pairs in the given <see cref="KeyValueConfigurationCollection"/>.
        /// </summary>
        /// <param name="collection">The collection to fill.</param>
        /// <param name="configCollection">The <see cref="KeyValueConfigurationCollection"/> to use as a fill source.</param>
        public static void FillWith(this NameValueCollection collection, KeyValueConfigurationCollection configCollection)
        {
            collection.Clear();

            foreach (KeyValueConfigurationElement element in configCollection)
            {
                collection.Add(element.Key, element.Value);
            }
        }
        public void Should_invoke_mapper_with_reader_results()
        {
            Given_a_application_settings_provider();

            var keyValueConfigurationCollection = new KeyValueConfigurationCollection();
            _configReader.LoadSettings().Returns(keyValueConfigurationCollection);
             _configProvider.ReadConfiguration();
            _mapper.Received(1).Map(keyValueConfigurationCollection);
        }
Пример #14
0
        public FDUserSettings()
        {
            localConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
            settings = localConfig.AppSettings.Settings;
            RestoresEnabled = false;

            if(settings["DataStoreFile"] != null)
                DataStoreFile = settings["DataStoreFile"].Value;
            else {
                settings.Add ("DataStoreFile", "index.sqlite");
                DataStoreFile = settings["DataStoreFile"].Value;
            }

            if (localConfig.AppSettings.Settings["DataStorePath"] != null)
                DataStorePath = settings["DataStorePath"].Value;
            else {
                settings.Add ("DataStorePath", System.IO.Path.GetDirectoryName(localConfig.FilePath));
                DataStorePath = settings["DataStorePath"].Value;
            }

            if(settings["AWSAccessKey"] != null)
                AWSAccessKey = settings["AWSAccessKey"].Value;
            else {
                settings.Add ("AWSAccessKey", "");
                AWSAccessKey = settings["AWSAccessKey"].Value;
            }

            if(settings["AWSSecretKey"] != null)
                AWSSecretKey = settings["AWSSecretKey"].Value;
            else {
                settings.Add ("AWSSecretKey", "");
                AWSSecretKey = settings["AWSSecretKey"].Value;
            }

            string AWSRegionTemp;
            if(settings["AWSRegion"] != null)
                    AWSRegionTemp = settings["AWSRegion"].Value;
            else {
                settings.Add ("AWSRegion", "");
                AWSRegionTemp = settings["AWSRegion"].Value;
            }

            if(!String.IsNullOrWhiteSpace(AWSRegionTemp)) AWSRegion = int.Parse(AWSRegionTemp);
            else AWSRegion = 0;

            if(settings["AWSGlacierVaultName"] != null)
                AWSGlacierVaultName = settings["AWSGlacierVaultName"].Value;
            else {
                settings.Add ("AWSGlacierVaultName", "");
                AWSGlacierVaultName = settings["AWSGlacierVaultName"].Value;
            }

            CurrentDataStore = DataStorePath + System.IO.Path.DirectorySeparatorChar + DataStoreFile;

            localConfig.Save (ConfigurationSaveMode.Modified);
        }
Пример #15
0
        private static KeyValueConfigurationCollection GetKeyValueCollection()
        {
            var collection = new KeyValueConfigurationCollection();
            collection.Add("Name", "Value");
            collection.Add("Email", "*****@*****.**");
            collection.Add("Company", "IBM");
            collection.Add("Year", "2011");

            return collection;
        }
Пример #16
0
        public static KeyValueConfigurationCollection ToConfig(
            IDictionary<string, string> dictionary)
        {
            KeyValueConfigurationCollection keyValueConfigurationCollection = new KeyValueConfigurationCollection();

            foreach (var item in dictionary)
            {
                keyValueConfigurationCollection.Add(item.Key, item.Value);
            }
            return keyValueConfigurationCollection;
        }
Пример #17
0
        public static IDictionary<string, string> GetFromConfig(
            KeyValueConfigurationCollection keyValueConfigurationCollection)
        {
            IDictionary<string, string> dictionary = new Dictionary<string, string>();

            foreach (KeyValueConfigurationElement item in keyValueConfigurationCollection)
            {
                dictionary.Add(item.Key, item.Value);
            }
            return dictionary;
        }
 protected override void AddAppConfigSpecificItems(KeyValueConfigurationCollection kvcc)
 {
     // NOTE: insert a valid connection string to a SqlServer 2008 db
     try
     {
         if (kvcc["SqlServer2008ConnectionString"] == null) 
             kvcc.Add("SqlServer2008ConnectionString", "Data Source=localhost\\SQLEXPRESS;Database=NTSTests;Integrated Security=SSPI;");
     }
     catch
     {
         kvcc.Add("SqlServer2008ConnectionString", "Data Source=localhost\\SQLEXPRESS;Database=NTSTests;Integrated Security=SSPI;");
     }
 }
        public void Should_map_features()
        {
            var settings = new KeyValueConfigurationCollection();
            settings.Add(new KeyValueConfigurationElement("Feature", "true"));
            settings.Add(new KeyValueConfigurationElement("Feature1", "false"));
            var mapper = new KeyValueFeatureMapper();

            var feature = mapper.Map(settings).ToList();

            feature.Count.ShouldBe(2);

            feature[0].Name.ShouldBe("Feature");
            feature[0].State.ShouldBe(true);
        }
Пример #20
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="exeConfigFile">配置文件路径</param>
        public ConfigAppSettingHelper(string exeConfigFile)
        {
            ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
            configMap.ExeConfigFilename = exeConfigFile;

            appConfig = ConfigurationManager.OpenMappedExeConfiguration(configMap,
                                    ConfigurationUserLevel.None);

            if (appConfig != null)
                eles = appConfig.AppSettings.Settings;

            _autoSave = true;
            _sameNameReplace = true;
        }
Пример #21
0
        private void ReloadLocalConfiguration()
        {
            Configuration config;

            ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();

            configFile.ExeConfigFilename = applicationStartupPath + @"\Local.config";
            config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
            LocalConfigurationSettings = config.AppSettings.Settings;

            if (LocalConfigurationSettings["RMS.CLIENT_CODE"] != null)
            {
                clientCode = LocalConfigurationSettings["RMS.CLIENT_CODE"].Value;
            }
        }
Пример #22
0
        public void Initialize()
        {
            var configCollection = new KeyValueConfigurationCollection
            {
                {"tequilla", "salsa"},
                {"gringo", ""},
                {"enchilada", "bacalao,gasolina,macarena"},
                {"mariachi", "1"},
                {"banderas", "3"},
                {"ronaldo", "true"},
                {"nein", "False"}
            };

            _config = new Configuration(configCollection);
        }
Пример #23
0
        internal AppConfig(
            ConnectionStringSettingsCollection connectionStrings,
            KeyValueConfigurationCollection appSettings,
            EntityFrameworkSection entityFrameworkSettings,
            ProviderServicesFactory providerServicesFactory = null)
        {
            DebugCheck.NotNull(connectionStrings);

            _connectionStrings = connectionStrings;
            _appSettings = appSettings ?? new KeyValueConfigurationCollection();
            _entityFrameworkSettings = entityFrameworkSettings ?? new EntityFrameworkSection();
            _providerServicesFactory = providerServicesFactory ?? new ProviderServicesFactory();

            _providerServices = new Lazy<IList<NamedDbProviderService>>(
                () => _entityFrameworkSettings
                          .Providers
                          .OfType<ProviderElement>()
                          .Select(
                              e => new NamedDbProviderService(
                                       e.InvariantName,
                                       _providerServicesFactory.GetInstance(e.ProviderTypeName, e.InvariantName)))
                          .ToList());

            if (_entityFrameworkSettings.DefaultConnectionFactory.ElementInformation.IsPresent)
            {
                _defaultConnectionFactory = new Lazy<IDbConnectionFactory>(
                    () =>
                        {
                            var setting = _entityFrameworkSettings.DefaultConnectionFactory;

                            try
                            {
                                var type = setting.GetFactoryType();
                                var args = setting.Parameters.GetTypedParameterValues();
                                return (IDbConnectionFactory)Activator.CreateInstance(type, args);
                            }
                            catch (Exception ex)
                            {
                                throw new InvalidOperationException(
                                    Strings.SetConnectionFactoryFromConfigFailed(setting.FactoryTypeName), ex);
                            }
                        }, isThreadSafe: true);
            }
            else
            {
                _defaultConnectionFactory = _defaultDefaultConnectionFactory;
            }
        }
Пример #24
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            var config = N2.Context.Current.Resolve<EditSection>();
            if (config != null)
            {
                configJsPath = Url.ResolveTokens(config.CkEditor.ConfigJsPath);
                overwriteStylesSet = Url.ResolveTokens(config.CkEditor.OverwriteStylesSet);
                overwriteFormatTags = config.CkEditor.OverwriteFormatTags;
                overwriteLanguage = config.CkEditor.OverwriteLanguage;
                contentCssUrl = Url.ResolveTokens(config.CkEditor.ContentsCssPath);
                advancedMenues = config.CkEditor.AdvancedMenus;
                allowedContent = config.CkEditor.AllowedContent;
                customConfig = config.CkEditor.Settings ?? new KeyValueConfigurationCollection();
            }
        }
Пример #25
0
        public static String GetApplicationSettingsXmlString(KeyValueConfigurationCollection collection)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(Environment.NewLine);

            foreach (var key in collection.AllKeys)
            {
                var value = collection[key].Value;

                builder.Append(String.Format(
                    "    <add key=\"{0}\" value=\"{1}\" />{2}",
                    Escape(key),
                    Escape(value),
                    Environment.NewLine));
            }

            return builder.ToString();            
        }
Пример #26
0
        public static NameValueCollection ToNameValueCollection(this KeyValueConfigurationCollection keyValueCollection)
        {
            if (keyValueCollection == null)
            {
                return(null);
            }

            NameValueCollection nameValueCollection = new NameValueCollection();

            foreach (string key in keyValueCollection.AllKeys)
            {
                if (keyValueCollection[key] != null)
                {
                    nameValueCollection.Add(key, keyValueCollection[key].Value);
                }
            }

            return(nameValueCollection);
        }
        public void LoadSettings_WhenSuppliedWithConfiguration_TakesConfiguration()
        {
            KeyValueConfigurationCollection dictionary = new KeyValueConfigurationCollection
                                 {
                                     {"ConfigurationSyncIntervalMs","1"},
                                     {"DeploymentEnvironment","2"},
                                     {"InstallationDirectory","3"},
                                     {"NuGetRepository","4"},
                                     {"PackageSyncIntervalMs","5"},
                                     {"UnpackingLocation","6"},
                                 };

            var settings = _mgr.LoadSettings(dictionary);

            Assert.That(settings.ConfigurationSyncIntervalMs, Is.EqualTo(1));
            Assert.That(settings.DeploymentEnvironment, Is.EqualTo("2"));
            Assert.That(settings.InstallationDirectory, Is.StringContaining("3"));
            Assert.That(settings.NuGetRepository, Is.StringContaining("4"));
            Assert.That(settings.PackageSyncIntervalMs, Is.EqualTo(5));
            Assert.That(settings.UnpackingLocation, Is.StringContaining("6"));
        }
Пример #28
0
        public void Transform(String configPath, String outputPath, KeyValueConfigurationCollection settings)
        {
            var xsltTemplateReader = new XmlTextReader(configPath);

            var writerSettings = new XmlWriterSettings();
            writerSettings.ConformanceLevel = ConformanceLevel.Fragment;
            writerSettings.Indent = true;

            using (var outputWriter = XmlWriter.Create(outputPath, writerSettings))
            {
                var config = new FluentTemplateServiceConfiguration(
                        c => c.WithEncoding(Encoding.Raw));

                using (var service = new TemplateService(config))
                {
                    var template = System.IO.File.ReadAllText(configPath);
                    var model = MapSettings(settings);
                    string result = service.Parse(template, model);
                    outputWriter.WriteRaw(result);
                }
            }
        }
Пример #29
0
        /// <summary>
        /// Returns merged settings collection
        /// </summary>
        private KeyValueConfigurationCollection Merge(List<String> paths)
        {
            var mergedSettings = new KeyValueConfigurationCollection();

            foreach (var path in paths)
            {
                var settings = GetApplicationSettingsFromDirectory(path);

                if (settings == null)
                    continue;

                foreach (var key in settings.AllKeys)
                {
                    var value = settings[key].Value;

                    mergedSettings.Remove(key);
                    mergedSettings.Add(key, value);
                }                
            }

            return mergedSettings;
        }
        public MainWindow()
        {
            configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            confCollection = configManager.AppSettings.Settings;

            // find a place to copy audio file.
            WavFileUriPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "audio1.wav"); ;

            InitializeComponent();
            ButtonState = "Record";
            brushList = new List<Brush>();
            brushList.Add(Brushes.Crimson);
            brushList.Add(Brushes.ForestGreen);
            brushList.Add(Brushes.Navy);
            brushList.Add(Brushes.Goldenrod);
            brushList.Add(Brushes.Olive);
            brushList.Add(Brushes.OrangeRed);
            brushList.Add(Brushes.Indigo);

            //browser1.Scr
            browser1 = (System.Windows.Forms.WebBrowser)winformhost1.Child;
        }
Пример #31
0
        public FormPatcher(bool enableNotice, string windowTitle, string appFileName, string appArguments)
        {
            InitializeComponent();
            labelStatus.Text = "Initializing...";
            Refresh();
            this.enableNotice = enableNotice;
            this.appFileName = appFileName;
            this.appArguments = appArguments;
            this.windowTitle = windowTitle;
            hyperConfigFile = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
            hyperSettings = hyperConfigFile.AppSettings.Settings;
            hyperFolder = new DirectoryInfo(Environment.CurrentDirectory);
            stopwatch = new Stopwatch();
            buttonStartApp.Enabled = false;
            hasUpdates = false;
            Text = windowTitle;
            labelSpeed.Text = string.Empty;
            bool checkboxStatus;
            try
            {
                checkboxStatus = Convert.ToBoolean(hyperSettings["autostart"].Value);
                patchVersion = Convert.ToUInt32(hyperSettings["patchVersion"].Value);
                hyperVersion = Convert.ToUInt32(hyperSettings["hyperVersion"].Value);
                patchesWebPath = new Uri(hyperSettings["patchesWebPath"].Value);
            }
            catch (Exception)
            {
                checkboxStatus = false;
                patchVersion = 0;
                hyperVersion = 0;
            }
            checkBoxAutoStart.Checked = checkboxStatus;

            if (!enableNotice)
                TransformMini();
        }
Пример #32
0
        internal AppConfig(
            ConnectionStringSettingsCollection connectionStrings,
            KeyValueConfigurationCollection appSettings,
            EntityFrameworkSection entityFrameworkSettings)
        {
            //Contract.Requires(connectionStrings != null);

            _connectionStrings = connectionStrings;
            _appSettings = appSettings;
            _entityFrameworkSettings = entityFrameworkSettings ?? new EntityFrameworkSection();

            if (_entityFrameworkSettings.DefaultConnectionFactory.ElementInformation.IsPresent)
            {
                _defaultConnectionFactory = new Lazy<IDbConnectionFactory>(
                    () =>
                        {
                            var setting = _entityFrameworkSettings.DefaultConnectionFactory;

                            try
                            {
                                var type = setting.GetFactoryType();
                                var args = setting.Parameters.GetTypedParameterValues();
                                return (IDbConnectionFactory)Activator.CreateInstance(type, args);
                            }
                            catch (Exception ex)
                            {
                                throw new InvalidOperationException(
                                    Strings.SetConnectionFactoryFromConfigFailed(setting.FactoryTypeName), ex);
                            }
                        }, isThreadSafe: true);
            }
            else
            {
                _defaultConnectionFactory = _defaultDefaultConnectionFactory;
            }
        }
Пример #33
0
 public AppConfig(Configuration cm1, KeyValueConfigurationCollection confColl1)
 {
     this.cm       = cm1;
     this.confColl = confColl1;
 }