public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env) { if (env.IsEnvironment("Development")) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } //usesdefaultfiles() function to go into wwwroot folder to run some statuc files which starts with index.html or index.htm,etc app.UseDefaultFiles(); // app.UsePathBase("/app"); //app.UsePathBase(configuration["pathBase"]); app.UseStaticFiles(); app.UseNodeModules(); app.UseAuthentication();//have identifying the user // What they app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(cfg => { cfg.MapControllerRoute("Default", "{controller}/{action}/{id?}", new { controller = "App", action = "Index" } ); }); }
public void Configure(IApplicationBuilder app, HostingEnvironment env, DiagnosticListenerObserver observer) { if (env.IsDevelopment() || env.IsEnvironment("Testing")) { observer.Subscribe(); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Use(next => { return(async context => { await next(context); }); }); #if NETCOREAPP2_2 app.UseMvc(); #endif #if NETCOREAPP3_0 app.UseRouting(); app.UseEndpoints(routing => { routing.MapControllers(); }); #endif }
public static IClientBuilder ConfigureClustering( this IClientBuilder builder, IHostingEnvironment hostingEnvironment) { if (hostingEnvironment.IsDevelopment()) { return(builder.UseLocalhostClustering()); } else if (hostingEnvironment.IsEnvironment("Compose")) { return(builder.UseComposeClustering("host")); } else { return(builder.UseKubeGatewayListProvider(opt => { opt.Group = "orleans.dot.net"; })); } }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { _serviceDescriptors = services; string connectionstring = Configuration.GetConnectionString("PlDatabase"); bool isTestEnv = string.IsNullOrEmpty(connectionstring) || CurrentEnvironment.IsEnvironment("Testing"); services. AddSingleton <IElasticConnectionClient, ElasticConnectionClient>() .AddSingleton <IPasteBinService, PasteBinService>() .AddSingleton <IProviderFactory, ProviderFactory>() .AddSingleton <IContextTvgMediaHandler, ContextTvgMediaHandler>() .AddScoped <IXmltvService, XmltvService>() .AddScoped <IPiconsService, PiconsService>() .AddScoped <IPlaylistService, PlaylistService>() .AddScoped <IMediaRefService, MediaRefService>() .AddScoped <ISitePackService, SitePackService>() .AddScoped <ICommandService, CommandService>() .AddScoped <IXtreamService, XtreamService>() .AddScoped <IMediaScraper, MediaScraper>() .AddScoped <IWebGrabConfigService, WebGrabConfigService>() .AddScoped <IMessageQueueService, MessageQueueService>() .Configure <RabbitMQConfiguration>(Configuration.GetSection(nameof(RabbitMQConfiguration))) .Configure <List <PlaylistProviderOption> >(Configuration.GetSection(PlaylistProviderOption.PlaylistProvidersConfigurationKeyName)) .Configure <ElasticConfig>(Configuration.GetSection(nameof(ElasticConfig))) .Configure <JwtBearerOptions>(Configuration.GetSection(nameof(JwtBearerOptions))) .Configure <MediaServerOptions>(Configuration.GetSection(nameof(MediaServerOptions))) .Configure <GlobalOptions>(Configuration.GetSection(nameof(GlobalOptions))) .Configure <PastBinOptions>(Configuration.GetSection(nameof(PastBinOptions))) .Configure <VapidKeysOptions>(Configuration.GetSection(nameof(VapidKeysOptions))); var retryPolicy = HttpPolicyExtensions .HandleTransientHttpError() .RetryAsync(3); //.CircuitBreaker(5, TimeSpan.FromSeconds(30)); var noOp = Policy.NoOpAsync().AsAsyncPolicy <HttpResponseMessage>(); services.AddHttpClient <MediaServerService>(c => { var ServerMediaOptions = Provider.GetService <IOptions <MediaServerOptions> >(); var scheme = ServerMediaOptions.Value.IsSecure ? "https" : "http"; c.BaseAddress = new Uri($"{scheme}://{ServerMediaOptions.Value.Host}:{ServerMediaOptions.Value.Port}/"); c.DefaultRequestHeaders.Add("Accept", "application/json"); c.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory-Sample"); }).AddPolicyHandler(request => request.Method == HttpMethod.Get ? retryPolicy : noOp); //.AddTransientHttpErrorPolicy(p => p.RetryAsync(3)) //.AddTransientHttpErrorPolicy(p => p.CircuitBreakerAsync(5, TimeSpan.FromSeconds(30))); services.AddSingleton(typeof(HubLifetimeManager <>), typeof(DefaultHubLifetimeManager <>)); services.AddSingleton(typeof(IHubProtocolResolver), typeof(DefaultHubProtocolResolver)); services.AddScoped(typeof(IHubActivator <>), typeof(DefaultHubActivator <>)); services.AddHttpContextAccessor(); services.AddSignalR(); services.AddMemoryCache(); if (isTestEnv) { services.AddDbContext <SynkerDbContext>(options => { options.UseInMemoryDatabase("playlist"); }); } else { services.AddDbContext <SynkerDbContext>(options => { options.UseNpgsql(Configuration.GetConnectionString("PlDatabase"), sqlOptions => { sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); //Configuring Connection Resiliency: sqlOptions. EnableRetryOnFailure(3, TimeSpan.FromSeconds(30), null); }); //// Changing default behavior when client evaluation occurs to throw. //// Default in EFCore would be to log warning when client evaluation is done. //options.ConfigureWarnings(warnings => warnings.Throw( //RelationalEventId.QueryClientEvaluationWarning)); }); _synkerDbContext = Provider.GetService <SynkerDbContext>(); _synkerDbContext.Database.EnsureCreated(); } services.AddRabbitMq(); services.AddSecurity(); #region Compression services.Configure <GzipCompressionProviderOptions>(options => options.Level = System.IO.Compression.CompressionLevel.Optimal); services.AddResponseCompression(options => { options.MimeTypes = new[] { // Default "text/plain", "text/css", "application/javascript", "text/html", "application/xml", "text/xml", "application/json", "text/json", // Custom "image/svg+xml" }; }); #endregion //Logger LoggerFactory loggerFactory = new LoggerFactory(); //cache services.AddResponseCaching(options => { options.UseCaseSensitivePaths = true; options.MaximumBodySize = 1024; }); //MVC services.AddMvc(config => { config.EnableEndpointRouting = false; config.Filters.Add(typeof(GlobalExceptionFilterAttribute)); config.CacheProfiles.Add("Default", new CacheProfile() { Duration = 60, Location = ResponseCacheLocation.Any }); config.CacheProfiles.Add("Long", new CacheProfile() { Duration = 60 }); config.CacheProfiles.Add("Never", new CacheProfile() { Location = ResponseCacheLocation.None, NoStore = true }); }) .AddJsonOptions( options => { options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; options.SerializerSettings.Formatting = Formatting.Indented; options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; options.SerializerSettings.Converters.Add(new StringEnumConverter()); } ).SetCompatibilityVersion(CompatibilityVersion.Latest); services.AddApiVersioning(o => { o.AssumeDefaultVersionWhenUnspecified = true; o.DefaultApiVersion = new ApiVersion(1, 0); }); //https://github.com/domaindrivendev/Swashbuckle.AspNetCore var jwtOptions = Configuration.GetSection(nameof(JwtBearerOptions)).Get <JwtBearerOptions>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "Synker API", Description = $"Synchronize playlists API {AssemblyVersion}", TermsOfService = "None", Contact = new Contact { Name = "Synker", Email = "*****@*****.**", Url = "https://www.github.com/fazzani/synker2" }, License = new License { Name = "Use under MIT", Url = "" }, }); c.AddSecurityDefinition("oauth2", new OAuth2Scheme { Type = "oauth2", Description = "OAuth2 Implicit Grant", Flow = "implicit", AuthorizationUrl = $"{jwtOptions.Authority}/connect/authorize", TokenUrl = $"{jwtOptions.Authority}/connect/token", Scopes = new Dictionary <string, string> { { "synkerapi.full_access", "Full access operations" }, { "synkerapi.readonly", "ReadOnly access operations" } } }); c.OperationFilter <SecurityRequirementsOperationFilter>(); c.DescribeAllEnumsAsStrings(); c.DescribeStringEnumsInCamelCase(); c.IgnoreObsoleteActions(); c.IgnoreObsoleteProperties(); c.SchemaFilter <AutoRestSchemaFilter>(); }); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.WithOrigins(CurrentEnvironment.IsDevelopment() ? "http://localhost:56810" : "https://synker.ovh", "https://www.synker.ovh", "https://xviewer.synker.ovh", "https://holo.synker.ovh") .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); #region Webhooks // services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.UseGithubWebhook(() => new GithubOptions { ApiKey = Configuration.GetValue <string>("GitHubHookApiKey"), WebHookAction = genericHookAction }).UseAppVeyorWebhook(() => new AppveyorOptions { ApiKey = Configuration.GetValue <string>("AppveyorHookApiKey"), WebHookAction = genericHookAction }); #endregion }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddDbContext <ApplicationDbContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); }); services.AddIdentity <SipUser, SipRole>(options => { options.Password.RequireDigit = true; options.Password.RequireLowercase = true; options.Password.RequiredLength = 5; }).AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddAuthentication(auth => { auth.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; auth.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidateIssuer = false, ValidateAudience = false, ValidAudience = Configuration["AuthSettings:Audience"], ValidIssuer = Configuration["AuthSettings:Issuer"], RequireExpirationTime = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["AuthSettings:Key"])), ValidateIssuerSigningKey = true }; }); services.AddMvc(options => { options.InputFormatters.Insert(0, new BinaryInputFormatter()); }); if (_hostingEnvironment.IsEnvironment("Development")) { services.AddTransient <IClassificationProvider, DevClassificationProvider>(); services.AddTransient <IFrontContentProvider, DevFrontContentProvider>(); services.AddScoped <IUserService, DevUserService>(); services.AddScoped <IClaimCheck, DevClaimCheck>(); services.AddTransient <IFrontOrganizationProvider, DevFrontOrganizationProvider>(); services.AddTransient <IFrontProvider, DevFrontProvider>(); services.AddTransient <IContentProvider, DevContentProvider>(); } else { services.AddTransient <IClassificationProvider, ClassificationProvider>(); services.AddTransient <IFrontContentProvider, FrontContentProvider>(); services.AddScoped <IUserService, UserService>(); services.AddScoped <IClaimCheck, ClaimCheck>(); services.AddTransient <IFrontOrganizationProvider, FrontOrganizationProvider>(); services.AddTransient <IFrontProvider, FrontProvider>(); services.AddTransient <IContentProvider, ContentProvider>(); } services.AddControllers(); services.AddTransient <ISqlDataAccess, SqlDataAccess>(); services.AddTransient <ISearchProvider, SearchProvider>(); services.AddTransient <IMVCUIScreenProvider, MVCUIScreenProvider>(); services.AddTransient <IMetaContentProvider, MetaContentProvider>(); services.AddTransient <ILogProvider, LogProvider>(); services.AddTransient <IBaseProvider, BaseProvider>(); services.AddTransient <IFrontUserFavoriteProvider, FrontUserFavoriteProvider>(); services.AddTransient <IFrontUserFavoriteGroupProvider, FrontUserFavoriteGroupProvider>(); services.AddTransient <IProcessTypeFlowConditionProvider, ProcessTypeFlowConditionProvider>(); services.AddTransient <IProcessTypeFlowConditionTypeProvider, ProcessTypeFlowConditionTypeProvider>(); services.AddTransient <IObjectTypePropertyStatus, ObjectTypePropertyStatus>(); services.AddTransient <IProjectTypePropertyProvider, ProjectTypePropertyProvider>(); services.AddTransient <IProcessTypeFlowPassComparisonOperatorProvider, ProcessTypeFlowPassComparisonOperatorProvider>(); services.AddTransient <ICodeTypeProvider, CodeTypeProvider>(); services.AddTransient <IProjectMatrixTypeProvider, ProjectMatrixTypeProvider>(); services.AddTransient <IProjectTypeMatrixProvider, ProjectTypeMatrixProvider>(); services.AddTransient <IProcessTypeFlowPassTypeProvider, ProcessTypeFlowPassTypeProvider>(); services.AddTransient <IProcessTypeFlowPassProvider, ProcessTypeFlowPassProvider>(); services.AddTransient <IOrganizationPositionProvider, OrganizationPositionProvider>(); services.AddTransient <IMVCFavoriteProvider, MVCFavoriteProvider>(); services.AddTransient <IPersonPositionProvider, PersonPositionProvider>(); services.AddTransient <IPositionProvider, PositionProvider>(); services.AddTransient <IPropertyProvider, PropertyProvider>(); services.AddTransient <IClassificationLevelPropertyProvider, ClassificationLevelPropertyProvider>(); services.AddTransient <IPropertyStatusProvider, PropertyStatusProvider>(); services.AddTransient <IClassificationValuePropertyProvider, ClassificationValuePropertyProvider>(); services.AddTransient <IPropertyValueProvider, PropertyValueProvider>(); services.AddTransient <IPropertyTypeProvider, PropertyTypeProvider>(); services.AddTransient <IUserRoleProvider, UserRoleProvider>(); services.AddTransient <IValueUpdateTypeProvider, ValueUpdateTypeProvider>(); services.AddTransient <IRoleClaimProvider, RoleClaimProvider>(); services.AddTransient <IFrontPersonProvider, FrontPersonProvider>(); services.AddTransient <IFrontClassificationValueProvider, FrontClassificationValueProvider>(); // services.AddTransient<IFrontUserProvider, FrontUserProvider>(); services.AddTransient <IFrontProjectProvider, FrontProjectProvider>(); services.AddTransient <IProcessTypeFlowProvider, ProcessTypeFlowProvider>(); services.AddTransient <ICheckProvider, CheckProvider>(); services.AddTransient <ISettingProvider, SettingProvider>(); services.AddTransient <IClassificationLevelProvider, ClassificationLevelProvider>(); services.AddTransient <IDateLevelProvider, DateLevelProvider>(); services.AddTransient <IAddressTypeProvider, AddressTypeProvider>(); services.AddTransient <IPersonAddressProvider, PersonAddressProvider>(); services.AddTransient <IPersonRelationProvider, PersonRelationProvider>(); services.AddTransient <IPersonTelecomProvider, PersonTelecomProvider>(); services.AddTransient <IProcessTypeStageFieldStatusProvider, ProcessTypeStageFieldStatusProvider>(); services.AddTransient <IProcessTypeGroupProvider, ProcessTypeGroupProvider>(); services.AddTransient <IProcessTypeStageFieldProvider, ProcessTypeStageFieldProvider>(); services.AddTransient <IProcessTypeFieldStageProvider, ProcessTypeFieldStageProvider>(); services.AddTransient <IProcessTypeFieldTypeProvider, ProcessTypeFieldTypeProvider>(); services.AddTransient <IPersonProvider, PersonProvider>(); services.AddTransient <IPageSectionDataTypeProvider, PageSectionDataTypeProvider>(); services.AddTransient <ISecurityLevelProvider, SecurityLevelProvider>(); services.AddTransient <IProcessTypeStageProvider, ProcessTypeStageProvider>(); services.AddTransient <IProcessTypeGroupProvider, ProcessTypeGroupProvider>(); //services.AddTransient<IProcessTypeFieldProvider, ProcessTypeFieldProvider>(); services.AddTransient <IProcessTypeStageProvider, ProcessTypeStageProvider>(); services.AddTransient <IPageSectionTypeProvider, PageSectionTypeProvider>(); services.AddTransient <IUserMenuTypeProvider, UserMenuTypeProvider>(); services.AddTransient <ITelecomTypeProvider, TelecomTypeProvider>(); services.AddTransient <IProcessTypeFieldProvider, ProcessTypeFieldProvider>(); services.AddTransient <IProcessTypeFlowConditionComparisonOperatorProvider, ProcessTypeFlowConditionComparisonOperatorProvider>(); services.AddTransient <IClassificationUserProvider, ClassificationUserProvider>(); services.AddTransient <IClassificationRoleProvider, ClassificationRoleProvider>(); //services.AddTransient<IClassificationPageProvider, ClassificationPageProvider>(); //services.AddTransient<IClassificationPageSectionProvider, ClassificationPageSectionProvider>(); services.AddTransient <IClassificationRelationTypeProvider, ClassificationRelationTypeProvider>(); services.AddTransient <IClassificationValueProvider, ClassificationValueProvider>(); services.AddTransient <IClassificationValueRoleProvider, ClassificationValueRoleProvider>(); services.AddTransient <IClassificationValueUserProvider, ClassificationValueUserProvider>(); services.AddTransient <IRoleGroupProvider, RoleGroupProvider>(); services.AddTransient <IFrontUserPageProvider, FrontUserPageProvider>(); services.AddTransient <IFrontUserPageSectionProvider, FrontUserPageSectionProvider>(); services.AddTransient <IPartialProvider, PartialProvider>(); services.AddTransient <IContentStatusProvider, ContentStatusProvider>(); services.AddTransient <IContentTypeClassificationProvider, ContentTypeClassificationProvider>(); services.AddTransient <IContentTypeClassificationStatusProvider, ContentTypeClassificationStatusProvider>(); services.AddTransient <IContentTypeGroupProvider, ContentTypeGroupProvider>(); services.AddTransient <IContentTypeProvider, ContentTypeProvider>(); services.AddTransient <IFrontProcessProvider, FrontProcessProvider>(); services.AddTransient <IGenderProvider, GenderProvider>(); services.AddTransient <ILanguageProvider, LanguageProvider>(); services.AddTransient <IRoleProvider, RoleProvider>(); services.AddTransient <IFrontUserMenuProvider, FrontUserMenuProvider>(); services.AddTransient <IUserMenuTemplateProvider, UserMenuTemplateProvider>(); services.AddTransient <IUserProvider, UserProvider>(); services.AddTransient <IPersonRelationTypeProvider, PersonRelationTypeProvider>(); services.AddTransient <IUserMenuTemplateOptionProvider, UserMenuTemplateOptionProvider>(); services.AddTransient <IFrontUserPreferenceProvider, FrontUserPreferenceProvider>(); services.AddTransient <IProjectProvider, ProjectProvider>(); services.AddTransient <IProjectTypeProvider, ProjectTypeProvider>(); services.AddTransient <IPageProvider, PageProvider>(); services.AddTransient <IPageSectionProvider, PageSectionProvider>(); services.AddTransient <IPageSectionContentConditionProvider, PageSectionContentConditionProvider>(); services.AddTransient <IPageSectionContentConditionTypeProvider, PageSectionContentConditionTypeProvider>(); services.AddTransient <IPageSectionProcessConditionProvider, PageSectionProcessConditionProvider>(); services.AddTransient <IPageSectionProcessConditionTypeProvider, PageSectionProcessConditionTypeProvider>(); services.AddTransient <IProcessProvider, ProcessProvider>(); services.AddTransient <IProcessTypeProvider, ProcessTypeProvider>(); services.AddTransient <IProcessTypeStageTypeProvider, ProcessTypeStageTypeProvider>(); services.AddTransient <IOrganizationProvider, OrganizationProvider>(); services.AddTransient <IOrganizationAddressProvider, OrganizationAddressProvider>(); services.AddTransient <IOrganizationTelecomProvider, OrganizationTelecomProvider>(); services.AddTransient <IOrganizationTypeProvider, OrganizationTypeProvider>(); services.AddTransient <IMetaProvider, MetaProvider>(); services.AddTransient <IMasterProvider, MasterProvider>(); services.AddTransient <IMasterListProvider, MasterListProvider>(); services.AddTransient <IHomeProvider, HomeProvider>(); services.AddTransient <SIPx.API.DataProviders.IUITermLanguageCustomizationProvider, UITermLanguageCustomizationProvider>(); services.AddSwaggerGen(x => { x.SwaggerDoc("v1", new OpenApiInfo { Title = "SIP API", Version = "v1" }); var security = new Dictionary <string, IEnumerable <string> > { { "Bearer", new string[0] } }; x.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Name = "Authorization", Type = SecuritySchemeType.Http, Scheme = "bearer", BearerFormat = "JWT", In = ParameterLocation.Header, Description = "JWT Authorization header using the Bearer scheme." }); x.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "bearer", Name = "Bearer", In = ParameterLocation.Header, }, new string[] {} } }); }); }
private static ConsoleTheme GetTheme(HostingEnvironment hostingEnvironment) { return(hostingEnvironment.IsEnvironment("Testing") ? ConsoleTheme.None : AnsiConsoleTheme.Code); }