Public Class Program
Public Class Program
Configuration = configuration;
ServicePointManager.ServerCertificateValidationCallback +=
if (development)
return true;
};
.MinimumLevel.Debug()
.Enrich.With<MethodInvocationEnricher>()
.Enrich.FromLogContext()
.WriteTo.File("C:\\logcontext\\loglog.txt",
outputTemplate: "{Timestamp:HH:mm:ss} [{Level}]
[{CorrelationID}] [{InvocationContextClassName}] [{InvocationContextMethodName}]
{Message} {NewLine} {Exception}",
rollingInterval: RollingInterval.Day)
.CreateLogger();
CreateHostBuilder(args).Build().Run();
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
webBuilder.UseKestrel()
.UseIIS()
.UseStartup<Program>();
webBuilder.ConfigureAppConfiguration(ConfigureConfig);
}).ConfigureServices(
services =>
services.AddSingleton<IHttpContextAccessor,
HttpContextAccessor>();
services.AddSingleton<ICustomIsomSerializer,
CustomIsomSerializer>();
services.AddSingleton<IDeviceSearchRequestMapper,
DeviceSearchRequestMapper>();
})
.UseServiceProviderFactory(new AutofacServiceProviderFactory());
arg2.ReadFrom.Configuration(arg1.Configuration);
//arg2.ReadFrom.Configuration(arg1.Configuration);
}
private static void ConfigureConfig(WebHostBuilderContext hostingContext,
IConfigurationBuilder configBuilder)
configBuilder.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath).AddJso
nFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.
{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
.AddEnvironmentVariables();
configBuilder.AddOcelot($"./GatewayConfig/{deploymentType}",
hostingContext.HostingEnvironment).AddOcelotWithSwaggerSupport((o) => { o.Folder =
$"GatewayConfig/{deploymentType}"; });
// This method gets called by the runtime. Use this method to add services to
the container.
services.AddHealthChecks();
services.AddHttpContextAccessor();
ConfigureSwagger(services);
SetUpAuthentication(services);
opts.JsonSerializerOptions.Converters.Add(new
JsonStringEnumConverter());
});
//services.AddControllers().AddNewtonsoftJson(opts =>
//{
// opts.SerializerSettings.Converters.Add(new StringEnumConverter());
//});
var moduleManager = ModuleManager<IServiceCollection>.Create(services,
path);
moduleManager.InitializeModule();
_moduleManager = moduleManager;
mvcBuilder.AddApplicationPart(assembly);
services.AddCors(options =>
options.AddPolicy("AllowOrigin",
builder =>
builder.WithOrigins(Configuration.GetSection("AllowedOrigins").Value).AllowCredenti
als().AllowAnyHeader().AllowAnyMethod());
});
services.AddSwaggerForOcelot(Configuration);
services.AddOcelot().AddCacheManager(x =>
x.WithDictionaryHandle();
})
.AddPolly()
.AddDelegatingHandler<SpaceIsomSearchHandler>()
.AddDelegatingHandler<SpaceIsomHandler>()
.AddDelegatingHandler<DeviceIsomHandler>()
.AddDelegatingHandler<DoorOperationsHandler>()
.AddDelegatingHandler<TokenHandler>()
.AddDelegatingHandler<RevokeTokenHandler>()
.AddDelegatingHandler<UnAcknowledgeAlarmsRollUpHandler>()
.AddDelegatingHandler<AcknowledgeAlarmsRollUpHandler>()
.AddDelegatingHandler<MaxproAuthenticationHandler>()
.AddDelegatingHandler<StreamConfigHandler>()
.AddDelegatingHandler<CameraStreamConfigHandler>()
.AddDelegatingHandler<MaxproStreamConfigHandler>()
.AddDelegatingHandler<CameraHandler>()
.AddDelegatingHandler<ValidateSupervisorPinIsomHandler>()
.AddDelegatingHandler<RecorderSummaryHandler>()
.AddDelegatingHandler<RecordingUnavailabilityHandler>()
.AddDelegatingHandler<HostInjectorDelegatingHandler>()
.AddDelegatingHandler<CameraConfigHandler>();
services.AddOptions();
services.AddScoped<IGatewayNegotiate, GatewayNegotiateService>();
services.AddScoped<IApiClientHelper, ApiClientHelper>();
services.AddScoped<IDeviceDetailHelper, DeviceDetailHelper>();
services.AddScoped<IUvisomRequestHandler, UvisomRequestHandler>();
services.AddTransient<IEntityMapper, EntityMapper>();
services.AddOptions();
if
(Configuration.GetValue<string>("DeploymentType").Equals("IntegratedSecurity",
StringComparison.InvariantCultureIgnoreCase) ||
Configuration.GetValue<string>("DeploymentType").Equals("PROWATCH",
StringComparison.InvariantCultureIgnoreCase))
//Create Seri Logger Instance and add it to Log Factory to fetch a ILogger
Instance
.ReadFrom.Configuration(Configuration)
.CreateLogger();
var logFactory = LoggerFactory.Create(builder =>
builder.AddSerilog(seriLogger);
});
Microsoft.Extensions.Logging.ILogger logger =
logFactory.CreateLogger(LogLevel.Information.ToString());
services.AddICAuthentication(Configuration, logger);
else
AuthSetup.ConfigureAuthentication(services, Configuration);
if (!Configuration.GetValue<bool>("AllowAnonymous"))
services.AddMvc(options =>
options.EnableEndpointRouting = false;
}).AddControllersAsServices();
else
services.AddMvc(options =>
options.EnableEndpointRouting = false;
options.Filters.Add(new AllowAnonymousFilter());
}).AddControllersAsServices();
containerBuilder.RegisterGeneric(typeof(AppLogger<>)).As(typeof(IAppLogger<>));
// This method gets called by the runtime. Use this method to configure
the HTTP request pipeline.
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
HoneyEngine.ServiceProvider = app.ApplicationServices;
_moduleManager.StartModule(app.ApplicationServices);
app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();
app.UseHttpsRedirection();
app.UseRouting();
app.UseSerilogRequestLogging();
app.UseCors(builder =>
builder.WithOrigins(Configuration.GetSection("AllowedOrigins").Value).AllowCredenti
als().AllowAnyHeader().AllowAnyMethod());
app.UseMiddleware<ApiLoggerMiddleware>();
app.UseMiddleware<NegotiateMiddleware>();
app.UseMiddleware<NegotiateMiddlewareV2>();
app.UseSwaggerForOcelotUI(options =>
_ocelotConfigBuilder.GetSwaggerConfiguration(options));
app.UseOcelot(_ocelotConfigBuilder.GetOcelotPipelineConfiguration()).Wait();
app.UseMvc();
UserLocalization(app);
services.AddSwaggerGen(c =>
var xmlFiles =
Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"*.xml");
c.IncludeXmlComments(xmlFile);
c.EnableAnnotations();
Name = "Bearer",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "bearer"
};
c.IgnoreObsoleteActions();
c.AddSecurityDefinition("Bearer", securityScheme);
new OpenApiSecurityScheme
},
new[] {"Bearer"}
};
c.AddSecurityRequirement(securityRequirement);
});
services.AddSwaggerGenNewtonsoftSupport();
// use localization
var supportedCulturesStrings =
Configuration.GetSection("SupportedCultures").Get<string[]>();
DefaultRequestCulture = new
RequestCulture(Configuration.GetSection("DefaultRequestCulture").Value),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
};
app.UseRequestLocalization(options);
}
}