From dcbfec645f852d10b1e605d867483571ac0b7b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikha=C3=ABl=20Regni?= Date: Fri, 27 May 2022 10:43:31 +0200 Subject: [PATCH] Fixing folder structure issues #1745 --- EmbyStat.Core/DataStore/EsDbContext.cs | 3 +-- EmbyStat.Core/DataStore/SqliteBootstrap.cs | 9 ++++++--- EmbyStat.Web/Program.cs | 13 ++++++++++--- EmbyStat.Web/Startup.cs | 9 ++++++--- Tests.Unit/Controllers/JobControllerTests.cs | 1 - Tests.Unit/Controllers/SettingsControllerTests.cs | 1 - Tests.Unit/Services/AccountServiceTests.cs | 1 - Tests.Unit/Services/LogServiceTests.cs | 1 - Tests.Unit/Services/MediaServerServiceTests.cs | 1 - Tests.Unit/Services/MovieServiceTests.cs | 1 - Tests.Unit/Services/SettingsServiceTests.cs | 1 - Tests.Unit/Services/SystemServiceTests.cs | 1 - 12 files changed, 23 insertions(+), 19 deletions(-) diff --git a/EmbyStat.Core/DataStore/EsDbContext.cs b/EmbyStat.Core/DataStore/EsDbContext.cs index bb6f03323..30240f652 100644 --- a/EmbyStat.Core/DataStore/EsDbContext.cs +++ b/EmbyStat.Core/DataStore/EsDbContext.cs @@ -44,8 +44,7 @@ public EsDbContext(DbContextOptions options): base(options) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.EnableDetailedErrors(); - optionsBuilder.UseSqlite("Data Source=SqliteData.db", x => x.MigrationsAssembly("EmbyStat.Migrations")); + } diff --git a/EmbyStat.Core/DataStore/SqliteBootstrap.cs b/EmbyStat.Core/DataStore/SqliteBootstrap.cs index 3fe7618b4..403e82caf 100644 --- a/EmbyStat.Core/DataStore/SqliteBootstrap.cs +++ b/EmbyStat.Core/DataStore/SqliteBootstrap.cs @@ -1,13 +1,16 @@ -using Microsoft.Data.Sqlite; +using EmbyStat.Configuration.Interfaces; +using Microsoft.Data.Sqlite; namespace EmbyStat.Core.DataStore; public class SqliteBootstrap : ISqliteBootstrap { private readonly string _connectionString; - public SqliteBootstrap() + public SqliteBootstrap(IConfigurationService configurationService) { - _connectionString = "Data Source=SqliteData.db"; + var config = configurationService.Get(); + var path = Path.Combine(config.SystemConfig.Dirs.Data, "SqliteData.db"); + _connectionString = $"Data Source={path}"; } diff --git a/EmbyStat.Web/Program.cs b/EmbyStat.Web/Program.cs index 0c3ead42b..402adf1bc 100644 --- a/EmbyStat.Web/Program.cs +++ b/EmbyStat.Web/Program.cs @@ -139,6 +139,7 @@ private static ApplicationModes GetApplicationMode() private static IHost BuildConsoleHost(StartupOptions options) { + CreateFolder("config"); GenerateDefaultConfiguration(); var memoryConfig = options.ToKeyValuePairs(); @@ -151,6 +152,9 @@ private static IHost BuildConsoleHost(StartupOptions options) var config = configurationRoot.Get(); + CreateFolder(config.SystemConfig.Dirs.Logs); + CreateFolder(config.SystemConfig.Dirs.Data); + SetupLogger(config.SystemConfig.Dirs.Logs, options.LogLevel ?? 2); LogStartupParameters(config, options.LogLevel ?? 2, options.RunAsService ?? false); @@ -209,14 +213,17 @@ private static IHost BuildConsoleHost(StartupOptions options) .Build(); } - private static void GenerateDefaultConfiguration() + private static void CreateFolder(string folder) { - var dir = Path.Combine(Directory.GetCurrentDirectory(), "config"); + var dir = Path.Combine(Directory.GetCurrentDirectory(), folder); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } - + } + + private static void GenerateDefaultConfiguration() + { var path = Path.Combine(Directory.GetCurrentDirectory(),"config", "config.json"); if (!File.Exists(path)) { diff --git a/EmbyStat.Web/Startup.cs b/EmbyStat.Web/Startup.cs index d68516833..32aeb81eb 100644 --- a/EmbyStat.Web/Startup.cs +++ b/EmbyStat.Web/Startup.cs @@ -16,7 +16,6 @@ using EmbyStat.Clients.Base; using EmbyStat.Clients.Base.Api; using EmbyStat.Common; -using EmbyStat.Common.Enums; using EmbyStat.Common.Exceptions; using EmbyStat.Common.Extensions; using EmbyStat.Common.Models.Entities; @@ -121,7 +120,6 @@ public void ConfigureServices(IServiceCollection services) ConfigureRollbarInfrastructure(); - services.AddRollbarLogger(loggerOptions => { loggerOptions.Filter = loggerOptions.Filter = (_, loglevel) => loglevel >= LogLevel.Error; @@ -133,7 +131,12 @@ public void ConfigureServices(IServiceCollection services) }); services.AddSignalR(); - services.AddDbContext(); + var dbPath = Path.Combine(configuration.SystemConfig.Dirs.Data, "SqliteData.db"); + services.AddDbContext(options => + { + options.EnableDetailedErrors(); + options.UseSqlite($"Data Source={dbPath}", x => x.MigrationsAssembly("EmbyStat.Migrations")); + }); services.AddAuthorization(options => { diff --git a/Tests.Unit/Controllers/JobControllerTests.cs b/Tests.Unit/Controllers/JobControllerTests.cs index 5aa8ea300..df1373b8d 100644 --- a/Tests.Unit/Controllers/JobControllerTests.cs +++ b/Tests.Unit/Controllers/JobControllerTests.cs @@ -10,7 +10,6 @@ using EmbyStat.Controllers; using EmbyStat.Controllers.Job; using EmbyStat.Core.Jobs.Interfaces; -using EmbyStat.Core.Rollbar.Interfaces; using EmbyStat.Jobs; using FluentAssertions; using Hangfire; diff --git a/Tests.Unit/Controllers/SettingsControllerTests.cs b/Tests.Unit/Controllers/SettingsControllerTests.cs index aa5ffed06..be5c116d8 100644 --- a/Tests.Unit/Controllers/SettingsControllerTests.cs +++ b/Tests.Unit/Controllers/SettingsControllerTests.cs @@ -6,7 +6,6 @@ using EmbyStat.Common.Models.Entities; using EmbyStat.Controllers.Settings; using EmbyStat.Core.Languages.Interfaces; -using EmbyStat.Core.Rollbar.Interfaces; using FluentAssertions; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; diff --git a/Tests.Unit/Services/AccountServiceTests.cs b/Tests.Unit/Services/AccountServiceTests.cs index c44376ac3..a5d163a5d 100644 --- a/Tests.Unit/Services/AccountServiceTests.cs +++ b/Tests.Unit/Services/AccountServiceTests.cs @@ -4,7 +4,6 @@ using EmbyStat.Common.Models.Account; using EmbyStat.Common.Models.Entities; using EmbyStat.Core.Account; -using EmbyStat.Core.Rollbar.Interfaces; using FluentAssertions; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; diff --git a/Tests.Unit/Services/LogServiceTests.cs b/Tests.Unit/Services/LogServiceTests.cs index 67ddcffee..fa6210772 100644 --- a/Tests.Unit/Services/LogServiceTests.cs +++ b/Tests.Unit/Services/LogServiceTests.cs @@ -6,7 +6,6 @@ using EmbyStat.Common.Models.Entities; using EmbyStat.Core.Logs; using EmbyStat.Core.MediaServers.Interfaces; -using EmbyStat.Core.Rollbar.Interfaces; using FluentAssertions; using Moq; using Xunit; diff --git a/Tests.Unit/Services/MediaServerServiceTests.cs b/Tests.Unit/Services/MediaServerServiceTests.cs index 04dc11ee4..b45e9a7dc 100644 --- a/Tests.Unit/Services/MediaServerServiceTests.cs +++ b/Tests.Unit/Services/MediaServerServiceTests.cs @@ -12,7 +12,6 @@ using EmbyStat.Core.Jobs.Interfaces; using EmbyStat.Core.MediaServers; using EmbyStat.Core.MediaServers.Interfaces; -using EmbyStat.Core.Rollbar.Interfaces; using EmbyStat.Core.Sessions.Interfaces; using EmbyStat.Core.Statistics.Interfaces; using FluentAssertions; diff --git a/Tests.Unit/Services/MovieServiceTests.cs b/Tests.Unit/Services/MovieServiceTests.cs index 4a5eb3443..756c67cbe 100644 --- a/Tests.Unit/Services/MovieServiceTests.cs +++ b/Tests.Unit/Services/MovieServiceTests.cs @@ -12,7 +12,6 @@ using EmbyStat.Core.MediaServers.Interfaces; using EmbyStat.Core.Movies; using EmbyStat.Core.Movies.Interfaces; -using EmbyStat.Core.Rollbar.Interfaces; using EmbyStat.Core.Statistics.Interfaces; using FluentAssertions; using Microsoft.Extensions.Logging; diff --git a/Tests.Unit/Services/SettingsServiceTests.cs b/Tests.Unit/Services/SettingsServiceTests.cs index 84dd1008d..e66d4693d 100644 --- a/Tests.Unit/Services/SettingsServiceTests.cs +++ b/Tests.Unit/Services/SettingsServiceTests.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using EmbyStat.Core.Rollbar; using FluentAssertions; using Microsoft.Extensions.Options; using Moq; diff --git a/Tests.Unit/Services/SystemServiceTests.cs b/Tests.Unit/Services/SystemServiceTests.cs index 928ce7a84..d8551b3d4 100644 --- a/Tests.Unit/Services/SystemServiceTests.cs +++ b/Tests.Unit/Services/SystemServiceTests.cs @@ -4,7 +4,6 @@ using EmbyStat.Core.MediaServers.Interfaces; using EmbyStat.Core.Movies.Interfaces; using EmbyStat.Core.People.Interfaces; -using EmbyStat.Core.Rollbar.Interfaces; using EmbyStat.Core.Shows.Interfaces; using EmbyStat.Core.Statistics.Interfaces; using EmbyStat.Core.System;