Example #1
0
 public ActionResult Edit(CmsSetting attr)
 {
     this.settingService.Update(attr);
     TempData["SuccessResult"] = "Item was successfully updated.";
     return(RedirectToAction("Edit",
                             "Settings",
                             new { id = attr.Id }));
 }
 public string CreateConfigKeyName(CmsSetting setting)
 {
     return(CreateConfigKeyName(
                setting.Name,
                setting.SiteName,
                setting.CategoryName
                ));
 }
 public ActionResult Edit(CmsSetting attr)
 {
     this.settingService.Update(attr);
     TempData["SuccessResult"] = "Item was successfully updated.";
     return RedirectToAction("Edit",
                             "Settings",
                             new {id = attr.Id});
 }
Example #4
0
 public ViewResult Edit(int?id)
 {
     if (null != id)
     {
         CmsSetting attr = this.settingService.Load(id.Value);
         return(View(attr));
     }
     else
     {
         return(View(new CmsSetting()));
     }
 }
Example #5
0
 public CmsPage LoadDefault()
 {
     try
     {
         CmsSetting defaultSetting = settingData.Get(Constant.Settings.DefaultPageId);
         return(Load(defaultSetting.GetIntValue()));
     }
     catch (Exception ex)
     {
         log.Warn(ex.Message);
         return(pageData.LoadAll().FirstOrDefault());
     }
 }
Example #6
0
        public void CreateConfigKeyName_WithCategoryName_ContainsCategoryNameSection(string settingsKeyName, string siteName, string categoryName, bool useCategorySections)
        {
            var options = new CmsSettingsConfigBuilderOptions
            {
                UseCategorySections = useCategorySections
            };

            var sut = new CmsSettingConfigKeyNameFactory(Configuration, options);

            var    setting = new CmsSetting(settingsKeyName, string.Empty, categoryName, siteName);
            string actual  = sut.CreateConfigKeyName(setting);

            Assert.That(
                actual,
                Does.Contain($"{categoryName}{AppConfigurationPath.KeyDelimiter}")
                );
        }
        public void CreateConfigSettings_WithCategorySections_PreservesGlobalSettingsForSites(bool useCategorySections)
        {
            var globalSetting = new CmsSetting("Key1", "Value1", "Category1", null);
            var siteSetting   = new CmsSetting("Key2", "Value2", "Category1", "Site");

            ReadOnlyCollection <CmsSetting> settings = new List <CmsSetting>
            {
                globalSetting,
                siteSetting
            }
            .AsReadOnly();

            IQueryHandler <AllConfigCmsSettingsQuery, IReadOnlyCollection <CmsSetting> > allSettingsQueryHandler = A.Fake <IQueryHandler <AllConfigCmsSettingsQuery, IReadOnlyCollection <CmsSetting> > >();

            A.CallTo(() => allSettingsQueryHandler.Handle(A <AllConfigCmsSettingsQuery> .Ignored))
            .Returns(settings);

            var configurationManager = new ConfigurationManagerAdapter();
            var configuration        = new AppConfiguration(configurationManager);
            var options = new CmsSettingsConfigBuilderOptions
            {
                UseCategorySections = useCategorySections
            };
            var configKeyNameFactory = new CmsSettingConfigKeyNameFactory(configuration, options);

            var sut = new CmsSettingsConfigBuilderInternal(
                options,
                allSettingsQueryHandler,
                configKeyNameFactory
                );

            ICollection <KeyValuePair <string, string> > values = sut.GetAllValues(null);

            // If a category has at least one Site setting value, all other keys in that category should be made available within the corresponding Site "section" by falling back to Global settings values where a Site specific value is not available

            string globalSettingKey = configKeyNameFactory.CreateConfigKeyName(globalSetting);
            string expected         = globalSetting.Value;

            KeyValuePair <string, string> configSetting = values.FirstOrDefault(setting => setting.Key == globalSettingKey);
            string actual = configSetting.Value;

            Assert.That(actual, Is.EqualTo(expected));
        }
Example #8
0
        public string GetSettingValue(string settingKey, Cache cache)
        {
            string settingFromCache = GetFromCache(settingKey, cache);

            if (null != settingFromCache)
            {
                return(settingFromCache);
            }

            CmsSetting setting = settingData.Get(settingKey);

            if (null == setting)
            {
                CacheSetting(settingKey, string.Empty, cache);
                return(string.Empty);
            }

            CacheSetting(settingKey, setting.Value, cache);
            return(setting.Value);
        }
Example #9
0
        public void CreateConfigKeyName_WithKeyPrefix_StripsPrefixWhenDirected(string siteName, string categoryName, string keyPrefix, string keyName, bool stripPrefix, bool useCategorySections)
        {
            var options = new CmsSettingsConfigBuilderOptions
            {
                UseCategorySections = useCategorySections,
                KeyPrefix           = keyPrefix,
                StripPrefix         = stripPrefix
            };

            var sut = new CmsSettingConfigKeyNameFactory(Configuration, options);

            string settingsKeyName = $"{keyPrefix}{keyName}";

            var    setting = new CmsSetting(settingsKeyName, string.Empty, categoryName, siteName);
            string actual  = sut.CreateConfigKeyName(setting);

            Assert.That(
                actual,
                stripPrefix ? Does.Not.Contain(keyPrefix) : Does.Contain(keyPrefix)
                );
        }
