BlueCollar.Dashboard.StaticFile.Create C# (CSharp) Method

Create() private method

private Create ( string urlRoot, string path ) : StaticFile
urlRoot string
path string
return StaticFile
        public static StaticFile Create(string urlRoot, string path)
        {
            if (string.IsNullOrEmpty(urlRoot))
            {
                throw new ArgumentNullException("urlRoot", "urlRoot must contain a value.");
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path", "path must contain a value.");
            }

            if (Regex.IsMatch(urlRoot, "^~/"))
            {
                urlRoot = urlRoot.Substring(1);
            }

            if (urlRoot.LastIndexOf("/", StringComparison.Ordinal) == urlRoot.Length - 1)
            {
                urlRoot = urlRoot.Substring(0, urlRoot.Length - 1);
            }

            if (Regex.IsMatch(path, "^~/"))
            {
                path = path.Substring(2);
            }

            path = path.ToLowerInvariant();
            string[] pathParts = path.Split('/');
            string ext = System.IO.Path.GetExtension(path);

            return new StaticFile()
            {
                ContentType = GetContentType(ext),
                Extension = ext,
                OriginalPath = path,
                Name = System.IO.Path.GetFileNameWithoutExtension(path),
                Path = pathParts.Length > 1 ? string.Join("/", pathParts.Take(pathParts.Length - 1).ToArray()) : string.Empty,
                ResourceName = string.Concat("BlueCollar.Dashboard.Static.", string.Join(".", pathParts)),
                UrlRoot = urlRoot.ToLowerInvariant()
            };
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the Index class.
        /// </summary>
        /// <param name="applicationName">The name of the current application.</param>
        /// <param name="file">The <see cref="StaticFile"/> instance representing the index XSLT stylesheet.</param>
        /// <param name="counts">The counts record to initialize this instance with.</param>
        public Index(string applicationName, StaticFile file, CountsRecord counts)
        {
            if (string.IsNullOrEmpty(applicationName))
            {
                throw new ArgumentNullException("applicationName", "applicationName must contain a value.");
            }

            if (file == null)
            {
                throw new ArgumentNullException("file", "file cannot be null.");
            }

            if (!"index.xslt".Equals(file.OriginalPath, StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("file must represent index.xslt.", "file");
            }

            if (counts == null)
            {
                throw new ArgumentNullException("counts", "counts cannot be null.");
            }

            this.ApplicationName = applicationName;
            this.file            = file;

            this.CountsJson    = JsonConvert.SerializeObject(counts);
            this.CssUrl        = StaticFile.Create(this.file.UrlRoot, "css/collar.css").Url;
            this.Html5JSUrl    = StaticFile.Create(this.file.UrlRoot, "js/html5.js").Url;
            this.JSApiUrl      = "//www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['corechart']}]}";
            this.JSUrl         = StaticFile.Create(this.file.UrlRoot, "js/collar.js").Url;
            this.LogoHeaderUrl = StaticFile.Create(this.file.UrlRoot, "img/logo-header.png").Url;
            this.TemplatesHtml = GetTemplatesHtml();
            this.UrlRoot       = file.UrlRoot;
            this.Version       = typeof(Index).Assembly.GetName().Version.ToString(2);
        }
All Usage Examples Of BlueCollar.Dashboard.StaticFile::Create