| | | 1 | | using Microsoft.AspNetCore.Authentication.JwtBearer; |
| | | 2 | | using Microsoft.AspNetCore.Authorization; |
| | | 3 | | using Microsoft.Extensions.Options; |
| | | 4 | | using Microsoft.AspNetCore.Builder; |
| | | 5 | | using Microsoft.AspNetCore.Hosting; |
| | | 6 | | using Microsoft.AspNetCore.Localization; |
| | | 7 | | using Microsoft.EntityFrameworkCore; |
| | | 8 | | using Microsoft.Extensions.Configuration; |
| | | 9 | | using Microsoft.Extensions.DependencyInjection; |
| | | 10 | | using Microsoft.Extensions.Hosting; |
| | | 11 | | using Microsoft.Extensions.Logging; |
| | | 12 | | using Microsoft.IdentityModel.Tokens; |
| | | 13 | | using Microsoft.OpenApi.Models; |
| | | 14 | | using Newtonsoft.Json; |
| | | 15 | | using SVETA.Api.ConfigureOptions; |
| | | 16 | | using Serilog; |
| | | 17 | | using System.Collections.Generic; |
| | | 18 | | using CrmVtbc; |
| | | 19 | | using SVETA.Api.Data.DTO; |
| | | 20 | | using SVETA.Api.Data.Domain; |
| | | 21 | | using SVETA.Api.Helpers; |
| | | 22 | | using SVETA.Api.Helpers.Authorize; |
| | | 23 | | using SVETA.Api.Services.Implements; |
| | | 24 | | using SVETA.Api.Services.Interfaces; |
| | | 25 | | using System; |
| | | 26 | | using System.Linq; |
| | | 27 | | using System.Globalization; |
| | | 28 | | using System.IO; |
| | | 29 | | using System.Reflection; |
| | | 30 | | using System.Text; |
| | | 31 | | using System.Threading.Tasks; |
| | | 32 | | using IdentityModel; |
| | | 33 | | using IdentityServer4.AccessTokenValidation; |
| | | 34 | | using IdentityServer4.Models; |
| | | 35 | | using Microsoft.AspNetCore.Http.Connections; |
| | | 36 | | using Microsoft.AspNetCore.SignalR; |
| | | 37 | | using SVETA.Api.Services; |
| | | 38 | | using WinSolutions.Sveta.Server.Data.DataModel.Contexts; |
| | | 39 | | using WinSolutions.Sveta.Server.Services.Implements; |
| | | 40 | | using WinSolutions.Sveta.Server.Services.Interfaces; |
| | | 41 | | using Wkhtmltopdf.NetCore; |
| | | 42 | | using WinSolutions.Sveta.Common; |
| | | 43 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 44 | | using SVETA.Api.CustomMiddleware; |
| | | 45 | | using SVETA.Api.Hubs; |
| | | 46 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 47 | | using Serilog.Exceptions; |
| | | 48 | | using Serilog.Formatting.Elasticsearch; |
| | | 49 | | using Serilog.Formatting.Json; |
| | | 50 | | using Serilog.Sinks.Elasticsearch; |
| | | 51 | | using Serilog.Sinks.File; |
| | | 52 | | using SVETA.Api.Services.Interfaces.ImportingExporting; |
| | | 53 | | using SVETA.Api.Services.Implements.ImportingExporting; |
| | | 54 | | using SVETA.Api.Services.Implements.ImportingExporting.Importers; |
| | | 55 | | |
| | | 56 | | namespace SVETA.Api |
| | | 57 | | { |
| | | 58 | | public class Startup |
| | | 59 | | { |
| | 0 | 60 | | public IConfiguration Configuration { get; } |
| | 0 | 61 | | public Startup(IConfiguration configuration, IWebHostEnvironment env) |
| | 0 | 62 | | { |
| | | 63 | | |
| | | 64 | | //Configuration = configuration; |
| | 0 | 65 | | Configuration = new ConfigurationBuilder() |
| | 0 | 66 | | .SetBasePath(Environment.CurrentDirectory) |
| | 0 | 67 | | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
| | 0 | 68 | | .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) |
| | 0 | 69 | | .AddEnvironmentVariables() |
| | 0 | 70 | | .Build(); |
| | 0 | 71 | | Log.Logger = new LoggerConfiguration() |
| | 0 | 72 | | .Enrich.FromLogContext() |
| | 0 | 73 | | .Enrich.WithExceptionDetails() |
| | 0 | 74 | | .Enrich.WithMachineName() |
| | 0 | 75 | | .WriteTo.ElasticCollector(Configuration["ElasticCollector:url"], Configuration["ElasticCollector:service |
| | 0 | 76 | | .ReadFrom.Configuration(configuration) |
| | 0 | 77 | | .CreateLogger(); |
| | | 78 | | //считываем основной ключ шифрования |
| | 0 | 79 | | SymmetricCrypto.ProtectKey = Configuration.GetValue("CryptoKey", ""); |
| | | 80 | | |
| | 0 | 81 | | } |
| | | 82 | | |
| | | 83 | | // This method gets called by the runtime. Use this method to add services to the container. |
| | | 84 | | public void ConfigureServices(IServiceCollection services) |
| | 0 | 85 | | { |
| | | 86 | | /**********Этот блок не переносить, так как он используется дальше****/ |
| | 0 | 87 | | services.AddEntityFrameworkNpgsql().AddDbContext<SvetaDbContext>(opt => opt.UseNpgsql(Configuration.GetConne |
| | 0 | 88 | | //services.AddEntityFrameworkNpgsql().AddDbContext<SvetaDbContext>(opt => opt.UseNpgsql("Host=localhost;Port |
| | 0 | 89 | | //services.AddEntityFrameworkNpgsql().AddDbContext<SvetaDbContext>(opt => opt.UseNpgsql("Host=localhost;Port |
| | 0 | 90 | | b => b.MigrationsAssembly("SVETA.Api"))); |
| | 0 | 91 | | services.AddSingleton<IConfigureOptions<ConfigurationsSettings>, ConfigureConfigurationsOptions>(); |
| | | 92 | | /*************************/ |
| | | 93 | | |
| | | 94 | | //Настройки отправки в Telegramm |
| | 0 | 95 | | var _telegramSettings = new TelegramSettings(); |
| | 0 | 96 | | Configuration.GetSection("TelegramSettings").Bind(_telegramSettings); |
| | 0 | 97 | | Telegram.ChatId = _telegramSettings.ChatId; |
| | 0 | 98 | | Telegram.Token = _telegramSettings.Token.Encrypted |
| | 0 | 99 | | ? SymmetricCrypto.DecryptData(Convert.FromBase64String(_telegramSettings.Token.Value)) |
| | 0 | 100 | | : _telegramSettings.Token.Value; |
| | | 101 | | |
| | | 102 | | /***********************Синхронизация с CRM VTB*************************/ |
| | | 103 | | // ICrmService можно подключить и как Singltone и как Scoped |
| | 0 | 104 | | services.AddSingleton<ICrmService, CrmOData>(data => |
| | 0 | 105 | | { |
| | 0 | 106 | | var _crmSettings = new CrmSettings(); |
| | 0 | 107 | | Configuration.GetSection("CrmSettings").Bind(_crmSettings); |
| | 0 | 108 | | var crm = new CrmOData( |
| | 0 | 109 | | new CreatioODataCredentials() |
| | 0 | 110 | | { |
| | 0 | 111 | | AuthServiceUri = _crmSettings.AuthServiceUri, |
| | 0 | 112 | | ODataServiceAddr = _crmSettings.ODataServiceAddr, |
| | 0 | 113 | | Username = _crmSettings.Username, |
| | 0 | 114 | | Password = _crmSettings.Password.Encrypted ? SymmetricCrypto.DecryptData(Convert.FromBase64String( |
| | 0 | 115 | | ForceUseSession = _crmSettings.ForceUseSession, |
| | 0 | 116 | | DaDataServiceAddr = _crmSettings.DaDataServiceAddr |
| | 0 | 117 | | }, |
| | 0 | 118 | | new CrmODataOptions() |
| | 0 | 119 | | { |
| | 0 | 120 | | IsTracingOn = true, // Вывод в консоль всех OData запросов |
| | 0 | 121 | | IgnoreResourceNotFoundException = true, // Отключение назойливых уведомлений |
| | 0 | 122 | | CollectionNamePattern = "{0}Collection" // Особенность именования коллекций BPMOnline |
| | 0 | 123 | | }); |
| | 0 | 124 | | if (crm != null) |
| | 0 | 125 | | { |
| | 0 | 126 | | // Подгружаются метаданные OData для работы с CRM BPMOnline |
| | 0 | 127 | | // Эта операция может работать исключительно долго - до 1 минуты |
| | 0 | 128 | | // Подгруженные метададнные статически кешируются, при повторном создании |
| | 0 | 129 | | // OData-клиента метаданные уже не скачиваются повторно |
| | 0 | 130 | | // AsyncContext.Run() из пакета Nitro.AsyncEx позволяет нормально выполнять |
| | 0 | 131 | | // асинхронные вызовы в не асинхронном методе |
| | 0 | 132 | | //AsyncContext.Run(async () => { await crm.Init(); }); |
| | 0 | 133 | | System.Threading.Tasks.Task.Run(async () => { await crm.Init(); }); |
| | 0 | 134 | | } |
| | 0 | 135 | | return crm; |
| | 0 | 136 | | }); |
| | | 137 | | /********************************/ |
| | 0 | 138 | | services.AddCors(); |
| | 0 | 139 | | services.ConfigureOptions<ConfigureCorsOptions>(); |
| | | 140 | | |
| | 0 | 141 | | var guestPolicy = new AuthorizationPolicyBuilder() |
| | 0 | 142 | | .RequireAuthenticatedUser() |
| | 0 | 143 | | //.RequireClaim("scope", "dataEventRecords") |
| | 0 | 144 | | //.RequireClaim("", "dataEventRecords") |
| | 0 | 145 | | .Build(); |
| | | 146 | | |
| | 0 | 147 | | services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) |
| | 0 | 148 | | .AddIdentityServerAuthentication(options => |
| | 0 | 149 | | { |
| | 0 | 150 | | var _authSettings = new AuthorizationSettings(); |
| | 0 | 151 | | Configuration.GetSection("AuthorizationSettings").Bind(_authSettings); |
| | 0 | 152 | | options.RequireHttpsMetadata = false; |
| | 0 | 153 | | options.TokenRetriever = CustomTokenRetriever.FromHeaderAndQueryString; |
| | 0 | 154 | | options.Authority = _authSettings.IdentityUrl; |
| | 0 | 155 | | options.ApiName = _authSettings.ApiName; |
| | 0 | 156 | | options.ApiSecret = _authSettings.ApiSecret.Encrypted ? SymmetricCrypto.DecryptData(Convert.FromBase |
| | 0 | 157 | | }); |
| | | 158 | | |
| | 0 | 159 | | services.AddAuthorization(options => |
| | 0 | 160 | | { |
| | 0 | 161 | | // "boss" claims role=boss |
| | 0 | 162 | | // API- /Who/boss |
| | 0 | 163 | | options.AddPolicy("boss", policyAdmin => |
| | 0 | 164 | | { |
| | 0 | 165 | | policyAdmin.RequireClaim("role", "boss"); |
| | 0 | 166 | | }); |
| | 0 | 167 | | |
| | 0 | 168 | | // "owner" claims role=owner |
| | 0 | 169 | | options.AddPolicy("owner", policyUser => |
| | 0 | 170 | | { |
| | 0 | 171 | | policyUser.RequireClaim("role", "owner"); |
| | 0 | 172 | | }); |
| | 0 | 173 | | options.AddPolicy("svetaDDistr", policyUser => |
| | 0 | 174 | | { |
| | 0 | 175 | | policyUser.RequireClaim("scope", "svetaDDistr"); |
| | 0 | 176 | | }); |
| | 0 | 177 | | // "policy3" claims scope=ddistr |
| | 0 | 178 | | options.AddPolicy("policy3", policyUser => |
| | 0 | 179 | | { |
| | 0 | 180 | | policyUser.RequireClaim("scope", "ddistr"); |
| | 0 | 181 | | }); |
| | 0 | 182 | | }); |
| | | 183 | | |
| | 0 | 184 | | services.Replace(ServiceDescriptor.Transient<IAuthorizationService, CaptureAuthorizationService>()); |
| | | 185 | | |
| | 0 | 186 | | services.AddHttpContextAccessor(); |
| | 0 | 187 | | services.AddScoped<IAuthenticationService, AuthenticationService>(); |
| | | 188 | | |
| | 0 | 189 | | services.AddScoped<IPhotoService, PhotoService>(); |
| | 0 | 190 | | services.AddScoped<IDownloadGoodsImagesTaskService, DownloadGoodsImagesTaskService>(); |
| | 0 | 191 | | services.AddScoped<IDownloadGoodsImagesWorker, DownloadGoodsImagesWorker>(); |
| | 0 | 192 | | services.AddScoped<IDiskStorageService, DiskStorageService>(); |
| | 0 | 193 | | services.AddScoped<IGoodService, GoodService>(); |
| | 0 | 194 | | services.AddScoped<IDepartmentService, DepartmentService>(); |
| | 0 | 195 | | services.AddScoped<IEventService, EventService>(); |
| | 0 | 196 | | services.AddScoped<IIncidentService, IncidentService>(); |
| | 0 | 197 | | services.AddScoped<IMovementService, MovementService>(); |
| | 0 | 198 | | services.AddScoped<INotificationService, NotificationService>(); |
| | 0 | 199 | | services.AddScoped<INotificationUsersService, NotificationUsersService>(); |
| | 0 | 200 | | services.AddScoped<IPriceTrendService, PriceTrendService>(); |
| | 0 | 201 | | services.AddScoped<IPromoBidService, PromoBidService>(); |
| | 0 | 202 | | services.AddScoped<IPromoOfferService, PromoOfferService>(); |
| | 0 | 203 | | services.AddScoped<IRestService, RestService>(); |
| | 0 | 204 | | services.AddScoped<ISupplyContractService, SupplyContractService>(); |
| | 0 | 205 | | services.AddScoped<IUserService, UserService>(); |
| | 0 | 206 | | services.AddScoped<IGoodSettingService, GoodSettingService>(); |
| | 0 | 207 | | services.AddScoped<IContragentService, ContragentService>(); |
| | 0 | 208 | | services.AddScoped<ICategoryService, CategoryService>(); |
| | 0 | 209 | | services.AddScoped<IBrandService, BrandService>(); |
| | 0 | 210 | | services.AddScoped<ICountryService, CountryService>(); |
| | 0 | 211 | | services.AddScoped<IClusterService, ClusterService>(); |
| | 0 | 212 | | services.AddScoped<IMovementWorker, MovementWorker>(); |
| | 0 | 213 | | services.AddScoped<IPriceWorker, PriceWorker>(); |
| | 0 | 214 | | services.AddScoped<IEmailService, EmailService>(); |
| | 0 | 215 | | services.AddScoped<IBarcodeService, BarcodeService>(); |
| | 0 | 216 | | services.AddScoped<IAddressService, AddressService>(); |
| | 0 | 217 | | services.AddScoped<IDirectoriesService, DirectoriesService>(); |
| | 0 | 218 | | services.AddScoped<ICategoryRatioService, CategoryRatioService>(); |
| | 0 | 219 | | services.AddScoped<IMovementTypeStatusService, MovementTypeStatusService>(); |
| | 0 | 220 | | services.AddScoped<ITaxSystemService, TaxSystemService>(); |
| | 0 | 221 | | services.AddSingleton<IAuthorizationPolicyProvider, MethodPolicyProvider>(); |
| | 0 | 222 | | services.AddScoped<IMethodRolesService, MethodRolesService>(); |
| | 0 | 223 | | services.AddScoped<IAuthorizationHandler, MethodAuthorizationHandler>(); |
| | 0 | 224 | | services.AddScoped<IBankAccountService, BankAccountService>(); |
| | 0 | 225 | | services.AddScoped<IUploadService, UploadService>(); |
| | 0 | 226 | | services.AddScoped<IMovementStatusJournalService, MovementStatusJournalService>(); |
| | 0 | 227 | | services.AddScoped<IShowcaseWorker, ShowcaseWorker>(); |
| | 0 | 228 | | services.AddScoped<IWorkScheduleService, WorkScheduleService>(); |
| | 0 | 229 | | services.AddScoped<IWalletService, WalletService>(); |
| | 0 | 230 | | services.AddScoped<IWalletHttpClient, WalletHttpClient>(); |
| | 0 | 231 | | services.AddScoped<IWalletPaymentService, WalletPaymentService>(); |
| | 0 | 232 | | services.AddScoped<IMovementRouteService, MovementRouteService>(); |
| | 0 | 233 | | services.AddScoped<IMovementStatusRouter, MovementStatusRouter>(); |
| | 0 | 234 | | services.AddScoped<IMovementNotesService, MovementNotesService>(); |
| | 0 | 235 | | services.AddScoped<ICommonUserService, CommonUserService>(); |
| | 0 | 236 | | services.AddScoped<ICommonContragentService, CommonContragentService>(); |
| | 0 | 237 | | services.AddScoped<ICrmSyncWorker, CrmSyncWorker>(); |
| | 0 | 238 | | services.AddScoped<IControlsAccessService, ControlsAccessService>(); |
| | 0 | 239 | | services.AddScoped<IJobService, JobService>(); |
| | 0 | 240 | | services.AddScoped<IDiscountColorService, DiscountColorService>(); |
| | 0 | 241 | | services.AddScoped<INotificationWorker, NotificationWorker>(); |
| | 0 | 242 | | services.AddScoped<IExchangeTokenService, ExchangeTokenService>(); |
| | 0 | 243 | | services.AddScoped<IFeedsWorker, FeedsWorker>(); |
| | 0 | 244 | | services.AddScoped<IEmailWorker, EmailWorker>(); |
| | 0 | 245 | | services.AddScoped<ICategoryWorker, CategoryWorker>(); |
| | 0 | 246 | | services.AddScoped<IGoodWorker, GoodWorker>(); |
| | 0 | 247 | | services.AddScoped<IRestHoldService, RestHoldService>(); |
| | 0 | 248 | | services.AddScoped<IConfigurationService, ConfigurationService>(); |
| | 0 | 249 | | services.AddScoped<IReportService, ReportService>(); |
| | 0 | 250 | | services.AddSingleton<IUserIdProvider, CustomUserIdProvider>(); |
| | 0 | 251 | | services.AddScoped<IUploadWorker, UploadWorker>(); |
| | 0 | 252 | | services.AddScoped<IMovementRouteActionsService, MovementRouteActionsService>(); |
| | 0 | 253 | | services.AddScoped<IGoodLabelService, GoodLabelService>(); |
| | 0 | 254 | | services.AddScoped<IDepartmentWorker, DepartmentWorker>(); |
| | 0 | 255 | | services.AddScoped<IAnonymousMovementService, AnonymousMovementService>(); |
| | 0 | 256 | | services.AddScoped<ITelegramNotificationService, TelegramNotificationService>(); |
| | 0 | 257 | | services.AddScoped<ISmsWorker, SmsWorker>(); |
| | 0 | 258 | | services.AddScoped<ISmsHistoryService, SmsHistoryService>(); |
| | 0 | 259 | | services.AddScoped<IEmailGateHistoryService, EmailGateHistoryService>(); |
| | | 260 | | |
| | 0 | 261 | | services.AddScoped<IRecordImporter<RestRecord>, RestImporter>(); |
| | 0 | 262 | | services.AddScoped<IRecordImporter<GoodSettingRecord>, GoodSettingImporter>(); |
| | 0 | 263 | | services.AddScoped<IImportService, ImportService>(); |
| | | 264 | | |
| | 0 | 265 | | services.Configure<CommonSettings>(Configuration.GetSection("CommonSettings")); |
| | 0 | 266 | | services.Configure<ImagesSettings>(Configuration.GetSection("ImageSettings")); |
| | 0 | 267 | | services.Configure<DaDataSettings>(Configuration.GetSection("DaDataSettings")); |
| | 0 | 268 | | services.Configure<UploadDownloadSettings>(Configuration.GetSection("UploadDownloadSettings")); |
| | 0 | 269 | | services.Configure<MigrateSettings>(Configuration.GetSection("MigrateSettings")); |
| | 0 | 270 | | services.Configure<WalletSettings>(Configuration.GetSection("WalletSettings")); |
| | 0 | 271 | | services.Configure<AuthorizationSettings>(Configuration.GetSection("AuthorizationSettings")); |
| | 0 | 272 | | services.Configure<EmailSettings>(Configuration.GetSection("EmailSettings")); |
| | 0 | 273 | | services.Configure<TelegramSettings>(Configuration.GetSection("TelegramSettings")); |
| | 0 | 274 | | services.Configure<SmsSettings>(Configuration.GetSection("SmsSettings")); |
| | | 275 | | |
| | 0 | 276 | | services.AddHostedService<DownloadGoodsImagesTaskProcessor>(); |
| | 0 | 277 | | services.AddHostedService<MovementStatusChecker>(); |
| | 0 | 278 | | services.AddHostedService<SendEmailJob>(); |
| | 0 | 279 | | services.AddHostedService<FeedGenerateJob>(); |
| | 0 | 280 | | services.AddHostedService<AnonymousMovementJob>(); |
| | 0 | 281 | | if (Configuration.GetValue<bool>("UseUpdatingLinkImagesJob")) |
| | 0 | 282 | | services.AddHostedService<UpdatingLinkImagesJob>(); |
| | 0 | 283 | | services.AddWkhtmltopdf(); |
| | | 284 | | |
| | 0 | 285 | | services.AddControllers() |
| | 0 | 286 | | .AddNewtonsoftJson(options => |
| | 0 | 287 | | { |
| | 0 | 288 | | options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; |
| | 0 | 289 | | //options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc; |
| | 0 | 290 | | options.SerializerSettings.DateFormatString = "yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"; |
| | 0 | 291 | | }); |
| | 0 | 292 | | services.AddSignalR(options => |
| | 0 | 293 | | { |
| | 0 | 294 | | options.EnableDetailedErrors = true; |
| | 0 | 295 | | }); |
| | | 296 | | |
| | 0 | 297 | | services.AddSwaggerGen(c => |
| | 0 | 298 | | { |
| | 0 | 299 | | c.SwaggerDoc("v1", new OpenApiInfo { Title = "SVETA API", Version = "v1" }); |
| | 0 | 300 | | c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
| | 0 | 301 | | { |
| | 0 | 302 | | In = ParameterLocation.Header, |
| | 0 | 303 | | Description = "JWT Authorization header using the Bearer scheme. Example: \"Bearer {token}\"", |
| | 0 | 304 | | Name = "Authorization", |
| | 0 | 305 | | BearerFormat = "JWT", |
| | 0 | 306 | | Type = SecuritySchemeType.ApiKey, |
| | 0 | 307 | | Scheme = "Bearer" |
| | 0 | 308 | | }); |
| | 0 | 309 | | c.AddSecurityRequirement(new OpenApiSecurityRequirement |
| | 0 | 310 | | { |
| | 0 | 311 | | { |
| | 0 | 312 | | new OpenApiSecurityScheme |
| | 0 | 313 | | { |
| | 0 | 314 | | Reference = new OpenApiReference |
| | 0 | 315 | | { |
| | 0 | 316 | | Type = ReferenceType.SecurityScheme, |
| | 0 | 317 | | Id = "Bearer", |
| | 0 | 318 | | } |
| | 0 | 319 | | }, |
| | 0 | 320 | | new string[] {} |
| | 0 | 321 | | } |
| | 0 | 322 | | }); |
| | 0 | 323 | | var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; |
| | 0 | 324 | | var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); |
| | 0 | 325 | | c.IncludeXmlComments(xmlPath); |
| | 0 | 326 | | c.EnableAnnotations(); |
| | 0 | 327 | | }); |
| | 0 | 328 | | } |
| | | 329 | | |
| | | 330 | | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| | | 331 | | public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostApplicationLifetime appLifetim |
| | 0 | 332 | | { |
| | | 333 | | |
| | 0 | 334 | | app.UseExceptionHandler("/api/v1/Error"); |
| | 0 | 335 | | app.UseHsts(); |
| | | 336 | | |
| | 0 | 337 | | var supportedCultures = new[] |
| | 0 | 338 | | { |
| | 0 | 339 | | new CultureInfo("ru-RU"), |
| | 0 | 340 | | new CultureInfo("ru") |
| | 0 | 341 | | }; |
| | 0 | 342 | | app.UseRequestLocalization(new RequestLocalizationOptions |
| | 0 | 343 | | { |
| | 0 | 344 | | DefaultRequestCulture = new RequestCulture("ru-RU"), |
| | 0 | 345 | | SupportedCultures = supportedCultures, |
| | 0 | 346 | | SupportedUICultures = supportedCultures |
| | 0 | 347 | | }); |
| | 0 | 348 | | if (Configuration.GetValue<bool>("UseSwagger")) |
| | 0 | 349 | | { |
| | 0 | 350 | | app.UseSwagger(); |
| | 0 | 351 | | app.UseSwaggerUI(c => |
| | 0 | 352 | | { |
| | 0 | 353 | | c.SwaggerEndpoint("/swagger/v1/swagger.json", "SVETA API v1"); |
| | 0 | 354 | | }); |
| | 0 | 355 | | } |
| | 0 | 356 | | app.ConfigureCustomExceptionMiddleware(); |
| | 0 | 357 | | app.UseRouting(); |
| | 0 | 358 | | app.UseCors(); |
| | 0 | 359 | | app.UseAuthentication(); |
| | 0 | 360 | | app.UseAuthorization(); |
| | | 361 | | |
| | 0 | 362 | | app.UseEndpoints(endpoints => |
| | 0 | 363 | | { |
| | 0 | 364 | | endpoints.MapHub<SignalHub>("api/hubs/signal"); |
| | 0 | 365 | | endpoints.MapHub<NotificationHub>("api/hubs/notification", options => |
| | 0 | 366 | | { |
| | 0 | 367 | | options.Transports = HttpTransportType.WebSockets; |
| | 0 | 368 | | }); |
| | 0 | 369 | | endpoints.MapControllers(); |
| | 0 | 370 | | }); |
| | | 371 | | |
| | 0 | 372 | | loggerFactory.AddSerilog(); |
| | | 373 | | |
| | 0 | 374 | | appLifetime.ApplicationStopping.Register(Shutdown); |
| | 0 | 375 | | appLifetime.ApplicationStopped.Register(Stopped); |
| | 0 | 376 | | } |
| | | 377 | | |
| | | 378 | | private void Stopped() |
| | 0 | 379 | | { |
| | 0 | 380 | | Console.WriteLine("Application Stopped"); |
| | 0 | 381 | | } |
| | | 382 | | |
| | | 383 | | private void Shutdown() |
| | 0 | 384 | | { |
| | 0 | 385 | | Console.WriteLine("Shutdown application"); |
| | 0 | 386 | | } |
| | | 387 | | } |
| | | 388 | | } |