예제 #1
0
        public HttpResponseMessage ValidatePageTree(GenerateTabsPostModel model)
        {
            int level         = 0;
            int previousLevel = -1;
            int lineCounter   = 0;

            foreach (string pageName in model.PageTree.Split('\n'))
            {
                // reset level to 0
                level = 0;
                // save the original pagenane, since GetLevelFromPageName is going to alter the pagename
                string originalPageName = pageName;
                string newPageName      = pageName;

                // get the level from the pagename. This removes the indent characters from the beginning from the pagename
                level = GetLevelFromPageName(model.IndentCharacter, ref newPageName, ref level);

                // there might a typo in the list.
                // eg if item x has text ">>PageName",
                // then item x+1 cannot have either just "PageName" or ">>>>PageName"
                // in other words, levels cannot differ by more than 1
                if (previousLevel < 0 && pageName.StartsWith(model.IndentCharacter))
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, $"PageTree being added cannot start with the set indent character ({model.IndentCharacter})"));
                }
                else if (previousLevel >= 0 && (level - previousLevel > 1) && (level != 0))
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, $"Unexpected Level at line {lineCounter + 1}, text: {originalPageName}"));
                }

                lineCounter++;
                previousLevel = level;
            }
            return(Request.CreateResponse(HttpStatusCode.OK, "OK"));
        }
예제 #2
0
        public HttpResponseMessage Do(GenerateTabsPostModel model)
        {
            List <string> PageTree = model.PageTree.Split('\n').ToList();

            TabController objTabs = new TabController();

            if (PageTree.First().StartsWith(model.IndentCharacter))
            {
                // we have to make sure that the first item in the list is not starting with an indent,
                // since we are adding this tree (optionaly) below another page anyway
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, $"PageTree being added cannot start with the set indent character ({model.IndentCharacter})"));
            }

            TabPermissionCollection defaultTabPermissionCollection = CreateTabPermissions();

            int level               = 0;
            int startingLevel       = 0;
            int previousLevel       = -1;
            int lineCounter         = 0;
            int startingParentTabId = Null.NullInteger;

            // see if user selected another page to put the tree under.
            // we need the startingTabID and the StartingLevel
            if (model.ParentTabId > 0)
            {
                startingParentTabId = model.ParentTabId;
                TabInfo tempTab = objTabs.GetTab(startingParentTabId, PortalSettings.PortalId, true);
                startingLevel = tempTab.Level + 1;
            }
            int            parentTabId = Null.NullInteger;
            List <TabInfo> tabList     = new List <TabInfo>();

            // first check whether all levels are ok, if there is an error we are not going to do anything
            foreach (string pageName in PageTree)
            {
                // reset level to 0
                level = 0;
                // save the original pagenane, since GetLevelFromPageName is going to alter the pagename
                string originalPageName = pageName;
                string newPageName      = pageName;

                // get the level from the pagename. This removes the indent characters from the beginning from the pagename
                level = GetLevelFromPageName(model.IndentCharacter, ref newPageName, ref level);

                // there might a typo in the list.
                // eg if item x has text ">>PageName",
                // then item x+1 cannot have either just "PageName" or ">>>>PageName"
                // in other words, levels cannot differ by more than 1
                if ((level - previousLevel > 1) && (level != 0))
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, $"Unexpected Level at line {lineCounter + 1}, text: {originalPageName}"));
                }
                lineCounter  += 1;
                previousLevel = level;
            }

            lineCounter   = 0;
            previousLevel = -1;
            foreach (string pageName in PageTree)
            {
                level = 0;
                // save the original pagename, since GetLevelFromPageName is going to alter the pagename
                string originalPageName = pageName;
                string newPageName      = pageName;

                // get the level from the pagename. This removes the indent characters from the beginning from the pagename
                level = GetLevelFromPageName(model.IndentCharacter, ref newPageName, ref level);

                // get the parentTabId
                parentTabId = startingParentTabId;
                if ((level > 0) && (lineCounter >= tabList.Count))
                {
                    // For i As Integer = tabList.Count - 1 To 0 Step -1
                    for (int i = 0; i <= tabList.Count - 1; i++)
                    {
                        // walk the list of already created back up
                        // in order to find the first previous tab of 1 level up
                        if (tabList[i].Level == startingLevel + level - 1)
                        {
                            parentTabId = tabList[i].TabID;
                        }
                    }
                }

                // create the new page
                TabInfo newTab = new TabInfo()
                {
                    PortalID          = PortalSettings.PortalId,
                    TabName           = newPageName,
                    ParentId          = parentTabId,
                    IsVisible         = true,
                    DisableLink       = false,
                    IsSecure          = false,
                    PermanentRedirect = false,
                    SiteMapPriority   = (float)0.5,
                    Level             = level
                };
                newTab.TabPermissions.AddRange(defaultTabPermissionCollection);

                try
                {
                    // adding the tab returns a tabId, so we can set that to the tab object
                    newTab.TabID = objTabs.AddTab(newTab);

                    // add the newly created tab to a list
                    tabList.Add(newTab);
                }
                catch (Exception ex)
                {
                }

                lineCounter  += 1;
                previousLevel = level;
            }

            // Clear the tabcache, so we know for sure that we will get a correct menu next page refresh
            //DotNetNuke.Common.Utilities.DataCache.ClearTabsCache(PortalId);

            return(Request.CreateResponse(HttpStatusCode.OK, "OK"));
        }