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("}");
                    }
                }
            }
        }
Beispiel #2
0
// <snippet4>
        protected override void PerformDataBinding()
        {
            base.PerformDataBinding();

            // Do not attempt to bind data if there is no
            // data source set.
            if (!IsBoundUsingDataSourceID && (DataSource == null))
            {
                return;
            }

            HierarchicalDataSourceView view = GetData(RootNode.DataPath);

            if (view == null)
            {
                throw new InvalidOperationException
                          ("No view returned by data source control.");
            }

            IHierarchicalEnumerable enumerable = view.Select();

            if (enumerable != null)
            {
                Nodes.Clear();

                try {
                    RecurseDataBindInternal(RootNode, enumerable, 1);
                }
                finally {
                }
            }
        }
 /// <summary>
 /// Renders the menu
 /// </summary>
 /// <param name="menuItems"></param>
 /// <returns></returns>
 public string Render(IHierarchicalEnumerable menuItems)
 {
     StringBuilder menuDiv = new StringBuilder();
     menuDiv.AppendLine("<div id=\"myslidemenu\" class=\"jqueryslidemenu\">");
     RenderMenuItems(menuDiv, menuItems, 0);
     menuDiv.AppendLine("<br style=\"clear: left\" />");
     menuDiv.AppendLine("</div>");
     return menuDiv.ToString();
 }
Beispiel #4
0
        public override IHierarchicalEnumerable GetDesignTimeData(out bool isSampleData)
        {
            IHierarchicalEnumerable hierarchicalRuntimeEnumerable = this._owner.GetHierarchicalRuntimeEnumerable(base.Path);

            if (hierarchicalRuntimeEnumerable != null)
            {
                isSampleData = false;
                return(hierarchicalRuntimeEnumerable);
            }
            return(base.GetDesignTimeData(out isSampleData));
        }
Beispiel #5
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);
        }
    }
Beispiel #6
0
        protected override void PerformDataBinding()
        {
            base.PerformDataBinding();
            this.InitializeDataBindings();
            HierarchicalDataSourceView data = this.GetData(string.Empty);

            if (data != null)
            {
                this.Nodes.Clear();
                IHierarchicalEnumerable hEnumerable = data.Select();
                this.FillBoundChildrenRecursive(hEnumerable, this.Nodes);
            }
        }
        HierarchicalDataSourceView IHierarchicalDataSource.GetHierarchicalView(string viewPath)
        {
            IHierarchicalDataSource source = this._dataSource as IHierarchicalDataSource;

            if (source != null)
            {
                return(source.GetHierarchicalView(viewPath));
            }
            IHierarchicalEnumerable dataSource = this._dataSource as IHierarchicalEnumerable;

            if (((dataSource != null) && (viewPath != null)) && (viewPath.Length != 0))
            {
                throw new InvalidOperationException(System.Web.SR.GetString("ReadOnlyHierarchicalDataSourceView_CantAccessPathInEnumerable"));
            }
            return(new ReadOnlyHierarchicalDataSourceView(dataSource));
        }
Beispiel #8
0
        protected override void PerformDataBinding()
        {
            base.PerformDataBinding();
            if (!(IsBoundUsingDataSourceID) && (DataSource != null))
            {
                return;
            }
            HierarchicalDataSourceView view       = GetData(String.Empty);
            IHierarchicalEnumerable    enumerable = view.Select();

            if (enumerable != null)
            {
                StringBuilder sb = new StringBuilder();
                RecursiveDataBindInternal(enumerable, sb);
                _items = sb.ToString();
            }
        }
Beispiel #9
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);
             }
         }
     }
 }
        /// <devdoc>
        /// Check for IHierarchicalDataSource and IHierarchicalEnumerable, and
        /// return an approprite HierarchicalDataSourceView.
        /// </devdoc>
        HierarchicalDataSourceView IHierarchicalDataSource.GetHierarchicalView(string viewPath)
        {
            // Check first for IHierarchicalDataSource
            IHierarchicalDataSource ds = _dataSource as IHierarchicalDataSource;

            if (ds != null)
            {
                return(ds.GetHierarchicalView(viewPath));
            }

            IHierarchicalEnumerable enumerable = _dataSource as IHierarchicalEnumerable;

            if (enumerable != null && viewPath != null && viewPath.Length != 0)
            {
                throw new InvalidOperationException(SR.GetString(SR.ReadOnlyHierarchicalDataSourceView_CantAccessPathInEnumerable));
            }
            return(new ReadOnlyHierarchicalDataSourceView(enumerable));
        }
