示例#1
0
 public ApiFeature(
     IServerBuilder x42ServerBuilder,
     X42Server x42Server,
     ApiFeatureOptions apiFeatureOptions,
     ApiSettings apiSettings,
     ILoggerFactory loggerFactory,
     ICertificateStore certificateStore)
 {
     serverBuilder          = x42ServerBuilder;
     this.x42Server         = x42Server;
     this.apiFeatureOptions = apiFeatureOptions;
     this.apiSettings       = apiSettings;
     this.certificateStore  = certificateStore;
     logger = loggerFactory.CreateLogger(GetType().FullName);
 }
示例#2
0
        public BaseFeature(ServerSettings serverSettings,
                           DataFolder dataFolder,
                           IX42ServerLifetime serverLifetime,
                           IDateTimeProvider dateTimeProvider,
                           IAsyncLoopFactory asyncLoopFactory,
                           ILoggerFactory loggerFactory,
                           X42Server network)
        {
            this.serverSettings = Guard.NotNull(serverSettings, nameof(serverSettings));
            this.dataFolder     = Guard.NotNull(dataFolder, nameof(dataFolder));
            this.serverLifetime = Guard.NotNull(serverLifetime, nameof(serverLifetime));
            this.network        = network;


            this.dateTimeProvider = dateTimeProvider;
            this.asyncLoopFactory = asyncLoopFactory;
            this.loggerFactory    = loggerFactory;
            logger = loggerFactory.CreateLogger(GetType().FullName);
        }
        public IActionResult Stats()
        {
            string content = new X42Server().LastLogOutput;

            return(Content(content));
        }
示例#4
0
        public static IWebHost Initialize(IEnumerable <ServiceDescriptor> services, X42Server x42Server,
                                          ApiSettings apiSettings, ICertificateStore store, IWebHostBuilder webHostBuilder)
        {
            Guard.NotNull(x42Server, nameof(x42Server));
            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;
                }

                Action <ListenOptions> configureListener = listenOptions => { listenOptions.UseHttps(certificate); };
                IPAddress[] ipAddresses = Dns.GetHostAddresses(apiSettings.ApiUri.DnsSafeHost);
                foreach (IPAddress 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 x42 server to the Api.
                // also copies over singleton instances already defined
                foreach (ServiceDescriptor service in services)
                {
                    object obj = x42Server.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 <ApiBuilder>();

            IWebHost host = webHostBuilder.Build();

            host.Start();

            return(host);
        }