コード例 #1
0
        public override ConfigItem TryGetConfigItem(string key)
        {
            key = key.ToLowerInvariant();

            var data = configItemsFunc();

            if (data.ContainsKey(key))
            {
                return(data[key]);
            }

            return(ConfigItemCollection?.TryGetConfigItem(key));
        }
コード例 #2
0
        private void DataBindRecursive(Node node, IHierarchicalEnumerable enumerable)
        {            
            int depth = node != null ? (node.Depth + 1) : 0;

            foreach (object item in enumerable)
            {
                IHierarchyData data = enumerable.GetHierarchyData(item);

                string nodeId = "";
                bool leaf = false;
                bool allowDrag = true;
                bool allowDrop = true;
                bool? _checked = null;
                string cls = "";
                bool editable = true;
                bool expandable = false;
                bool expanded = false;
                string href = "#";
                string hrefTarget = "";
                string iconFile = "";
                Icon icon = Icon.None;
                string iconCls = "";
                string qtip = "";
                string qtitle = "";
                string text = ""; 
                ConfigItemCollection customAttributes = null;
                object attributesObject = null;

                string dataMember = String.Empty;                

                dataMember = data.Type;

                NodeBinding level = this.DataBindings.GetBinding(dataMember, depth);

                bool populateOnDemand = level.PopulateOnDemand;

                if (level != null)
                {
                    PropertyDescriptorCollection props = TypeDescriptor.GetProperties(item);
                    
                    string field = level.TextField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (!String.IsNullOrEmpty(level.FormatString))
                                {
                                    text = string.Format(CultureInfo.CurrentCulture, level.FormatString, objData);
                                }
                                else
                                {
                                    text = objData.ToString();
                                }
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "TextField"));
                        }
                    }

                    if (String.IsNullOrEmpty(text))
                    {
                        text = level.Text;
                    }


                    field = level.NodeIDField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                nodeId = objData.ToString();
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "NodeIDField"));
                        }
                    }
                    else
                    {
                        nodeId = level.NodeID;
                    }

                    field = level.LeafField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (objData is bool)
                                {
                                    leaf = (bool)objData;
                                }
                                else
                                {
                                    if (!bool.TryParse(objData.ToString(), out leaf))
                                    {
                                        throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "LeafField"));
                                    }
                                }
                            }
                            else
                            {
                                leaf = level.Leaf;
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "LeafField"));
                        }
                    }
                    else
                    {
                        leaf = level.Leaf;
                    }

                    field = level.AllowDragField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (objData is bool)
                                {
                                    allowDrag = (bool)objData;
                                }
                                else
                                {
                                    if (!bool.TryParse(objData.ToString(), out allowDrag))
                                    {
                                        throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "AllowDragField"));
                                    }
                                }
                            }
                            else
                            {
                                allowDrag = level.AllowDrag;
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "AllowDragField"));
                        }
                    }
                    else
                    {
                        allowDrag = level.AllowDrag;
                    }

                    field = level.AllowDropField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (objData is bool)
                                {
                                    allowDrop = (bool)objData;
                                }
                                else
                                {
                                    if (!bool.TryParse(objData.ToString(), out allowDrop))
                                    {
                                        throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "AllowDropField"));
                                    }
                                }
                            }
                            else
                            {
                                allowDrop = level.AllowDrop;
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "AllowDropField"));
                        }
                    }
                    else
                    {
                        allowDrop = level.AllowDrop;
                    }

                    field = level.CheckedField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (objData is bool?)
                                {
                                    _checked = (bool?)objData;
                                }
                                else if (objData is bool)
                                {
                                    _checked = (bool)objData;
                                }
                                else
                                {
                                    bool _temp;
                                    if (!bool.TryParse(objData.ToString(), out _temp))
                                    {
                                        throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "CheckedField"));
                                    }
                                    _checked = _temp;
                                }
                            }
                            else
                            {
                                _checked = level.Checked;
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "CheckedField"));
                        }
                    }
                    else
                    {
                        _checked = level.Checked;
                    }

                    field = level.ExpandableField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (objData is bool)
                                {
                                    expandable = (bool)objData;
                                }
                                else
                                {
                                    bool _temp;
                                    if (!bool.TryParse(objData.ToString(), out _temp))
                                    {
                                        throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "ExpandableField"));
                                    }
                                    expandable = _temp;
                                }
                            }
                            else
                            {
                                expandable = level.Expandable.HasValue ? level.Expandable.Value : false;
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "ExpandableField"));
                        }
                    }
                    else
                    {
                        expandable = level.Expandable.HasValue ? level.Expandable.Value : false;
                    }

                    field = level.EditableField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (objData is bool)
                                {
                                    editable = (bool)objData;
                                }
                                else
                                {
                                    if (!bool.TryParse(objData.ToString(), out editable))
                                    {
                                        throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "EditableField"));
                                    }
                                }
                            }
                            else
                            {
                                editable = level.Editable;
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "EditableField"));
                        }
                    }
                    else
                    {
                        editable = level.Editable;
                    }

                    field = level.ExpandedField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (objData is bool)
                                {
                                    expanded = (bool)objData;
                                }
                                else
                                {
                                    if (!bool.TryParse(objData.ToString(), out expanded))
                                    {
                                        throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "ExpandedField"));
                                    }
                                }
                            }
                            else
                            {
                                expanded = level.Expanded;
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "ExpandedField"));
                        }
                    }
                    else
                    {
                        expanded = level.Expanded;
                    }

                    field = level.ClsField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                cls = objData.ToString();
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "ClsField"));
                        }
                    }

                    if (String.IsNullOrEmpty(cls))
                    {
                        cls = level.Cls;
                    }

                    field = level.HrefField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                href = objData.ToString();
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "HrefField"));
                        }
                    }

                    if (String.IsNullOrEmpty(href))
                    {
                        href = level.Href;
                    }

                    field = level.HrefTargetField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                hrefTarget = objData.ToString();
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "HrefTargetField"));
                        }
                    }

                    if (String.IsNullOrEmpty(hrefTarget))
                    {
                        hrefTarget = level.HrefTarget;
                    }

                    field = level.IconFileField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                iconFile = objData.ToString();
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "IconFileField"));
                        }
                    }

                    if (String.IsNullOrEmpty(iconFile))
                    {
                        iconFile = level.IconFile;
                    }

                    field = level.IconClsField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                iconCls = objData.ToString();
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "IconClsField"));
                        }
                    }

                    if (String.IsNullOrEmpty(iconCls))
                    {
                        iconCls = level.IconCls;
                    }

                    field = level.QtipField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                qtip = objData.ToString();
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "QtipField"));
                        }
                    }

                    if (String.IsNullOrEmpty(qtip))
                    {
                        qtip = level.Qtip;
                    }

                    field = level.QtitleField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                qtitle = objData.ToString();
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "QtitleField"));
                        }
                    }

                    if (String.IsNullOrEmpty(qtitle))
                    {
                        qtitle = level.Qtitle;
                    }                    

                    field = level.IconField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                if (objData is Icon)
                                {
                                    icon = (Icon)objData;
                                }
                                else if (objData is string)
                                {
                                    try
                                    {
                                        icon = (Icon)Enum.Parse(typeof(Icon), objData.ToString(), true);
                                    }
                                    catch
                                    {
                                        throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "IconField"));
                                    }
                                }
                                else
                                {
                                    throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "IconField"));
                                }
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "IconField"));
                        }
                    }
                    else
                    {
                        icon = level.Icon;
                    }

                    field = level.AttributesField;
                    if (field.Length > 0)
                    {
                        PropertyDescriptor desc = props.Find(field, true);
                        if (desc != null)
                        {
                            object objData = desc.GetValue(item);
                            if (objData != null)
                            {
                                attributesObject = objData;
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(ServiceMessages.TREESTORE_INVALID_DATA_BINDING.FormatWith(field, "AttributesField"));
                        }
                    }
                    else
                    {
                        attributesObject = level.AttributesObject;
                    }

                    customAttributes = new ConfigItemCollection();
                    customAttributes.AddRange(level.CustomAttributes);                    
                }
                else
                {
                    if (item is INavigateUIData)
                    {
                        INavigateUIData navigateUIData = (INavigateUIData)item;
                        text = navigateUIData.Name;
                        href = navigateUIData.NavigateUrl;
                        customAttributes = new ConfigItemCollection { 
                            new ConfigItem("value", navigateUIData.Value, ParameterMode.Value)
                        };
                        
                        qtip = navigateUIData.Description;
                    }

                    populateOnDemand = false;
                }                

                Node newNode = new Node();
                if (nodeId.IsNotEmpty())
                {
                    newNode.NodeID = nodeId;
                }

                if (text.IsNotEmpty())
                {
                    newNode.Text = text;
                }

                newNode.Leaf = leaf;
                newNode.AllowDrag = allowDrag;
                newNode.AllowDrop = allowDrop;
                newNode.Checked = _checked;
                newNode.Expandable = expandable;
                newNode.Expanded = expanded;

                if (cls.IsNotEmpty())
                {
                    newNode.Cls = cls;
                }

                if (href.IsNotEmpty())
                {
                    newNode.Href = href;
                }

                if (hrefTarget.IsNotEmpty())
                {
                    newNode.HrefTarget = hrefTarget;
                }

                if (iconFile.IsNotEmpty())
                {
                    newNode.IconFile = iconFile;
                }

                if (iconCls.IsNotEmpty())
                {
                    newNode.IconCls = iconCls;
                }

                if (qtip.IsNotEmpty())
                {
                    newNode.Qtip = qtip;
                }

                if (qtitle.IsNotEmpty())
                {
                    newNode.Qtitle = qtitle;
                }

                if (customAttributes != null)
                {
                    newNode.CustomAttributes.AddRange(customAttributes);
                }

                if (attributesObject != null)
                {
                    newNode.AttributesObject = attributesObject;
                }

                if (icon != Icon.None)
                {
                    newNode.Icon = icon;
                }

                if (!newNode.Leaf && populateOnDemand)
                {
                    newNode.DataPath = data.Path;
                }

                if (node == null)
                {
                    this.Root.Add(newNode);
                }
                else
                {
                    node.Children.Add(newNode);
                }                

                if (String.Equals(data.Path, this.currentSiteMapNodeDataPath, StringComparison.OrdinalIgnoreCase))
                {
                    //newNode.Selected = true; //??? may be implemente selected property for the node

                    if (!X.IsAjaxRequest)
                    {
                        Node newNodeParent = newNode.ParentNode;
                        while (newNodeParent != null)
                        {
                            if (newNodeParent.Expanded != true)
                            {
                                newNodeParent.Expanded = true;
                            }

                            newNodeParent = newNodeParent.ParentNode;
                        }
                    }
                }

                if (data.HasChildren && !populateOnDemand)
                {
                    IHierarchicalEnumerable newEnumerable = data.GetChildren();
                    if (newEnumerable != null)
                    {
                        this.DataBindRecursive(newNode, newEnumerable);
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="modelName"></param>
        /// <param name="props"></param>
        /// <param name="item"></param>
        /// <param name="attrs"></param>
        protected virtual void GetModelProperties(string modelName, PropertyDescriptorCollection props, object item, ConfigItemCollection attrs)
        {
            var model = Ext.Net.Model.Get(modelName);
            if (model == null)
            {
                return;
            }

            foreach (var field in model.Fields)
            {
                object value = this.GetFieldValue(props, item, field);
                if (value != null)
                {
                    attrs.Add(new ConfigItem(string.IsNullOrEmpty(field.Mapping) ? field.Name : field.Mapping, JSON.Serialize(value), ParameterMode.Raw));
                }
            }
        }
コード例 #4
0
ファイル: ConfigGroup.cs プロジェクト: Nementon/ck-desktop
 public ConfigGroup( ConfigManager configManager )
     : base( configManager )
 {
     Items = new ConfigItemCollection( this );
 }