예제 #1
0
        public IDictionary <string, Umbraco.Core.Models.PreValue> GetPreValues(PreValueContext context)
        {
            var doc = new XmlDocument();

            doc.Load(_path);
            var result = new Dictionary <string, Umbraco.Core.Models.PreValue>();

            foreach (XmlNode node in doc.DocumentElement.ChildNodes)
            {
                var value     = node.InnerText.Trim();
                var alias     = node.Attributes["alias"].InnerText;
                int sortOrder = 0;
                if (node.Attributes["sortOrder"] != null)
                {
                    sortOrder = int.Parse(node.Attributes["sortOrder"].InnerText);
                }
                result.Add(alias, new Umbraco.Core.Models.PreValue(0, value, sortOrder));
            }

            return(result);
        }
예제 #2
0
        protected IDictionary <string, PreValue> GetPreValuesInternal(PreValueContext context, int maxNumberOverride = -1)
        {
            Dictionary <string, PreValue> result = new Dictionary <string, PreValue>();

            string typeAlias;

            try
            {
                Type target = this.GetType();
                while ((!target.IsGenericType || target.GetGenericTypeDefinition() != typeof(NodePicker <,>)) && target.BaseType != null)
                {
                    target = target.BaseType;
                }

                if (((!target.IsGenericType || target.GetGenericTypeDefinition() != typeof(NodePicker <,>)) && target.BaseType != null))
                {
                    throw new CodeFirstException("The type " + this.GetType().FullName + " does not specify a valid content type as its generic parameter");
                }

                typeAlias = target.GetGenericArguments().First().GetCodeFirstAttribute <ContentTypeAttribute>()?.Alias ?? string.Empty;
            }
            catch (Exception e)
            {
                throw new CodeFirstException("The type " + this.GetType().FullName + " does not specify a valid content type as its generic parameter", e);
            }

            var configAttribute = context.CurrentMember.GetCodeFirstAttribute <NodePickerConfigAttribute>();
            var startNodeString = string.Empty;
            var minNumberString = string.Empty;
            var maxNumberString = string.Empty;

            if (configAttribute != null)
            {
                if (configAttribute.StartNodeId > 0)
                {
                    startNodeString = ", \"id\": " + configAttribute.StartNodeId.ToString();
                }
                if (configAttribute.MinimumItems > -1)
                {
                    minNumberString = configAttribute.MinimumItems.ToString();
                }
                if (configAttribute.MaximumItems > -1)
                {
                    maxNumberString = configAttribute.MaximumItems.ToString();
                }
                typeAlias += "," + configAttribute.AllowedDescendantString;
            }

            if (maxNumberOverride != -1)
            {
                maxNumberString = maxNumberOverride.ToString();
            }

            result.Add("startNode", new PreValue(id: 0, value: "{\"type\": \"" + _type.ToString() + "\"" + startNodeString + "}", sortOrder: 1));
            result.Add("filter", new PreValue(id: 0, value: typeAlias, sortOrder: 2));
            result.Add("minNumber", new PreValue(id: 0, value: minNumberString, sortOrder: 3));
            result.Add("maxNumber", new PreValue(id: 0, value: maxNumberString, sortOrder: 4));
            if (configAttribute != null)
            {
                result.Add("showEditButton", new PreValue(id: 0, value: configAttribute.ShowEditButton ? "1" : "0", sortOrder: 5));
                result.Add("showOpenButton", new PreValue(id: 0, value: configAttribute.ShowOpenButton ? "1" : "0", sortOrder: 6));
                result.Add("showPathOnHover", new PreValue(id: 0, value: configAttribute.ShowPathsWhenHovering ? "1" : "0", sortOrder: 7));
            }
            else
            {
                result.Add("showEditButton", new PreValue(id: 0, value: "0", sortOrder: 5));
                result.Add("showOpenButton", new PreValue(id: 0, value: "0", sortOrder: 6));
                result.Add("showPathOnHover", new PreValue(id: 0, value: "0", sortOrder: 7));
            }
            return(result);
        }
예제 #3
0
 public virtual IDictionary <string, PreValue> GetPreValues(PreValueContext context)
 {
     return(GetPreValuesInternal(context));
 }