Пример #1
0
        private void LoadRequiredObjects(KeyValueConfigurationCollection moduleSettings)
        {
            try
            {
                // ----------------------------------------------------
                //     First load the MainWorkItem for this module
                // ----------------------------------------------------
                string workItemName = moduleSettings[SettingsKeys.Namespace].Value + "." +
                                      moduleSettings[SettingsKeys.MainWorkItem].Value;

                // add the new MainWorkItem to the RootWorkItem
                moduleWorkItem = RootWorkItem.WorkItems.AddNew(childAssembly.GetType(workItemName), moduleSettings[SettingsKeys.MainWorkItem].Value) as LaytonWorkItem;
                moduleSettings.Remove(SettingsKeys.MainWorkItem);

                // ----------------------------------------------------
                //     Load the WorkItemController into the WorkItem
                // ----------------------------------------------------
                string controllerName = moduleSettings[SettingsKeys.Namespace].Value + "." +
                                        moduleSettings[SettingsKeys.WorkItemController].Value;

                // add the new WorkItemController into the WorkItem's Items collection
                moduleWorkItem.Items.AddNew(childAssembly.GetType(controllerName), ControllerNames.WorkItemController);
                moduleSettings.Remove(SettingsKeys.WorkItemController);

                // ----------------------------------------------------
                //     Load the ToolbarsController into the WorkItem
                // ----------------------------------------------------
                string toolbarsName = moduleSettings[SettingsKeys.Namespace].Value + "." +
                                      moduleSettings[SettingsKeys.ToolbarsController].Value;

                // add the new ToolbarsController into the WorkItem's Items collection
                moduleWorkItem.Items.AddNew(childAssembly.GetType(toolbarsName), ControllerNames.ToolbarsController);
                moduleSettings.Remove(SettingsKeys.ToolbarsController);

                // ----------------------------------------------------
                //     Load the MainExplorerView into the WorkItem
                // ----------------------------------------------------
                string explorerViewName = moduleSettings[SettingsKeys.Namespace].Value + "." +
                                          moduleSettings[SettingsKeys.MainExplorerView].Value;

                // add the new MainExplorerView to the WorkItem's SmartParts collection
                moduleWorkItem.Items.AddNew(childAssembly.GetType(explorerViewName), ViewNames.MainExplorerView);
                moduleSettings.Remove(SettingsKeys.MainExplorerView);

                // ----------------------------------------------------
                //     Load the MainTabView into the WorkItem
                // ----------------------------------------------------
                string tabViewName = moduleSettings[SettingsKeys.Namespace].Value + "." +
                                     moduleSettings[SettingsKeys.MainTabView].Value;

                // add the new MainTabView to the WorkItem's SmartParts collection
                moduleWorkItem.Items.AddNew(childAssembly.GetType(tabViewName), ViewNames.MainTabView);
                moduleSettings.Remove(SettingsKeys.MainTabView);
            }
            catch (Exception e)
            {
                throw new Exception(String.Format("Error loading Required CAB Module objects for Assembly: {0}{1}{2}", assemblyFileName, Environment.NewLine, e.Message), e);
            }
        }
Пример #2
0
 public void Remove(string key)
 {
     foreach (XmlElement add in _xmlAppSettings.OriginalXmlElement.ChildNodes)
     {
         if (add.Name == "add" && add.Attributes["key"].Value == key)
         {
             _xmlAppSettings.OriginalXmlElement.RemoveChild(add);
             _originalCollection.Remove(key);
         }
     }
 }