Beispiel #11
0
        protected virtual IHierarchicalEnumerable GetDesignTimeDataSource()
        {
            bool flag;
            IHierarchicalEnumerable            designTimeData = null;
            DesignerHierarchicalDataSourceView designerView   = this.DesignerView;

            if (designerView != null)
            {
                try
                {
                    designTimeData = designerView.GetDesignTimeData(out flag);
                }
                catch (Exception exception)
                {
                    if (base.Component.Site != null)
                    {
                        IComponentDesignerDebugService service = (IComponentDesignerDebugService)base.Component.Site.GetService(typeof(IComponentDesignerDebugService));
                        if (service != null)
                        {
                            service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerHierarchicalDataSourceView.GetDesignTimeData", exception.Message }));
                        }
                    }
                }
            }
            else
            {
                DataBinding binding = base.DataBindings["DataSource"];
                if (binding != null)
                {
                    designTimeData = DesignTimeData.GetSelectedDataSource(base.Component, binding.Expression, null) as IHierarchicalEnumerable;
                }
            }
            if (designTimeData != null)
            {
                ICollection is2 = designTimeData as ICollection;
                if ((is2 == null) || (is2.Count > 0))
                {
                    return(designTimeData);
                }
            }
            flag = true;
            return(this.GetSampleDataSource());
        }
Beispiel #12
0
        void FillGridWithHierarchicalData(C1FlexGrid flex, IHierarchicalEnumerable dataSource)
        {
            // configure grid
            flex.Rows.Count      = flex.Rows.Fixed;
            flex.Cols.Count      = flex.Cols.Fixed + 1;
            flex.Tree.Column     = flex.Cols.Count - 1;
            flex.ExtendLastCol   = true;
            flex.AllowEditing    = false;
            flex.Cols[1].Caption = "Items";

            // add data
            foreach (IHierarchyData item in dataSource)
            {
                var p = item.GetParent();
                if (p == null)
                {
                    AddItem(flex, item, 0);
                }
            }
        }
Beispiel #13
0
        protected override void DataBind(BaseDataBoundControl dataBoundControl)
        {
            IHierarchicalEnumerable designTimeDataSource = this.GetDesignTimeDataSource();
            string dataSourceID = dataBoundControl.DataSourceID;
            object dataSource   = dataBoundControl.DataSource;
            HierarchicalDataBoundControl control = (HierarchicalDataBoundControl)dataBoundControl;

            control.DataSource   = designTimeDataSource;
            control.DataSourceID = string.Empty;
            try
            {
                if (designTimeDataSource != null)
                {
                    control.DataBind();
                }
            }
            finally
            {
                control.DataSource   = dataSource;
                control.DataSourceID = dataSourceID;
            }
        }
        public override IHierarchicalEnumerable GetDesignTimeData(out bool isSampleData)
        {
            string siteMapProvider             = null;
            string startingNodeUrl             = null;
            IHierarchicalEnumerable enumerable = null;

            isSampleData    = true;
            siteMapProvider = this._owner.SiteMapDataSource.SiteMapProvider;
            startingNodeUrl = this._owner.SiteMapDataSource.StartingNodeUrl;
            this._owner.SiteMapDataSource.Provider = this._owner.DesignTimeSiteMapProvider;
            try
            {
                this._owner.SiteMapDataSource.StartingNodeUrl = null;
                enumerable   = ((IHierarchicalDataSource)this._owner.SiteMapDataSource).GetHierarchicalView(base.Path).Select();
                isSampleData = false;
            }
            finally
            {
                this._owner.SiteMapDataSource.StartingNodeUrl = startingNodeUrl;
                this._owner.SiteMapDataSource.SiteMapProvider = siteMapProvider;
            }
            return(enumerable);
        }
Beispiel #15
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;
    }
Beispiel #16
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");
            }
        }
Beispiel #17
0
 public ReadOnlyDataSourceView (IHierarchicalEnumerable datasource)
 {
     this.datasource = datasource;
 }
Beispiel #18
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("}");
                        }
                    }
                }
            }
        }
Beispiel #19
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));
                     }
                 }
             }
         }
     }
 }
