public IMicroServiceEngine Build() { var hostingServices = BuildHostingServices(); var hostingContainer = hostingServices.BuildServiceProvider(); var appEnvironment = hostingContainer.GetRequiredService<IApplicationEnvironment>(); var startupLoader = hostingContainer.GetRequiredService<StartupLoader>(); var engine = new HostingEngine(hostingServices, startupLoader, _config); // Only one of these should be set, but they are used in priority engine.StartupType = _startupType; engine.StartupAssemblyName = _startupAssemblyName ?? appEnvironment.ApplicationName; return engine; }
private static void DeconstructUrlTest(string url, bool valid, string scheme, string host, string port, string path) { string schemePart; string hostPart; string portPart; string pathPart; HostingEngine.DeconstructUrl( url, out schemePart, out hostPart, out portPart, out pathPart).ShouldBe(valid); schemePart.ShouldBe(scheme); hostPart.ShouldBe(host); portPart.ShouldBe(port); pathPart.ShouldBe(path); }
public static IServiceProvider CreateServiceProvider(Action <IServiceCollection> configure) { var context = new HostingContext { ServerFactory = new ServerFactory(), StartupMethods = new StartupMethods( _ => { }, services => { services.AddSignalR(); configure(services); return(services.BuildServiceProvider()); }) }; var engine = new HostingEngine().Start(context); return(context.ApplicationServices); }
private void startServer(OwinSettings settings, string physicalPath, int port) { var parameters = new StartOptions { Port = port }; parameters.Urls.Add("http://*:" + port); //for netsh http add urlacl if (physicalPath != null) { FubuMvcPackageFacility.PhysicalRootPath = physicalPath; } var context = new StartContext(parameters) { App = FubuOwinHost.ToAppFunc(_runtime, settings), }; settings.EnvironmentData.ToDictionary().Each(pair => context.EnvironmentData.Add(pair)); settings.EnvironmentData[OwinConstants.AppMode] = FubuMode.Mode().ToLower(); context.EnvironmentData.AddRange(settings.EnvironmentData.ToDictionary()); var engine = new HostingEngine(new AppBuilderFactory(), new TraceOutputFactory(), new AppLoader(new IAppLoaderFactory[0]), new ServerFactoryLoader(new ServerFactoryActivator(new ServiceProvider()))); try { _server = engine.Start(context); } catch (TargetInvocationException e) { if (e.InnerException != null && e.InnerException.Message.Contains("Access is denied")) { throw new KatanaRightsException(e.InnerException); } throw; } }
private static DbContext TryCreateContextFromStartup(Type type) { #if DNX451 || DNXCORE50 try { var context = new HostingContext { ServerFactory = new ServerFactory(), }; var instance = new HostingEngine().Start(context); return(context.ApplicationServices.GetService(type) as DbContext); } catch { } #endif return(null); }
private void startServer(OwinSettings settings, IList <RouteBase> routes, string physicalPath, int port) { var parameters = new StartOptions { Port = port }; parameters.Urls.Add("http://*:" + port); //for netsh http add urlacl // Adding the static middleware settings.AddMiddleware <StaticFileMiddleware>(_services.GetInstance <IFubuApplicationFiles>(), settings); if (physicalPath != null) { FubuMvcPackageFacility.PhysicalRootPath = physicalPath; } Action <IAppBuilder> startup = FubuOwinHost.ToStartup(settings, routes); var context = new StartContext(parameters) { Startup = startup, }; settings.EnvironmentData[OwinConstants.AppMode] = FubuMode.Mode().ToLower(); context.EnvironmentData.AddRange(settings.EnvironmentData.ToDictionary()); var engine = new HostingEngine(new AppBuilderFactory(), new TraceOutputFactory(), new AppLoader(new IAppLoaderFactory[0]), new ServerFactoryLoader(new ServerFactoryActivator(new ServiceProvider()))); try { _server = engine.Start(context); } catch (TargetInvocationException e) { if (e.InnerException != null && e.InnerException.Message.Contains("Access is denied")) { throw new KatanaRightsException(e.InnerException); } throw; } }
private static string GetDisplayUrl(StartOptions options) { IList <string> urls = options.Urls; if (urls.Count > 0) { return("urls: " + string.Join(", ", urls)); } int port; string message = "port: "; if (!HostingEngine.TryDetermineCustomPort(options, out port)) { port = HostingEngine.DefaultPort; message = "the default " + message; } return(message + port + " (http://localhost:" + port + "/)"); }
private void startServer(IList <RouteBase> routes, string physicalPath, int port) { var parameters = new StartOptions { Port = port }; parameters.Urls.Add("http://*:" + port); //for netsh http add urlacl FubuMvcPackageFacility.PhysicalRootPath = physicalPath ?? AppDomain.CurrentDomain.BaseDirectory; Action <IAppBuilder> startup = FubuOwinHost.ToStartup(routes); var context = new StartContext(parameters) { Startup = startup }; var engine = new HostingEngine(new AppBuilderFactory(), new TraceOutputFactory(), new AppLoader(new IAppLoaderFactory[0]), new ServerFactoryLoader(new ServerFactoryActivator(new ServiceProvider()))); _server = engine.Start(context); }
public void Main(string[] args) { var applicationRoot = Directory.GetCurrentDirectory(); var serverPort = 2000; var logLevel = LogLevel.Information; var hostPID = -1; var transportType = TransportType.Http; var otherArgs = new List <string>(); var enumerator = args.GetEnumerator(); while (enumerator.MoveNext()) { var arg = (string)enumerator.Current; if (arg == "-s") { enumerator.MoveNext(); applicationRoot = Path.GetFullPath((string)enumerator.Current); } else if (arg == "-p") { enumerator.MoveNext(); serverPort = int.Parse((string)enumerator.Current); } else if (arg == "-v") { logLevel = LogLevel.Verbose; } else if (arg == "--hostPID") { enumerator.MoveNext(); hostPID = int.Parse((string)enumerator.Current); } else if (arg == "--stdio") { transportType = TransportType.Stdio; } else { otherArgs.Add((string)enumerator.Current); } } Environment = new OmnisharpEnvironment(applicationRoot, serverPort, hostPID, logLevel, transportType, otherArgs.ToArray()); var config = new Configuration() .AddCommandLine(new[] { "--server.urls", "http://localhost:" + serverPort }); var engine = new HostingEngine(_serviceProvider); var context = new HostingContext() { ServerFactoryLocation = "Kestrel", Configuration = config, }; var writer = new SharedConsoleWriter(); context.Services.AddInstance <IOmnisharpEnvironment>(Environment); context.Services.AddInstance <ISharedTextWriter>(writer); if (transportType == TransportType.Stdio) { context.Server = null; context.ServerFactory = new Stdio.StdioServerFactory(Console.In, writer); } var serverShutdown = engine.Start(context); var appShutdownService = _serviceProvider.GetRequiredService <IApplicationShutdown>(); var shutdownHandle = new ManualResetEvent(false); appShutdownService.ShutdownRequested.Register(() => { serverShutdown.Dispose(); shutdownHandle.Set(); }); #if DNXCORE50 var ignored = Task.Run(() => { Console.WriteLine("Started"); Console.ReadLine(); appShutdownService.RequestShutdown(); }); #else Console.CancelKeyPress += (sender, e) => { appShutdownService.RequestShutdown(); }; #endif if (hostPID != -1) { try { var hostProcess = Process.GetProcessById(hostPID); hostProcess.EnableRaisingEvents = true; hostProcess.OnExit(() => appShutdownService.RequestShutdown()); } catch { // If the process dies before we get here then request shutdown // immediately appShutdownService.RequestShutdown(); } } shutdownHandle.WaitOne(); }