private Task DocumentConfiguration(IOwinContext context)
        {
            Func <IEnumerable <ExtensionConfiguration>, string> formatExtensions = (extensions) =>
            {
                var sb = new StringBuilder();
                sb.Append("<pre>[<br/>");
                var first = true;
                foreach (var extension in extensions)
                {
                    if (first)
                    {
                        sb.Append("&nbsp;&nbsp;{<br/>");
                        first = false;
                    }
                    else
                    {
                        sb.Append(",<br/>&nbsp;&nbsp;{<br/>");
                    }
                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;\"extension\":\"" + extension.Extension + "\",<br/>");
                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;\"mimeType\":\"" + extension.MimeType + "\"<br/>");
                    sb.Append("&nbsp;&nbsp;}");
                }
                sb.Append("<br/>]</pre>");
                return(sb.ToString());
            };

            var document = GetScriptResource("configuration.html");

            document = document.Replace("{staticFilesRootUrl}", _configuration.StaticFilesRootUrl);
            document = document.Replace("{documentationRootUrl}", _configuration.DocumentationRootUrl);
            document = document.Replace("{rootDirectory}", _configuration.RootDirectory);
            document = document.Replace("{enabled}", _configuration.Enabled.ToString());
            document = document.Replace("{includeSubFolders}", _configuration.IncludeSubFolders.ToString());
            document = document.Replace("{fileExtensions}", formatExtensions(_configuration.FileExtensions));
            document = document.Replace("{maximumFileSizeToCache}", _configuration.MaximumFileSizeToCache.ToString());
            document = document.Replace("{maximumCacheTime}", _configuration.MaximumCacheTime.ToString());
            document = document.Replace("{requiredPermission}", _configuration.RequiredPermission);
            document = document.Replace("{analyticsEnabled}", _configuration.AnalyticsEnabled.ToString());

            var defaultConfiguration = new StaticFilesConfiguration();

            document = document.Replace("{staticFilesRootUrl.default}", defaultConfiguration.StaticFilesRootUrl);
            document = document.Replace("{documentationRootUrl.default}", defaultConfiguration.DocumentationRootUrl);
            document = document.Replace("{rootDirectory.default}", defaultConfiguration.RootDirectory);
            document = document.Replace("{enabled.default}", defaultConfiguration.Enabled.ToString());
            document = document.Replace("{includeSubFolders.default}", defaultConfiguration.IncludeSubFolders.ToString());
            document = document.Replace("{fileExtensions.default}", formatExtensions(defaultConfiguration.FileExtensions));
            document = document.Replace("{maximumFileSizeToCache.default}", defaultConfiguration.MaximumFileSizeToCache.ToString());
            document = document.Replace("{maximumCacheTime.default}", defaultConfiguration.MaximumCacheTime.ToString());
            document = document.Replace("{requiredPermission.default}", defaultConfiguration.RequiredPermission);
            document = document.Replace("{analyticsEnabled.default}", defaultConfiguration.AnalyticsEnabled.ToString());

            context.Response.ContentType = "text/html";
            return(context.Response.WriteAsync(document));
        }
        public void Configure(IConfiguration configuration, string path)
        {
            _traceFilter.ConfigureWith(configuration);

            _configurationRegistration = configuration.Register(
                path,
                cfg =>
            {
                _configuration = cfg;

                Func <string, string> normalizeFolder = p =>
                {
                    p = p.Replace("/", "\\");

                    if (p.Length > 0 && !p.EndsWith("\\"))
                    {
                        p = p + "\\";
                    }

                    return(_hostingEnvironment.MapPath(p));
                };

                Func <string, PathString> normalizeUrl = u =>
                {
                    u = u.Replace("\\", "/");

                    if (u.Length > 0 && u.EndsWith("/"))
                    {
                        u = u.Substring(0, u.Length - 1);
                    }

                    if (!u.StartsWith("/"))
                    {
                        u = "/" + u;
                    }

                    return(new PathString(u));
                };

                _rootFolder = normalizeFolder(cfg.RootDirectory ?? "");
                _rootUrl    = normalizeUrl(cfg.StaticFilesRootUrl ?? "");
            },
                new StaticFilesConfiguration());
        }