Пример #3
0
        private void LoadWorkItemProperties(KeyValueConfigurationCollection moduleSettings)
        {
            // ----------------------------------------------------
            //     Set the value of this WorkItem's title
            // ----------------------------------------------------
            string title = moduleSettings[SettingsKeys.Title].Value;

            if (title == null)
            {
                throw new Exception(String.Format("The CAB assembly, {0}, is missing the following setting in it's configuration file:  {1}", assemblyFileName, SettingsKeys.Title));
            }
            // set the value to the LaytonWorkItem.Title
            moduleWorkItem.Title = title;
            moduleSettings.Remove(SettingsKeys.Title);

            // ----------------------------------------------------
            //     Set the value of this WorkItem's description
            // ----------------------------------------------------
            string description = moduleSettings[SettingsKeys.Description].Value;

            if (description == null)
            {
                throw new Exception(String.Format("The CAB assembly, {0}, is missing the following setting in it's configuration file:  {1}", assemblyFileName, SettingsKeys.Description));
            }
            // set the value to the LaytonWorkItem.Description
            moduleWorkItem.Description = description;
            moduleSettings.Remove(SettingsKeys.Description);

            // ----------------------------------------------------
            //     Set the value of this WorkItem's Image
            // ----------------------------------------------------
            string imageName     = moduleSettings[SettingsKeys.Image].Value;
            string namespaceName = moduleSettings[SettingsKeys.Namespace].Value;

            if (imageName == null)
            {
                throw new Exception(String.Format("The CAB assembly, {0}, is missing the following setting in it's configuration file:  {1}", assemblyFileName, SettingsKeys.Image));
            }
            if (namespaceName == null)
            {
                throw new Exception(String.Format("The CAB assembly, {0}, is missing the following setting in it's configuration file:  {1}", assemblyFileName, SettingsKeys.Namespace));
            }

            // set the value to the LaytonWorkItem.Image
            ResourceManager resourceManager = new ResourceManager(namespaceName + ".Properties.Resources", childAssembly);

            moduleWorkItem.Image = (System.Drawing.Image)resourceManager.GetObject(imageName);
            moduleSettings.Remove(SettingsKeys.Image);
        }
Пример #4
0
        private void buttonOkSettings_Click(object sender, EventArgs e)
        {
            if (textBoxServer.Text == "" ||
                textBoxPort.Text == "" ||
                textBoxUserId.Text == "" ||
                textBoxDatabase.Text == "")
            {
                MessageBox.Show("Hiba: nincs minden kötelező mező kitöltve!");
                return;
            }

            settings.Remove("server");
            settings.Remove("port");
            settings.Remove("user_id");
            settings.Remove("password");
            settings.Remove("database");

            settings.Add("server", textBoxServer.Text);
            settings.Add("port", textBoxPort.Text);
            settings.Add("user_id", textBoxUserId.Text);
            settings.Add("database", textBoxDatabase.Text);

            if (checkBoxRememberPassword.Checked)
            {
                settings.Add("password", textBoxPassword.Text);
            }

            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");

            ConnectionDetails.server   = textBoxServer.Text;
            ConnectionDetails.port     = textBoxPort.Text;
            ConnectionDetails.database = textBoxDatabase.Text;
            ConnectionDetails.user     = textBoxUserId.Text;
            ConnectionDetails.password = textBoxPassword.Text;

            if (mustFill)
            {
                Form1 mainForm = new Form1();
                mainForm.Show();
                this.Owner = mainForm;
                this.Hide();
            }
            else
            {
                this.Close();
            }
        }
Пример #5
0
        /// <summary>
        /// App.config 에서 strKey에 strValue 내용을 설정함
        /// </summary>
        /// <param name="strKey">설정할 키값</param>
        /// <param name="nValue">해당 키값에 넣을 데이터</param>
        /// <returns> 유무</returns>
        public static bool SetAppConfig(string strKey, int nValue)
        {
            bool bResult;

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection configCollection = config.AppSettings.Settings;

            try
            {
                configCollection.Remove(strKey);

                string strNValue = nValue.ToString();
                configCollection.Add(strKey, strNValue);

                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);

                bResult = true;
            }
            catch
            {
                bResult = false;
            }

            return(bResult);
        }
