private void RecursiveDataBindInternal(IHierarchicalEnumerable enumerable, StringBuilder sb)
        {
            bool first = true;

            if (this.Site != null)
            {
                return;
            }
            foreach (object item in enumerable)
            {
                IHierarchyData data = enumerable.GetHierarchyData(item);
                if (null != data)
                {
                    PropertyDescriptorCollection props = TypeDescriptor.GetProperties(data);
                    if (props.Count > 0)
                    {
                        string title       = ((string)(props["Title"].GetValue(data)));
                        string description = ((string)(props["Description"].GetValue(data)));
                        string url         = ((string)(props["Url"].GetValue(data)));
                        string cssClass    = null;
                        if (item is SiteMapNode)
                        {
                            cssClass = ((SiteMapNode)(item))["cssClass"];
                        }
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            sb.Append(",");
                        }
                        sb.AppendFormat("{{\'title\':\'{0}\',\'url\':\'{1}\'", BusinessRules.JavaScriptString(title), BusinessRules.JavaScriptString(url));
                        if (!(String.IsNullOrEmpty(description)))
                        {
                            sb.AppendFormat(",\'description\':\'{0}\'", BusinessRules.JavaScriptString(description));
                        }
                        if (url == Page.Request.RawUrl)
                        {
                            sb.Append(",\'selected\':true");
                        }
                        if (!(String.IsNullOrEmpty(cssClass)))
                        {
                            sb.AppendFormat(",\'cssClass\':\'{0}\'", cssClass);
                        }
                        if (data.HasChildren)
                        {
                            IHierarchicalEnumerable childEnumerable = data.GetChildren();
                            if (null != childEnumerable)
                            {
                                sb.Append(",\'children\':[");
                                RecursiveDataBindInternal(childEnumerable, sb);
                                sb.Append("]");
                            }
                        }
                        sb.Append("}");
                    }
                }
            }
        }
Esempio n. 2
0
    // <Snippet3>
    private void Page_Load(object sender, System.EventArgs e)
    {
        IHierarchicalEnumerable ihe         = (IHierarchicalEnumerable)SiteMap.RootNode.ChildNodes;
        IEnumerator             enumeration = ihe.GetEnumerator();

        while (enumeration.MoveNext())
        {
            // Print out SiteMapNode Titles.
            IHierarchyData hierarchicalNode = ihe.GetHierarchyData(enumeration.Current);
            PrintFullChildNodeInfo(hierarchicalNode);
        }
    }
Esempio n. 3
0
 private void FillBoundChildrenRecursive(IHierarchicalEnumerable hEnumerable, MyTreeNodeCollection nodeCollection)
 {
     if (hEnumerable != null)
     {
         foreach (object obj2 in hEnumerable)
         {
             IHierarchyData hierarchyData = hEnumerable.GetHierarchyData(obj2);
             MyTreeNode     child         = new MyTreeNode(this);
             nodeCollection.Add(child);
             child.Bind(hierarchyData);
             if (((this.MaxDataBindDepth < 0) || (child.Depth != this.MaxDataBindDepth)) && ((hierarchyData != null) && hierarchyData.HasChildren))
             {
                 IHierarchicalEnumerable children = hierarchyData.GetChildren();
                 this.FillBoundChildrenRecursive(children, child.ChildNodes);
             }
         }
     }
 }
Esempio n. 4
0
    protected void ASPxCallback1_Callback(object sender, CallbackEventArgs e)
    {
        int newsID = int.Parse(e.Parameter);
        IHierarchicalDataSource    dataSource = (IHierarchicalDataSource)XmlDataSource1;
        HierarchicalDataSourceView view       = dataSource.GetHierarchicalView("");
        IHierarchicalEnumerable    enumerable = view.Select();
        int    index = 1;
        string text  = "";

        foreach (object obj in enumerable)
        {
            if (newsID == index)
            {
                IHierarchyData data = enumerable.GetHierarchyData(obj);
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(data);
                PropertyDescriptor           descriptor = properties.Find("Text", true);
                text = descriptor.GetValue(obj).ToString();
                break;
            }
            index++;
        }
        e.Result = text;
    }
