Пример #1
0
        /// <summary>
        /// Recursivly group all items ending with .csql together.
        /// </summary>
        /// <param name="items"></param>
        private void GroupItems(UIHierarchyItems items)
        {
            ItemGroups groups = new ItemGroups();

            // Build the groups
            foreach (UIHierarchyItem item in items)
            {
                bool isCSqlFile = false;
                if (IsFile(item))
                {
                    string fileName = GetItemFileName(item).ToLower().Trim();

                    if (fileName.Length > ".csql".Length && fileName.EndsWith(".csql"))
                    {
                        isCSqlFile = true;
                    }
                }
                if (isCSqlFile)
                {
                    string    name      = item.Name;
                    int       firstDot  = name.IndexOf('.');
                    string    groupName = name.Substring(0, firstDot);
                    ItemGroup group     = groups.GetGroup(groupName);
                    group.Items.Add(item);
                    AddSubItemsToItemGroup(group, item);
                }
                else
                {
                    GroupItems(item.UIHierarchyItems);
                }
            }

            // Restructure the project hierarchy.
            foreach (ItemGroup group in groups.Values)
            {
                if (group.MasterItem == null)
                {
                    continue;
                }

                UIHierarchyItem master = group.MasterItem;
                IEnumerable <UIHierarchyItem> childs = group.ChildItems;
                ProjectItem masterItem = (ProjectItem)master.Object;

                foreach (UIHierarchyItem item in childs)
                {
                    ProjectItem childItem = (ProjectItem)item.Object;
                    AddItemToMasterItem(masterItem, childItem);
                }
            }
        }