コード例 #1
0
        public static void UpdateDynamicPageFormFormulas(AgilityContent existingContent, AgilityContent deltaContent)
        {
            if (deltaContent == null || deltaContent.DataSet == null)
            {
                return;
            }



            Dictionary <string, List <int> > dpIndex = BaseCache.GetDynamicPageIndex();

            List <int> lstPageIDs = null;

            if (dpIndex.TryGetValue(deltaContent.ReferenceName.ToLowerInvariant(), out lstPageIDs))
            {
                foreach (int pageID in lstPageIDs)
                {
                    AgilityPage page = BaseCache.GetPageFromID(pageID, deltaContent.LanguageCode, AgilityContext.WebsiteName, null);
                    if (page != null)
                    {
                        //update all of the DynamicPageIndexes that this content appears on...
                        BaseCache.UpdateDynamicPageFormulaIndex(page, existingContent, deltaContent, deltaContent.ReferenceName, existingContent == null);
                    }
                }
            }
        }
コード例 #2
0
        private static void RedirectToDynamicPreviewUrl(Dictionary <string, AgilityRouteCacheItem> routes, string path, string languageCode)
        {
            List <string> urlPaths = new List <string>();

            string[] pathParts   = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            string   staticRoute = string.Empty;

            AgilityRouteCacheItem routeItem = null;

            //keep some parent objects...
            AgilityPage            parentPage    = null;
            DynamicPageFormulaItem dpItemParent  = null;
            AgilityContent         parentContent = null;

            int previewContentID = -1;
            int previewVersionID = -1;

            if (!int.TryParse(AgilityContext.HttpContext.Request.Query["previewContentID"], out previewContentID))
            {
                if (!int.TryParse(AgilityContext.HttpContext.Request.Query["previewVersionID"], out previewVersionID))
                {
                    int.TryParse(AgilityContext.HttpContext.Request.Query["ContentID"], out previewContentID);
                }
            }

            foreach (string pathPart in pathParts)
            {
                string testStaticRoute = string.Format("{0}/{1}", staticRoute, pathPart);

                if (routes.TryGetValue(testStaticRoute, out routeItem))
                {
                    int pageID = routeItem.PageID;



                    //get the page...
                    AgilityPage page = BaseCache.GetPageFromID(pageID, languageCode, AgilityContext.WebsiteName, null);
                    if (page == null)
                    {
                        //if the page is null at this point, assume it's a folder page and jsut insert the static path...
                        urlPaths.Add(pathPart);
                        staticRoute = testStaticRoute;
                        continue;
                    }

                    string contentReferenceName = null;
                    int    parentContentID      = -1;



                    if (string.IsNullOrEmpty(page.DynamicPageContentViewReferenceName) &&
                        string.IsNullOrEmpty(page.DynamicPageParentFieldName))
                    {
                        //static page...
                        urlPaths.Add(pathPart);
                    }
                    else
                    {
                        //dynamic page..
                        if (!string.IsNullOrEmpty(page.DynamicPageContentViewReferenceName))
                        {
                            contentReferenceName = page.DynamicPageContentViewReferenceName;

                            if (!string.IsNullOrEmpty(page.DynamicPageParentFieldName))
                            {
                                if (parentPage == null || dpItemParent == null)
                                {
                                    return;
                                }

                                //we have to match up to the parent page...
                                parentContentID = dpItemParent.ContentID;
                            }
                        }
                        else if (!string.IsNullOrEmpty(page.DynamicPageParentFieldName))
                        {
                            //get the dynamic content from the PARENT page
                            if (parentPage == null || dpItemParent == null)
                            {
                                return;
                            }

                            object obj = dpItemParent.GetContentItemValue(page.DynamicPageParentFieldName);
                            if (obj != null)
                            {
                                contentReferenceName = string.Format("{0}", obj);
                            }
                        }

                        if (string.IsNullOrEmpty(contentReferenceName))
                        {
                            return;
                        }


                        //get the content first if we are in development or staging mode...
                        AgilityContentServer.AgilityContent content = BaseCache.GetContent(contentReferenceName, languageCode, AgilityContext.WebsiteName);


                        //get the dynamic content for this page
                        DynamicPageFormulaItemIndex dpIndex = BaseCache.GetDynamicPageFormulaIndex(pageID, contentReferenceName, languageCode, page, true);
                        if (dpIndex == null || dpIndex.Count == 0)
                        {
                            return;
                        }


                        DynamicPageFormulaItem dpItem = null;


                        //try to use the preview url
                        if (previewVersionID > 0 || previewContentID > 0)
                        {
                            DataRow row = null;
                            if (previewContentID > 0)
                            {
                                row = content.GetItemByContentID(previewContentID);
                            }
                            else
                            {
                                DataRow[] rows = content.DataSet.Tables["ContentItems"].Select(string.Format("VersionID = {0}", previewVersionID));
                                if (rows.Length > 0)
                                {
                                    row = rows[0];
                                }
                            }

                            if (row != null)
                            {
                                string pageName = string.Format("/{0}", DynamicPageFormulaItem.ResolveFormula(page.DynamicPageName, row, true)).ToLowerInvariant();
                                if (dpIndex.TryGetValue(pageName, out dpItem))
                                {
                                    //adjust the parent if we need to...
                                    if (!string.IsNullOrEmpty(page.DynamicPageParentFieldName) && dpItemParent != null)
                                    {
                                        //grab the parent id...
                                        object parentIDObj = dpItem.GetContentItemValue(page.DynamicPageParentFieldName);
                                        if (parentIDObj != null)
                                        {
                                            string parentIDStr = string.Format("{0}", parentIDObj);
                                            if (parentIDStr.IndexOf(",") != -1)
                                            {
                                                parentIDStr = parentIDStr.Substring(0, parentIDStr.IndexOf(","));
                                            }
                                            int adjustedParentID = -1;
                                            if (int.TryParse(parentIDStr, out adjustedParentID))
                                            {
                                                if (dpItemParent.ContentID != adjustedParentID)
                                                {
                                                    // if the parent id DOES NOT match, we need to do some URL jigging...
                                                    DataRow parentRow = parentContent.GetItemByContentID(adjustedParentID);

                                                    parentContentID = adjustedParentID;
                                                    if (parentRow != null)
                                                    {
                                                        //get the parent page name and switch it up in the url..
                                                        string parentPageName = string.Format("/{0}", DynamicPageFormulaItem.ResolveFormula(parentPage.DynamicPageName, parentRow, true)).ToLowerInvariant();
                                                        urlPaths[urlPaths.Count - 1] = parentPageName.Substring(1);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }


                        if (dpItem == null)
                        {
                            //use the first one if we don't have an item yet...
                            dpItem = dpIndex.Values.FirstOrDefault();
                        }


                        if (parentContentID > 1 && previewVersionID < 1 && previewContentID < 1)
                        {
                            //unless we have a parent id to follow...

                            foreach (DynamicPageFormulaItem item in dpIndex.Values)
                            {
                                object testParentContentIDObj = item.GetContentItemValue(page.DynamicPageParentFieldName);
                                if (testParentContentIDObj != null)
                                {
                                    int    testParentContentID    = -1;
                                    string testParentContentIDStr = string.Format("{0}", testParentContentIDObj);

                                    if (int.TryParse(testParentContentIDStr, out testParentContentID))
                                    {
                                        //if the value is an int, test for equality...
                                        if (parentContentID == testParentContentID)
                                        {
                                            dpItem = item;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        //value is NOT an int, test for "in" '[id],' or ',[id],' or ',[id]'
                                        if (testParentContentIDStr.StartsWith(string.Format("{0},", parentContentID)) ||
                                            testParentContentIDStr.EndsWith(string.Format(",{0}", parentContentID)) ||
                                            testParentContentIDStr.Contains(string.Format(",{0},", parentContentID)))
                                        {
                                            dpItem = item;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (dpItem == null)
                        {
                            return;
                        }


                        urlPaths.Add(dpItem.Name.TrimStart("/".ToCharArray()));
                        dpItemParent  = dpItem;
                        parentContent = content;
                    }

                    staticRoute = testStaticRoute;
                    parentPage  = page;
                }
                else
                {
                    //if we can't find a static route, kick out.
                    return;
                }
            }

            if (urlPaths.Count > 0)
            {
                StringBuilder sbUrl = new StringBuilder("~/");
                sbUrl.Append(string.Join("/", urlPaths.ToArray()));

                if (AgilityContext.HttpContext.Request.Path.Value.EndsWith(".aspx", StringComparison.CurrentCultureIgnoreCase))
                {
                    sbUrl.Append(".aspx");
                }
                if (!string.IsNullOrEmpty(AgilityContext.HttpContext.Request.QueryString.Value))
                {
                    sbUrl.Append(AgilityContext.HttpContext.Request.QueryString.Value);
                }

                string redirectUrl = sbUrl.ToString();

                //strip off the querystrings that we don't want...
                redirectUrl = Agility.Web.Util.Url.RemoveQueryString(redirectUrl, "ContentID&VersionID&previewContentID&previewVersionID");


                Agility.Web.HttpModules.AgilityHttpModule.RedirectResponse(redirectUrl, 301);

                AgilityContext.IsResponseEnded = true;
            }
        }
コード例 #3
0
        internal static bool IsStagingItemOutOfDate(object existingItem)
        {
            if (existingItem == null)
            {
                return(true);
            }
            AgilityContent         existingItem_Content = existingItem as AgilityContent;
            AgilitySitemap         existingItem_Sitemap = existingItem as AgilitySitemap;
            AgilityPage            existingItem_Page    = existingItem as AgilityPage;
            AgilityModule          existingItem_Module  = existingItem as AgilityModule;
            AgilityAssetMediaGroup existingItem_Gallery = existingItem as AgilityAssetMediaGroup;

            if (existingItem_Content != null)
            {
                //CONTENT
                int versionID             = 0;
                int maxVersionIDInDataSet = 0;
                if (existingItem_Content.DataSet != null)
                {
                    if (existingItem_Content.DataSet.ExtendedProperties.ContainsKey("MaxVersionID"))
                    {
                        int.TryParse(string.Format("{0}", existingItem_Content.DataSet.ExtendedProperties["MaxVersionID"]), out maxVersionIDInDataSet);
                    }

                    DataTable dt = existingItem_Content.DataSet.Tables["ContentItems"];
                    if (dt != null && dt.Columns["VersionID"] != null)
                    {
                        try
                        {
                            object maxObj = dt.Compute("max(VersionID)", "");
                            if (!int.TryParse($"{maxObj}", out versionID))
                            {
                                versionID = -1;
                            }
                        } catch (Exception ex)
                        {
                            throw ex;
                        }
                    }


                    if (maxVersionIDInDataSet > versionID)
                    {
                        versionID = maxVersionIDInDataSet;
                    }
                }


                int latestVersionID = CheckContentIndex(versionID, existingItem_Content.ReferenceName, existingItem_Content.LanguageCode);
                if (latestVersionID > 0)
                {
                    if (existingItem_Content.DataSet != null)
                    {
                        existingItem_Content.DataSet.ExtendedProperties["MaxVersionID"] = latestVersionID;
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (existingItem_Page != null)
            {
                //PAGE
                return(CheckPageIndex(existingItem_Page.ZVersionID, existingItem_Page.ID, existingItem_Page.LanguageCode));
            }
            else if (existingItem_Module != null)
            {
                //MODULE DEF
                return(CheckContentDefinitionIndex(existingItem_Module.ID, existingItem_Module.LastAccessDate));
            }
            else if (existingItem_Sitemap != null)
            {
                //SITEMAP
                return(CheckPageIndex(existingItem_Sitemap.XMaxPageVersionID, -1, existingItem_Sitemap.LanguageCode));
            }
            else if (existingItem_Gallery != null)
            {
                //MEDIA GROUPING/GALLERY

                DateTime dtModifiedOn = existingItem_Gallery.ModifiedOn;

                if (existingItem_Gallery.Media != null && existingItem_Gallery.Media.Length > 0)
                {
                    //check for the most recent item..

                    DateTime dtItem = existingItem_Gallery.Media.Max(d => d.ModifiedOn);
                    if (dtItem > dtModifiedOn)
                    {
                        dtModifiedOn = dtItem;
                    }
                }


                return(CheckMediaGalleryIndex(existingItem_Gallery.ID, dtModifiedOn));
            }



            return(true);
        }