| } | } | ||||
| } | } | ||||
| } | } | ||||
| catch (Exception e) | |||||
| catch (Exception _) | |||||
| { | { | ||||
| model = new LinkModel { IsValid = false }; | model = new LinkModel { IsValid = false }; | ||||
| } | } |
| namespace SecureSharing; | |||||
| // namespace SecureSharing; | |||||
| // | |||||
| // public sealed class Program | |||||
| // { | |||||
| // public static void Main(string[] args) | |||||
| // { | |||||
| // CreateHostBuilder(args).Build().Run(); | |||||
| // } | |||||
| // | |||||
| // public static IHostBuilder CreateHostBuilder(string[] args) | |||||
| // { | |||||
| // return Host.CreateDefaultBuilder(args) | |||||
| // .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); | |||||
| // } | |||||
| // } | |||||
| public sealed class Program | |||||
| { | |||||
| public static void Main(string[] args) | |||||
| { | |||||
| CreateHostBuilder(args).Build().Run(); | |||||
| } | |||||
| using Microsoft.AspNetCore.Identity; | |||||
| using Quartz; | |||||
| using Quartz.Impl; | |||||
| using Quartz.Spi; | |||||
| using SecureSharing.Business.Infrastructure; | |||||
| using SecureSharing.Business.Infrastructure.Extensions; | |||||
| using SecureSharing.Business.Infrastructure.Settings; | |||||
| using SecureSharing.Business.Interfaces; | |||||
| using SecureSharing.Business.Services; | |||||
| using SecureSharing.Data.DbContexts; | |||||
| using SecureSharing.Infrastructure; | |||||
| using SecureSharing.Infrastructure.Middleware; | |||||
| using SecureSharing.Quartz; | |||||
| var builder = WebApplication.CreateBuilder(args); | |||||
| var Configuration = builder.Configuration; | |||||
| var services = builder.Services; | |||||
| StartupConfiguration.ConfigureStartupConfig<EmailSettings>(services, Configuration); | |||||
| services.AddControllersWithViews(); | |||||
| services.AddRazorPages(); | |||||
| StartupExtensions.ConfigureServices(services); | |||||
| services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false) | |||||
| .AddDefaultUI() | |||||
| .AddRoles<IdentityRole>() | |||||
| .AddEntityFrameworkStores<AppDbContext>(); | |||||
| services.AddScoped<IMessageService, MessageService>(); | |||||
| services.AddScoped<IModelFactory, ModelFactory>(); | |||||
| public static IHostBuilder CreateHostBuilder(string[] args) | |||||
| services.AddAuthentication() | |||||
| .AddGoogle(options => | |||||
| { | { | ||||
| return Host.CreateDefaultBuilder(args) | |||||
| .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); | |||||
| } | |||||
| } | |||||
| options.ClientId = Configuration.GetSection("EmailSettings").GetSection("ClientId").Value; | |||||
| options.ClientSecret = Configuration.GetSection("EmailSettings").GetSection("ClientSecret").Value; | |||||
| }); | |||||
| // Add Quartz services | |||||
| services.AddSingleton<IJobFactory, JobFactory>(); | |||||
| services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>(); | |||||
| // Add our jobs | |||||
| services.AddScoped<MessageDeletionJob>(); | |||||
| services.AddSingleton(new JobMetadata( | |||||
| typeof(MessageDeletionJob), | |||||
| "0 0 12 * * ?")); | |||||
| services.AddHostedService<JobsService>(); | |||||
| var app = builder.Build(); | |||||
| if (builder.Environment.IsDevelopment()) | |||||
| { | |||||
| app.UseDeveloperExceptionPage(); | |||||
| } | |||||
| else | |||||
| { | |||||
| app.UseExceptionHandler("/Home/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.UseMiddleware(typeof(ExceptionHandlingMiddleware)); | |||||
| app.UseEndpoints(endpoints => | |||||
| { | |||||
| endpoints.MapControllerRoute( | |||||
| "default", | |||||
| "{controller=Home}/{action=Index}/{id?}"); | |||||
| endpoints.MapRazorPages(); | |||||
| }); | |||||
| app.Run(); |
| using System; | |||||
| using System.Threading.Tasks; | |||||
| using Quartz; | |||||
| using Quartz; | |||||
| using SecureSharing.Business.Interfaces; | using SecureSharing.Business.Interfaces; | ||||
| namespace SecureSharing.Quartz; | namespace SecureSharing.Quartz; |
| </PropertyGroup> | </PropertyGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="AutoMapper" Version="11.0.1"/> | |||||
| <PackageReference Include="Microsoft.AspNet.Identity.Core" Version="2.2.3"/> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.9"/> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.9"/> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.9"/> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.9"/> | |||||
| <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.9"/> | |||||
| <PackageReference Include="AutoMapper" Version="11.0.1" /> | |||||
| <PackageReference Include="Microsoft.AspNet.Identity.Core" Version="2.2.3" /> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="6.0.9" /> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.9" /> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.9" /> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.9" /> | |||||
| <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.9" /> | |||||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.9"> | <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.9"> | ||||
| <PrivateAssets>all</PrivateAssets> | <PrivateAssets>all</PrivateAssets> | ||||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||||
| </PackageReference> | </PackageReference> | ||||
| <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.9"/> | |||||
| <PackageReference Include="Newtonsoft.Json" Version="13.0.1"/> | |||||
| <PackageReference Include="Quartz" Version="3.5.0"/> | |||||
| <PackageReference Include="Serilog" Version="2.12.0"/> | |||||
| <PackageReference Include="Serilog.AspNetCore" Version="6.0.1"/> | |||||
| <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.9" /> | |||||
| <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | |||||
| <PackageReference Include="Quartz" Version="3.5.0" /> | |||||
| <PackageReference Include="Serilog" Version="2.12.0" /> | |||||
| <PackageReference Include="Serilog.AspNetCore" Version="6.0.1" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <ProjectReference Include="..\SecureSharing.Business\SecureSharing.Business.csproj"/> | |||||
| <ProjectReference Include="..\SecureSharing.Data\SecureSharing.Data.csproj"/> | |||||
| <ProjectReference Include="..\SecureSharing.Business\SecureSharing.Business.csproj" /> | |||||
| <ProjectReference Include="..\SecureSharing.Data\SecureSharing.Data.csproj" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <Folder Include="AppData\Errors\"/> | |||||
| <Folder Include="AppData\Errors\" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| </Project> | </Project> |
| using Microsoft.AspNetCore.Builder; | |||||
| using Microsoft.AspNetCore.Hosting; | |||||
| using Microsoft.AspNetCore.Identity; | |||||
| using Microsoft.Extensions.Configuration; | |||||
| using Microsoft.Extensions.DependencyInjection; | |||||
| using Microsoft.Extensions.Hosting; | |||||
| using Quartz; | |||||
| using Quartz.Impl; | |||||
| using Quartz.Spi; | |||||
| using SecureSharing.Business.Infrastructure; | |||||
| using SecureSharing.Business.Infrastructure.Extensions; | |||||
| using SecureSharing.Business.Infrastructure.Settings; | |||||
| using SecureSharing.Business.Interfaces; | |||||
| using SecureSharing.Business.Services; | |||||
| using SecureSharing.Data.DbContexts; | |||||
| using SecureSharing.Infrastructure; | |||||
| using SecureSharing.Infrastructure.Middleware; | |||||
| using SecureSharing.Quartz; | |||||
| namespace SecureSharing; | |||||
| public sealed 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. | |||||
| public void ConfigureServices(IServiceCollection services) | |||||
| { | |||||
| StartupConfiguration.ConfigureStartupConfig<EmailSettings>(services, Configuration); | |||||
| services.AddControllersWithViews(); | |||||
| services.AddRazorPages(); | |||||
| StartupExtensions.ConfigureServices(services); | |||||
| services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false) | |||||
| .AddDefaultUI() | |||||
| .AddRoles<IdentityRole>() | |||||
| .AddEntityFrameworkStores<AppDbContext>(); | |||||
| services.AddScoped<IMessageService, MessageService>(); | |||||
| services.AddScoped<IModelFactory, ModelFactory>(); | |||||
| services.AddAuthentication() | |||||
| .AddGoogle(options => | |||||
| { | |||||
| options.ClientId = Configuration.GetSection("EmailSettings").GetSection("ClientId").Value; | |||||
| options.ClientSecret = Configuration.GetSection("EmailSettings").GetSection("ClientSecret").Value; | |||||
| }); | |||||
| // Add Quartz services | |||||
| services.AddSingleton<IJobFactory, JobFactory>(); | |||||
| services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>(); | |||||
| // Add our jobs | |||||
| services.AddScoped<MessageDeletionJob>(); | |||||
| services.AddSingleton(new JobMetadata( | |||||
| typeof(MessageDeletionJob), | |||||
| "0 0 12 * * ?")); | |||||
| services.AddHostedService<JobsService>(); | |||||
| } | |||||
| // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |||||
| public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |||||
| { | |||||
| if (env.IsDevelopment()) | |||||
| { | |||||
| app.UseDeveloperExceptionPage(); | |||||
| } | |||||
| else | |||||
| { | |||||
| app.UseExceptionHandler("/Home/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.UseMiddleware(typeof(ExceptionHandlingMiddleware)); | |||||
| app.UseEndpoints(endpoints => | |||||
| { | |||||
| endpoints.MapControllerRoute( | |||||
| "default", | |||||
| "{controller=Home}/{action=Index}/{id?}"); | |||||
| endpoints.MapRazorPages(); | |||||
| }); | |||||
| } | |||||
| } |