Skip to content

Commit

Permalink
Moving program code to startup project, #1781
Browse files Browse the repository at this point in the history
  • Loading branch information
mregni committed Jun 9, 2022
1 parent 477e13a commit 101708e
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 162 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,20 @@ __pycache__/
**/updateFiles/**

usersettings.json
**/Embystat.Web/config/**
**/issues.json
**/coverage/**
**/ClientApp/build/**
EmbyStat.Web/ClientApp/.eslintcache
**/logs

*.db-shm

*.db-wal

EmbyStat.Web/ClientApp/junit.xml

EmbyStat.Web/ClientApp/.eslintcache
EmbyStat.Web/ClientApp/report.json

EmbyStat.Web/ClientApp/test-report.xml

EmbyStat.Hosts.Cmd/config/
EmbyStat.Hosts.Cmd/data/
EmbyStat.Hosts.Cmd/logs/
1 change: 0 additions & 1 deletion EmbyStat.Common/Models/StartupOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CommandLine;

Expand Down
1 change: 0 additions & 1 deletion EmbyStat.Controllers/About/AboutController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AutoMapper;
using EmbyStat.Core.About;
using EmbyStat.Core.About.Interfaces;
using Microsoft.AspNetCore.Mvc;

Expand Down
1 change: 0 additions & 1 deletion EmbyStat.Controllers/Account/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using EmbyStat.Common.Models.Account;
using EmbyStat.Core.Account;
using EmbyStat.Core.Account.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace EmbyStat.Web;
namespace EmbyStat.Hosts.Cmd;

public enum ApplicationModes
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using EmbyStat.Common.Enums;
using EmbyStat.Common.Enums;
using EmbyStat.Common.Generators;
using EmbyStat.Configuration;

namespace EmbyStat.Web;
namespace EmbyStat.Hosts.Cmd;

public static class DefaultConfig
{
Expand Down
100 changes: 100 additions & 0 deletions EmbyStat.Hosts.Cmd/EmbyStat.Hosts.Cmd.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ApplicationIcon>..\branding\NSIS\install.ico</ApplicationIcon>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
<Platforms>AnyCPU;x64;x86</Platforms>
<Version>1.2.3.4</Version>
<AssemblyVersion>1.2.3.4</AssemblyVersion>
<FileVersion>1.2.3.4</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<AssemblyName>EmbyStat</AssemblyName>
<ProjectGuid>{1D5D997D-34AE-45BE-9935-14E0D63EAC02}</ProjectGuid>
<ServerGarbageCollection>false</ServerGarbageCollection>

<SpaRoot>..\EmbyStat.Web\ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
<BuildServerSideRenderer>false</BuildServerSideRenderer>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="FluentMigrator.Runner" Version="3.3.2" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.29" />
<PackageReference Include="Hangfire.MemoryStorage.Core" Version="1.4.0" />
<PackageReference Include="Hangfire.RecurringJobExtensions" Version="1.1.6" />
<PackageReference Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.3.1" />
<PackageReference Include="Refit.HttpClientFactory" Version="6.3.2" />
<PackageReference Include="Rollbar.NetCore.AspNet" Version="5.2.0" />
<PackageReference Include="Rollbar.PlugIns.NLog" Version="5.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EmbyStat.Controllers\EmbyStat.Controllers.csproj" />
<ProjectReference Include="..\EmbyStat.DI\EmbyStat.DI.csproj" />
<ProjectReference Include="..\EmbyStat.Migrations\EmbyStat.Migrations.csproj" />
<ProjectReference Include="..\EmbyStat.Migrator\EmbyStat.Migrator.csproj" />
<ProjectReference Include="..\EmbyStat.Repositories\EmbyStat.Repositories.csproj" />
<ProjectReference Include="..\EmbyStat.Jobs\EmbyStat.Jobs.csproj" />
</ItemGroup>

<ItemGroup>
<SonarQubeSetting Include="sonar.eslint.reportPaths">
<Value>../EmbyStat.Web/ClientApp/report.json</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.ts.excludetypedefinitionfiles">
<Value>true</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.javascript.lcov.reportPaths">
<Value>../EmbyStat.Web/ClientApp/coverage/lcov.info</Value>
</SonarQubeSetting>
<SonarQubeSetting Include="sonar.typescript.tsconfigPath">
<Value>../EmbyStat.Web/ClientApp/tsconfig.json</Value>
</SonarQubeSetting>
</ItemGroup>

<ItemGroup>
<Content Update="..\EmbyStat.Web\ClientApp\**\*" CopyToPublishDirectory="Never" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES2019</TypeScriptTarget>
<TypeScriptJSXEmit>React</TypeScriptJSXEmit>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
<TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
<TypeScriptRemoveComments>True</TypeScriptRemoveComments>
<TypeScriptOutFile />
<TypeScriptOutDir />
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
<TypeScriptSourceMap>True</TypeScriptSourceMap>
<TypeScriptMapRoot />
<TypeScriptSourceRoot />
</PropertyGroup>

</Project>
30 changes: 16 additions & 14 deletions EmbyStat.Web/Program.cs → EmbyStat.Hosts.Cmd/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
Expand All @@ -11,11 +7,7 @@
using EmbyStat.Common.Generators;
using EmbyStat.Common.Models;
using EmbyStat.Configuration;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting.WindowsServices;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Serilog;
Expand All @@ -26,7 +18,7 @@

// ReSharper disable All

namespace EmbyStat.Web;
namespace EmbyStat.Hosts.Cmd;

public class Program
{
Expand All @@ -51,10 +43,15 @@ public static int Main(string[] args)
return 0;
}

StartupOptions options = null;
StartupOptions? options = null;
parseResult.MapResult(opt => options = opt, NotParedOptions);
options = CheckEnvironmentVariables(options);

if (options == null)
{
return 1;
}

var mode = GetApplicationMode();
switch (mode)
{
Expand Down Expand Up @@ -82,7 +79,7 @@ public static int Main(string[] args)
}
}

