Exemplo n.º 1
0
        public Task Invoke(IDictionary <string, object> environment)
        {
            // reference embedded resouces
            const string prefix = "LightNode.Swagger.SwaggerUI.";

            var path = environment.AsRequestPath().Trim('/');

            if (path == "")
            {
                path = "index.html";
            }
            var filePath = prefix + path.Replace("/", ".");

            if (path.Split('.').Last() == "json")
            {
                var engineId = Path.GetFileNameWithoutExtension(path);
                // only use first item
                var target = (engineId == "api-default")
                    ? LightNodeServerMiddleware.GetRegisteredHandlersInfo().First().First()
                    : LightNodeServerMiddleware.GetRegisteredHandlersInfo()[engineId].First();

                var bytes = BuildSwaggerJson(options, environment, target);
                environment.AsResponseBody().Write(bytes, 0, bytes.Length);
                environment.AsResponseHeaders()["Content-Type"] = new[] { "application/json" };
                environment[OwinConstants.ResponseStatusCode]   = 200;
                return(Task.FromResult(0));
            }

            var myAssembly = typeof(LightNodeSwaggerMiddleware).Assembly;

            using (var stream = myAssembly.GetManifestResourceStream(filePath))
            {
                if (options.ResolveCustomResource == null)
                {
                    if (stream == null)
                    {
                        return(next(environment));
                    }

                    var response = environment.AsResponseBody();
                    stream.CopyTo(response);
                }
                else
                {
                    byte[] bytes;
                    if (stream == null)
                    {
                        bytes = options.ResolveCustomResource(path, null);
                    }
                    else
                    {
                        using (var ms = new MemoryStream())
                        {
                            stream.CopyTo(ms);
                            bytes = options.ResolveCustomResource(path, ms.ToArray());
                        }
                    }

                    if (bytes == null)
                    {
                        return(next(environment));
                    }

                    var response = environment.AsResponseBody();
                    response.Write(bytes, 0, bytes.Length);
                }
            }

            var mediaType = GetMediaType(filePath);

            environment.AsResponseHeaders()["Content-Type"] = new[] { mediaType };
            environment[OwinConstants.ResponseStatusCode]   = 200;

            return(Task.FromResult(0));
        }
Exemplo n.º 2
0
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
        public void Hoge(string p)
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
        {
            var hoge = LightNodeServerMiddleware.GetRegisteredHandlersInfo();
        }
Exemplo n.º 3
0
 public void Hoge(string p)
 {
     var hoge = LightNodeServerMiddleware.GetRegisteredHandlersInfo();
 }