public Server(string name, string fileName, bool autoReload, PSHost host, int port, bool https) { if (string.IsNullOrEmpty(name)) { Name = $"Dashboard{_lastId}"; _lastId++; } else { Name = name; } FileName = fileName; Port = port; _reloadKey = Guid.NewGuid().ToString(); if (_reloader == null) { _reloader = new AutoReloader(host); } if (autoReload) { _reloader.StartWatchingFile(fileName, Port, _reloadKey, https); } if (Servers.Any(m => m.Name.Equals(Name, StringComparison.OrdinalIgnoreCase))) { throw new Exception($"Server with name {Name} already exists."); } }
public void ConfigureServices(IServiceCollection services) { var autoReloaderService = services.FirstOrDefault(m => m.ServiceType == typeof(AutoReloader)); _reloader = autoReloaderService?.ImplementationInstance as AutoReloader; var dashboardService = services.FirstOrDefault(m => m.ServiceType == typeof(IDashboardService)).ImplementationInstance as IDashboardService; services.AddResponseCompression(); services.AddSignalR(hubOptions => { hubOptions.EnableDetailedErrors = true; }).AddJsonProtocol(x => { x.PayloadSerializerSettings.ContractResolver = new CustomContractResolver(); }); services.AddTransient <StateRequestService>(); services.AddSingleton <IHostedService, ScheduledEndpointManager>(); services.AddTransient <IExecutionService, ExecutionService>(); services.AddCors(); services.AddDirectoryBrowser(); services.AddSingleton(ExecutionService.MemoryCache); services.AddMvc().AddJsonOptions(x => { x.SerializerSettings.ContractResolver = new CustomContractResolver(); }); services.AddScoped <IFilterProvider, EncFilterProvider>(); services.AddSession(options => { options.IdleTimeout = dashboardService.Dashboard == null ? TimeSpan.FromMinutes(25) : dashboardService.Dashboard.IdleTimeout; options.Cookie.HttpOnly = true; options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest; }); }
public void ConfigureServices(IServiceCollection services) { var autoReloaderService = services.FirstOrDefault(m => m.ServiceType == typeof(AutoReloader)); _reloader = autoReloaderService?.ImplementationInstance as AutoReloader; var dashboardService = services.FirstOrDefault(m => m.ServiceType == typeof(IDashboardService)).ImplementationInstance as IDashboardService; services.AddResponseCompression(); services.AddSignalR(); services.AddTransient <StateRequestService>(); services.AddSingleton <IHostedService, ScheduledEndpointManager>(); services.AddTransient <IExecutionService, ExecutionService>(); services.AddCors(); services.AddDirectoryBrowser(); services.AddSingleton(ExecutionService.MemoryCache); services.AddMvc(); services.AddScoped <IFilterProvider, EncFilterProvider>(); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(25); options.Cookie.HttpOnly = true; options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest; }); }
public void ConfigureServices(IServiceCollection services) { var autoReloaderService = services.FirstOrDefault(m => m.ServiceType == typeof(AutoReloader)); _reloader = autoReloaderService?.ImplementationInstance as AutoReloader; var dashboardService = services.FirstOrDefault(m => m.ServiceType == typeof(IDashboardService)).ImplementationInstance as IDashboardService; services.AddResponseCompression(); services.AddSignalR(hubOptions => { hubOptions.EnableDetailedErrors = true; }).AddJsonProtocol(x => { x.PayloadSerializerSettings.ContractResolver = new CustomContractResolver(); }); services.AddTransient <StateRequestService>(); services.AddSingleton <IHostedService, ScheduledEndpointManager>(); services.AddTransient <IExecutionService, ExecutionService>(); services.AddTransient <ILanguageExecutionService, PowerShellExecutionService>(); services.AddCors(); services.AddDirectoryBrowser(); services.AddMemoryCache(); services.AddSingleton(new ConnectionManager()); services.AddMvc().AddJsonOptions(x => { x.SerializerSettings.ContractResolver = new CustomContractResolver(); }); if (dashboardService?.DashboardOptions?.Certificate != null || dashboardService?.DashboardOptions?.CertificateFile != null) { if (dashboardService.DashboardOptions.Port == dashboardService.DashboardOptions.HttpsPort) { Logger.Warn("Port and HTTPS port are the same. HTTPS Redirection will not work. Select two different ports."); } else { services.AddHttpsRedirection(options => { options.RedirectStatusCode = StatusCodes.Status308PermanentRedirect; options.HttpsPort = dashboardService.DashboardOptions.HttpsPort; }); } } services.AddScoped <IFilterProvider, EncFilterProvider>(); services.AddSession(options => { options.IdleTimeout = dashboardService.Dashboard == null ? TimeSpan.FromMinutes(25) : dashboardService.Dashboard.IdleTimeout; options.Cookie.HttpOnly = true; options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest; }); var serviceDescriptor = services.FirstOrDefault(descriptor => descriptor.ServiceType.Name == "IRegistryPolicyResolver"); services.Remove(serviceDescriptor); dashboardService.ServiceProvider = services.BuildServiceProvider(); }