2018-04-08 02:44:42 -04:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore
|
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2018-04-08 02:44:42 -04:00
|
|
|
|
private IHostingEnvironment _appHost;
|
|
|
|
|
public static IConfigurationRoot Configuration { get; private set; }
|
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
public Startup(IHostingEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
var builder = new ConfigurationBuilder()
|
|
|
|
|
.SetBasePath(env.ContentRootPath)
|
2018-03-14 01:36:25 -04:00
|
|
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
.AddEnvironmentVariables();
|
2018-04-06 20:15:17 -04:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
Configuration = builder.Build();
|
2018-04-06 20:15:17 -04:00
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
_appHost = env;
|
|
|
|
|
|
|
|
|
|
using (var db = new DatabaseContext())
|
2018-04-06 20:15:17 -04:00
|
|
|
|
{
|
2018-04-08 02:44:42 -04:00
|
|
|
|
db.Database.EnsureCreated();
|
|
|
|
|
db.Database.Migrate();
|
|
|
|
|
new ContextSeed(db).Seed().Wait();
|
2018-04-06 20:15:17 -04:00
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
// Add framework services.
|
|
|
|
|
services.AddMvc();
|
2018-04-08 02:44:42 -04:00
|
|
|
|
services.AddEntityFrameworkSqlite()
|
|
|
|
|
.AddDbContext<DatabaseContext>();
|
|
|
|
|
|
|
|
|
|
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
|
|
|
|
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
|
|
|
|
|
{
|
|
|
|
|
options.AccessDeniedPath = "/";
|
|
|
|
|
options.LoginPath = "/";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!IW4MAdmin.Program.Start())
|
|
|
|
|
Environment.Exit(-1);
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
|
|
|
{
|
|
|
|
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
|
|
|
|
loggerFactory.AddDebug();
|
|
|
|
|
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
app.UseBrowserLink();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
app.UseExceptionHandler("/Home/Error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseStaticFiles();
|
2018-04-08 02:44:42 -04:00
|
|
|
|
app.UseAuthentication();
|
2018-04-04 15:38:34 -04:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
|
{
|
|
|
|
|
routes.MapRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|