Пример #1
0
        private ClusterNode(
            IIxHost indirectXHost,
            IWebHostBuilder webHostBuilder,
            IConfigurationRoot configRoot,
            IJsonLogger logger)
        {
            Log         = new ClassJsonLogger <ClusterNode>(logger);
            _executeCts = new CancellationTokenSource();
            _executeCancellationToken = _executeCts.Token;

            _indirectXHost = indirectXHost;
            _configRoot    = configRoot;

            Log.Info(_ => _("Starting Asp.Net core..."));

            _webHost = webHostBuilder
                       .UseStartup <ClusterNodeStartup>()
                       .Build();

            _webHost.Start();
            _hostLifetimeService = _webHost.Services.GetRequiredService <IApplicationLifetime>();

            Key = new ClusterNodeKey(_configRoot.GetValue(ClusterNodeIdKey, "single-node"));

            var addressesFeature = _webHost.ServerFeatures.Get <IServerAddressesFeature>();

            foreach (string addressesFeatureAddress in addressesFeature.Addresses)
            {
                Log.Info(
                    addressesFeatureAddress,
                    (_, addr) => _($"NodeId = '{Key.Code}' listening on: {addr}").Data(new { ListenAddress = addr }));
            }

            Console.CancelKeyPress += (sender, e) =>
            {
                if (!_executeCancellationToken.IsCancellationRequested)
                {
                    Log.Trace(_ => _("Termination raised by system."));
                    _executeCts.Cancel();
                }

                e.Cancel = true;
            };
        }
Пример #2
0
        // [Require(typeof(IClusterNode))]
        private LoggerWebApp(
            IIxResolver resolver,
            IWebHostBuilder webHostBuilder,
            IJsonLogger logger,
            ILogReader logReader,
            LoggerWebAppConfig config)
        {
            Log = new ClassJsonLogger <LoggerWebApp>(logger);

            Log.Info(_ => _("Starting Asp.Net core..."));
            _webHost = webHostBuilder

                       // Should be removed after adoption IndirectX to Asp.Net core.
                       .ConfigureServices(
                x => x
                .AddHttpRequestScopeService()
                .AddScopedHttpContextAccessor()
                .AddSingleton(new Tuple <IJsonLogger, IIxResolver>(Log, resolver))
                .AddSingleton <ILogReader>(logReader)
                .AddSingleton(config))
                       .UseStartup <LoggerWebAppStartup>()
                       .ConfigureJsonFormatters(JsonDefaults.RestRpcSerializerSource.Settings)
                       .Build();
            _webHost.Start();

            var addressesFeature = _webHost.ServerFeatures.Get <IServerAddressesFeature>();
            var addresses        = new HashSetEx <string>();

            foreach (string addressesFeatureAddress in addressesFeature.Addresses)
            {
                addresses.Add(addressesFeatureAddress);
                Log.Info(
                    addressesFeatureAddress,
                    (_, addr) => _($"Now listening on: {addr}").Data(new { ListenAddress = addr }));
            }

            HostingUrls = addresses;
        }