/// <summary>
        /// Resolves an absolute web path for the file path
        /// </summary>
        /// <param name="file"></param>
        /// <param name="http"></param>
        /// <returns></returns>
        public static string ResolveFilePath(this IClientDependencyFile file, HttpContextBase http)
        {
            var trimmedPath = file.FilePath.Trim();

            if (string.IsNullOrEmpty(trimmedPath))
            {
                throw new ArgumentException("The Path specified is null", "Path");
            }
            if (trimmedPath.StartsWith("~/"))
            {
                return(http.ResolveUrl(file.FilePath));
            }
            if (trimmedPath.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) ||
                trimmedPath.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
            {
                return(file.FilePath);
            }

            var filePath = file.FilePath;

            if (!http.IsAbsolute(filePath))
            {
                //get the relative path
                var path = http.Request.AppRelativeCurrentExecutionFilePath.Substring(0, http.Request.AppRelativeCurrentExecutionFilePath.LastIndexOf('/') + 1);
                filePath = http.ResolveUrl(path + filePath);
            }

            var uri = new Uri(new Uri("https://example.com"), filePath);

            return(uri.PathAndQuery);
        }
 public ClientDependencyInclude(IClientDependencyFile file)
 {
     Priority = file.Priority;
     PathNameAlias = file.PathNameAlias;
     FilePath = file.FilePath;
     DependencyType = file.DependencyType;
 }
Exemple #3
0
 protected ClientDependencyInclude(IClientDependencyFile file)
 {
     Priority       = file.Priority;
     PathNameAlias  = file.PathNameAlias;
     FilePath       = file.FilePath;
     DependencyType = file.DependencyType;
     Group          = file.Group;
     HtmlAttributes = new Dictionary <string, string>();
 }
        protected ClientDependencyInclude(IClientDependencyFile file)
		{
			Priority = file.Priority;
			PathNameAlias = file.PathNameAlias;
			FilePath = file.FilePath;
			DependencyType = file.DependencyType;
            Group = file.Group;
            HtmlAttributes = new Dictionary<string, string>();
		}
