当前位置: 首页>>代码示例>>C#>>正文


C# Url.GetNormalizedContentUrl方法代码示例

本文整理汇总了C#中N2.Web.Url.GetNormalizedContentUrl方法的典型用法代码示例。如果您正苦于以下问题:C# Url.GetNormalizedContentUrl方法的具体用法?C# Url.GetNormalizedContentUrl怎么用?C# Url.GetNormalizedContentUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在N2.Web.Url的用法示例。


在下文中一共展示了Url.GetNormalizedContentUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolvePath

        public PathData ResolvePath(Url url, ContentItem startNode = null, string remainingPath = null)
        {
            if (url == null)
                return PathData.Empty;

            url = url.GetNormalizedContentUrl();

            var urlKey = GetUrlLowerInvariantString(url);

            // Make sure the cached path data is initialized thread safely
            Dictionary<string, PathData> cachedPathData;
            if ((cachedPathData = cache.Get<Dictionary<string, PathData>>("N2.PathDataCache")) == null)
            {
                lock (classLock)
                {
                    if ((cachedPathData = cache.Get<Dictionary<string, PathData>>("N2.PathDataCache")) == null)
                    {
                        cachedPathData = new Dictionary<string, PathData>();
                        cache.Add("N2.PathDataCache", cachedPathData, new CacheOptions { SlidingExpiration = SlidingExpiration });
                    }
                }
            }

            PathData data;
            if (cachedPathData.TryGetValue(urlKey, out data))
            {
                data = data.Attach(persister);
                if (data == null || data.ID == 0)
                {
                    // Cached path has to CMS content
                    return data;
                }

                logger.Debug("Retrieving " + url + " from cache");
                if (!string.IsNullOrEmpty(url.Query))
                    data.UpdateParameters(Url.Parse(url).GetQueries());
            }
            else
            {
                // The requested url doesn't exist in the cached path data
                lock (classLock)
                {
                    if (!cachedPathData.TryGetValue(urlKey, out data))
                    {
                        remainingPath = remainingPath ?? Url.ToRelative(url.Path).TrimStart('~');

                        string path = remainingPath;
                        var pathData = GetStartNode(url, cachedPathData, ref path, 0);

                        data = pathData.ID == 0
                            ? inner.ResolvePath(url)
                            : inner.ResolvePath(url, persister.Get(pathData.ID), remainingPath.Substring(path.Length, remainingPath.Length - path.Length));

                        if (data.IsCacheable)
                        {
                            logger.Debug("Adding " + urlKey + " to cache");
                            cachedPathData.Add(urlKey, data.Detach());
                        }
                    }
                }
            }

            return data;
        }
开发者ID:GrimaceOfDespair,项目名称:n2cms,代码行数:64,代码来源:CachingUrlParserDecorator.cs

示例2: FindPath

        /// <summary>Finds the path associated with an url.</summary>
        /// <param name="url">The url to the template to locate.</param>
        /// <param name="startNode">The node to start finding path from if none supplied will start from StartNode</param>
        /// <param name="remainingPath">The remaining path to search</param>
        /// <returns>A PathData object. If no template was found the object will have empty properties.</returns>
        public PathData FindPath(Url url, ContentItem startNode = null, string remainingPath = null)
        {
            if (url == null)
                return PathData.Empty;

            url = url.GetNormalizedContentUrl();

            var urlKey = GetUrlLowerInvariantString(url);

            // Make sure the cached path data is initialized thread safely
            Dictionary<string, PathData> cachedPathData;
            if ((cachedPathData = cache.Get<Dictionary<string, PathData>>("N2.PathDataCache")) == null)
            {
                lock (pathLock)
                {
                    if ((cachedPathData = cache.Get<Dictionary<string, PathData>>("N2.PathDataCache")) == null)
                    {
                        cachedPathData = new Dictionary<string, PathData>();
                        cache.Add("N2.PathDataCache", cachedPathData, new CacheOptions { SlidingExpiration = SlidingExpiration });
                    }
                }
            }

            PathData data;
            bool pathDataFound;
            lock (pathLock)
            {
                pathDataFound = cachedPathData.TryGetValue(urlKey, out data);
            }
            
            if (pathDataFound)
            {
                logger.DebugFormat("Retrieving path {0} from cache for key {1} ({2})", data, urlKey, data.GetHashCode());

                data = data.Attach(persister);
                if (data == null || data.ID == 0)
                {
                    // Cached path has to CMS content
                    return data;
                }

                if (!string.IsNullOrEmpty(url.Query))
                    data.UpdateParameters(Url.Parse(url).GetQueries());
            }
            else
            {
                // The requested url doesn't exist in the cached path data
                lock (pathLock)
                {
                    if (cachedPathData.TryGetValue(urlKey, out data))
                    {
                        logger.DebugFormat("Retrieving path {0} from cache (second chance) for key {1} ({2})", data, urlKey, data.GetHashCode());

                        data = data.Attach(persister);
                        if (data == null || data.ID == 0)
                        {
                            // Cached path has to CMS content
                            return data;
                        }

                        if (!string.IsNullOrEmpty(url.Query))
                            data.UpdateParameters(Url.Parse(url).GetQueries());
                    }
                    else
                    {
                        remainingPath = remainingPath ?? Url.ToRelative(url.Path).TrimStart('~');

                        string path = remainingPath;
                        PathData partialPath = GetStartNode(url, cachedPathData, ref path, 0);

                        if (partialPath.ID == 0)
                        {
                            data = inner.FindPath(url);
                            logger.DebugFormat("Found path {0} for url {1}", data, url);
                        }
                        else
                        {
                            string subpath = remainingPath.Substring(path.Length, remainingPath.Length - path.Length);
                            data = inner.FindPath(url, persister.Get(partialPath.ID), subpath);
                            logger.DebugFormat("Found path {0} for subpath {1} below {2}", data, subpath, partialPath.ID);
                        }

                        if (data.IsCacheable)
                        {
                            var detached = data.Detach();
                            logger.DebugFormat("Adding {0} to cache for key {1} ({2})", detached, urlKey, detached.GetHashCode());
                            cachedPathData.Add(urlKey, detached);
                        }
                    }
                }
            }

            return data;
        }
开发者ID:brianmatic,项目名称:n2cms,代码行数:99,代码来源:CachingUrlParserDecorator.cs


注:本文中的N2.Web.Url.GetNormalizedContentUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。