public static string TranslateSystemUrl(this UrlHelper urlHelper, string url, string defaultBaseUrl = null)
        {
            if (String.IsNullOrWhiteSpace(url))
                return null;

            url = url.Trim();

            if (url.Contains("://"))
            {
                return url;
            }
            else if (url.StartsWith("//"))
            {
                return String.Format("{0}:{1}", urlHelper.RequestContext.HttpContext.Request.Url.Scheme, url);
            }
            else if (!url.StartsWith("~") && !url.StartsWith("/") && !String.IsNullOrWhiteSpace(defaultBaseUrl))
            {
                defaultBaseUrl = defaultBaseUrl.TrimEnd('/');
                if (defaultBaseUrl.Contains("://"))
                {
                    return defaultBaseUrl + "/" + url;
                }
                else if (defaultBaseUrl.StartsWith("//"))
                {
                    return String.Format("{0}:{1}/{2}", urlHelper.RequestContext.HttpContext.Request.Url.Scheme, defaultBaseUrl, url);
                }

                return urlHelper.Content(defaultBaseUrl + "/" + url);
            }

            return urlHelper.Content(url);
        }
Example #2
0
        public static HtmlString LessCss(this UrlHelper helper, string lessJsPath, params string[] cssFiles)
        {
            var html = new StringBuilder();

            var useClientside = false;
            var lessLinkTagFormat = @"<link rel=""stylesheet/less"" type=""text/css"" href=""{0}"">";
            var cssLinkTagFormat = @"<link rel=""stylesheet"" type=""text/css"" href=""{0}"">";
            #if DEBUG
            useClientside = true;
            #endif

            foreach (var css in cssFiles)
            {
                if (!css.EndsWith(".less"))
                    html.AppendFormat(cssLinkTagFormat, helper.Content(css));
                else if( useClientside )
                    html.AppendFormat(lessLinkTagFormat, helper.Content(css));
                else
                    html.AppendFormat(cssLinkTagFormat, helper.Content(TranslateToCss(css)));
            }

            if (useClientside)
                html.AppendFormat(@"<script src=""{0}"" type=""text/javascript""></script>", helper.Content(lessJsPath));

            return new HtmlString(html.ToString());
        }
Example #3
0
        public static string AvatarUrl(this UrlHelper urlHelper, string avatarIdentifier)
        {
            if (string.IsNullOrEmpty(avatarIdentifier))
                return urlHelper.Content("~/content/img/avatar.jpg");

            return urlHelper.Content("~/avatar/" + avatarIdentifier);
        }
        /// <summary>
        /// Retrieves a CSS link based on a themes path
        /// </summary>
        /// <param name="urlHelper"></param>
        /// <param name="cssFile"></param>
        /// <param name="theme"></param>
        /// <returns></returns>
        public static string Css(this UrlHelper urlHelper, string cssFile, string theme = null)
        {                        
            object oTheme = urlHelper.RequestContext.HttpContext.Session["Theme"];
            if (oTheme != null)
                theme = oTheme as string;
            
            string url = null;

            if (string.IsNullOrEmpty(theme))
                url = urlHelper.Content("~/css/" + cssFile);
            else
            {
                string lowerCssFile = cssFile.ToLower();
                theme=theme.ToLower();
                string key = theme + "|" + cssFile;


                if (CssFileCache.ContainsKey(key))
                    return CssFileCache[key];

                foreach (string path in CssPaths)
                {
                    string webPath = string.Format(path, cssFile, theme);
                    if (File.Exists(urlHelper.RequestContext.HttpContext.Server.MapPath(webPath)))
                    {
                        url = urlHelper.Content(webPath);
                        CssFileCache.Add(key, url);
                        break;
                    }
                }
            }

            return url;
        }
 public static string ImageProduct(this UrlHelper urlHelper, string imageName)
 {
     if (string.IsNullOrEmpty(imageName))
     {
         return urlHelper.Content("~/Contents/Images/image.jpg");
     }
     return urlHelper.Content("~/Contents/Images/Product/" + imageName);
 }
 public static string GetPhotoUrl(this UrlHelper helper, string imageId, string size, string defaultUrl = null)
 {
     var photo = PhotoManager.Provider.GetPhotoResize(imageId, size);
     if (photo != null)
     {
         return helper.Content(photo.Url);
     }
     return defaultUrl != null ? helper.Content(defaultUrl) : "";
 }
Example #7
0
        public static string Content(this System.Web.Mvc.UrlHelper Url, string Path, bool addTimeStamp)
        {
            if (!addTimeStamp)
                return Url.Content(Path);

            string serverPath = HttpContext.Current.Server.MapPath(Path);
            DateTime lastWrite = File.GetLastWriteTimeUtc(serverPath);
            string result = lastWrite.Ticks.ToString();
            return Url.Content(Path) + "?t=" + result;
        }
