public Func <IDictionary <string, object>, Task> Build() { var fixerSetupMethod = FindFixerSetupMethod(); var fixer = new Fixer(); object instance = fixerSetupMethod.IsStatic || fixerSetupMethod.DeclaringType == null ? null : Activator.CreateInstance(fixerSetupMethod.DeclaringType); var parameters = new object[1]; var parameterType = fixerSetupMethod.GetParameters().Single().ParameterType; if (parameterType.IsAssignableFrom(typeof(Fixer))) { parameters[0] = fixer; } else { var adapter = _adapters.FirstOrDefault(a => parameterType.IsAssignableFrom(a.AdaptedType)); if (adapter != null) { parameters[0] = adapter.Adapt(fixer); } } if (parameters[0] == null) { parameters[0] = new Action <Func <IDictionary <string, object>, Func <IDictionary <string, object>, Task>, Task> >(f => fixer.Use(f)); } fixerSetupMethod.Invoke(instance, parameters); return(fixer.Build()); }
public Func<IDictionary<string, object>, Task> Build() { var fixerSetupMethod = FindFixerSetupMethod(); var fixer = new Fixer(); object instance = fixerSetupMethod.IsStatic || fixerSetupMethod.DeclaringType == null ? null : Activator.CreateInstance(fixerSetupMethod.DeclaringType); var parameters = new object[1]; var parameterType = fixerSetupMethod.GetParameters().Single().ParameterType; if (parameterType.IsAssignableFrom(typeof (Fixer))) { parameters[0] = fixer; } else { var adapter = _adapters.FirstOrDefault(a => parameterType.IsAssignableFrom(a.AdaptedType)); if (adapter != null) { parameters[0] = adapter.Adapt(fixer); } } if (parameters[0] == null) { parameters[0] = new Action<Func<IDictionary<string, object>, Func<IDictionary<string, object>, Task>, Task>>(f => fixer.Use(f)); } fixerSetupMethod.Invoke(instance, parameters); return fixer.Build(); }
public Func<IDictionary<string, object>, Task> BuildApp() { var staticBuilder = Simple.Owin.Static.Statics.AddFolder("/assets").AddFolder("/app"); var app = new Fixer() .Use(staticBuilder.Build()) .Use(Application.Run) .Build(); return app; }
public static void Main(string[] args) { int port = 0; if (args.Length == 0) { port = 3333; } else if (args.Length == 1) { if (!int.TryParse(args[0], out port)) { Console.Error.WriteLine("Usage: flux.exe [port]"); Environment.Exit(1); } } else { Console.Error.WriteLine("Usage: flux.exe [port]"); Environment.Exit(1); } using (var server = new Server(port)) { _fixer = new Fixer(server.Start, server.Stop); if (Directory.EnumerateFiles(Environment.CurrentDirectory, "*.dll").Any()) { FixUpAssemblies(_fixer, "*.dll", Environment.CurrentDirectory); } else { var bin = Path.Combine(Environment.CurrentDirectory, "bin"); if (Directory.Exists(bin)) { FixUpAssemblies(_fixer, "*.dll", bin); } else { Console.Error.WriteLine("No application found in {0} or {0}\\bin", Environment.CurrentDirectory); Environment.Exit(1); } } Console.CancelKeyPress += ConsoleOnCancelKeyPress; Console.TreatControlCAsInput = false; _fixer.Start(); Console.WriteLine("Flux {0}: listening on port {1}. Press CTRL-C to stop.", Assembly.GetExecutingAssembly().GetName().Version, port); while (!_stop) { Console.ReadKey(); } } }
static void Main(string[] args) { var app = new Fixer().Use(Start).Build(); var builder = ServerBuilder.New() .SetPort(1234) .SetOwinApp(app); using (builder.Start()) { Console.WriteLine("Listening on port 8888. Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { var app = new Fixer().Use( Statics.AddFileAlias("/index.html", "/") .AddFolder("/css") .AddFolderAlias("/assets/images", "/images") .AddFolderAlias("/Scripts", "/js/vendor") ).Build(); using (var server = Nowin.ServerBuilder.New().SetPort(8282).SetOwinApp(app).Build()) { server.Start(); Console.WriteLine("Running. Press ENTER to stop."); Console.ReadLine(); } }
static void Main(string[] args) { var prefix = args.Length == 1 ? args[0] : "http://*:3333/"; using (var server = new Server(prefix)) { var fixer = new Fixer(func => server.Start(func), server.Stop); using (var catalog = new DirectoryCatalog(Environment.CurrentDirectory)) { var container = new CompositionContainer(catalog); container.ComposeParts(fixer); } fixer.Start(); Console.Write("Running. Press Enter to stop."); Console.ReadLine(); fixer.Stop(); } }
public Func<IDictionary<string, object>, Task> Build() { var fixerSetupMethod = FindFixerSetupMethod(); var fixer = new Fixer(); object instance = fixerSetupMethod.IsStatic || fixerSetupMethod.DeclaringType == null ? null : CreateInstanceOfOwinAppSetupClass(fixerSetupMethod.DeclaringType); object[] parameters; var parameterInfos = fixerSetupMethod.GetParameters(); if (parameterInfos.Length == 1) { parameters = new object[1]; var parameterType = parameterInfos[0].ParameterType; if (parameterType.IsAssignableFrom(typeof (Fixer))) { parameters[0] = fixer; } else { var adapter = _adapters.FirstOrDefault(a => parameterType.IsAssignableFrom(a.AdaptedType)); if (adapter != null) { parameters[0] = adapter.Adapt(fixer); } } if (parameters[0] == null) { parameters[0] = new Action<Func<AppFunc, AppFunc>>(f => fixer.Use(f)); } } else { var useAction = new Action<Func<AppFunc, AppFunc>>(f => fixer.Use(f)); var mapAction = new Action<string, Func<AppFunc, AppFunc>>((p,f) => fixer.Map(p,f)); parameters = new object[]{useAction, mapAction}; } fixerSetupMethod.Invoke(instance, parameters); return fixer.Build(); }
static void Main() { var nancyOptions = new NancyOptions { Bootstrapper = new DefaultNancyBootstrapper() }; var app = new Fixer() .Use((env, next) => new NancyOwinHost(next, nancyOptions).Invoke(env)) .Build(); // Set up the Nowin server var builder = ServerBuilder.New() .SetPort(8888) .SetOwinApp(app); // Run using (builder.Start()) { Console.WriteLine("Listening on port 1337. Enter to exit."); Console.ReadLine(); } }
// Based on http://blog.markrendle.net/2013/10/01/fix-and-owin-and-simple-web/ static void Main() { var config = new HttpConfiguration(); config.Routes.MapHttpRoute("ApiDefault", "{controller}/{id}", new {id = RouteParameter.Optional}); var server = new HttpServer(config); // Build the OWIN app var app = new Fixer() // I'm creating a new handler *for each* request // because the next is defined in the HttpMessageHandlerAdapter ctor, .Use((ctx, next) => new HttpMessageHandlerAdapter( new AdapterMiddleware(next), server, new OwinBufferPolicySelector()) .Invoke(new OwinContext(ctx))) // Final middleware to return a 404 .Use(async (ctx, next) => { var kctx = new OwinContext(ctx); kctx.Response.StatusCode = 404; kctx.Response.Headers.Append("Content-Type", "text/plain"); await kctx.Response.WriteAsync("No one has the resource identified by the request"); }) .Build(); // Set up the Nowin server var builder = ServerBuilder.New() .SetPort(8080) .SetOwinApp(app); // Run using (builder.Start()) { Console.WriteLine("Listening on port 8080. Enter to exit."); Console.ReadLine(); } }
public static void Setup(Fixer fixer) { fixer.Use(Application.Run); }
private static void Initialize(HttpContext context) { lock (SyncApp) { if (_app == null) { var fixer = new Fixer(); string path = Path.Combine(context.Request.PhysicalApplicationPath ?? Environment.CurrentDirectory, "bin"); var aggregateCatalog = new AggregateCatalog(); foreach (var file in Directory.EnumerateFiles(path, "*.dll")) { var justFileName = Path.GetFileName(file); if (justFileName == null) continue; // Skip Microsoft DLLs, because they break MEF if (justFileName.StartsWith("Microsoft.") || justFileName.StartsWith("System.")) continue; var catalog = new AssemblyCatalog(file); aggregateCatalog.Catalogs.Add(catalog); } var container = new CompositionContainer(aggregateCatalog); container.ComposeParts(fixer); _app = fixer.BuildApp(); _serverVariables = context.Request.ServerVariables.AllKeys .ToDictionary(v => v, v => context.Request.ServerVariables.Get(v)); } } }
private static void FixUpAssemblies(Fixer fixer, string searchPattern, string directory) { using (var catalog = new AggregateCatalog()) { foreach (var file in Directory.GetFiles(directory, searchPattern)) { try { var assembly = Assembly.LoadFile(file); if (assembly.FullName.StartsWith("Microsoft.") || assembly.FullName.StartsWith("System.")) { continue; } var assemblyCatalog = new AssemblyCatalog(assembly); catalog.Catalogs.Add(assemblyCatalog); } catch (Exception ex) { Trace.TraceError(ex.Message); } } var container = new CompositionContainer(catalog); container.ComposeParts(fixer); } }