#1513 Added storage path

pull/1526/head^2
Jamie.Rees 7 years ago
parent e735df5d0a
commit d9ab803a11

@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Security.Principal; using System.Security.Principal;
using Hangfire; using Hangfire;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -99,10 +101,9 @@ namespace Ombi.DependencyInjection
services.AddTransient<ICouchPotatoApi, CouchPotatoApi>(); services.AddTransient<ICouchPotatoApi, CouchPotatoApi>();
} }
public static void RegisterStore(this IServiceCollection services) public static void RegisterStore(this IServiceCollection services) {
{
services.AddEntityFrameworkSqlite().AddDbContext<OmbiContext>(); services.AddEntityFrameworkSqlite().AddDbContext<OmbiContext>();
services.AddScoped<IOmbiContext, OmbiContext>(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 services.AddScoped<IOmbiContext, OmbiContext>(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6
services.AddTransient<ISettingsRepository, SettingsJsonRepository>(); services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
services.AddTransient<ISettingsResolver, SettingsResolver>(); services.AddTransient<ISettingsResolver, SettingsResolver>();

@ -0,0 +1,13 @@
namespace Ombi.Helpers
{
public class StoragePathSingleton
{
private static StoragePathSingleton instance;
private StoragePathSingleton() { }
public static StoragePathSingleton Instance => instance ?? (instance = new StoragePathSingleton());
public string StoragePath { get; set; }
}
}

@ -1,4 +1,5 @@
using System; using System;
using System.IO;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -14,12 +15,10 @@ namespace Ombi.Store.Context
public OmbiContext() public OmbiContext()
{ {
if (_created) return; if (_created) return;
_created = true; _created = true;
Database.Migrate(); Database.Migrate();
// Add the notifcation templates
} }
public DbSet<NotificationTemplates> NotificationTemplates { get; set; } public DbSet<NotificationTemplates> NotificationTemplates { get; set; }
@ -44,7 +43,8 @@ namespace Ombi.Store.Context
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseSqlite("Data Source=Ombi.db"); var i = StoragePathSingleton.Instance;
optionsBuilder.UseSqlite($"Data Source={Path.Combine(i.StoragePath,"Ombi.db")}");
} }
protected override void OnModelCreating(ModelBuilder builder) protected override void OnModelCreating(ModelBuilder builder)

@ -9,6 +9,8 @@ using Ombi.Store.Entities;
using CommandLine; using CommandLine;
using CommandLine.Text; using CommandLine.Text;
using Microsoft.AspNetCore; using Microsoft.AspNetCore;
using Microsoft.EntityFrameworkCore;
using Ombi.Helpers;
namespace Ombi namespace Ombi
{ {
@ -33,6 +35,8 @@ namespace Ombi
UrlArgs = host; UrlArgs = host;
var urlValue = string.Empty; var urlValue = string.Empty;
var instance = StoragePathSingleton.Instance;
instance.StoragePath = storagePath ?? string.Empty;
using (var ctx = new OmbiContext()) using (var ctx = new OmbiContext())
{ {
var config = ctx.ApplicationConfigurations.ToList(); var config = ctx.ApplicationConfigurations.ToList();

@ -16,6 +16,7 @@ using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.SpaServices.Webpack; using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.AspNetCore.StaticFiles; using Microsoft.AspNetCore.StaticFiles;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -36,6 +37,7 @@ namespace Ombi
{ {
public class Startup public class Startup
{ {
public static StoragePathSingleton StoragePath => StoragePathSingleton.Instance;
public Startup(IHostingEnvironment env) public Startup(IHostingEnvironment env)
{ {
Console.WriteLine(env.ContentRootPath); Console.WriteLine(env.ContentRootPath);
@ -48,11 +50,24 @@ namespace Ombi
//if (env.IsDevelopment()) //if (env.IsDevelopment())
//{ //{
Log.Logger = new LoggerConfiguration() Serilog.ILogger config;
.MinimumLevel.Debug() if (string.IsNullOrEmpty(StoragePath.StoragePath))
.WriteTo.RollingFile(Path.Combine(env.ContentRootPath, "Logs", "log-{Date}.txt")) {
.WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Debug) config = new LoggerConfiguration()
.CreateLogger(); .MinimumLevel.Debug()
.WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Debug)
.CreateLogger();
}
else
{
config = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.SQLite(Path.Combine(StoragePath.StoragePath, "Ombi.db"), "Logs", LogEventLevel.Debug)
.CreateLogger();
}
Log.Logger = config;
//} //}
//if (env.IsProduction()) //if (env.IsProduction())
//{ //{
@ -69,9 +84,10 @@ namespace Ombi
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services) public IServiceProvider ConfigureServices(IServiceCollection services)
{ {
// Add framework services. // Add framework services.
services.AddDbContext<OmbiContext>(); services.AddDbContext<OmbiContext>();
services.AddIdentity<OmbiUser, IdentityRole>() services.AddIdentity<OmbiUser, IdentityRole>()
.AddEntityFrameworkStores<OmbiContext>() .AddEntityFrameworkStores<OmbiContext>()
.AddDefaultTokenProviders() .AddDefaultTokenProviders()
@ -113,6 +129,7 @@ namespace Ombi
x.UseConsole(); x.UseConsole();
}); });
// Build the intermediate service provider // Build the intermediate service provider
return services.BuildServiceProvider(); return services.BuildServiceProvider();
} }

Loading…
Cancel
Save