Beispiel #1
0
        internal void InitFromConfiguration()
        {
            this._Categories = new UserSettingsCategoryCollection();

            foreach (PropertyGroupConfigurationElement elem in UserSettingsConfig.GetConfig().Categories)
            {
                this._Categories.Add(new UserSettingsCategory(elem));
            }
        }
Beispiel #2
0
        public string GetDefaultValue()
        {
            //object defaultValue = UserSettingsConfig.GetConfig().Applications[AppName].Programs[ProgName].SettingProperties[PropName].DefaultValue;
            object defaultValue = UserSettingsConfig.GetConfig().Categories[Categoryname].AllProperties[PropName].DefaultValue;

            if (defaultValue != null)
            {
                return(defaultValue.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
        public DateTime GetTicketCutoffTime()
        {
            String currentCutOffTime = this.userSettingDao.GetSetting(UserSettingsConfig.CFG_TICKET_SELLING_CUTOFF_TIME);

            if (String.IsNullOrWhiteSpace(currentCutOffTime))
            {
                ValidateConfigDetails(UserSettingsConfig.CFG_TICKET_SELLING_CUTOFF_TIME,
                                      UserSettingsConfig.CutoffTimeDefaultValue);
                this.userSettingDao.InsertSetting(UserSettingsConfig.CFG_TICKET_SELLING_CUTOFF_TIME,
                                                  UserSettingsConfig.CutoffTimeDefaultValue);
                return(UserSettingsConfig.CFG_TICKET_SELLING_CUTOFF_TIME_DEFAULT);
            }

            return(UserSettingsConfig.ConvertCutoffTimeToDateTime(currentCutOffTime));
        }
        static void Main(string[] args)
        {
            var userSettings = new UserSettingsConfig();

            var writingController = new WritingController(userSettings);
            var readingController = new ReadingController(userSettings);

            var theme = readingController.GetTheme();

            Console.WriteLine("The current theme is: {0}", theme);

            writingController.SetTheme("CustomThemeName");

            theme = readingController.GetTheme();
            Console.WriteLine("The new theme is: {0}", theme);
            Console.ReadKey();
        }
        public void SaveTicketCutoffTime(DateTime newCutoffTime)
        {
            String oldCutOffTime = this.userSettingDao.GetSetting(UserSettingsConfig.CFG_TICKET_SELLING_CUTOFF_TIME);

            ValidateConfigDetails(UserSettingsConfig.CFG_TICKET_SELLING_CUTOFF_TIME,
                                  UserSettingsConfig.ConvertCutoffTimeToConfigValue(newCutoffTime));
            if (String.IsNullOrWhiteSpace(oldCutOffTime))
            {
                this.userSettingDao.InsertSetting(UserSettingsConfig.CFG_TICKET_SELLING_CUTOFF_TIME,
                                                  UserSettingsConfig.ConvertCutoffTimeToConfigValue(newCutoffTime));
            }
            else
            {
                this.userSettingDao.UpdateSetting(UserSettingsConfig.CFG_TICKET_SELLING_CUTOFF_TIME,
                                                  UserSettingsConfig.ConvertCutoffTimeToConfigValue(newCutoffTime));
            }
        }
 public UserSettingsCacheItemDependency()
 {
     this.originalConfigHashCode = UserSettingsConfig.GetConfig().GetHashCode();
 }
Beispiel #7
0
        /// <summary>
        /// Initializes the <see cref="MonahrqConfiguration"/> class.
        /// </summary>
        static MonahrqConfiguration()
        {
            try
            {
                if (!File.Exists(ConfigFilePath))
                {
                    //	Create Config Directory if not present.
                    if (!Directory.Exists(ConfigDirectoryPath))
                    {
                        Directory.CreateDirectory(ConfigDirectoryPath);
                    }

                    //	Copy the config file from the User Roaming Directory, if present.
                    var curUserConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
                    if (File.Exists(curUserConfig.FilePath))
                    {
                        FileInfo finfo = new FileInfo(curUserConfig.FilePath);
                        finfo.CopyTo(ConfigFilePath);
                    }
                    //	File not present in User Roamin Directory; try to find it in the last 'versioned' directory for app.
                    else
                    {
                        var dirPath = curUserConfig.FilePath.Replace("\\user.config", "\\..");
                        if (Directory.Exists(dirPath))
                        {
                            List <string> dirs               = new List <string>(Directory.EnumerateDirectories(dirPath));
                            var           versions           = dirs.Select(d => new Version(d.Substring(d.LastIndexOf("\\") + 1))).ToList();
                            var           latestVersionIndex = versions.IndexOf(versions.Max());
                            if (latestVersionIndex > -1)
                            {
                                //FileInfo finfo = new FileInfo(dirs[latestVersionIndex] + "\\user.config");
                                //finfo.CopyTo(ConfigFilePath);

                                var monahrqConfig = UserSettingsConfig.GetMonahrqSectionGroup().Sections.Get(MonahrqConfigurationSection.MonahrqConfigurationSectionSectionName)
                                                    as MonahrqConfigurationSection;
                                TransformToNewConfig(dirs[latestVersionIndex] + "\\user.config", ConfigFilePath, ref monahrqConfig);

                                Save(monahrqConfig);
                            }
                        }
                    }
                }

                //  Test that section is valid.
                var config             = UserSettingsConfig;
                var group              = config.GetMonahrqSectionGroup();
                var tempMonahrqSetcion = group.Sections.Get(MonahrqConfigurationSection.MonahrqConfigurationSectionSectionName)
                                         as MonahrqConfigurationSection;

                //if (tempMonahrqSetcion != null && !string.IsNullOrEmpty(tempMonahrqSetcion.UpdateScriptToRunAtStartup))
                //    config.Save();
            }
            catch (ConfigurationErrorsException ex)
            {
                var config = UserSettingsConfig;
                var group  = config.GetMonahrqSectionGroup();
                group.Sections.Remove(MonahrqConfigurationSection.MonahrqConfigurationSectionSectionName);
                config.Save(ConfigurationSaveMode.Minimal);
            }
            catch (Exception ex)
            {
                var config = UserSettingsConfig;
                var group  = config.GetMonahrqSectionGroup();
                group.Sections.Remove(MonahrqConfigurationSection.MonahrqConfigurationSectionSectionName);
                config.Save(ConfigurationSaveMode.Minimal);
            }
        }