|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using AutoMapper.EquivalencyExpression;
|
|
|
|
|
using Hangfire;
|
|
|
|
|
using Hangfire.MemoryStorage;
|
|
|
|
|
using Hangfire.SQLite;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Ombi.Auth;
|
|
|
|
|
using Ombi.Config;
|
|
|
|
|
using Ombi.DependencyInjection;
|
|
|
|
|
using Ombi.Mapping;
|
|
|
|
|
using Ombi.Schedule;
|
|
|
|
|
using Serilog;
|
|
|
|
|
using Serilog.Events;
|
|
|
|
|
|
|
|
|
|
namespace Ombi
|
|
|
|
|
{
|
|
|
|
|
public partial class Startup
|
|
|
|
|
{
|
|
|
|
|
public Startup(IHostingEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(env.ContentRootPath);
|
|
|
|
|
var builder = new ConfigurationBuilder()
|
|
|
|
|
.SetBasePath(env.ContentRootPath)
|
|
|
|
|
.AddJsonFile("appsettings.json", false, true)
|
|
|
|
|
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
|
|
|
|
|
.AddEnvironmentVariables();
|
|
|
|
|
Configuration = builder.Build();
|
|
|
|
|
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
|
|
|
.MinimumLevel.Debug()
|
|
|
|
|
.WriteTo.RollingFile(Path.Combine(env.ContentRootPath, "Logs", "log-{Date}.txt"))
|
|
|
|
|
.WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Debug)
|
|
|
|
|
.CreateLogger();
|
|
|
|
|
}
|
|
|
|
|
if (env.IsProduction())
|
|
|
|
|
{
|
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
|
|
|
.MinimumLevel.Information()
|
|
|
|
|
.WriteTo.RollingFile(Path.Combine(env.ContentRootPath, "Logs", "log-{Date}.txt"))
|
|
|
|
|
.WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Debug)
|
|
|
|
|
.CreateLogger();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IConfigurationRoot Configuration { get; }
|
|
|
|
|
|
|
|
|
|
// 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.AddMemoryCache();
|
|
|
|
|
services.AddMvc();
|
|
|
|
|
services.AddOmbiMappingProfile();
|
|
|
|
|
services.AddAutoMapper(expression =>
|
|
|
|
|
{
|
|
|
|
|
expression.AddCollectionMappers();
|
|
|
|
|
});
|
|
|
|
|
services.RegisterDependencies(); // Ioc and EF
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
|
services.AddScoped<IPrincipal>(sp => sp.GetService<IHttpContextAccessor>().HttpContext.User);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services.Configure<TokenAuthenticationOptions>(Configuration.GetSection("TokenAuthentication"));
|
|
|
|
|
services.Configure<ApplicationSettings>(Configuration.GetSection("ApplicationSettings"));
|
|
|
|
|
|
|
|
|
|
services.AddHangfire(x =>
|
|
|
|
|
{
|
|
|
|
|
x.UseSQLiteStorage("Data Source=Ombi.db;");
|
|
|
|
|
//x.UseMemoryStorage(new MemoryStorageOptions());
|
|
|
|
|
x.UseActivator(new IoCJobActivator(services.BuildServiceProvider()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
|
|
loggerFactory.AddSerilog();
|
|
|
|
|
|
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseHangfireServer();
|
|
|
|
|
app.UseHangfireDashboard();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setup the scheduler
|
|
|
|
|
var jobSetup = (IJobSetup)app.ApplicationServices.GetService(typeof(IJobSetup));
|
|
|
|
|
jobSetup.Setup();
|
|
|
|
|
|
|
|
|
|
ConfigureAuth(app, (IOptions<TokenAuthenticationOptions>)app.ApplicationServices.GetService(typeof(IOptions<TokenAuthenticationOptions>)));
|
|
|
|
|
|
|
|
|
|
var provider = new FileExtensionContentTypeProvider();
|
|
|
|
|
provider.Mappings[".map"] = "application/octet-stream";
|
|
|
|
|
|
|
|
|
|
app.UseStaticFiles(new StaticFileOptions()
|
|
|
|
|
{
|
|
|
|
|
ContentTypeProvider = provider
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.UseMvc(routes =>
|
|
|
|
|
{
|
|
|
|
|
routes.MapRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
|
|
|
|
|
routes.MapSpaFallbackRoute(
|
|
|
|
|
name: "spa-fallback",
|
|
|
|
|
defaults: new { controller = "Home", action = "Index" });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|