示例#1
0
        private string CompressCss(IEnumerable <IPath> cssFiles)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var file in cssFiles)
            {
                using (FileStream fileStream = new FileStream(file.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var content = fileStream.ReadString();
                    sb.AppendFormat("{0}\n", CSSMinify.Minify(Url, file.VirtualPath, Request.Url.AbsolutePath, content));
                }
            }
            return(sb.ToString());
        }
示例#2
0
        private string CompressCss(IEnumerable <IPath> cssFiles)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var file in cssFiles)
            {
                string content;
                var    dynamicResource = DynamicClientResourceFactory.Default.ResolveProvider(file.PhysicalPath);

                if (dynamicResource != null)
                {
                    content = dynamicResource.Parse(file.VirtualPath);
                }
                else
                {
                    content = IOUtility.ReadAsString(file.PhysicalPath);
                }
                sb.AppendFormat("{0}\n", CSSMinify.Minify(Url, file.VirtualPath, Request.Url.AbsolutePath, content));
            }
            return(sb.ToString());
        }
示例#3
0
        public static IHtmlString ExternalResources(this HtmlHelper htmlHelper, RouteValueDictionary htmlAttributes, params string[] files)
        {
            string key = Cryptor.EncryptMD5(string.Join(";", files));

            if (ResourceRoutting.list.Contains(key))
            {
                return(new HtmlString(""));
            }

            string output = key;

            // Combine
            using (StreamWriter sw = new StreamWriter(output))
            {
                foreach (var fileInfo in files)
                {
                    string content = System.IO.File.ReadAllText(htmlHelper.ViewContext.HttpContext.Server.MapPath(fileInfo));


                    content = CSSMinify.Minify(null, fileInfo, "", content);
                    sw.WriteLine(content.Trim());
                }
            }
            // Combine
            using (StreamWriter sw = new StreamWriter(output))
            {
                foreach (var fileInfo in files)
                {
                    string content = System.IO.File.ReadAllText(htmlHelper.ViewContext.HttpContext.Server.MapPath(fileInfo));


                    content = CSSMinify.Minify(null, fileInfo, "", content);
                    sw.WriteLine(content.Trim());
                }
            }
            return(new HtmlString(""));
        }