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.
155 lines
5.5 KiB
155 lines
5.5 KiB
using BlazorApp.Data;
|
|
|
|
using BlazorApp.Shared;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Syncfusion.Blazor;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.AspNetCore.Components.Server;
|
|
using Radzen;
|
|
using Blazored.SessionStorage;
|
|
using BlazorApp.Helper;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace BlazorApp
|
|
{
|
|
public class ThemeState
|
|
{
|
|
public string CurrentTheme { get; set; } = "default";
|
|
}
|
|
public class Startup
|
|
{
|
|
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
|
|
services.AddDbContext<BlazorAppContext>(options =>
|
|
options.UseSqlServer(
|
|
Configuration.GetConnectionString("BlazorAppContextConnection")));
|
|
services.AddDefaultIdentity<IdentityUser>()
|
|
.AddRoles<IdentityRole>()
|
|
.AddEntityFrameworkStores<BlazorAppContext>();
|
|
|
|
services.AddScoped<DialogService>();
|
|
services.AddScoped<NotificationService>();
|
|
services.AddScoped<TooltipService>();
|
|
services.AddScoped<ContextMenuService>();
|
|
services.AddBlazoredSessionStorage();
|
|
//services.AddScoped<SessionState>();
|
|
// services.AddAuthentication("Identity.Application")
|
|
//.AddCookie();
|
|
|
|
|
|
|
|
services.AddControllers();
|
|
#region Localization
|
|
// Set the resx file folder path to access
|
|
services.AddLocalization(options => options.ResourcesPath = "Resources");
|
|
services.AddSyncfusionBlazor();
|
|
// Register the Syncfusion locale service to customize the SyncfusionBlazor component locale culture
|
|
services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SyncfusionLocalizer));
|
|
services.Configure<RequestLocalizationOptions>(options =>
|
|
{
|
|
// Define the list of cultures your app will support
|
|
var supportedCultures = new List<CultureInfo>()
|
|
{
|
|
new CultureInfo("en-US"),
|
|
new CultureInfo("de"),
|
|
new CultureInfo("fr-CH"),
|
|
new CultureInfo("zh")
|
|
};
|
|
// Set the default culture
|
|
options.DefaultRequestCulture = new RequestCulture("en-US");
|
|
options.SupportedCultures = supportedCultures;
|
|
options.SupportedUICultures = supportedCultures;
|
|
});
|
|
#endregion
|
|
services.AddRazorPages();
|
|
services.AddServerSideBlazor();
|
|
services.AddSingleton<WeatherForecastService>();
|
|
services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SyncfusionLocalizer));
|
|
services.AddSyncfusionBlazor();
|
|
|
|
//Radzen
|
|
services.AddScoped<ThemeState>();
|
|
services.AddScoped<ExampleService>();
|
|
services.AddScoped<MenuService>();
|
|
// services.AddScoped<SessionState>();
|
|
services.AddProtectedBrowserStorage();
|
|
|
|
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("@31392e332e30fiDefXUOcJO49JmXhgG2Hsyqek3O7OMX/3FKEUOUU9I=");
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapBlazorHub();
|
|
endpoints.MapFallbackToPage("/_Host");
|
|
});
|
|
app.UseFastReport();
|
|
|
|
|
|
}
|
|
|
|
|
|
private async Task DeveloperLogin(HttpContext httpContext)
|
|
{
|
|
|
|
var UserManager = httpContext.RequestServices.GetRequiredService<UserManager<IdentityUser>>();
|
|
var signInManager = httpContext.RequestServices.GetRequiredService<SignInManager<IdentityUser>>();
|
|
|
|
var _user = await UserManager.FindByNameAsync("info@shub.ch");
|
|
|
|
await signInManager.SignInAsync(_user, isPersistent: false);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|