Пример #6
0
 /// <summary>
 /// Change the value for specified key
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void ChangeKeyValue(string key, string value, bool isConnectionString, bool isAppSetting)
 {
     if (isAppSetting)
     {
         Configuration      config      = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         AppSettingsSection App_Section = (AppSettingsSection)config.GetSection("appSettings");
         KeyValueConfigurationCollection app_settings = App_Section.Settings;
         KeyValueConfigurationElement    element      = app_settings[key];
         if (element != null)
         {
             element.Value = value;
             app_settings.Remove(key);
             app_settings.Add(element);
             config.Save(ConfigurationSaveMode.Full, true);
             ConfigurationManager.RefreshSection("appSettings");
         }
     }
     if (isConnectionString)
     {
         Configuration                      config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         ConnectionStringsSection           connectionString_Section  = (ConnectionStringsSection)config.GetSection("appSettings");
         ConnectionStringSettingsCollection connectionString_settings = connectionString_Section.ConnectionStrings;
         ConnectionStringSettings           element = connectionString_settings[key];
         if (element != null)
         {
             element.ConnectionString = "blah";
             connectionString_settings.Remove(key);
             connectionString_settings.Add(element);
             config.Save(ConfigurationSaveMode.Full, true);
             ConfigurationManager.RefreshSection("appSettings");
         }
     }
 }
        public static void Set(this KeyValueConfigurationCollection collection, SettingInfo keyInfo, string value, Version currentVersion = null)
        {
            // If either SupportedFrom or RemovedFrom exists then we need the currentVersion
            if (keyInfo.SupportedFrom != null || keyInfo.RemovedFrom != null)
            {
                if (currentVersion == null)
                {
                    throw new ArgumentNullException(nameof(currentVersion), $"Version info is required before setting or removing {keyInfo.Name}");
                }
            }

            collection.Remove(keyInfo.Name);

            if (keyInfo.SupportedFrom != null && currentVersion < keyInfo.SupportedFrom)
            {
                return;
            }

            if (keyInfo.RemovedFrom != null && currentVersion >= keyInfo.RemovedFrom)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(value))
            {
                collection.Add(new KeyValueConfigurationElement(keyInfo.Name, value));
            }
        }
Пример #8
0
        private static KeyValueConfigurationCollection GetConfiguration()
        {
            var    args       = Environment.GetCommandLineArgs();
            var    opts       = new Dictionary <string, string>();
            string configFile = null;
            KeyValueConfigurationCollection settings = null;

            for (int i = 1; i < args.Length - 1; ++i)
            {
                string opt = args[i];
                if (!opt.StartsWith("--", StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }

                // analyze options
                string optname = opt.Substring(2);
                switch (optname)
                {
                case "ConfigFile":
                    configFile = args[i + 1];
                    break;

                default:
                    opts.Add(optname, args[i + 1]);
                    break;
                }
                ++i;
            }
            // load different config file
            if (configFile != null)
            {
                string configPath = Path.Combine(Environment.CurrentDirectory, configFile);

                try
                {
                    // Get the mapped configuration file
                    var config = ConfigurationManager.OpenExeConfiguration(configPath);
                    settings = ((AppSettingsSection)config.GetSection("appSettings")).Settings;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not load config file {0}, reason: {1}", configPath, ex.Message);
                }
            }
            if (settings == null)
            {
                settings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings;
            }

            // override config options with options from command line
            foreach (var pair in opts)
            {
                settings.Remove(pair.Key);
                settings.Add(pair.Key, pair.Value);
            }

            return(settings);
        }
        public void RemoveKey()
        {
            var collection = new KeyValueConfigurationCollection();

            collection.Add("foo", "foo");
            Assert.Equal("foo", collection["foo"].Value);
            collection.Remove("foo");
            Assert.Null(collection["foo"]);
        }
Пример #10
0
        public static void Update(this KeyValueConfigurationCollection settings, string key, string value)
        {
            if (settings[key] != null)
            {
                settings.Remove(key);
            }

            settings.Add(key, value);
        }
Пример #11
0
        public static void SetAppConfig(string key, string value)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection cfgCollection = config.AppSettings.Settings;

            cfgCollection.Remove(key);
            cfgCollection.Add(key, value); config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
        }
Пример #12
0
 /// <summary>
 /// Removes a property from the storage by name
 /// </summary>
 public virtual void Delete(string path, string name)
 {
     lock (Sync)
     {
         Configuration config;
         KeyValueConfigurationCollection settings = Open(path, out config);
         settings.Remove(MakePath(path, name));
         config.Save(ConfigurationSaveMode.Minimal, false);
     }
 }
Пример #13
0
        public static void setConfig(string key, string value)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            KeyValueConfigurationCollection cfgCollection = config.AppSettings.Settings;

            cfgCollection.Remove(key);
            cfgCollection.Add(key, value);
            config.Save();
        }
 public void ResetCollection(IEnumerable <ConfigurationElement> configurationElements)
 {
     foreach (string key in keyValueCollection.AllKeys.ToArray())
     {
         keyValueCollection.Remove(key);
     }
     foreach (KeyValueConfigurationElement keyValueElement in configurationElements.OfType <KeyValueConfigurationElement>())
     {
         keyValueCollection.Add(keyValueElement.Key, keyValueElement.Value);
     }
 }
