Beispiel #1
0
        public List <SimpleSetting> Settings(RenderContext context)
        {
            var           setting = new List <SimpleSetting>();
            SimpleSetting item    = new SimpleSetting();

            item.Name        = "Url";
            item.ControlType = Data.ControlType.Selection;

            var sitedb = context.WebSite.SiteDb();

            var allpages = sitedb.Pages.All();

            foreach (var page in allpages)
            {
                var url = Kooboo.Sites.Service.ObjectService.GetObjectRelativeUrl(sitedb, page);

                if (url != null)
                {
                    if (url.Contains("{") && url.Contains("}"))
                    {
                        continue;
                    }
                    else
                    {
                        item.SelectionValues[url] = url;
                    }
                }
            }
            setting.Add(item);
            return(setting);
        }
Beispiel #2
0
        public T GetValue <T>(string key)
        {
            SimpleSetting settings = SelectSetting(key);

            if (settings.Value == string.Empty)
            {
                return(default);
Beispiel #3
0
        public List <SimpleSetting> Settings(RenderContext context)
        {
            List <SimpleSetting> setting       = new List <SimpleSetting>();
            SimpleSetting        foldersetting = new SimpleSetting();

            foldersetting.Name        = "ContentFolder";
            foldersetting.ControlType = Data.ControlType.Selection;
            var folders = context.WebSite.SiteDb().ContentFolders.All();

            foreach (var item in folders)
            {
                foldersetting.SelectionValues.Add(item.Id.ToString(), item.Name);
            }
            setting.Add(foldersetting);
            return(setting);
        }
Beispiel #4
0
        public List<SimpleSetting> Settings(RenderContext context)
        {
            List<SimpleSetting> setting = new List<SimpleSetting>();
            SimpleSetting foldersetting = new SimpleSetting();
            foldersetting.Name = "Api";
            foldersetting.ControlType = Data.ControlType.Selection;

            var codes = context.WebSite.SiteDb().Code.ListByCodeType(Models.CodeType.Api);
            foreach (var item in codes)
            {
                foldersetting.SelectionValues.Add(item.Id.ToString(), item.Name);
            }
            setting.Add(foldersetting);

            return setting;
        }
Beispiel #5
0
        private static void Main(string[] args)
        {
            // Create new simple settings & fill them.
            Console.WriteLine("Create new simple settings.");

            SimpleSetting intSetting = SimpleSetting.CreateSetting("IntOnlySetting", 5, true);

            Console.WriteLine("Int only done.");

            SimpleSetting stringSetting = SimpleSetting.CreateSetting("StringOnlySetting", "Hello World", true);

            Console.WriteLine("String only done.");

            SimpleSetting mixedSetting = SimpleSetting.CreateSetting("MixedSetting", 10);

            mixedSetting.SetValue("Mixed setting String value");
            Console.WriteLine("Mixed done.");

            SimpleSetting emptySetting = new SimpleSetting("EmptySetting", false);

            Console.WriteLine("Empty done.");


            // Get value of settings correctly
            Console.WriteLine($"Int Only[{intSetting.Key}]: {intSetting.GetValue<int>()}");
            Console.WriteLine($"String Only[{stringSetting.Key}]: {stringSetting.GetValue<string>()}");
            Console.WriteLine($"MixedSetting[{mixedSetting.Key}]: {mixedSetting.GetValue<int>()} - {mixedSetting.GetValue<string>()}");

            Console.WriteLine("\n\n");

            // Test possible exceptions
            Console.WriteLine($"Set wrong type value in TypeLock setting: \n {RunAndGiveExceptionMessage(() => intSetting.SetValue("Not allowed string."))}");
            Console.Write("\n");
            Console.WriteLine($"Get wrong type value in TypeLock setting: \n {RunAndGiveExceptionMessage(() => intSetting.GetValue<string>())}");
            Console.Write("\n");
            Console.WriteLine($"Set invalid type: \n {RunAndGiveExceptionMessage(() => mixedSetting.SetValue<Action>(() => { }))}");
            Console.Write("\n");
            Console.WriteLine($"Get invalid type: \n {RunAndGiveExceptionMessage(() => mixedSetting.GetValue<Action>())}");
            Console.Write("\n");
            Console.WriteLine($"Get value from empty Setting: \n {RunAndGiveExceptionMessage(() => emptySetting.GetValue<string>())}");

            // Wait for input.
            Console.ReadLine();
        }
Beispiel #6
0
        public static List <Data.Models.SimpleSetting> GetSetting(WebSite website, Models.Code code)
        {
            var config = Kooboo.Sites.Scripting.Manager.ExeConfig(code, website);

            List <Data.Models.SimpleSetting> settings = new List <SimpleSetting>();

            if (config != null)
            {
                var items = ((IEnumerable)config).Cast <object>().ToList();

                if (items != null && items.Count() > 0)
                {
                    foreach (var item in items)
                    {
                        SimpleSetting setting = new SimpleSetting();

                        var dict = item as IDictionary <string, object>;

                        object SelectionValues = null;

                        foreach (var keyvalue in dict)
                        {
                            var lowerkey = keyvalue.Key.ToLower();

                            if (lowerkey == "name")
                            {
                                setting.Name = keyvalue.Value.ToString();
                            }
                            else if (lowerkey == "tooltip")
                            {
                                setting.ToolTip = keyvalue.Value.ToString();
                            }
                            else if (lowerkey == "controltype")
                            {
                                setting.ControlType = GetControlType(keyvalue.Value.ToString());
                            }
                            else if (lowerkey == "value" || lowerkey == "defaultvalue")
                            {
                                setting.DefaultValue = keyvalue.Value;
                            }
                            else if (lowerkey == "selectionvalues" || lowerkey == "selectionvalues")
                            {
                                SelectionValues = keyvalue.Value;
                            }
                        }

                        if (setting.ControlType == Data.ControlType.Selection && SelectionValues != null)
                        {
                            var selections = SelectionValues as IDictionary <string, object>;

                            if (selections != null)
                            {
                                if (setting.SelectionValues == null)
                                {
                                    setting.SelectionValues = new Dictionary <string, string>();
                                }

                                foreach (var se in selections)
                                {
                                    setting.SelectionValues.Add(se.Key, se.Value.ToString());
                                }
                            }
                        }

                        settings.Add(setting);
                    }
                }
            }

            return(settings);
        }