private List <DataNode> AddNodes(TemplateNode template, List <ItemData> data) { var dummy = new DataNode(); foreach (var d in data) { AddNode(dummy, 0, template, d); } foreach (var c in dummy.Children) { c.Parent = this; } return(dummy.Children); }
/// <summary> /// Add node to hierarchy where root collection are nodes relating to groups[0]. If groups is empty, all nodes are added to root collection. /// </summary> /// <param name="parent"></param> /// <param name="groups"></param> /// <param name="currentGroup"></param> /// <param name="node"></param> private void AddNode(DataNode parent, int currentGroup, TemplateNode template, ItemData item) { if (currentGroup >= template.GroupBy.Count) { // add node to bottom level DataNode node = new DataNode(); node.DerivedFrom = template; node.Parent = parent; parent.Children.Add(node); node.ID = item.Id; node.Data = item.Data; node.Text = item.ReplacePlaceholders(template.Text); //node.IsMatch = results.Contains(item.Id); // TODO } else { // add group node if it doesn't already exist and recurse var field = item.Subject[template.GroupBy[currentGroup].FieldSourceName]; var format = (!String.IsNullOrEmpty(field.DisplayFormat) ? String.Concat("{0:", field.DisplayFormat, "}") : "{0}"); var groupName = String.Format(format, (item.Data[field] ?? "")); var groupNode = parent.Children.Find(n => n.Text.Equals(groupName)); if (groupNode == null) { groupNode = new DataNode(); groupNode.DerivedFrom = template; groupNode.Parent = parent; parent.Children.Add(groupNode); groupNode.GroupIndex = currentGroup; //node.ID = item.Id; //node.Data = item.Data; groupNode.Text = groupName; } AddNode(groupNode, currentGroup + 1, template, item); } }
private List<DataNode> AddNodes(TemplateNode template, List<ItemData> data) { var dummy = new DataNode(); foreach (var d in data) AddNode(dummy, 0, template, d); foreach (var c in dummy.Children) c.Parent = this; return dummy.Children; }
/// <summary> /// Add node to hierarchy where root collection are nodes relating to groups[0]. If groups is empty, all nodes are added to root collection. /// </summary> /// <param name="parent"></param> /// <param name="groups"></param> /// <param name="currentGroup"></param> /// <param name="node"></param> private void AddNode(DataNode parent, int currentGroup, TemplateNode template, ItemData item) { if (currentGroup >= template.GroupBy.Count) { // add node to bottom level DataNode node = new DataNode(); node.DerivedFrom = template; node.Parent = parent; parent.Children.Add(node); node.ID = item.Id; node.Data = item.Data; node.Text = item.ReplacePlaceholders (template.Text); //node.IsMatch = results.Contains(item.Id); // TODO } else { // add group node if it doesn't already exist and recurse var field = item.Subject[template.GroupBy[currentGroup].FieldSourceName]; var format = (!String.IsNullOrEmpty(field.DisplayFormat) ? String.Concat("{0:", field.DisplayFormat, "}") : "{0}"); var groupName = String.Format(format, (item.Data[field] ?? "")); var groupNode = parent.Children.Find(n => n.Text.Equals(groupName)); if (groupNode == null) { groupNode = new DataNode(); groupNode.DerivedFrom = template; groupNode.Parent = parent; parent.Children.Add(groupNode); groupNode.GroupIndex = currentGroup; //node.ID = item.Id; //node.Data = item.Data; groupNode.Text = groupName; } AddNode(groupNode, currentGroup + 1, template, item); } }