Пример #1
0
        /// <summary>
        /// Upgrades the top menu navigation sections.
        /// </summary>
        /// <param name="topMenu">The top menu.</param>
        private static void UpgradeTopMenuNavSections(TopMenu topMenu)
        {
            NavSection appTabNavSection = null;
            var        resourcesToMove  = new List <Resource>();
            bool       saveAppTab       = false;

            if (topMenu.FolderContents == null)
            {
                return;
            }

            // Get all the immediate children of the top menu
            foreach (Resource resource in topMenu.FolderContents)
            {
                bool isAppTab   = false;
                var  navSection = resource.As <NavSection>();

                if (navSection != null && ((navSection.IsAppTab ?? false) || navSection.Name == topMenu.Name))
                {
                    isAppTab = true;
                }

                if (!isAppTab)
                {
                    resourcesToMove.Add(resource);
                }
                else
                {
                    if (appTabNavSection == null)
                    {
                        appTabNavSection = navSection.AsWritable <NavSection>();
                    }
                }
            }

            if (resourcesToMove.Count > 0)
            {
                // Clear the existing top menu items
                var topMenuWritable = topMenu.AsWritable <TopMenu>();
                var folderContents  = topMenuWritable.FolderContents;
                folderContents.RemoveRange(resourcesToMove);
                topMenuWritable.FolderContents = folderContents;
                topMenuWritable.Save();
            }

            if (appTabNavSection == null)
            {
                // Create a new app tab as a child of the top menu
                appTabNavSection      = CreateSection(topMenu.As <NavContainer>(), topMenu.InSolution, topMenu.Name, true);
                appTabNavSection.Name = topMenu.Name;
                saveAppTab            = true;
            }

            if (resourcesToMove.Count > 0)
            {
                var folderContents = appTabNavSection.FolderContents;
                folderContents.AddRange(resourcesToMove);
                appTabNavSection.FolderContents = folderContents;
                saveAppTab = true;
            }

            if (saveAppTab)
            {
                appTabNavSection.Save();
            }
        }