private void RestoreGrouping(LiveShapingItem lsi, CollectionViewGroupRoot.GroupTreeNode node, int level, List <AbandonedGroupItem> deleteList)
 {
     if (node.ContainsItem)
     {
         object obj = this.GetGroupName(lsi.Item, node.Group.GroupBy, level);
         if (obj != CollectionViewGroupRoot.UseAsItemDirectly)
         {
             ICollection c         = obj as ICollection;
             ArrayList   arrayList = c == null ? (ArrayList)null : new ArrayList(c);
             for (CollectionViewGroupRoot.GroupTreeNode groupTreeNode = node.FirstChild; groupTreeNode != null; groupTreeNode = groupTreeNode.Sibling)
             {
                 if (arrayList == null)
                 {
                     if (object.Equals(obj, groupTreeNode.Group.Name))
                     {
                         groupTreeNode.ContainsItem = true;
                         obj = DependencyProperty.UnsetValue;
                         break;
                     }
                 }
                 else if (arrayList.Contains(groupTreeNode.Group.Name))
                 {
                     groupTreeNode.ContainsItem = true;
                     arrayList.Remove(groupTreeNode.Group.Name);
                 }
             }
             if (arrayList == null)
             {
                 if (obj != DependencyProperty.UnsetValue)
                 {
                     this.AddToSubgroup(lsi.Item, lsi, node.Group, level, obj, false);
                 }
             }
             else
             {
                 foreach (object name in arrayList)
                 {
                     this.AddToSubgroup(lsi.Item, lsi, node.Group, level, name, false);
                 }
             }
         }
     }
     else if (node.ContainsItemDirectly)
     {
         deleteList.Add(new AbandonedGroupItem(lsi, node.Group));
     }
     for (CollectionViewGroupRoot.GroupTreeNode node1 = node.FirstChild; node1 != null; node1 = node1.Sibling)
     {
         this.RestoreGrouping(lsi, node1, level + 1, deleteList);
     }
 }
        private CollectionViewGroupRoot.GroupTreeNode BuildGroupTree(LiveShapingItem lsi)
        {
            CollectionViewGroupInternal viewGroupInternal1 = lsi.ParentGroup;

            if (viewGroupInternal1 != null)
            {
                CollectionViewGroupRoot.GroupTreeNode groupTreeNode = new CollectionViewGroupRoot.GroupTreeNode()
                {
                    Group = viewGroupInternal1,
                    ContainsItemDirectly = true
                };
                while (true)
                {
                    viewGroupInternal1 = viewGroupInternal1.Parent;
                    if (viewGroupInternal1 != null)
                    {
                        groupTreeNode = new CollectionViewGroupRoot.GroupTreeNode()
                        {
                            Group      = viewGroupInternal1,
                            FirstChild = groupTreeNode
                        }
                    }
                    ;
                    else
                    {
                        break;
                    }
                }
                return(groupTreeNode);
            }
            else
            {
                List <CollectionViewGroupInternal>           parentGroups   = lsi.ParentGroups;
                List <CollectionViewGroupRoot.GroupTreeNode> list           = new List <CollectionViewGroupRoot.GroupTreeNode>(parentGroups.Count + 1);
                CollectionViewGroupRoot.GroupTreeNode        groupTreeNode1 = (CollectionViewGroupRoot.GroupTreeNode)null;
                foreach (CollectionViewGroupInternal viewGroupInternal2 in parentGroups)
                {
                    CollectionViewGroupRoot.GroupTreeNode groupTreeNode2 = new CollectionViewGroupRoot.GroupTreeNode()
                    {
                        Group = viewGroupInternal2,
                        ContainsItemDirectly = true
                    };
                    list.Add(groupTreeNode2);
                }
                for (int index1 = 0; index1 < list.Count; ++index1)
                {
                    CollectionViewGroupRoot.GroupTreeNode groupTreeNode2 = list[index1];
                    CollectionViewGroupInternal           parent         = groupTreeNode2.Group.Parent;
                    CollectionViewGroupRoot.GroupTreeNode groupTreeNode3 = (CollectionViewGroupRoot.GroupTreeNode)null;
                    if (parent == null)
                    {
                        groupTreeNode1 = groupTreeNode2;
                    }
                    else
                    {
                        for (int index2 = list.Count - 1; index2 >= 0; --index2)
                        {
                            if (list[index2].Group == parent)
                            {
                                groupTreeNode3 = list[index2];
                                break;
                            }
                        }
                        if (groupTreeNode3 == null)
                        {
                            CollectionViewGroupRoot.GroupTreeNode groupTreeNode4 = new CollectionViewGroupRoot.GroupTreeNode()
                            {
                                Group      = parent,
                                FirstChild = groupTreeNode2
                            };
                            list.Add(groupTreeNode4);
                        }
                        else
                        {
                            groupTreeNode2.Sibling    = groupTreeNode3.FirstChild;
                            groupTreeNode3.FirstChild = groupTreeNode2;
                        }
                    }
                }
                return(groupTreeNode1);
            }
        }
 internal void RestoreGrouping(LiveShapingItem lsi, List <AbandonedGroupItem> deleteList)
 {
     CollectionViewGroupRoot.GroupTreeNode node = this.BuildGroupTree(lsi);
     node.ContainsItem = true;
     this.RestoreGrouping(lsi, node, 0, deleteList);
 }