Beispiel #20
0
        protected override void PerformDataBinding()
        {
            base.PerformDataBinding();
            if (!(IsBoundUsingDataSourceID) && (DataSource != null))
            {
                return;
            }
            HierarchicalDataSourceView view       = GetData(String.Empty);
            IHierarchicalEnumerable    enumerable = view.Select();

            if (ApplicationServices.IsSiteContentEnabled && !(ApplicationServices.IsSafeMode))
            {
                SiteContentFileList sitemaps = ApplicationServices.Current.ReadSiteContent("sys/sitemaps%", "%");
                if (sitemaps.Count > 0)
                {
                    bool hasMain = false;
                    foreach (SiteContentFile f in sitemaps)
                    {
                        if (f.PhysicalName == "main")
                        {
                            hasMain = true;
                            sitemaps.Remove(f);
                            sitemaps.Insert(0, f);
                            break;
                        }
                    }
                    if (!(hasMain) && (enumerable != null))
                    {
                        StringBuilder msb = new StringBuilder();
                        BuildMainMenu(enumerable, msb, 1);
                        SiteContentFile main = new SiteContentFile();
                        main.Text = Localizer.Replace("Pages", Path.GetFileName(Page.Request.PhysicalPath), msb.ToString());
                        sitemaps.Insert(0, main);
                    }
                    string text = null;
                    if (sitemaps.Count > 1)
                    {
                        SiteMapBuilder sm = new SiteMapBuilder();
                        foreach (SiteContentFile cf in sitemaps)
                        {
                            string sitemapText = cf.Text;
                            if (!(String.IsNullOrEmpty(sitemapText)))
                            {
                                MatchCollection coll = MenuItemRegex.Matches(sitemapText);
                                foreach (Match m in coll)
                                {
                                    sm.Insert(m.Groups["Title"].Value, m.Groups["Depth"].Value.Length, m.Groups["Text"].Value);
                                }
                            }
                        }
                        text = sm.ToString();
                    }
                    else
                    {
                        text = sitemaps[0].Text;
                    }
                    StringBuilder sb = new StringBuilder();
                    if (!(String.IsNullOrEmpty(text)))
                    {
                        bool  first = true;
                        Match m     = MenuItemRegex.Match(text);
                        while (m.Success)
                        {
                            BuildNode(ref m, sb, first);
                            if (first)
                            {
                                first = false;
                            }
                        }
                        _items = Regex.Replace(sb.ToString(), "(\\{\\}\\,?)+", String.Empty).Replace("},]", "}]");
                        return;
                    }
                }
            }
            if (enumerable != null)
            {
                StringBuilder sb = new StringBuilder();
                RecursiveDataBindInternal(enumerable, sb);
                _items = sb.ToString();
            }
        }
        private void RenderMenuItems(StringBuilder sb, IHierarchicalEnumerable menuItems, int count)
        {
            if (menuItems == null)
                return;

            sb.AppendLine("<ul>");

            foreach (SiteMapNode node in menuItems)
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "<li><a href=\"{0}\">{1}</a>", node.Url, node.Title);
                sb.AppendLine();

                if (!Pages.ContainsKey(node.Key))
                {
                    Pages.Add(node.Key, count.ToString(new NumberFormatInfo()));
                }

                if (node.HasChildNodes)
                {
                    RenderMenuItems(sb, node.ChildNodes, 1);
                }

                if (node.HasChildNodes)
                    sb.AppendLine("</li>");

                count++;
            }
            sb.AppendLine("</ul>");
        }
Beispiel #22
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;
                    }
                }
            }
        }
Beispiel #23
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);
			}
		}
Beispiel #24
0
 public ReadOnlyDataSourceView(IHierarchicalEnumerable datasource)
 {
     this.datasource = datasource;
 }
Beispiel #25
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("}");
                 }
             }
         }
     }
 }
Beispiel #26
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);
			}
		}
 public ReadOnlyHierarchicalDataSourceView(IHierarchicalEnumerable dataSource) {
     _dataSource = dataSource;
 }
 public ReadOnlyHierarchicalDataSourceView(IHierarchicalEnumerable dataSource)
 {
     _dataSource = dataSource;
 }
        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);
                    }
                }
            }
        }
 public HierarchicalModelDataSourceView(IHierarchicalEnumerable dataSource)
 {
     _dataSource = dataSource;
 }