Пример #15
0
        public static void delete(string key)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            KeyValueConfigurationCollection settings = config.AppSettings.Settings;

            if (settings[key] != null)
            {
                settings.Remove(key);
            }
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
        }
Пример #16
0
        private void SaveBackupForm_Closing(object sender, EventArgs e)
        {
            try
            {
                Configuration configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                KeyValueConfigurationCollection confCollection = configManager.AppSettings.Settings;

                confCollection.Remove("InputPath");
                confCollection.Remove("OutputPath");
                confCollection.Remove("BackupName");
                confCollection.Remove("MaxBackups");
                confCollection.Remove("BackupInterval");
                confCollection.Remove("FileNames");

                confCollection.Add("InputPath", this.InputPath.Text);
                confCollection.Add("OutputPath", this.OutputPath.Text);
                confCollection.Add("BackupName", this.BackupFolderName.Text);
                confCollection.Add("MaxBackups", this.MaxBackups.Value.ToString());
                confCollection.Add("BackupInterval", this.BackupInterval.Value.ToString());



                List <string> fileNames = this.TargetFileNames.Items.Cast <String>().ToList();
                confCollection.Add("FileNames", string.Join(",", fileNames));

                configManager.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(configManager.AppSettings.SectionInformation.Name);
            }
            catch { }
        }
Пример #17
0
        public static void RemoveSimilar(this KeyValueConfigurationCollection appSettingsCollection, string key)
        {
            var nameList = new List <string>();

            nameList.AddRange(appSettingsCollection.AllKeys);
            foreach (var item in nameList)
            {
                if (item.Contains(key))
                {
                    appSettingsCollection.Remove(item);
                }
            }
        }
Пример #18
0
 private void Write2ConfigFile(string key, string value)
 {
     try
     {
         hyperSettings.Remove(key);
         hyperSettings.Add(key, value);
         hyperConfigFile.Save(ConfigurationSaveMode.Modified);
     } catch (Exception e)
     {
         MessageBox.Show(e.Message + "\n\n" + e.StackTrace, "Write2ConfigFile Error");
         Environment.Exit(0);
     }
 }
Пример #19
0
        public override void SetUp()
        {
            base.SetUp();
            _config = GetConfig();
            var section = (AppSettingsSection)_config.GetSection(TestConfig.SECTION_NAME);

            _settings = section.Settings;
            _settings.AllKeys
            .ToList()
            .ForEach(s => _settings.Remove(s));
            _config.Save();
            _testConfig = new TestConfig(_config);
        }
Пример #20
0
    private void UpdateLatestChangset(int cid)
    {
        // Open App.Config of executable
        System.Configuration.Configuration config =
            ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

        KeyValueConfigurationCollection settings = config.AppSettings.Settings;

        settings.Remove("tfs.changeset");
        settings.Add("tfs.changeset", cid.ToString());

        // Save the configuration file.
        config.Save(ConfigurationSaveMode.Modified);
    }
Пример #21
0
        /// <summary>
        /// 테그가 일치하는 기존값을 삭제하고 신규값을 저장한다.
        /// </summary>
        /// <param name="_strTagName">AppSettings 테그명</param>
        /// <param name="_strValue">AppSettings 값</param>
        public static void SetAppSettings(string _strTagName, string _strValue)
        {
            try
            {
                System.Configuration.Configuration config        = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                KeyValueConfigurationCollection    cfgCollection = config.AppSettings.Settings;

                cfgCollection.Remove(_strTagName);
                cfgCollection.Add(_strTagName, _strValue);

                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
            }
            catch { throw; }
        }
 public bool RemoveUser(string username, string password)
 {
     Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     KeyValueConfigurationCollection settings = (config.GetSection("users") as AppSettingsSection).Settings;
     //string unsecuredPassword = DecipherPassword(password);
     //string persistentPassword = GetHash(unsecuredPassword);
     string persistentPassword = GetHash(password);
     if (settings[username] == null && settings[username].Value == persistentPassword)
     {
         settings.Remove(username);
         config.Save();
         ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
         return true;
     }
     return false;
 }