Example #8
0
 public static string Content(this UrlHelper url, string contentPath, bool absolute)
 {
     Uri requestUrl = url.RequestContext.HttpContext.Request.Url;
     if (absolute)
     {
         string absoluteAction = "{0}://{1}{2}".FormatWith(requestUrl.Scheme, requestUrl.Authority, url.Content(contentPath));
         return absoluteAction;
     }
     return url.Content(contentPath);
 }
        /// <summary>
        /// Provides a Javascript script tag for the Bootstrap framework.
        /// </summary>
        public static MvcHtmlString BootstrapJS(this UrlHelper helper)
        {
            string bootStrapPath = helper.Content("~/Assets/bootstrap/js/bootstrap.min.js");
            string respondPath = helper.Content("~/Assets/bootstrap/js/respond.min.js");

            string html = string.Format("<script type=\"text/javascript\" language=\"javascript\" src=\"{0}?version={1}\"></script>", bootStrapPath, ApplicationSettings.ProductVersion);
            html += string.Format("\n<script type=\"text/javascript\" language=\"javascript\" src=\"{0}?version={1}\"></script>", respondPath, ApplicationSettings.ProductVersion);

            return MvcHtmlString.Create(html);
        }
Example #10
0
 public static string Script(this UrlHelper helper, string file)
 {
     if (Config.ActiveConfiguration.MinifyFiles)
     {
         return helper.Content(String.Format("~/Content/{0}/{1}.min.js", ContentDirectory.script.ToString(), file));
     }
     else
     {
         return helper.Content(String.Format("~/Content/{0}/{1}.js", ContentDirectory.script.ToString(), file));
     }
 }
 public static string Image(this UrlHelper urlHelper, string imageName)
 {
     if (imageName == "Banner")
     {
         return urlHelper.Content("~/Contents/Images/Banner.JPG");
     }
     else if(string.IsNullOrEmpty(imageName))
     {
         return urlHelper.Content("~/Contents/Images/image.jpg");
     }
     return urlHelper.Content("~/Contents/Images/" + imageName);
 }
        public static string Image(this UrlHelper url, string imageName)
        {
            string path = ConfigurationManager.AppSettings["ImagePath"];

            if (string.IsNullOrWhiteSpace(path))
                path = "~/Content/Images";

            if (string.IsNullOrWhiteSpace(imageName))
                return url.Content(path);

            return url.Content(String.Format("{0}/{1}", path, imageName));
        }
Example #13
0
        /// <summary>
        /// Provides a CSS link tag for the CSS file provided. If the relative path does not begin with ~ then
        /// the Assets/Css folder is assumed.
        /// </summary>
        public static MvcHtmlString CssLink(this UrlHelper helper, string relativePath)
        {
            if (!relativePath.StartsWith("~"))
                relativePath = "~/Assets/CSS/" + relativePath;

            return MvcHtmlString.Create("<link href=\"" + helper.Content(relativePath) + "\" rel=\"stylesheet\" type=\"text/css\" />");
        }
        public static string Script(this UrlHelper urlHelper, string fileName)
        {
            if (!fileName.EndsWith(".js"))
                fileName += ".js";

            return urlHelper.Content(string.Format("~/Content/{0}/{1}?version={2}", ScriptDir, fileName, RevisionNumber));
        }
        public static string ContentVersioned(this UrlHelper urlHelper, string contentPath)
        {
            string url = urlHelper.Content(contentPath);
            int revisionNumber = GetRevisionNumber();

            return String.Format("{0}?v={1}", url, revisionNumber);
        }
        public static string ContentWithVersion(this UrlHelper helper, string path)
        {
            var contentPath = helper.Content(path);
            var assemblyVersionString = GetAssemblyVersionString();

            return string.Format("{0}?ver={1}", contentPath, assemblyVersionString);
        }
 public static string Script(this UrlHelper helper, string fileName)
 {
     TagBuilder builder = new TagBuilder("script");
     builder.Attributes["type"] = "text/javascript";
     builder.Attributes["src"] = helper.Content(String.Format("~/Scripts/{0}", fileName));
     return builder.ToString();
 }
 /// <summary>
 /// Generates a fully qualified URL to the specified content by using the specified content path. Converts a 
 /// virtual (relative) path to an application absolute path.
 /// </summary>
 /// <param name="url">The URL helper.</param>
 /// <param name="contentPath">The content path.</param>
 /// <returns>The absolute URL.</returns>
 public static string AbsoluteContent(
     this IUrlHelper url,
     string contentPath)
 {
     HttpRequest request = Context.HttpContext.Request;
     return new Uri(new Uri(request.Scheme + "://" + request.Host.Value), url.Content(contentPath)).ToString();
 }
        public static string Content(this UrlHelper urlHelper, string contentPath, bool toAbsolute = false)
        {
            var path = urlHelper.Content(contentPath);
            var url = new Uri(HttpContext.Current.Request.Url, path);

            return toAbsolute ? url.AbsoluteUri : path;
        }
Example #20
0
        public static string AbsContent(this UrlHelper urlHelper, string contentPath)
        {
            var path = urlHelper.Content(contentPath);
            var url = new Uri(urlHelper.RequestContext.HttpContext.Request.Url, path);

            return url.AbsoluteUri;
        }