Esempio n. 5
0
        public void GetHierarchicalView()
        {
            Page    page = new Page();
            DSPoker ds   = new DSPoker();

            ds.ID   = "ds";
            ds.Data = @"<?xml version=""1.0"" encoding=""utf-8""?>
					<bookstore xmlns:bk=""urn:samples"">
					  <book genre=""novel"" publicationdate=""1999"" bk:ISBN=""0192100262"">
					    <title>Pride and Prejudice</title>
					    <author>
					      <first-name>Jane</first-name>
					      <last-name>Austen</last-name>
					    </author>
					    <price>24.95</price>
					  </book>
					  <book genre=""novel"" publicationdate=""1985"" bk:ISBN=""0771008139"">
					    <title>The Handmaid's Tale</title>
					    <author>
					      <first-name>Margaret</first-name>
					      <last-name>Atwood</last-name>
					    </author>
					    <price>29.95</price>
					  </book>
					</bookstore>"                    ;
            HierarchicalDataSourceView view = ds.DoGetHierarchicalView("");
            IHierarchicalEnumerable    num  = view.Select();

            foreach (object obj in num)
            {
                IHierarchyData hdata   = num.GetHierarchyData(obj);
                XmlElement     element = (XmlElement)hdata.Item;
                Assert.AreEqual("bookstore", element.Name, "RootElementName");
                Assert.AreEqual("Pride and PrejudiceJaneAusten24.95The Handmaid's TaleMargaretAtwood29.95", element.InnerText, "InnerText");
                Assert.AreEqual(2, element.ChildNodes.Count, "ChildElementNodes");
            }
        }
Esempio n. 6
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);
                    }
                }
            }
        }
