Example #1
0
 /// <summary>
 /// Get the default configuration.
 /// </summary>
 /// <param name="builder">The string builder to add the settings to.</param>
 /// <param name="network">The network to base the defaults off.</param>
 public static void BuildDefaultConfigurationFile(StringBuilder builder, Network network)
 {
     ApiSettings.BuildDefaultConfigurationFile(builder, network);
 }
Example #2
0
        public static IWebHost Initialize(IEnumerable <ServiceDescriptor> services, FullNode fullNode,
                                          ApiSettings apiSettings, ICertificateStore store, IWebHostBuilder webHostBuilder)
        {
            Guard.NotNull(fullNode, nameof(fullNode));
            Guard.NotNull(webHostBuilder, nameof(webHostBuilder));

            Uri apiUri = apiSettings.ApiUri;

            X509Certificate2 certificate = apiSettings.UseHttps
                ? GetHttpsCertificate(apiSettings.HttpsCertificateFilePath, store)
                : null;

            webHostBuilder
            .UseKestrel(options =>
            {
                if (!apiSettings.UseHttps)
                {
                    return;
                }

                options.AllowSynchronousIO = true;
                Action <ListenOptions> configureListener = listenOptions => { listenOptions.UseHttps(certificate); };
                var ipAddresses = Dns.GetHostAddresses(apiSettings.ApiUri.DnsSafeHost);
                foreach (var ipAddress in ipAddresses)
                {
                    options.Listen(ipAddress, apiSettings.ApiPort, configureListener);
                }
            })
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseUrls(apiUri.ToString())
            .ConfigureServices(collection =>
            {
                if (services == null)
                {
                    return;
                }

                // copies all the services defined for the full node to the Api.
                // also copies over singleton instances already defined
                foreach (ServiceDescriptor service in services)
                {
                    // open types can't be singletons
                    if (service.ServiceType.IsGenericType || service.Lifetime == ServiceLifetime.Scoped)
                    {
                        collection.Add(service);
                        continue;
                    }

                    object obj = fullNode.Services.ServiceProvider.GetService(service.ServiceType);
                    if (obj != null && service.Lifetime == ServiceLifetime.Singleton && service.ImplementationInstance == null)
                    {
                        collection.AddSingleton(service.ServiceType, obj);
                    }
                    else
                    {
                        collection.Add(service);
                    }
                }
            })
            .UseStartup <Startup>();

            IWebHost host = webHostBuilder.Build();

            host.Start();

            return(host);
        }
Example #3
0
 /// <summary>
 /// Prints command-line help.
 /// </summary>
 /// <param name="network">The network to extract values from.</param>
 public static void PrintHelp(Network network)
 {
     ApiSettings.PrintHelp(network);
 }
Example #4
0
        public static IWebHost Initialize(IEnumerable <ServiceDescriptor> services, FullNode fullNode, ApiSettings apiSettings)
        {
            Guard.NotNull(fullNode, nameof(fullNode));

            Uri apiUri = apiSettings.ApiUri;

            IWebHost host = new WebHostBuilder()
                            .UseKestrel()
                            .UseContentRoot(Directory.GetCurrentDirectory())
                            .UseIISIntegration()
                            .UseUrls(apiUri.ToString())
                            .ConfigureServices(collection =>
            {
                if (services == null)
                {
                    return;
                }

                // copies all the services defined for the full node to the Api.
                // also copies over singleton instances already defined
                foreach (ServiceDescriptor service in services)
                {
                    object obj = fullNode.Services.ServiceProvider.GetService(service.ServiceType);
                    if (obj != null && service.Lifetime == ServiceLifetime.Singleton && service.ImplementationInstance == null)
                    {
                        collection.AddSingleton(service.ServiceType, obj);
                    }
                    else
                    {
                        collection.Add(service);
                    }
                }
            })
                            .UseStartup <Startup>()
                            .Build();

            host.Start();

            return(host);
        }