You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
281 lines
10 KiB
281 lines
10 KiB
using System;
|
|
using System.IO;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|
using Win_in.Sfs.Print.Web.Menus;
|
|
using StackExchange.Redis;
|
|
using Microsoft.OpenApi.Models;
|
|
using Volo.Abp;
|
|
using Volo.Abp.AspNetCore.Authentication.OpenIdConnect;
|
|
using Volo.Abp.AspNetCore.Mvc.Client;
|
|
using Volo.Abp.AspNetCore.Mvc.Localization;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Bundling;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
|
|
using Volo.Abp.AspNetCore.Serilog;
|
|
using Volo.Abp.Autofac;
|
|
using Volo.Abp.AutoMapper;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.Http.Client.IdentityModel.Web;
|
|
using Volo.Abp.Identity.Web;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.MultiTenancy;
|
|
using Volo.Abp.SettingManagement.Web;
|
|
using Volo.Abp.Swashbuckle;
|
|
using Volo.Abp.TenantManagement.Web;
|
|
using Volo.Abp.UI.Navigation.Urls;
|
|
using Volo.Abp.UI.Navigation;
|
|
using Volo.Abp.VirtualFileSystem;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Win_in.Sfs.Print.Application.Contacts;
|
|
using Win_in.Sfs.Print.Domain.Shared;
|
|
using Win_in.Sfs.Print.HttpApi;
|
|
using Win_in.Sfs.Print.HttpApi.Client;
|
|
|
|
namespace Win_in.Sfs.Print.Web
|
|
{
|
|
[DependsOn(
|
|
typeof(PrintHttpApiModule),
|
|
typeof(PrintHttpApiClientModule),
|
|
typeof(AbpAspNetCoreAuthenticationOpenIdConnectModule),
|
|
typeof(AbpAspNetCoreMvcClientModule),
|
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule),
|
|
typeof(AbpAutofacModule),
|
|
//typeof(AbpCachingStackExchangeRedisModule),
|
|
typeof(AbpSettingManagementWebModule),
|
|
typeof(AbpHttpClientIdentityModelWebModule),
|
|
typeof(AbpIdentityWebModule),
|
|
typeof(AbpTenantManagementWebModule),
|
|
typeof(AbpAspNetCoreSerilogModule),
|
|
typeof(AbpSwashbuckleModule)
|
|
)]
|
|
public class PrintWebModule : AbpModule
|
|
{
|
|
public override void PreConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options =>
|
|
{
|
|
options.AddAssemblyResource(
|
|
typeof(PrintResource),
|
|
typeof(PrintDomainSharedModule).Assembly,
|
|
typeof(PrintApplicationContractsModule).Assembly,
|
|
typeof(PrintWebModule).Assembly
|
|
);
|
|
});
|
|
}
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
ConfigureBundles();
|
|
ConfigureCache();
|
|
//ConfigureRedis(context, configuration, hostingEnvironment);
|
|
ConfigureUrls(configuration);
|
|
ConfigureAuthentication(context, configuration);
|
|
ConfigureAutoMapper();
|
|
ConfigureVirtualFileSystem(hostingEnvironment);
|
|
ConfigureNavigationServices(configuration);
|
|
ConfigureMultiTenancy();
|
|
ConfigureCors(context, configuration);
|
|
ConfigureSwaggerServices(context.Services);
|
|
}
|
|
|
|
private void ConfigureBundles()
|
|
{
|
|
Configure<AbpBundlingOptions>(options =>
|
|
{
|
|
options.StyleBundles.Configure(
|
|
BasicThemeBundles.Styles.Global,
|
|
bundle =>
|
|
{
|
|
bundle.AddFiles("/global-styles.css");
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
private void ConfigureCache()
|
|
{
|
|
Configure<AbpDistributedCacheOptions>(options =>
|
|
{
|
|
options.KeyPrefix = "Print:";
|
|
});
|
|
}
|
|
|
|
private void ConfigureUrls(IConfiguration configuration)
|
|
{
|
|
Configure<AppUrlOptions>(options =>
|
|
{
|
|
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
|
|
});
|
|
}
|
|
|
|
private void ConfigureMultiTenancy()
|
|
{
|
|
Configure<AbpMultiTenancyOptions>(options =>
|
|
{
|
|
options.IsEnabled = MultiTenancyConsts.IsEnabled;
|
|
});
|
|
}
|
|
|
|
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
|
|
{
|
|
context.Services.AddAuthentication(options =>
|
|
{
|
|
options.DefaultScheme = "Cookies";
|
|
options.DefaultChallengeScheme = "oidc";
|
|
})
|
|
.AddCookie("Cookies", options =>
|
|
{
|
|
options.ExpireTimeSpan = TimeSpan.FromDays(365);
|
|
})
|
|
.AddAbpOpenIdConnect("oidc", options =>
|
|
{
|
|
options.Authority = configuration["AuthServer:Authority"];
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
|
|
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
|
|
|
|
options.ClientId = configuration["AuthServer:ClientId"];
|
|
options.ClientSecret = configuration["AuthServer:ClientSecret"];
|
|
|
|
options.SaveTokens = true;
|
|
options.GetClaimsFromUserInfoEndpoint = true;
|
|
|
|
options.Scope.Add("role");
|
|
options.Scope.Add("email");
|
|
options.Scope.Add("phone");
|
|
options.Scope.Add("Print");
|
|
});
|
|
}
|
|
|
|
private void ConfigureAutoMapper()
|
|
{
|
|
Configure<AbpAutoMapperOptions>(options =>
|
|
{
|
|
options.AddMaps<PrintWebModule>();
|
|
});
|
|
}
|
|
|
|
private void ConfigureVirtualFileSystem(IWebHostEnvironment hostingEnvironment)
|
|
{
|
|
if (hostingEnvironment.IsDevelopment())
|
|
{
|
|
Configure<AbpVirtualFileSystemOptions>(options =>
|
|
{
|
|
options.FileSets.ReplaceEmbeddedByPhysical<PrintDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}Win_in.Sfs.Print.Domain"));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<PrintApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}Win_in.Sfs.Print.Application.Contracts"));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<PrintWebModule>(hostingEnvironment.ContentRootPath);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void ConfigureNavigationServices(IConfiguration configuration)
|
|
{
|
|
Configure<AbpNavigationOptions>(options =>
|
|
{
|
|
options.MenuContributors.Add(new PrintMenuContributor(configuration));
|
|
});
|
|
|
|
Configure<AbpToolbarOptions>(options =>
|
|
{
|
|
options.Contributors.Add(new PrintToolbarContributor());
|
|
});
|
|
}
|
|
|
|
private void ConfigureSwaggerServices(IServiceCollection services)
|
|
{
|
|
services.AddAbpSwaggerGen(
|
|
options =>
|
|
{
|
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Print API", Version = "v1" });
|
|
options.DocInclusionPredicate((docName, description) => true);
|
|
options.CustomSchemaIds(type => type.FullName);
|
|
}
|
|
);
|
|
}
|
|
|
|
//����
|
|
private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
|
|
{
|
|
context.Services.AddCors(options =>
|
|
{
|
|
options.AddDefaultPolicy(builder =>
|
|
{
|
|
builder
|
|
.WithOrigins(
|
|
configuration["App:CorsOrigins"]
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(o => o.RemovePostFix("/"))
|
|
.ToArray()
|
|
)
|
|
.WithAbpExposedHeaders()
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
}
|
|
private void ConfigureRedis(
|
|
ServiceConfigurationContext context,
|
|
IConfiguration configuration,
|
|
IWebHostEnvironment hostingEnvironment)
|
|
{
|
|
if (!hostingEnvironment.IsDevelopment())
|
|
{
|
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
|
|
context.Services
|
|
.AddDataProtection()
|
|
.PersistKeysToStackExchangeRedis(redis, "Print-Protection-Keys");
|
|
}
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
var env = context.GetEnvironment();
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
app.UseAbpRequestLocalization();
|
|
|
|
if (!env.IsDevelopment())
|
|
{
|
|
app.UseErrorPage();
|
|
}
|
|
|
|
app.UseCorrelationId();
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseCors();
|
|
app.UseAuthentication();
|
|
|
|
if (MultiTenancyConsts.IsEnabled)
|
|
{
|
|
app.UseMultiTenancy();
|
|
}
|
|
|
|
app.UseAuthorization();
|
|
app.UseSwagger();
|
|
app.UseAbpSwaggerUI(options =>
|
|
{
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Print API");
|
|
});
|
|
app.UseAbpSerilogEnrichers();
|
|
app.UseConfiguredEndpoints();
|
|
}
|
|
}
|
|
}
|
|
|