コード例 #1
0
ファイル: CssMinify.cs プロジェクト: kooboo-jifeng/CMS
        public static string Minify(System.Web.Mvc.UrlHelper urlHelper, string cssPath, string requestPath, string cssContent)
        {
            // this construct is to enable us to refer to the relativePath above ...
            MatchEvaluator urlDelegate = new MatchEvaluator(delegate(Match m)
            {
                // Change relative (to the original CSS) URL references to make them relative to the requested URL (controller / action)
                string url = m.Value;

                Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);

                if (uri.IsAbsoluteUri || VirtualPathUtility.IsAbsolute(url))
                {
                    // if the URL is absolute ("http://server/path/file.ext") or app absolute ("/path/file.ext") then leave it as it is
                }
                else
                {
                    // get app relative url
                    url = VirtualPathUtility.Combine(cssPath, url);
                    url = VirtualPathUtility.MakeRelative(requestPath, url);

                    url = urlHelper.Content(url);
                }

                return url;
            });
            return Minify(urlHelper, urlDelegate, cssContent, 0);
        }
コード例 #2
0
ファイル: ImageModel.cs プロジェクト: strider-/striderMVC
        public ImageModel(string ImagePath, System.Web.Mvc.UrlHelper url)
        {
            dir = new DirectoryInfo(ImagePath);
            thumbDir = dir.GetDirectories("t").FirstOrDefault();

            if(!dir.Exists)
                dir.Create();
            if(thumbDir == null || !thumbDir.Exists)
                thumbDir = dir.CreateSubdirectory("t");

            Images = from f in dir.GetFiles()
                     let exists = File.Exists(Path.Combine(thumbDir.FullName, f.Name))
                     select new Img {
                         Filename = f.Name,
                         ImageUrl = url.Content("~/Images/" + f.Name),
                         Uploaded = f.CreationTime,
                         Size = f.Length,
                         HasThumbnail = exists,
                         ThumbnailUrl = exists ? url.Content("~/Images/t/" + f.Name) : null
                     };
        }