Пример #23
0
        public void RemoveKey(string keyName)
        {
            try
            {
                if (_settings[keyName] != null)
                {
                    _settings.Remove(keyName);
                }

                _configFile.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(_configFile.AppSettings.SectionInformation.Name);
            }
            catch (ConfigurationErrorsException)
            {
                throw;
            }
        }
        public static void RemoveIfRetired(this KeyValueConfigurationCollection collection, SettingInfo keyInfo, Version currentVersion)
        {
            if (keyInfo.RemovedFrom == null)
            {
                return;
            }

            if (currentVersion == null)
            {
                throw new ArgumentNullException(nameof(currentVersion), $"Version info is required before setting or removing {keyInfo.Name}");
            }

            if (currentVersion >= keyInfo.RemovedFrom)
            {
                collection.Remove(keyInfo.Name);
            }
        }
Пример #25
0
        private void SetAppConfig()
        {
            try
            {
                if (MessageBox.Show("DIDSystem IP Address를 저장 하시겠습니까?", "알림", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
                    == DialogResult.OK)
                {
                    //xmlRead.AppSettingXmlSave(ipFTxt.Text + "." + ipMTxt.Text + "." + ipLTxt.Text + "." + ipLLTxt.Text, @"Config.xml");
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    KeyValueConfigurationCollection cfgCollextion = config.AppSettings.Settings;

                    cfgCollextion.Remove("DIDip");
                    cfgCollextion.Add("DIDip", ipFTxt.Text + "." + ipMTxt.Text + "." + ipLTxt.Text + "." + ipLLTxt.Text);

                    config.Save(ConfigurationSaveMode.Modified);
                    ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
                }
            }
            catch (Exception ex) { WriteLog.WriteLogger(ex.ToString()); }
        }
Пример #26
0
        /// <summary>
        /// Update the config files with newly added items, or update the old items with new value.
        /// </summary>
        /// <param name="fileName">Full path to the config file</param>
        /// <param name="key">Add the config item if key doesn't exist.</param>
        /// <param name="value">The value to be set</param>
        public static void AddConfigurationItem(string fileName, string key, string value)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("File Not Found: " + fileName, fileName);
            }

            ExeConfigurationFileMap configurationMap = new ExeConfigurationFileMap {
                ExeConfigFilename = fileName
            };
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configurationMap, ConfigurationUserLevel.None);
            KeyValueConfigurationCollection settings = config.AppSettings.Settings;

            if (settings[key] != null)
            {
                settings.Remove(key);
            }
            settings.Add(key, value);
            config.Save();
        }
Пример #27
0
        protected void SetSetting <TProperty>(TProperty value, [CallerMemberName] string propertyName = "")
        {
            //var accessor = new PropertyAccessor<TProperty>(settingProperty);
            var keyExists = _appSettings.AllKeys.Contains(propertyName);
            var isDirty   = false;

            if (value == null)
            {
                if (keyExists)
                {
                    _appSettings.Remove(propertyName);
                    _propertyCache.Remove(propertyName);
                    isDirty = true;
                }
            }
            else
            {
                if (keyExists)
                {
                    var valueText = ConvertEx.ChangeType <string>(value);
                    if (_appSettings[propertyName].Value != valueText)
                    {
                        _appSettings[propertyName].Value = valueText;
                        _propertyCache[propertyName]     = value;
                        isDirty = true;
                    }
                }
                else
                {
                    _appSettings.Add(propertyName, value.ToString());
                    _propertyCache.Add(propertyName, value);
                    isDirty = true;
                }
            }

            if (isDirty)
            {
                _config.Save();
                ConfigurationManager.RefreshSection("appSettings");
            }
        }
Пример #28
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            KeyValueConfigurationCollection cc = new KeyValueConfigurationCollection();

            foreach (ComboBox cb in Controls.OfType <ComboBox>())
            {
                string appKey = cb.Name.Replace("cb", "") + "Mapping";
                string value  = ((KeyValuePair <string, string>)cb.SelectedItem).Key;

                if (cc[appKey] == null)
                {
                    cc.Add(appKey, value);
                }
                else
                {
                    cc.Remove(appKey);
                    cc.Add(appKey, value);
                }
            }

            _onSave(cc);
        }
Пример #29
0
            public void AddOrUpdateSettings(string key, string value)
            {
                if (string.IsNullOrEmpty(key))
                {
                    return;
                }

                try
                {
                    if (settings.AllKeys.Contains(key))
                    {
                        settings.Remove(key);
                    }
                    settings.Add(key, value);
                    //settings[""].
                    config.Save();
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message, ex);
                }
            }
Пример #30
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);
        }