public void Configuration(IAppBuilder builder) { builder.UseAlpha("a", "b"); builder.UseFunc(app => Alpha.Invoke(app, "a", "b")); builder.UseFunc(Alpha.Invoke, "a", "b"); builder.Use(Beta.Invoke("a", "b")); builder.UseFunc(Beta.Invoke, "a", "b"); builder.UseGamma("a", "b"); builder.Use(typeof(Gamma), "a", "b"); builder.UseType <Gamma>("a", "b"); builder.UseFunc <AppFunc>(app => new Gamma(app, "a", "b").Invoke); builder.Use(typeof(Delta), "a", "b"); builder.UseType <Delta>("a", "b"); builder.UseFunc <AppFunc>(app => new Delta(app, "a", "b").Invoke); builder.Run(this); }
public void Configuration(IAppBuilder builder) { builder.UseAlpha("a", "b"); builder.UseFunc(app => Alpha.Invoke(app, "a", "b")); builder.UseFunc(Alpha.Invoke, "a", "b"); builder.Use(Beta.Invoke("a", "b")); builder.UseFunc(Beta.Invoke, "a", "b"); builder.UseGamma("a", "b"); builder.Use(typeof(Gamma), "a", "b"); builder.UseType<Gamma>("a", "b"); builder.UseFunc<AppFunc>(app => new Gamma(app, "a", "b").Invoke); builder.Use(typeof(Delta), "a", "b"); builder.UseType<Delta>("a", "b"); builder.UseFunc<AppFunc>(app => new Delta(app, "a", "b").Invoke); builder.Run(this); }
public void Configuration(IAppBuilder app) { app.UseFunc(LogBefore); app.UseShowExceptions(); app.UseStatic(".", new List<string> { "/favicon.ico", "/images", "/html", "/css" }); app.Run(WebApp.App(new GmcJobList())); }
public static IAppBuilder UseGate(this IAppBuilder builder, Action <Request> app) { return(builder.UseFunc(next => environment => { app.Invoke(new Request(environment)); return next(environment); })); }
public static IAppBuilder UseGate(this IAppBuilder builder, Action <Request, Response> app) { return(builder.UseFunc(next => environment => { app.Invoke(new Request(environment), new Response(environment)); return TaskHelpers.Completed(); })); }
public static IAppBuilder UseFunc <T1>(this IAppBuilder builder, Func <T1, Func <AppFunc, AppFunc> > middleware, T1 arg1) { if (builder == null) { throw new ArgumentNullException("builder"); } return(builder.UseFunc <AppFunc>(app => middleware(arg1)(app))); }
public static IAppBuilder UseHandler( this IAppBuilder builder, Func <OwinRequest, OwinResponse, Task> handler) { return(builder.UseFunc( next => env => handler( new OwinRequest(env), new OwinResponse(env)))); }
public override void AttachToHttpApp(IRobot robo, IAppBuilder app) { app.UseFunc(next => async environment => { var req = new Request(environment); TraceRequest(robo, req); await next(environment); TraceResponse(robo, req, new Response(environment)); }); }
public static IAppBuilder UseFunc <T1, T2, T3, T4>(this IAppBuilder builder, Func <AppFunc, T1, T2, T3, T4, AppFunc> middleware, T1 arg1, T2 arg2, T3 arg3, T4 arg4) { if (builder == null) { throw new ArgumentNullException("builder"); } return(builder.UseFunc <AppFunc>(app => middleware(app, arg1, arg2, arg3, arg4))); }
public void Configuration(IAppBuilder app) { var bootstrapper = new DefaultNancyBootstrapper(); app .UseFunc(LogRequests) // defined below .UseShowExceptions() // from Gate.Middleware package .MapHubs("/signalr") // from SignalR.Server assembly .RunNancy(bootstrapper); // from Gate.Adapters.Nancy package }
public static IAppBuilder UseFilter( this IAppBuilder builder, Action <OwinRequest> filter) { return(builder.UseFunc( next => env => { filter(new OwinRequest(env)); return next(env); })); }
public void HelloWorld(IAppBuilder app) { app.UseFunc(_ => env => { var output = (Stream)env["owin.ResponseBody"]; using (var writer = new StreamWriter(output)) { writer.Write("Hello world!"); } return TaskHelpers.Completed(); }); }
public void HelloWorld(IAppBuilder app) { app.UseFunc(_ => env => { var output = (Stream)env["owin.ResponseBody"]; using (var writer = new StreamWriter(output)) { writer.Write("Hello world!"); } return(TaskHelpers.Completed()); }); }
public void AnotherAlternative(IAppBuilder builder) { Assembly.Load("Nancy.ViewEngines.Spark"); builder .UseFunc<AppDelegate>(ShowExceptions.Middleware) .UseType<ContentType>() .Map("/wilson", Wilson.App()) .Map("/wilsonasync", Wilson.App(true)) .RunCascade( DefaultPage.App(), NancyAdapter.App()); }
public void TextHtmlAlpha(IAppBuilder app) { app.UseFunc(next => env => { var headers = (IDictionary<string, string[]>)env["owin.ResponseHeaders"]; var body = (Stream)env["owin.ResponseBody"]; headers["Content-Type"] = new string[] { "text/html" }; using (var writer = new StreamWriter(body)) { writer.Write("<p>alpha</p>"); } return TaskHelpers.Completed(); }); }
public void TextHtmlAlpha(IAppBuilder app) { app.UseFunc(next => env => { var headers = (IDictionary <string, string[]>)env["owin.ResponseHeaders"]; var body = (Stream)env["owin.ResponseBody"]; headers["Content-Type"] = new string[] { "text/html" }; using (var writer = new StreamWriter(body)) { writer.Write("<p>alpha</p>"); } return(TaskHelpers.Completed()); }); }
public void AnotherAlternative(IAppBuilder builder) { Assembly.Load("Nancy.ViewEngines.Spark"); builder .UseFunc <AppFunc>(ShowExceptions.Middleware) .UseType <ContentType>() .Map("/wilson", Wilson.App()) .Map("/wilsonasync", Wilson.App(true)) .Use(NancyAdapter.App()); /* * .RunCascade( * DefaultPage.App(), * NancyAdapter.App()); */ }
public static IAppBuilder UseFilter( this IAppBuilder builder, Func <OwinRequest, Task> filter) { return(builder.UseFunc( next => env => { var task = filter(new OwinRequest(env)); if (task.IsCompleted) { if (task.IsFaulted || task.IsCanceled) { return task; } return next(env); } var syncContext = SynchronizationContext.Current; return task.ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { return t; } if (syncContext == null) { return next(env); } var tcs = new TaskCompletionSource <Task>(); syncContext.Post(_ => { try { tcs.TrySetResult(next(env)); } catch (Exception ex) { tcs.TrySetException(ex); } }, null); return tcs.Task.Unwrap(); }, TaskContinuationOptions.ExecuteSynchronously).Unwrap(); })); }
public static IAppBuilder UseDirect(this IAppBuilder builder, Func <Request, Response, Task> app) { return(builder.UseFunc <AppFunc>(next => environment => { var req = new Request(environment); var resp = new Response(environment) { Next = () => next(environment) }; app.Invoke(req, resp) .Then(() => resp.EndAsync()) .Catch(caught => { resp.End(caught.Exception); return caught.Handled(); }); return resp.Task; })); }
public static IAppBuilder UseHandler( this IAppBuilder builder, Action <OwinRequest, OwinResponse> handler) { return(builder.UseFunc( next => env => { try { handler( new OwinRequest(env), new OwinResponse(env)); return CompletedTask; } catch (Exception ex) { var tcs = new TaskCompletionSource <object>(); tcs.SetException(ex); return tcs.Task; } })); }
public MapBuilder(IAppBuilder builder, Func<AppFunc, IDictionary<string, AppFunc>, AppFunc> mapper) { _map = new Dictionary<string, AppFunc>(); _mapper = mapper; _builder = builder.UseFunc<AppFunc>(a => _mapper(a, _map)); }
public static IAppBuilder UseAlpha(this IAppBuilder builder, string arg1, string arg2) { return builder.UseFunc(Alpha.Invoke, arg1, arg2); }
public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif app.UseWelcomePage("/"); app.UseFunc(LoggingMiddleware); #region /mordor app.UseFunc( next => async env => { if (!string.Equals("/mordor", (string)env["owin.RequestPath"], StringComparison.Ordinal)) { await next(env); return; } using (var sw = new StreamWriter((Stream)env["owin.ResponseBody"])) { var content = string.Format("One does not simply {0} into Mordor.", env["owin.RequestMethod"]); var headers = (IDictionary<string, string[]>)env["owin.ResponseHeaders"]; headers["Content-Length"] = new[] { content.Length.ToString() }; headers["Content-Type"] = new[] { "text/plain" }; await sw.WriteAsync(content); } }); #endregion #region /email app.UseFunc( next => async env => { if (!string.Equals("/email", (string)env["owin.RequestPath"], StringComparison.Ordinal)) { await next(env); return; } using (var sw = new StreamWriter((Stream)env["owin.ResponseBody"])) { var content = "<html><body><form action='http://localhost:23456/api/send' method='POST'><label>Subject: <input name='Subject' /></label><input type='Submit'></form></body></html>"; var headers = (IDictionary<string, string[]>)env["owin.ResponseHeaders"]; headers["Content-Length"] = new[] { content.Length.ToString() }; headers["Content-Type"] = new[] { "text/html" }; await sw.WriteAsync(content); } }); #endregion app.UseFunc(EnvironmentEndpoint); }
public static IAppBuilder RunNancy(this IAppBuilder builder) { return(builder.UseFunc <AppFunc>(_ => App())); }
public static void Custom(IAppBuilder builder) { builder.UseFunc<AppDelegate>(App); }
public static IAppBuilder UseStatic(this IAppBuilder builder, IEnumerable <string> urls) { return(builder.UseFunc <AppFunc>(app => Static.Middleware(app, urls))); }
public static IAppBuilder UseShowExceptions(this IAppBuilder builder) { return(builder.UseFunc <AppFunc>(Middleware)); }
public static IAppBuilder UseGate(this IAppBuilder builder, Func <Request, Response, Func <Task>, Task> app) { return(builder.UseFunc(next => environment => app.Invoke(new Request(environment), new Response(environment), () => next(environment)))); }
public static IAppBuilder UseOwin( this IAppBuilder builder, Func <OwinRequest, OwinResponse, Func <Task>, Task> process) { return(builder.UseFunc(next => env => process(new OwinRequest(env), new OwinResponse(env), () => next(env)))); }
public MapBuilder(IAppBuilder builder, Func <AppFunc, IDictionary <string, AppFunc>, AppFunc> mapper) { _map = new Dictionary <string, AppFunc>(); _mapper = mapper; _builder = builder.UseFunc <AppFunc>(a => _mapper(a, _map)); }
public static IAppBuilder UseMethodOverride(this IAppBuilder builder) { return(builder.UseFunc <AppFunc>(Middleware)); }
public static IAppBuilder UseStatic(this IAppBuilder builder, string root) { return(builder.UseFunc <AppFunc>(app => Static.Middleware(app, root))); }
public static IAppBuilder UseWebSockets(this IAppBuilder builder) { return(builder.UseFunc <AppFunc>(OpaqueToWebSocket.Middleware)); }
public static IAppBuilder UseStatic(this IAppBuilder builder) { return(builder.UseFunc <AppFunc>(Static.Middleware)); }
public void Configuration(IAppBuilder app) { #if DEBUG app.UseErrorPage(); #endif app.UseWelcomePage("/"); app.UseFunc(LoggingMiddleware); #region /mordor app.UseFunc( next => async env => { if (!string.Equals("/mordor", (string)env["owin.RequestPath"], StringComparison.Ordinal)) { await next(env); return; } using (var sw = new StreamWriter((Stream)env["owin.ResponseBody"])) { var content = string.Format("One does not simply {0} into Mordor.", env["owin.RequestMethod"]); var headers = (IDictionary <string, string[]>)env["owin.ResponseHeaders"]; headers["Content-Length"] = new[] { content.Length.ToString() }; headers["Content-Type"] = new[] { "text/plain" }; await sw.WriteAsync(content); } }); #endregion #region /email app.UseFunc( next => async env => { if (!string.Equals("/email", (string)env["owin.RequestPath"], StringComparison.Ordinal)) { await next(env); return; } using (var sw = new StreamWriter((Stream)env["owin.ResponseBody"])) { var content = "<html><body><form action='http://localhost:23456/api/send' method='POST'><label>Subject: <input name='Subject' /></label><input type='Submit'></form></body></html>"; var headers = (IDictionary <string, string[]>)env["owin.ResponseHeaders"]; headers["Content-Length"] = new[] { content.Length.ToString() }; headers["Content-Type"] = new[] { "text/html" }; await sw.WriteAsync(content); } }); #endregion app.UseFunc(EnvironmentEndpoint); }
public static IAppBuilder RunNancy(this IAppBuilder builder, INancyBootstrapper bootstrapper) { return(builder.UseFunc <AppFunc>(_ => App(bootstrapper))); }