Esempio n. 1
0
 /// <summary>
 /// Gets all children hierarchy of this node.
 /// </summary>
 public static IEnumerable <IHierarchy> GetAllChildren(this IHierarchy @this)
 {
     return(@this.GetChildren()
            .Except(@this)
            .SelectMany(c => c.WithAllChildren())
            .OrderBy(i => i.GetFullPath())
            .ToArray());
 }
Esempio n. 2
0
        /// <summary>
        /// A formatter implementation that resolves a <see cref="IDictionary"/>.
        /// </summary>
        /// <param name="hierarchy">The hierarchy to parse.</param>
        /// <param name="valueTypes">The value types that forms a <see cref="KeyValuePair{TKey,TValue}"/>.</param>
        /// <returns>A <see cref="IDictionary"/> with <see cref="KeyValuePair{TKey,TValue}"/> of <paramref name="valueTypes"/> from the specified <paramref name="hierarchy"/>.</returns>
        public static IDictionary UseDictionary(this IHierarchy <DataPair> hierarchy, Type[] valueTypes)
        {
            var items       = hierarchy.GetChildren();
            var dic         = typeof(Dictionary <,>).MakeGenericType(valueTypes);
            var dicInstance = Activator.CreateInstance(dic);
            var addMethod   = dic.GetMethod("Add");

            foreach (var item in items.ParseDictionaryItem(valueTypes))
            {
                addMethod.Invoke(dicInstance, new[] { item.Key, item.Value });
            }
            return(dicInstance as IDictionary);
        }
Esempio n. 3
0
        /// <summary>
        /// A formatter implementation that resolves a <see cref="ICollection"/>.
        /// </summary>
        /// <param name="hierarchy">The hierarchy to parse.</param>
        /// <param name="valueType">The type of the objects in the collection.</param>
        /// <returns>A <see cref="ICollection"/> of <paramref name="valueType"/> from the specified <paramref name="hierarchy"/>.</returns>
        public static ICollection UseCollection(this IHierarchy <DataPair> hierarchy, Type valueType)
        {
            var items        = hierarchy.GetChildren();
            var list         = typeof(List <>).MakeGenericType(valueType);
            var listInstance = Activator.CreateInstance(list);
            var addMethod    = list.GetMethod("Add");

            foreach (var item in items.ParseCollectionItem(valueType))
            {
                addMethod.Invoke(listInstance, new[] { item });
            }
            return(listInstance as ICollection);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a hierarchy of nodes for a specified hirarchical item.
        /// </summary>
        public static void Add(this TreeNodeCollection nodes, IHierarchy item)
        {
            var node = new TreeNode(item.Name, item.GetId().ToString());

            foreach (var child in item.GetChildren())
            {
                node.ChildNodes.Add(child);
            }

            node.CollapseAll();
            node.SelectAction = TreeNodeSelectAction.None;

            nodes.Add(node);
        }
Esempio n. 5
0
        static void ConfigureTreeViewNode(this GridViewRow row, IHierarchy item, Func <IHierarchy, bool> isItemCollapsed)
        {
            var parent = item.GetParent();

            var isVisible = true;

            if (parent != null)
            {
                isVisible = !isItemCollapsed(parent);
            }

            var isCollapsed = isItemCollapsed(item);
            var isRoot      = parent == null;
            var isLeaf      = item.GetChildren().None();

            // setting up grid view row attributes
            row.Attributes["itemid"] = item.GetId().ToString();
            row.CssClass            += " {0}{1}{2}{3}".FormatWith(
                item.GetAllParents().Select(a => a.GetId()).ToString(" "),
                " treeview-leaf-node".OnlyWhen(isLeaf),
                " treeview-root-node".OnlyWhen(isRoot),
                " collapsed".OnlyWhen(isCollapsed && !isLeaf));

            if (!isVisible)
            {
                row.Style["display"]           = "none";
                row.Attributes["collapsedfor"] = parent.GetId().ToString();
            }

            // Creating additional controls
            var spacerSpan   = CreateSpacer(item.GetAllParents().Count());
            var collapseIcon = CreateLink(item.GetId().ToString());

            // putting additional controls in the right place
            var anchorControl = FindAnchorControl(row);

            var parentToAdd  = anchorControl?.Parent ?? row.Cells[0];
            var controlIndex = anchorControl == null ? 0 : parentToAdd.Controls.IndexOf(anchorControl);

            parentToAdd.Controls.AddAt(controlIndex, collapseIcon);
            parentToAdd.Controls.AddAt(controlIndex, spacerSpan);
        }
Esempio n. 6
0
        private void WriteXmlChildren(XmlWriter writer, IHierarchy <object> node)
        {
            foreach (IHierarchy <object> childNode in node.GetChildren().OrderByXmlAttributes())
            {
                if (childNode.HasXmlIgnoreAttribute())
                {
                    return;
                }

                XmlQualifiedEntity qualifiedEntity = childNode.LookupXmlStartElement();
                if (childNode.HasChildren && TypeUtility.IsComplex(childNode.InstanceType))
                {
                    writer.WriteStartElement(qualifiedEntity.Prefix, qualifiedEntity.LocalName, qualifiedEntity.Namespace);
                }
                WriteXmlNodes(writer, childNode);
                if (childNode.HasChildren && TypeUtility.IsComplex(childNode.InstanceType))
                {
                    writer.WriteEndElement();
                }
            }
        }
Esempio n. 7
0
 private void WriteXmlChildren(XmlWriter writer, IHierarchy <object> node)
 {
     foreach (IHierarchy <object> childNode in node.GetChildren().OrderByXmlAttributes())
     {
         if (childNode.HasXmlIgnoreAttribute())
         {
             continue;
         }
         if (!childNode.InstanceType.GetTypeInfo().IsValueType&& childNode.Instance == null)
         {
             continue;
         }
         if (childNode.InstanceType.IsEnumerable() && childNode.InstanceType != typeof(string) && !childNode.InstanceType.IsDictionary())
         {
             var i = childNode.Instance as IEnumerable;
             if (i == null || i.Cast <object>().Count() == 0)
             {
                 continue;
             }
         }
         XmlQualifiedEntity qualifiedEntity = childNode.LookupXmlStartElement();
         if (childNode.HasChildren && TypeUtility.IsComplex(childNode.InstanceType))
         {
             writer.WriteStartElement(qualifiedEntity);
         }
         var converter = Converters.FirstOrDefaultWriterConverter(childNode.InstanceType);
         if (converter != null)
         {
             converter.WriteXml(writer, childNode.Instance, qualifiedEntity);
         }
         else
         {
             WriteXmlNodes(writer, childNode);
         }
         if (childNode.HasChildren && TypeUtility.IsComplex(childNode.InstanceType))
         {
             writer.WriteEndElement();
         }
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Gets all children hierarchy of this node.
 /// </summary>
 public static IEnumerable <IHierarchy> GetAllChildren(this IHierarchy parent) =>
 parent.GetChildren().Except(parent).SelectMany(c => c.WithAllChildren()).OrderBy(i => i.GetFullPath()).ToArray();
Esempio n. 9
0
 internal static IEnumerable<IHierarchy<TSource>> DescendantsAndSelf<TSource>(IHierarchy<TSource> source)
 {
     return source.GetChildren();
 }