private static StartupOptions NotParedOptions(IEnumerable<Error> errs)
private static StartupOptions? NotParedOptions(IEnumerable<Error> errs)
{
var errors = errs.ToList();
if (errors.Any(x => x is HelpRequestedError))
Expand Down Expand Up @@ -138,7 +135,7 @@ private static ApplicationModes GetApplicationMode()
return ApplicationModes.Interactive;
}

private static IHost BuildConsoleHost(StartupOptions options)
private static IHost BuildConsoleHost(StartupOptions? options)
{
var memoryConfig = options.ToKeyValuePairs();
var dicConfig = memoryConfig.ToDictionary(x => x.Key, x => x.Value);
Expand All @@ -151,7 +148,7 @@ private static IHost BuildConsoleHost(StartupOptions options)
.Build();

var config = configurationRoot.Get<Config>();

//Dirs in options object worden hier genegeerd!

CreateFolder(config.SystemConfig.Dirs.Logs);
Expand Down Expand Up @@ -346,8 +343,13 @@ private static string GetEnvironmentName()
return str;
}

private static StartupOptions CheckEnvironmentVariables(StartupOptions options)
private static StartupOptions? CheckEnvironmentVariables(StartupOptions? options)
{
if (options == null)
{
return null;
}

var portStr = Environment.GetEnvironmentVariable("EMBYSTAT_PORT");
if (portStr != null && int.TryParse(portStr, out var port))
{
Expand Down
14 changes: 2 additions & 12 deletions EmbyStat.Web/Startup.cs → EmbyStat.Hosts.Cmd/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
using EmbyStat.Jobs;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Rollbar;
using Rollbar.NetCore.AspNet;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using EmbyStat.Clients.Base;
using EmbyStat.Clients.Base.Api;
using EmbyStat.Common;
Expand All @@ -23,7 +16,6 @@
using EmbyStat.Configuration.Interfaces;
using EmbyStat.Controllers;
using EmbyStat.Controllers.Middleware;
using EmbyStat.Core.Account;
using EmbyStat.Core.Account.Interfaces;
using EmbyStat.Core.DataStore;
using EmbyStat.Core.Hubs;
Expand All @@ -41,14 +33,12 @@
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Refit;
using Rollbar.DTOs;

namespace EmbyStat.Web;
namespace EmbyStat.Hosts.Cmd;

public class Startup
{
Expand Down Expand Up @@ -282,7 +272,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApp
{
if (env.IsDevelopment())
{
spa.Options.SourcePath = "ClientApp";
spa.Options.SourcePath = Path.Combine("..", "EmbyStat.Web", "ClientApp");
spa.UseReactDevelopmentServer("start");
}
else
Expand Down
Loading

0 comments on commit 101708e

Please sign in to comment.