Esempio n. 1
0
        /// <summary>Finds the content item and the template associated with an url.</summary>
        /// <param name="url">The url to the template to locate.</param>
        /// <returns>A TemplateData object. If no template was found the object will have empty properties.</returns>
        public PathData ResolvePath(Url url)
        {
            if (url == null)
            {
                return(PathData.Empty);
            }

            string key = url.ToString().ToLowerInvariant();

            PathData data = HttpRuntime.Cache[key] as PathData;

            if (data == null)
            {
                data = inner.ResolvePath(url);
                if (!data.IsEmpty() && data.IsCacheable)
                {
                    logger.Debug("Adding " + url + " to cache");
                    HttpRuntime.Cache.Add(key, data.Detach(), new ContentCacheDependency(persister), Cache.NoAbsoluteExpiration, SlidingExpiration, CacheItemPriority.Normal, null);
                }
            }
            else
            {
                logger.Debug("Retrieving " + url + " from cache");
                data = data.Attach(persister);
                data.UpdateParameters(Url.Parse(url).GetQueries());
            }

            return(data);
        }
Esempio n. 2
0
 public virtual PathData ResolveUrl(Url url)
 {
     try
     {
         if (IsObservable(url))
         {
             return(parser.ResolvePath(url.RemoveDefaultDocument(Url.DefaultDocument).RemoveExtension(observedExtensions)));
         }
     }
     catch (Exception ex)
     {
         errorHandler.Notify(ex);
     }
     return(PathData.Empty);
 }
Esempio n. 3
0
 public virtual PathData ResolveUrl(string url)
 {
     try
     {
         if (IsObservable(url))
         {
             return(parser.ResolvePath(url));
         }
     }
     catch (Exception ex)
     {
         errorHandler.Notify(ex);
     }
     return(PathData.Empty);
 }
Esempio n. 4
0
        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);
        }