Exemple #5
0
        /// <summary>
        /// Checks if the current file implements the html attribute interfaces and returns the appropriate html attributes
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private static IDictionary <string, string> GetHtmlAttributes(IClientDependencyFile file)
        {
            IDictionary <string, string> attributes = new Dictionary <string, string>();

            var htmlAttributes = file as IHaveHtmlAttributes;

            if (htmlAttributes != null)
            {
                var fileWithAttributes = htmlAttributes;
                attributes = fileWithAttributes.HtmlAttributes;

                var parsing = file as IRequiresHtmlAttributesParsing;
                if (parsing != null)
                {
                    //we need to parse the attributes into the dictionary
                    HtmlAttributesStringParser.ParseIntoDictionary(parsing.HtmlAttributesAsString, attributes);
                }
            }

            //now we must ensure that the correct js/css attribute exist!
            switch (file.DependencyType)
            {
            case ClientDependencyType.Javascript:
                if (!attributes.ContainsKey("type"))
                {
                    attributes.Add("type", "text/javascript");
                }
                if (attributes.ContainsKey("src"))
                {
                    attributes.Remove("src");
                }
                break;

            case ClientDependencyType.Css:
                if (!attributes.ContainsKey("type"))
                {
                    attributes.Add("type", "text/css");
                }
                if (!attributes.ContainsKey("rel"))
                {
                    attributes.Add("rel", "stylesheet");
                }
                if (attributes.ContainsKey("href"))
                {
                    attributes.Remove("href");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            //just return an empty dictionary
            return(attributes);
        }
 public void RegisterDependency(IClientDependencyFile file, object htmlAttributes)
 {
     RegisterDependency(
         file.Group,
         file.Priority,
         file.FilePath,
         file.PathNameAlias,
         file.DependencyType,
         htmlAttributes,
         file.ForceProvider,
         file.ForceBundle);
 }
Exemple #7
0
 protected ClientDependencyInclude(IClientDependencyFile file)
 {
     Priority       = file.Priority;
     PathNameAlias  = file.PathNameAlias;
     FilePath       = file.FilePath;
     DependencyType = file.DependencyType;
     Group          = file.Group;
     HtmlAttributes = new Dictionary <string, string>();
     AddTag         = true;
     Name           = "";
     Version        = "";
     ForceVersion   = false;
 }
Exemple #8
0
 public JsInclude(IClientDependencyFile file)
     : base(file)
 {
     DependencyType = ClientDependencyType.Javascript;
 }
        /// <summary>
        /// When the path type is one of the base64 paths, this will create the composite file urls for all of the dependencies. 
        /// </summary>
        /// <param name="type"></param>
        /// <param name="dependencies"></param>
        /// <param name="compositeFileHandlerPath"></param>
        /// <param name="http"></param>
        /// <param name="maxLength">the max length each url can be</param>
        /// <param name="version">the current cdf version</param>
        /// <returns></returns>
        /// <remarks>
        /// Generally there will only be one path returned but his depends on how many dependencies there are and whether the base64 created path will exceed the max url length parameter.
        /// If the string length exceeds it, then we need to creaet multiple paths all of which must be less length than the maximum provided.
        /// </remarks>
        internal IEnumerable<string> GetCompositeFileUrls(
            ClientDependencyType type,
            IClientDependencyFile[] dependencies,
            string compositeFileHandlerPath,
            HttpContextBase http,
            int maxLength,
            int version)
        {
            var files = new List<string>();
            var currBuilder = new StringBuilder();
            var base64Builder = new StringBuilder();
            var builderCount = 1;
            var stringType = type.ToString();

            var remaining = new Queue<IClientDependencyFile>(dependencies);
            while (remaining.Any())
            {
                var current = remaining.Peek();

                //update the base64 output to get the length
                base64Builder.Append(current.FilePath.EncodeTo64());

                //test if the current base64 string exceeds the max length, if so we need to split
                if ((base64Builder.Length
                     + compositeFileHandlerPath.Length
                     + stringType.Length
                     + version.ToString(CultureInfo.InvariantCulture).Length
                    //this number deals with the ampersands, etc...
                     + 10)
                    >= (maxLength))
                {
                    //we need to do a check here, this is the first one and it's already exceeded the max length we cannot continue
                    if (currBuilder.Length == 0)
                    {
                        throw new InvalidOperationException("The path for the single dependency: '" + current.FilePath + "' exceeds the max length (" + maxLength + "), either reduce the single dependency's path length or increase the CompositeDependencyHandler.MaxHandlerUrlLength value");
                    }

                    //flush the current output to the array
                    files.Add(currBuilder.ToString());
                    //create some new output
                    currBuilder = new StringBuilder();
                    base64Builder = new StringBuilder();
                    builderCount++;
                }
                else
                {
                    //update the normal builder
                    currBuilder.Append(current.FilePath + ";");
                    //remove from the queue
                    remaining.Dequeue();
                }
            }

            //foreach (var a in dependencies)
            //{
            //    //update the base64 output to get the length
            //    base64Builder.Append(a.FilePath.EncodeTo64());

            //    //test if the current base64 string exceeds the max length, if so we need to split
            //    if ((base64Builder.Length
            //        + compositeFileHandlerPath.Length
            //        + stringType.Length
            //        + version.Length
            //        + 10)
            //        >= (maxLength))
            //    {
            //        //add the current output to the array
            //        files.Add(currBuilder.ToString());
            //        //create some new output
            //        currBuilder = new StringBuilder();
            //        base64Builder = new StringBuilder();
            //        builderCount++;
            //    }

            //    //update the normal builder
            //    currBuilder.Append(a.FilePath + ";");
            //}

            if (builderCount > files.Count)
            {
                files.Add(currBuilder.ToString());
            }

            //now, compress each url
            for (var i = 0; i < files.Count; i++)
            {
                //append our version to the combined url
                var encodedFile = files[i].EncodeTo64Url();
                files[i] = GetCompositeFileUrl(encodedFile, type, http, UrlType, compositeFileHandlerPath, version);
            }

            return files.ToArray();
        }
 public static HtmlHelper RequiresJs(this HtmlHelper html, IClientDependencyFile file, object htmlAttributes = null)
 {
     html.ViewContext.GetLoader().RegisterDependency(file, htmlAttributes);
     return html;
 }
Exemple #11
0
 public CssInclude(IClientDependencyFile file, CssMediaType mediaType)
     : base(file)
 {
     DependencyType = ClientDependencyType.Css;
     CssMedia = mediaType;
 }
        ///// <summary>
        ///// Checks if the "website" config param has been passed in, if so this formats the url
        ///// to be an absolute URL with the pre-pended domain
        ///// </summary>
        ///// <param name="url"></param>
        ///// <returns></returns>
        //protected string MapToWebsiteBaseUrl(string url)
        //{
        //    if (!string.IsNullOrEmpty(WebsiteBaseUrl))
        //    {
        //        if (url.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)
        //            || url.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
        //            return url;

        //        // make sure the url begins with a /
        //        string slashedUrl = (url[0] != '/' ? "/" : string.Empty) + url;

        //        return WebsiteBaseUrl + slashedUrl;
        //    }
        //    return url;
        //}


        /// <summary>
        /// Checks if the current file implements the html attribute interfaces and returns the appropriate html attributes
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private static IDictionary<string, string> GetHtmlAttributes(IClientDependencyFile file)
        {
            IDictionary<string, string> attributes = new Dictionary<string, string>();

            if (file is IHaveHtmlAttributes)
            {
                var fileWithAttributes = (IHaveHtmlAttributes)file;
                attributes = fileWithAttributes.HtmlAttributes;

                if (file is IRequiresHtmlAttributesParsing)
                {
                    //we need to parse the attributes into the dictionary
                    HtmlAttributesStringParser.ParseIntoDictionary(((IRequiresHtmlAttributesParsing)file).HtmlAttributesAsString, attributes);                    
                }                
            }

            //now we must ensure that the correct js/css attribute exist!
            switch(file.DependencyType)
            {
                case ClientDependencyType.Javascript:
                    if (!attributes.ContainsKey("type"))
                        attributes.Add("type", "text/javascript");
                    if (attributes.ContainsKey("src"))
                        attributes.Remove("src");
                    break;
                case ClientDependencyType.Css:
                    if (!attributes.ContainsKey("type"))
                        attributes.Add("type", "text/css");
                    if (!attributes.ContainsKey("rel"))
                        attributes.Add("rel", "stylesheet");
                    if (attributes.ContainsKey("href"))
                        attributes.Remove("href");
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            //just return an empty dictionary
            return attributes;
        }
Exemple #13
0
 public void RegisterDependency(IClientDependencyFile file, object htmlAttributes)
 {
     RegisterDependency(
         file.Group,
         file.Priority,
         file.FilePath,
         file.PathNameAlias,
         file.DependencyType,
         htmlAttributes,
         file.ForceProvider,
         file.ForceBundle);
 }
 public CssInclude(IClientDependencyFile file, CssMediaType mediaType)
     : base(file)
 {
     DependencyType = ClientDependencyType.Css;
     CssMedia       = mediaType;
 }
		internal void AddDependency(IClientDependencyFile file)
		{
			Dependencies.Add(file);
		}
Exemple #16
0
 public JsInclude(IClientDependencyFile file)
     : base(file)
 {
     DependencyType = ClientDependencyType.Javascript;
 }
 internal void AddDependency(IClientDependencyFile file)
 {
     Dependencies.Add(file);
 }
Exemple #18
0
 public CssInclude(IClientDependencyFile file)
     : base(file)
 {
     DependencyType = ClientDependencyType.Css;
 }
 public void RegisterDependency(IClientDependencyFile file)
 {
     RegisterDependency(file, null);
 }
Exemple #20
0
 public static HtmlHelper RequiresCss(this HtmlHelper html, IClientDependencyFile file, object htmlAttributes = null)
 {
     html.ViewContext.GetLoader().RegisterDependency(file, htmlAttributes);
     return(html);
 }
Exemple #21
0
 public void RegisterDependency(IClientDependencyFile file)
 {
     RegisterDependency(file, null);
 }