Example #10
0
        public void CreateSettingsKeyName_WithGlobalConfigKey_CreatesGlobalSettingsKey(string settingsKeyName, string siteName, string categoryName, bool useCategorySections)
        {
            var options = new CmsSettingsConfigBuilderOptions
            {
                UseCategorySections = useCategorySections
            };

            var sut = new CmsSettingConfigKeyNameFactory(Configuration, options);

            var    setting   = new CmsSetting(settingsKeyName, string.Empty, categoryName, siteName);
            string configKey = sut.CreateConfigKeyName(setting);

            SettingsKeyName actual = sut.CreateSettingsKeyName(configKey);

            Assert.Multiple(() =>
            {
                Assert.That(actual.KeyName, Is.EqualTo(settingsKeyName));
                Assert.That(actual.SiteName, Is.Empty);
                Assert.IsTrue(actual.IsGlobal);
            });
        }
Example #11
0
        public void CreateSettingsKeyName_WithKeyPrefix_RestoresPrefixWhenStripped(string siteName, string categoryName, string keyPrefix, string keyName, bool stripPrefix, bool useCategorySections)
        {
            var options = new CmsSettingsConfigBuilderOptions
            {
                UseCategorySections = useCategorySections,
                KeyPrefix           = keyPrefix,
                StripPrefix         = stripPrefix
            };

            var sut = new CmsSettingConfigKeyNameFactory(Configuration, options);

            string settingsKeyName = $"{keyPrefix}{keyName}";

            var    setting   = new CmsSetting(settingsKeyName, string.Empty, categoryName, siteName);
            string configKey = sut.CreateConfigKeyName(setting);

            SettingsKeyName actual = sut.CreateSettingsKeyName(configKey);

            Assert.That(
                actual.KeyName,
                Does.StartWith(keyPrefix)
                );
        }
Example #12
0
        public IEnumerable <CmsPage> LoadLastCreated()
        {
            int numberOfLastPageToLoad = 10;

            try
            {
                CmsSetting lastCreated = settingData.Get(Constant.Settings.LastCreated);
                if (lastCreated != null)
                {
                    numberOfLastPageToLoad = lastCreated.GetIntValue();
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message);
            }

            IEnumerable <CmsPage> lastPages = pageData.LoadLast(numberOfLastPageToLoad);
            int defaultPageid = LoadDefault().Id;

            lastPages = lastPages.Where(x => x.Id != defaultPageid);
            return(lastPages.ToList());
        }
Example #13
0
 public void Update(CmsSetting cmsSetting)
 {
     settingData.Save(cmsSetting);
 }
Example #14
0
 public void Update(CmsSetting cmsSetting)
 {
     settingData.Save(cmsSetting);
 }
Example #15
0
 public void Save(CmsSetting setting)
 {
     base.Save(setting);
 }
Example #16
0
 public void Save(CmsSetting setting)
 {
     base.Save(setting);
 }
        public ICollection <KeyValuePair <string, string> > GetAllValues(string prefix)
        {
            var values = new Dictionary <string, string>();

            try
            {
                // Get all settings

                var query = new AllConfigCmsSettingsQuery(options.ProcName, prefix);
                IReadOnlyCollection <CmsSetting> settings = allSettingsQueryHandler.Handle(query);

                // Group settings by site (global settings represented by an empty string) so we can split up processing

                const string globalSiteName = "";

                var settingsBySite = settings.GroupBy(setting => setting.SiteName ?? globalSiteName)
                                     .ToDictionary(group => group.Key, group => group.ToList());

                // Add global settings first as these are a straight-forward add

                List <CmsSetting> globalSettings = settingsBySite[globalSiteName];

                foreach (CmsSetting setting in globalSettings)
                {
                    AddSetting(setting, values);
                }

                // Group global settings by category - these will be used as default values for site settings

                const string nullCategoryName = "";

                var globalSettingsByCategory = globalSettings
                                               .GroupBy(setting => setting.CategoryName ?? nullCategoryName)
                                               .ToDictionary(group => group.Key, group => group.ToList());

                // Now add site settings

                foreach (string siteName in settingsBySite.Keys)
                {
                    if (siteName == globalSiteName)
                    {
                        // We have already added global settings so continue

                        continue;
                    }

                    // We will add one category at a time and fallback to global values for any related category setting that is not set at site level - this is done to make it easier to get config settings by section (category)

                    var siteSettingsByCategory = settingsBySite[siteName]
                                                 .GroupBy(setting => setting.CategoryName ?? nullCategoryName)
                                                 .ToDictionary(group => group.Key, group => group.ToList());

                    foreach (string categoryName in siteSettingsByCategory.Keys)
                    {
                        List <CmsSetting> categoryGlobalSettings = globalSettingsByCategory[categoryName];
                        List <CmsSetting> categorySiteSettings   = siteSettingsByCategory[categoryName];

                        foreach (CmsSetting globalSetting in categoryGlobalSettings)
                        {
                            // There may not be a site setting present for each global setting in the category - if there is not add the setting with the global value; if there is add the setting with the site value

                            CmsSetting siteSetting = categorySiteSettings.FirstOrDefault(setting => setting.Name == globalSetting.Name);

                            var categorySetting = new CmsSetting(
                                globalSetting.Name,
                                siteSetting == null ? globalSetting.Value : siteSetting.Value,
                                categoryName,
                                siteName
                                );

                            AddSetting(categorySetting, values);
                        }
                    }
                }
            }
            catch (Exception)
            {
                if (!options.Optional)
                {
                    throw;
                }
            }

            return(values);
        }
        private void AddSetting(CmsSetting setting, Dictionary <string, string> values)
        {
            string key = configKeyNameFactory.CreateConfigKeyName(setting);

            values[key] = setting.Value;
        }