Exemplo n.º 1
0
        private static string DetermineOwinServer(StartContext context)
        {
            StartOptions options = context.Options;
            IDictionary <string, string> settings = context.Options.Settings;

            string serverName = options.ServerFactory;

            if (!string.IsNullOrWhiteSpace(serverName))
            {
                return(serverName);
            }

            if (settings != null &&
                settings.TryGetValue(Constants.SettingsOwinServer, out serverName) &&
                !string.IsNullOrWhiteSpace(serverName))
            {
                return(serverName);
            }

            serverName = Environment.GetEnvironmentVariable(Constants.EnvOwnServer, EnvironmentVariableTarget.Process);
            if (!string.IsNullOrWhiteSpace(serverName))
            {
                return(serverName);
            }

            return(Constants.DefaultServer);
        }
Exemplo n.º 2
0
        private static IDisposable EnableDisposing(StartContext context)
        {
            var cts = new CancellationTokenSource();

            context.Builder.Properties[Constants.HostOnAppDisposing] = cts.Token;
            context.EnvironmentData.Add(new KeyValuePair <string, object>(Constants.HostOnAppDisposing, cts.Token));
            return(new Disposable(() => cts.Cancel(false)));
        }
Exemplo n.º 3
0
        private void ResolveOutput(StartContext context)
        {
            if (context.TraceOutput == null)
            {
                context.Options.Settings.TryGetValue("traceoutput", out string traceoutput);
                context.TraceOutput = _traceOutputFactory.Create(traceoutput);
            }

            context.EnvironmentData.Add(new KeyValuePair <string, object>(Constants.HostTraceOutput, context.TraceOutput));
        }
Exemplo n.º 4
0
        private void ResolveServerFactory(StartContext context)
        {
            if (context.ServerFactory != null)
            {
                return;
            }

            string serverName = DetermineOwinServer(context);

            context.ServerFactory = _serverFactoryLoader.Load(serverName);
        }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="appBuilderFactory"></param>
 /// <param name="traceOutputFactory"></param>
 /// <param name="appLoader"></param>
 /// <param name="serverFactoryLoader"></param>
 /// <param name="loggerFactory"></param>
 public HostingEngine(
     IServiceProvider serviceProvider,
     IAppBuilderFactory appBuilderFactory,
     ITraceOutputFactory traceOutputFactory,
     IAppLoader appLoader,
     IServerFactoryLoader serverFactoryLoader,
     IOptions <StartOptions> options)
 {
     _appBuilderFactory   = appBuilderFactory ?? throw new ArgumentNullException("appBuilderFactory");
     _traceOutputFactory  = traceOutputFactory ?? throw new ArgumentNullException("traceOutputFactory");
     _appLoader           = appLoader ?? throw new ArgumentNullException("appLoader");
     _serverFactoryLoader = serverFactoryLoader;
     _serviceProvider     = serviceProvider;
     this._context        = new StartContext(options.Value);
 }
Exemplo n.º 6
0
        private void EnableTracing(StartContext context)
        {
            // string etwGuid = "CB50EAF9-025E-4CFB-A918-ED0F7C0CD0FA";
            // EventProviderTraceListener etwListener = new EventProviderTraceListener(etwGuid, "HostingEtwListener", "::");
            var textListener = new TextWriterTraceListener(context.TraceOutput, "HostingTraceListener");

            Trace.Listeners.Add(textListener);
            // Trace.Listeners.Add(etwListener);

            var source = new TraceSource("HostingTraceSource", SourceLevels.All);

            source.Listeners.Add(textListener);
            // source.Listeners.Add(etwListener);

            context.Builder.Properties[Constants.HostTraceOutput] = context.TraceOutput;
            context.Builder.Properties[Constants.HostTraceSource] = source;
        }
Exemplo n.º 7
0
        private static string DetermineApplicationName(StartContext context)
        {
            StartOptions options = context.Options;
            IDictionary <string, string> settings = context.Options.Settings;

            if (options != null && !string.IsNullOrWhiteSpace(options.AppStartup))
            {
                return(options.AppStartup);
            }

            if (settings.TryGetValue(Constants.SettingsOwinAppStartup, out string appName) &&
                !string.IsNullOrWhiteSpace(appName))
            {
                return(appName);
            }

            return(null);
        }
Exemplo n.º 8
0
        private void ResolveApp(StartContext context)
        {
            context.Builder.Use(typeof(Encapsulate), context.EnvironmentData);

            if (context.App == null)
            {
                IList <string> errors = new List <string>();
                if (context.Startup == null)
                {
                    string appName = DetermineApplicationName(context);
                    context.Startup = _appLoader.Load(appName, errors);
                }
                context.Startup(context.Builder);
            }
            else
            {
                context.Builder.Use(new Func <object, object>(_ => context.App));
            }
        }
Exemplo n.º 9
0
        private void InitializeBuilder(StartContext context)
        {
            if (context.Builder == null)
            {
                context.Builder = _appBuilderFactory.Create();
            }

            if (!string.IsNullOrWhiteSpace(context.Options.AppStartup))
            {
                context.Builder.Properties[Constants.HostAppName] = context.Options.AppStartup;
                context.EnvironmentData.Add(new KeyValuePair <string, object>(Constants.HostAppName, context.Options.AppStartup));
            }

            // This key lets us know the app was launched from Visual Studio.
            string vsVersion = Environment.GetEnvironmentVariable("VisualStudioVersion");

            if (!string.IsNullOrWhiteSpace(vsVersion))
            {
                context.Builder.Properties[Constants.HostAppMode] = Constants.AppModeDevelopment;
                context.EnvironmentData.Add(new KeyValuePair <string, object>(Constants.HostAppMode, Constants.AppModeDevelopment));
            }

            context.Builder.SetServiceProvider(_serviceProvider);
        }
Exemplo n.º 10
0
 private static IDisposable StartServer(StartContext context)
 {
     return(context.ServerFactory.Create(context.Builder));
 }
Exemplo n.º 11
0
 private static void InitializeServerFactory(StartContext context)
 {
     context.ServerFactory.Initialize(context.Builder);
 }