/// <summary>
        /// Injects additional Javascript files into the index.html page
        /// </summary>
        /// <param name="options"></param>
        /// <param name="path">A path to the javascript - i.e. the script "src" attribute</param>
        /// <param name="type">The script type - i.e. the script "type" attribute</param>
        public static void InjectJavascript(this EventBusDocUIOptions options, string path, string type = "text/javascript")
        {
            var builder = new StringBuilder(options.HeadContent);

            builder.AppendLine($"<script src='{path}' type='{type}'></script>");
            options.HeadContent = builder.ToString();
        }
        /// <summary>
        /// Injects additional CSS stylesheets into the index.html page
        /// </summary>
        /// <param name="options"></param>
        /// <param name="path">A path to the stylesheet - i.e. the link "href" attribute</param>
        /// <param name="media">The target media - i.e. the link "media" attribute</param>
        public static void InjectStylesheet(this EventBusDocUIOptions options, string path, string media = "screen")
        {
            var builder = new StringBuilder(options.HeadContent);

            builder.AppendLine($"<link href='{path}' rel='stylesheet' media='{media}' type='text/css' />");
            options.HeadContent = builder.ToString();
        }
        /// <summary>
        /// Adds Swagger JSON endpoints. Can be fully-qualified or relative to the UI page
        /// </summary>
        /// <param name="options"></param>
        /// <param name="url">Can be fully qualified or relative to the current host</param>
        /// <param name="name">The description that appears in the document selector drop-down</param>
        public static void EventBusDocEndPoint(this EventBusDocUIOptions options, string url, string name)
        {
            var urls = new List <UrlDescriptor>(options.ConfigObject.Urls ?? Enumerable.Empty <UrlDescriptor>());

            urls.Add(new UrlDescriptor {
                Url = url, Name = name
            });
            options.ConfigObject.Urls = urls;
        }
Exemple #4
0
 public EventBusDocUIMiddleware(
     RequestDelegate next,
     IHostingEnvironment hostingEnv,
     ILoggerFactory loggerFactory,
     EventBusDocUIOptions options)
 {
     _options = options ?? new EventBusDocUIOptions();
     _staticFileMiddleware = CreateStaticFileMiddleware(next, hostingEnv, loggerFactory, options);
 }
Exemple #5
0
        public static IApplicationBuilder UseEventBusDocUI(
            this IApplicationBuilder app,
            Action <EventBusDocUIOptions> setupAction = null)
        {
            if (setupAction == null)
            {
                // Don't pass options so it can be configured/injected via DI container instead
                app.UseMiddleware <EventBusDocUIMiddleware>();
            }
            else
            {
                // Configure an options instance here and pass directly to the middleware
                var options = new EventBusDocUIOptions();
                setupAction.Invoke(options);

                app.UseMiddleware <EventBusDocUIMiddleware>(options);
            }

            return(app);
        }
Exemple #6
0
        private StaticFileMiddleware CreateStaticFileMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, EventBusDocUIOptions options)
        {
            var staticFileOptions = new StaticFileOptions
            {
                RequestPath  = string.IsNullOrEmpty(options.RoutePrefix) ? string.Empty : $"/{options.RoutePrefix}",
                FileProvider = new EmbeddedFileProvider(typeof(EventBusDocUIMiddleware).GetTypeInfo().Assembly, EmbeddedFileNamespace),
            };

            //EmbeddedFileProvider -> Looks up files using embedded resources in the specified assembly. This file provider is case sensitive
            return(new StaticFileMiddleware(next, hostingEnv, Microsoft.Extensions.Options.Options.Create(staticFileOptions), loggerFactory));
        }