Esempio n. 7
0
        private void RecursiveDataBindInternal(IHierarchicalEnumerable enumerable, StringBuilder sb)
        {
            bool first = true;

            if (this.Site != null)
            {
                return;
            }
            foreach (object item in enumerable)
            {
                IHierarchyData data = enumerable.GetHierarchyData(item);
                if (null != data)
                {
                    PropertyDescriptorCollection props = TypeDescriptor.GetProperties(data);
                    if (props.Count > 0)
                    {
                        string title       = ((string)(props["Title"].GetValue(data)));
                        string description = ((string)(props["Description"].GetValue(data)));
                        string url         = ((string)(props["Url"].GetValue(data)));
                        string cssClass    = null;
                        bool   isPublic    = false;
                        if (item is SiteMapNode)
                        {
                            cssClass = ((SiteMapNode)(item))["cssClass"];
                            isPublic = ("true" == ((string)(((SiteMapNode)(item))["public"])));
                        }
                        string    roles    = String.Empty;
                        ArrayList roleList = ((ArrayList)(props["Roles"].GetValue(data)));
                        if (roleList.Count > 0)
                        {
                            roles = String.Join(",", ((string[])(roleList.ToArray(typeof(string)))));
                        }
                        bool resourceAuthorized = true;
                        if (resourceAuthorized)
                        {
                            if (first)
                            {
                                first = false;
                            }
                            else
                            {
                                sb.Append(",");
                            }
                            sb.AppendFormat("{{title:\"{0}\",url:\"{1}\"", BusinessRules.JavaScriptString(title), BusinessRules.JavaScriptString(url));
                            if (!(String.IsNullOrEmpty(description)))
                            {
                                sb.AppendFormat(",description:\"{0}\"", BusinessRules.JavaScriptString(description));
                            }
                            if (url == Page.Request.RawUrl)
                            {
                                sb.Append(",selected:true");
                            }
                            if (!(String.IsNullOrEmpty(cssClass)))
                            {
                                sb.AppendFormat(",cssClass:\"{0}\"", cssClass);
                            }
                            if (data.HasChildren)
                            {
                                IHierarchicalEnumerable childrenEnumerable = data.GetChildren();
                                if (null != childrenEnumerable)
                                {
                                    sb.Append(",\"children\":[");
                                    RecursiveDataBindInternal(childrenEnumerable, sb);
                                    sb.Append("]");
                                }
                            }
                            sb.Append("}");
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 private void BuildMainMenu(IHierarchicalEnumerable enumerable, StringBuilder sb, int depth)
 {
     foreach (object item in enumerable)
     {
         IHierarchyData data = enumerable.GetHierarchyData(item);
         if (data != null)
         {
             PropertyDescriptorCollection props = TypeDescriptor.GetProperties(data);
             if (props.Count > 0)
             {
                 string    title       = ((string)(props["Title"].GetValue(data)));
                 string    description = ((string)(props["Description"].GetValue(data)));
                 string    url         = ((string)(props["Url"].GetValue(data)));
                 string    cssClass    = null;
                 string    roles       = null;
                 ArrayList roleList    = ((ArrayList)(props["Roles"].GetValue(data)));
                 if (roleList.Count > 0)
                 {
                     roles = String.Join(",", ((string[])(roleList.ToArray(typeof(string)))));
                 }
                 if (item is SiteMapNode)
                 {
                     cssClass = ((SiteMapNode)(item))["cssClass"];
                     if ("true" == ((SiteMapNode)(item))["public"])
                     {
                         roles = "?";
                     }
                 }
                 sb.AppendFormat("{0} {1}", new String('+', depth), title);
                 sb.AppendLine();
                 if (!(String.IsNullOrEmpty(url)))
                 {
                     sb.AppendLine(url);
                 }
                 else
                 {
                     sb.AppendLine("about:blank");
                 }
                 if (!(String.IsNullOrEmpty(description)))
                 {
                     sb.AppendFormat("description: {0}", description);
                     sb.AppendLine();
                 }
                 if (!(String.IsNullOrEmpty(roles)))
                 {
                     sb.AppendFormat("roles: {0}", roles);
                     sb.AppendLine();
                 }
                 if (!(String.IsNullOrEmpty(cssClass)))
                 {
                     sb.AppendFormat("css-class: {0}", cssClass);
                     sb.AppendLine();
                 }
                 sb.AppendLine();
                 if (data.HasChildren)
                 {
                     IHierarchicalEnumerable childrenEnumerable = data.GetChildren();
                     if (childrenEnumerable != null)
                     {
                         BuildMainMenu(childrenEnumerable, sb, (depth + 1));
                     }
                 }
             }
         }
     }
 }
Esempio n. 9
0
		void FillBoundChildrenRecursive (IHierarchicalEnumerable hEnumerable, TreeNodeCollection nodeCollection)
		{
			if (hEnumerable == null)
				return;			
			
			foreach (object obj in hEnumerable) {
				IHierarchyData hdata = hEnumerable.GetHierarchyData (obj);
				TreeNode child = new TreeNode ();
				nodeCollection.Add (child);
				child.Bind (hdata);
				OnTreeNodeDataBound (new TreeNodeEventArgs (child));

				if (MaxDataBindDepth >= 0 && child.Depth == MaxDataBindDepth)
					continue;

				if (hdata == null || !hdata.HasChildren)
					continue;

				IHierarchicalEnumerable e = hdata.GetChildren ();
				FillBoundChildrenRecursive (e, child.ChildNodes);
			}
		}
Esempio n. 10
0
 private void RecursiveDataBindInternal(IHierarchicalEnumerable enumerable, StringBuilder sb)
 {
     bool first = true;
     if (this.Site != null)
         return;
     foreach (object item in enumerable)
     {
         IHierarchyData data = enumerable.GetHierarchyData(item);
         if (null != data)
         {
             PropertyDescriptorCollection props = TypeDescriptor.GetProperties(data);
             if (props.Count > 0)
             {
                 string title = ((string)(props["Title"].GetValue(data)));
                 string description = ((string)(props["Description"].GetValue(data)));
                 string url = ((string)(props["Url"].GetValue(data)));
                 string cssClass = null;
                 bool isPublic = false;
                 if (item is SiteMapNode)
                 {
                     cssClass = ((SiteMapNode)(item))["cssClass"];
                     isPublic = ("true" == ((string)(((SiteMapNode)(item))["public"])));
                 }
                 bool resourceAuthorized = true;
                 if (resourceAuthorized)
                 {
                     if (first)
                         first = false;
                     else
                         sb.Append(",");
                     sb.AppendFormat("{{title:\"{0}\",url:\"{1}\"", BusinessRules.JavaScriptString(title), BusinessRules.JavaScriptString(url));
                     if (!(String.IsNullOrEmpty(description)))
                         sb.AppendFormat(",description:\"{0}\"", BusinessRules.JavaScriptString(description));
                     if (url == Page.Request.RawUrl)
                         sb.Append(",selected:true");
                     if (!(String.IsNullOrEmpty(cssClass)))
                         sb.AppendFormat(",cssClass:\"{0}\"", cssClass);
                     if (data.HasChildren)
                     {
                         IHierarchicalEnumerable childrenEnumerable = data.GetChildren();
                         if (null != childrenEnumerable)
                         {
                             sb.Append(",\"children\":[");
                             RecursiveDataBindInternal(childrenEnumerable, sb);
                             sb.Append("]");
                         }
                     }
                     sb.Append("}");
                 }
             }
         }
     }
 }
Esempio n. 11
0
		void FillBoundChildrenRecursive (IHierarchicalEnumerable hEnumerable, MenuItemCollection itemCollection)
		{
			if (hEnumerable == null)
				return;
			foreach (object obj in hEnumerable) {
				IHierarchyData hdata = hEnumerable.GetHierarchyData (obj);
				MenuItem item = new MenuItem ();
				itemCollection.Add (item);
				item.Bind (hdata);

				SiteMapNode siteMapNode = hdata as SiteMapNode;
				if (siteMapNode != null) {
					if (_currSiteMapNode == null)
						_currSiteMapNode = siteMapNode.Provider.CurrentNode;
					if (siteMapNode == _currSiteMapNode)
						item.Selected = true;
				}
				
				OnMenuItemDataBound (new MenuEventArgs (item));

				if (hdata == null || !hdata.HasChildren)
					continue;

				IHierarchicalEnumerable e = hdata.GetChildren ();
				FillBoundChildrenRecursive (e, item.ChildItems);
			}
		}
Esempio n. 12
0
// <snippet5>
        private void RecurseDataBindInternal(TreeNode node,
                                             IHierarchicalEnumerable enumerable, int depth)
        {
            foreach (object item in enumerable)
            {
                IHierarchyData data = enumerable.GetHierarchyData(item);

                if (null != data)
                {
                    // Create an object that represents the bound data
                    // to the control.
                    TreeNode     newNode = new TreeNode();
                    RootViewNode rvnode  = new RootViewNode();

                    rvnode.Node  = newNode;
                    rvnode.Depth = depth;

                    // The dataItem is not just a string, but potentially
                    // an XML node or some other container.
                    // If DataTextField is set, use it to determine which
                    // field to render. Otherwise, use the first field.
                    if (DataTextField.Length > 0)
                    {
                        newNode.Text = DataBinder.GetPropertyValue
                                           (data, DataTextField, null);
                    }
                    else
                    {
                        PropertyDescriptorCollection props =
                            TypeDescriptor.GetProperties(data);

                        // Set the "default" value of the node.
                        newNode.Text = String.Empty;

                        // Set the true data-bound value of the TextBox,
                        // if possible.
                        if (props.Count >= 1)
                        {
                            if (null != props[0].GetValue(data))
                            {
                                newNode.Text =
                                    props[0].GetValue(data).ToString();
                            }
                        }
                    }

                    Nodes.Add(rvnode);

                    if (data.HasChildren)
                    {
                        IHierarchicalEnumerable newEnumerable =
                            data.GetChildren();
                        if (newEnumerable != null)
                        {
                            RecurseDataBindInternal(newNode,
                                                    newEnumerable, depth + 1);
                        }
                    }

                    if (_maxDepth < depth)
                    {
                        _maxDepth = depth;
                    }
                }
            }
        }