Provides access to embedded static files.
Exemplo 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs the concrete request operation and returns the output as a byte array.
        /// </summary>
        /// <param name="context">The HTTP context to perform the request for.</param>
        /// <param name="file">The static file to return the contents of.</param>
        /// <returns>The response to write.</returns>
        protected override byte[] PerformRequest(HttpContextBase context, StaticFile file)
        {
            string contents = Regex.Replace(
                Encoding.UTF8.GetString(file.Contents),
                @"url\(('|"")?([^'""#?\)]+)((#|\?)[^""'\)]+)?('|"")?\)",
                m =>
            {
                try
                {
                    return(string.Format(
                               CultureInfo.InvariantCulture,
                               "url({0}{1}{2}{3})",
                               m.Groups[1].Value,
                               StaticFile.Create(file.UrlRoot, m.Groups[2].Value).Url,
                               m.Groups[3].Value,
                               m.Groups[5].Value));
                }
                catch (FileNotFoundException)
                {
                    return(m.Groups[0].Value);
                }
            });

            return(EncodeString(contents));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs the concrete request operation and returns the output as a byte array.
        /// </summary>
        /// <param name="context">The HTTP context to perform the request for.</param>
        /// <param name="file">The static file to return the contents of.</param>
        /// <returns>The response to write.</returns>
        protected override byte[] PerformRequest(HttpContextBase context, StaticFile file)
        {
            string contents = Regex.Replace(
                Encoding.UTF8.GetString(file.Contents),
                @"url\(('|"")?([^'""#?\)]+)((#|\?)[^""'\)]+)?('|"")?\)",
                m =>
                {
                    try
                    {
                        return string.Format(
                            CultureInfo.InvariantCulture,
                            "url({0}{1}{2}{3})",
                            m.Groups[1].Value,
                            StaticFile.Create(file.UrlRoot, m.Groups[2].Value).Url,
                            m.Groups[3].Value,
                            m.Groups[5].Value);
                    }
                    catch (FileNotFoundException)
                    {
                        return m.Groups[0].Value;
                    }
                });

            return EncodeString(contents);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="StaticFile"/> instance corresponding with the current request.
        /// </summary>
        /// <param name="context">The HTTP context to create the file for.</param>
        /// <returns>A <see cref="StaticFile"/> instance.</returns>
        protected virtual StaticFile CreateFile(HttpContextBase context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context", "context cannot be null.");
            }

            return(StaticFile.Create(HandlerUrl, this.RequestedFileName));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Performs the concrete request operation and returns the output as a byte array.
        /// </summary>
        /// <param name="context">The HTTP context to perform the request for.</param>
        /// <param name="file">The static file to return the contents of.</param>
        /// <returns>The response to write.</returns>
        protected virtual byte[] PerformRequest(HttpContextBase context, StaticFile file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file", "file cannot be null.");
            }

            return(file.Contents);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the templates HTML as a string.
        /// </summary>
        /// <returns>The templates HTML as a string.</returns>
        private static string GetTemplatesHtml()
        {
            const string Key       = "BlueCollar.Dashboard.Index.Templates";
            string       templates = HttpRuntime.Cache[Key] as string;

            if (string.IsNullOrEmpty(templates))
            {
                templates = StaticFile.GetContentsAsString("BlueCollar.Dashboard.Static.templates.html");

                HttpRuntime.Cache.Add(
                    Key,
                    templates,
                    null,
                    Cache.NoAbsoluteExpiration,
                    Cache.NoSlidingExpiration,
                    CacheItemPriority.Normal,
                    null);
            }

            return(templates);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Performs the concrete request operation and returns the output as a byte array.
 /// </summary>
 /// <param name="context">The HTTP context to perform the request for.</param>
 /// <param name="file">The static file to return the contents of.</param>
 /// <returns>The response to write.</returns>
 protected override byte[] PerformRequest(HttpContextBase context, StaticFile file)
 {
     return EncodeString(new Index(ApplicationName, file, Repository.GetCounts(ApplicationName, null)).Transform());
 }
Exemplo n.º 9
0
 /// <summary>
 /// Performs the concrete request operation and returns the output as a byte array.
 /// </summary>
 /// <param name="context">The HTTP context to perform the request for.</param>
 /// <param name="file">The static file to return the contents of.</param>
 /// <returns>The response to write.</returns>
 protected override byte[] PerformRequest(HttpContextBase context, StaticFile file)
 {
     return(EncodeString(new Index(ApplicationName, file, Repository.GetCounts(ApplicationName, null)).Transform()));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Performs the concrete request operation and returns the output as a byte array.
        /// </summary>
        /// <param name="context">The HTTP context to perform the request for.</param>
        /// <param name="file">The static file to return the contents of.</param>
        /// <returns>The response to write.</returns>
        protected virtual byte[] PerformRequest(HttpContextBase context, StaticFile file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file", "file cannot be null.");
            }

            return file.Contents;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the Index class.
 /// </summary>
 public Index()
     : this(BlueCollarSection.Section.ApplicationName, StaticFile.Create(BlueCollarSection.Section.Dashboard.HandlerUrl, "index.xslt"), new CountsRecord())
 {
 }