Пример #1
0
        public static void ParseOptions(XPathNavigator node, List <ChoiceOption> options, out string enumTypeName)
        {
            options.Clear();
            enumTypeName = string.Empty;

            foreach (XPathNavigator optionElement in node.SelectChildren(XPathNodeType.Element))
            {
                if (optionElement.Name == "Enum")
                {
                    enumTypeName = optionElement.GetAttribute("type", "");
                    var enumType = TypeHandler.GetType(enumTypeName);
                    if (enumType == null)
                    {
                        throw new ContentRegistrationException("Enum");
                    }

                    var names  = Enum.GetNames(enumType);
                    var values = Enum.GetValues(enumType).Cast <int>().ToArray();
                    for (var i = 0; i < names.Length; i++)
                    {
                        var c = new ChoiceOption(values[i].ToString(), names[i]);
                        options.Add(c);
                    }
                }
                else
                {
                    var text = optionElement.InnerXml;
                    var key  = optionElement.GetAttribute("value", "");

                    if (text.Length == 0 && key.Length == 0)
                    {
                        key = options.Count.ToString();
                    }
                    if (text.Length == 0)
                    {
                        text = key;
                    }
                    if (key.Length == 0)
                    {
                        key = text;
                    }

                    bool enabled;
                    if (!Boolean.TryParse(optionElement.GetAttribute("enabled", ""), out enabled))
                    {
                        enabled = true;
                    }

                    var selected = false;
                    Boolean.TryParse(optionElement.GetAttribute("selected", ""), out selected);

                    options.Add(new ChoiceOption(key, text, enabled, selected));
                }
            }
        }
Пример #2
0
        public static void ParseOptions(XPathNavigator node, List <ChoiceOption> options, ChoiceFieldSetting fieldSetting, out string enumTypeName)
        {
            options.Clear();
            enumTypeName = string.Empty;

            foreach (XPathNavigator optionElement in node.SelectChildren(XPathNodeType.Element))
            {
                if (optionElement.Name == "Enum")
                {
                    enumTypeName = optionElement.GetAttribute("type", "");
                    var enumType = TypeResolver.GetType(enumTypeName);
                    if (enumType == null)
                    {
                        throw new ContentRegistrationException("Enum");
                    }

                    var resClassName = optionElement.GetAttribute("resourceClass", "");
                    if (string.IsNullOrEmpty(resClassName))
                    {
                        resClassName = CtdResourceClassName;
                    }

                    var names  = Enum.GetNames(enumType);
                    var values = Enum.GetValues(enumType).Cast <int>().ToArray();
                    for (var i = 0; i < names.Length; i++)
                    {
                        var resKey = fieldSetting == null ? string.Empty : fieldSetting.GetResourceKey(names[i]);
                        var text   = string.IsNullOrEmpty(resKey) ? names[i] : SenseNetResourceManager.GetResourceKey(resClassName, resKey);
                        var c      = new ChoiceOption(values[i].ToString(), text);
                        options.Add(c);
                    }
                }
                else
                {
                    // decode the xml string in order to handle &, < and > characters correctly
                    var text = HttpUtility.HtmlDecode(optionElement.InnerXml);
                    var key  = optionElement.GetAttribute("value", "");

                    if (text.Length == 0 && key.Length == 0)
                    {
                        key = options.Count.ToString();
                    }
                    if (text.Length == 0)
                    {
                        text = key;
                    }
                    if (key.Length == 0)
                    {
                        key = text;
                    }

                    bool enabled;
                    if (!Boolean.TryParse(optionElement.GetAttribute("enabled", ""), out enabled))
                    {
                        enabled = true;
                    }

                    var selected = false;
                    Boolean.TryParse(optionElement.GetAttribute("selected", ""), out selected);

                    options.Add(new ChoiceOption(key, text, enabled, selected));
                }
            }
        }
Пример #3
0
	    public static void ParseOptions(XPathNavigator node, List<ChoiceOption> options, out string enumTypeName)
        {
            options.Clear();
	        enumTypeName = string.Empty;

            foreach (XPathNavigator optionElement in node.SelectChildren(XPathNodeType.Element))
            {
                if (optionElement.Name == "Enum")
                {
                    enumTypeName = optionElement.GetAttribute("type", "");
                    var enumType = TypeHandler.GetType(enumTypeName);
                    if (enumType == null)
                        throw new ContentRegistrationException("Enum");

                    var names = Enum.GetNames(enumType);
                    var values = Enum.GetValues(enumType).Cast<int>().ToArray();
                    for (var i = 0; i < names.Length; i++)
                    {
                        var c = new ChoiceOption(values[i].ToString(), names[i]);
                        options.Add(c);
                    }
                }
                else
                {
                    var text = optionElement.InnerXml;
                    var key = optionElement.GetAttribute("value", "");

                    if (text.Length == 0 && key.Length == 0)
                        key = options.Count.ToString();
                    if (text.Length == 0)
                        text = key;
                    if (key.Length == 0)
                        key = text;

                    bool enabled;
                    if (!Boolean.TryParse(optionElement.GetAttribute("enabled", ""), out enabled))
                        enabled = true;

                    var selected = false;
                    Boolean.TryParse(optionElement.GetAttribute("selected", ""), out selected);

                    options.Add(new ChoiceOption(key, text, enabled, selected));
                }
            }
        }