Example #21
0
 public static string Script(this UrlHelper urlHelper, string scriptPath)
 {
     #if DEBUG
     scriptPath = scriptPath.Replace(".min.", ".");
     #endif
     return urlHelper.Content("~/Scripts/" + scriptPath);
 }
Example #22
0
 public static string GenericThemeContent(this UrlHelper helper, string url)
 {
     if (url.IsNullOrEmpty())
         return url;
     string s = helper.Content(url);
     return ThemeHelper.CreateGenericThemeViewPath(null, s);
 }
Example #23
0
		/// <summary>
		/// Provides a Javascript script tag for the installer Javascript file provided, using ~/Assets/Scripts/roadkill/installer as the base path.
		/// </summary>
		public static MvcHtmlString InstallerScriptLink(this UrlHelper helper, string filename)
		{
			string path = helper.Content("~/Assets/Scripts/roadkill/installer/" + filename);
			string html = string.Format("<script type=\"text/javascript\" language=\"javascript\" src=\"{0}?version={1}\"></script>", path, ApplicationSettings.ProductVersion);

			return MvcHtmlString.Create(html);
		}
		/// <summary>
		/// Creates a URL pointing to the appropriate Azure CDN, allows user to specify querystring value
		/// </summary>
		/// <param name="helper">The helper.</param>
		/// <param name="contentLocation">The resource.</param>
        /// <param name="queryStringValue">The value you want to append to the querystring</param>
		/// <returns></returns>
		public static string AzureCdnContent(this UrlHelper helper, string contentLocation, string queryStringValue)
		{
			var queryString = "?cachebuster=" + queryStringValue;
			var newLocation = FormatContentLocation(contentLocation, queryString);

			return helper.Content(newLocation);
		}
Example #25
0
        /// <summary>
        /// Provides a CSS tag for the Bootstrap framework.
        /// </summary>
        public static MvcHtmlString BootstrapCSS(this UrlHelper helper)
        {
            string path = helper.Content("~/Assets/bootstrap/css/bootstrap.min.css");
            string html = string.Format("<link href=\"{0}?version={1}\" rel=\"stylesheet\" type=\"text/css\" />", path, ApplicationSettings.ProductVersion);

            return MvcHtmlString.Create(html);
        }
        public static MvcHtmlString UpdatedResourceLink(this UrlHelper helper, string resourceURL)
        {
            //Dragos: convention - we always look at the "source" file and not at the minified file -> we disregard the /Minified folder from the path
             var link = helper.Content(resourceURL);
             var originalFile = resourceURL.Replace("/Minified", "");
             try
             {
            var fileLink = HttpContext.Current.Server.MapPath(originalFile);
            var file = File.GetLastWriteTime(fileLink);
            var fileTimestamp = file.ToString("yyyyMMddHHmmss");

            var strRegex = @"(.*)(\.css|\.js)$";
            RegexOptions myRegexOptions = RegexOptions.None;
            Regex myRegex = new Regex(strRegex, myRegexOptions);
            var matches = myRegex.Matches(link);
            if (matches.Count == 1)
            {
               var match = matches[0];
               link = match.Groups[1].Value + "." + fileTimestamp + match.Groups[2];
            }
             }
             catch (Exception ex)
             {
            //TODO we should log this somewhere
             }
             return new MvcHtmlString(link);
        }
Example #27
0
 public static string ThemeContent(this UrlHelper helper, string url)
 {
     if (url.IsNullOrEmpty())
         return url;
     string s = helper.Content(url);
     return ThemeHelper.CreateThemeViewPath(Actor.Me.ThemeName, null, s);
 }
Example #28
0
 public static string ContentCacheBreak(this UrlHelper url, string contentPath)
 {
     if (contentPath == null) throw new ArgumentNullException("contentPath");
     var path = url.Content(contentPath);
     path += "?" + MvcApplication.GetAssemblyVersion();
     return path;
 }
 public static string CurrentAction(this UrlHelper urlHelper)
 {
     var routeValueDictionary = urlHelper.RequestContext.RouteData.Values;
     // in case using virtual dirctory
     var rootUrl = urlHelper.Content("~/");
     return string.Format("{0}{1}/{2}/", rootUrl, routeValueDictionary["controller"], routeValueDictionary["action"]);
 }
Example #30
0
        public static string UserAvatar(this UrlHelper url, User user, ImageType type)
        {
            string imageUrl;
            if (user.AvatarUrl != null)
            {
                var parts = user.AvatarUrl.Split(Constants.ImageUrlsSeparator);
                switch (type)
                {
                    case ImageType.Thumbnail:
                        imageUrl = parts[0];
                        break;
                    case ImageType.Big:
                        imageUrl = parts[1];
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("type");
                }
            }
            else
            {
                imageUrl = AppConfigs.AvatarFolderPath + Constants.AnonymousAvatar;
            }

            return url.Content(imageUrl);
        }