private static string GetUrl(UrlHelper urlHelper, ResourcePackage package)
        {
            if (string.IsNullOrEmpty(_urlFormat))
            {
                throw new Exception(
                    "The ResourceMinifier Mvc Extension is not configured."
                        + " Run ResourceMvcExtensions.ConfigureRouting(string routePattern) at application startup."
                    );
            }

            string virtualPath, url;

            if (_etagInPath)
            {
                virtualPath = "~/" + string.Format(_urlFormat, package.Key, package.GetETag());
                url = urlHelper.Content(virtualPath);
            }
            else
            {
                virtualPath = "~/" + string.Format(_urlFormat, package.Key);
                url = urlHelper.Content(virtualPath) + "?etag=" + package.GetETag();
            }

            return url;
        }
Пример #2
0
        private string UpdateCache(ResourcePackage package)
        {
            lock (package)
            {
                var physicalPaths = new List<string>();
                var contentSb = new StringBuilder();
                var lastModified = DateTime.MinValue;

                foreach (var virtualPath in package.Paths)
                {
                    if (!virtualPath.StartsWith("~"))
                    {
                        throw PathFormatException(virtualPath);
                    }

                    string tmpPathPhysical;
                    DateTime tmpLastModified;
                    var tmpContent = RetrieveFromDisk(virtualPath, out tmpPathPhysical, out tmpLastModified);

                    physicalPaths.Add(tmpPathPhysical);

                    if (tmpLastModified > lastModified)
                    {
                        lastModified = tmpLastModified;
                    }

                    if (tmpContent == null)
                    {
                        contentSb.Append("/* ResourceMinifier error: Missing file */");
                    }
                    else if (DoMinify)
                    {
                        contentSb.Append(Minify(tmpContent));
                    }
                    else
                    {
                        contentSb.Append(tmpContent);
                    }

                    contentSb.AppendLine();
                    contentSb.AppendLine();
                }

                var contents = contentSb.ToString();

                var cacheDependency = physicalPaths.Count > 0
                    ? new CacheDependency(physicalPaths.ToArray())
                    : null;

                HttpRuntime.Cache.Insert(
                    package.GetCacheKey(),
                    contents,
                    cacheDependency,
                    Cache.NoAbsoluteExpiration,
                    Cache.NoSlidingExpiration
                    );

                package.UpdatedOn = DateTime.Now;

                return contents;
            }
        }
 private static string GetUrl(RequestContext requestContext, ResourcePackage package)
 {
     var urlHelper = new UrlHelper(requestContext);
     return GetUrl(urlHelper, package);
 }