renamed folders
This commit is contained in:
10
backend/app/app.Configuration/APISettings.cs
Normal file
10
backend/app/app.Configuration/APISettings.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace app.Configuration
|
||||
{
|
||||
public class APISettings
|
||||
{
|
||||
public bool RedirectToHTTPS { get; set; }
|
||||
public APIVersionSettings ApiVersion { get; set; }
|
||||
}
|
||||
}
|
15
backend/app/app.Configuration/APIVersionSettings.cs
Normal file
15
backend/app/app.Configuration/APIVersionSettings.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace app.Configuration
|
||||
{
|
||||
public class APIVersionSettings
|
||||
{
|
||||
public string Major { get; set; }
|
||||
public string Minor { get; set; }
|
||||
public string Micro { get; set; }
|
||||
|
||||
public override string ToString() {
|
||||
return $"{this.Major}.{this.Minor}.{this.Micro}";
|
||||
}
|
||||
}
|
||||
}
|
11
backend/app/app.Configuration/AuthentificationSettings.cs
Normal file
11
backend/app/app.Configuration/AuthentificationSettings.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace app.Configuration
|
||||
{
|
||||
public class AuthentificationSettings
|
||||
{
|
||||
public string SecretKey { get; set; }
|
||||
public string Issuer { get; set; }
|
||||
public string Audience { get; set; }
|
||||
public int TokenExpireTime { get; set; }
|
||||
public int RefreshTokenExpireTime { get; set; }
|
||||
}
|
||||
}
|
36
backend/app/app.Configuration/ConfigurationExtensions.cs
Normal file
36
backend/app/app.Configuration/ConfigurationExtensions.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
|
||||
namespace app.Configuration {
|
||||
public static class ConfigurationExtensions {
|
||||
public static TSetting GetSetting<TSetting>(this IConfiguration config, string sectionName)
|
||||
where TSetting : new() {
|
||||
var settings = new TSetting();
|
||||
config.GetSection(sectionName).Bind(settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static string GetDbConnectionString(this IConfiguration config, string sectionName) {
|
||||
var connectionString = config[$"{sectionName}:ConnectionString"];
|
||||
|
||||
if (string.IsNullOrEmpty(connectionString))
|
||||
throw new Exception($"ConnectionString is not set! SectionName:{sectionName}");
|
||||
|
||||
var dbCredentials = config[$"{sectionName}:Credentials"];
|
||||
|
||||
if (!string.IsNullOrEmpty(dbCredentials))
|
||||
connectionString += dbCredentials;
|
||||
|
||||
return connectionString;
|
||||
}
|
||||
|
||||
public static string GetCustomer(this IConfiguration config) {
|
||||
return config["CUSTOMER"];
|
||||
}
|
||||
|
||||
public static string GetComputerName(this IConfiguration config) {
|
||||
return config["COMPUTERNAME"];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
7
backend/app/app.Configuration/Constants.cs
Normal file
7
backend/app/app.Configuration/Constants.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace app.Configuration {
|
||||
public static class Constants {
|
||||
public const string CustomerEnvironmentVariable = "CUSTOMER";
|
||||
public const string ComputerNameEnvironmentVariable = "COMPUTERNAME";
|
||||
public const string CustomersDirectoryName = "customers";
|
||||
}
|
||||
}
|
8
backend/app/app.Configuration/DatabaseSettings.cs
Normal file
8
backend/app/app.Configuration/DatabaseSettings.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace app.Configuration
|
||||
{
|
||||
public class DatabaseSettings
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
public string Credentials { get; set; }
|
||||
}
|
||||
}
|
14
backend/app/app.Configuration/EMailSettings.cs
Normal file
14
backend/app/app.Configuration/EMailSettings.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace app.Configuration
|
||||
{
|
||||
public class EMailSettings
|
||||
{
|
||||
public string FromName { get; set; }
|
||||
public string FromAddress { get; set; }
|
||||
|
||||
public string MailServerAddress { get; set; }
|
||||
public int MailServerPort { get; set; }
|
||||
|
||||
public string Username { get; set; }
|
||||
public string Credentials { get; set; }
|
||||
}
|
||||
}
|
7
backend/app/app.Configuration/FrontendSettings.cs
Normal file
7
backend/app/app.Configuration/FrontendSettings.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace app.Configuration
|
||||
{
|
||||
public class FrontendSettings
|
||||
{
|
||||
public string URL { get; set; }
|
||||
}
|
||||
}
|
115
backend/app/app.Configuration/HostExtensions.cs
Normal file
115
backend/app/app.Configuration/HostExtensions.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.EventLog;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace app.Configuration {
|
||||
public static class HostExtensions {
|
||||
// copied from https://github.com/dotnet/extensions/blob/release/3.1/src/Hosting/Hosting/src/Host.cs,
|
||||
// modified to use customer environment
|
||||
public static IHostBuilder CreateBuilder(string[] args) {
|
||||
var builder = new HostBuilder();
|
||||
|
||||
builder.UseContentRoot(Directory.GetCurrentDirectory()); // UseWindowsService overrides content root to AppContext.BaseDirectory
|
||||
builder.ConfigureHostConfiguration(config => {
|
||||
config.AddEnvironmentVariables(prefix: "DOTNET_");
|
||||
config.AddEnvironmentVariables(prefix: "LOGINCOUNTER_");
|
||||
if (args != null) {
|
||||
config.AddCommandLine(args);
|
||||
}
|
||||
});
|
||||
|
||||
builder.ConfigureAppConfiguration((hostingContext, config) => {
|
||||
var env = hostingContext.HostingEnvironment;
|
||||
var customerEnv = hostingContext.Configuration.GetValue<string>(Constants.CustomerEnvironmentVariable);
|
||||
//var customerEnv = Environment.GetEnvironmentVariable(Constants.CustomerEnvironmentVariable);
|
||||
if (!string.IsNullOrEmpty(customerEnv))
|
||||
config.SetBasePath(Path.Combine(hostingContext.HostingEnvironment.ContentRootPath, Constants.CustomersDirectoryName, customerEnv));
|
||||
|
||||
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true);
|
||||
|
||||
var computerName = Environment.GetEnvironmentVariable(Constants.ComputerNameEnvironmentVariable);
|
||||
if (!string.IsNullOrEmpty(computerName))
|
||||
config.AddJsonFile($"appsettings.{computerName}.json", optional: true, reloadOnChange: true);
|
||||
|
||||
if (env.IsDevelopment() && !string.IsNullOrEmpty(env.ApplicationName)) {
|
||||
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
|
||||
if (appAssembly != null) {
|
||||
config.AddUserSecrets(appAssembly, optional: true);
|
||||
}
|
||||
}
|
||||
|
||||
config.AddEnvironmentVariables();
|
||||
config.AddEnvironmentVariables("IOTHUB_");
|
||||
|
||||
if (args != null) {
|
||||
config.AddCommandLine(args);
|
||||
}
|
||||
})
|
||||
.ConfigureLogging((hostingContext, logging) => {
|
||||
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
|
||||
// IMPORTANT: This needs to be added *before* configuration is loaded, this lets
|
||||
// the defaults be overridden by the configuration.
|
||||
if (isWindows) {
|
||||
// Default the EventLogLoggerProvider to warning or above
|
||||
logging.AddFilter<EventLogLoggerProvider>(level => level >= LogLevel.Warning);
|
||||
}
|
||||
|
||||
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
||||
logging.AddConsole();
|
||||
logging.AddDebug();
|
||||
logging.AddEventSourceLogger();
|
||||
|
||||
if (isWindows) {
|
||||
// Add the EventLogLoggerProvider on windows machines
|
||||
logging.AddEventLog();
|
||||
}
|
||||
})
|
||||
.UseDefaultServiceProvider((context, options) => {
|
||||
var isDevelopment = context.HostingEnvironment.IsDevelopment();
|
||||
options.ValidateScopes = isDevelopment;
|
||||
options.ValidateOnBuild = isDevelopment;
|
||||
});
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static void LogHostingEnvironment<T>(this IHost host) {
|
||||
var loggerFactory = host.Services.GetRequiredService<ILoggerFactory>();
|
||||
var configuration = host.Services.GetRequiredService<IConfiguration>();
|
||||
var hostEnvironment = host.Services.GetRequiredService<IHostEnvironment>();
|
||||
var logger = loggerFactory.CreateLogger<T>();
|
||||
logger.LogInformation("Running Host...");
|
||||
logger.LogInformation($"EnvironmentName:{hostEnvironment.EnvironmentName}");
|
||||
logger.LogInformation($"ContentRootPath:{hostEnvironment.ContentRootPath}");
|
||||
logger.LogInformation($"CurrentDirectory:{Environment.CurrentDirectory}");
|
||||
logger.LogInformation($"ApplicationName:{hostEnvironment.ApplicationName}");
|
||||
logger.LogInformation($"Customer:{configuration.GetCustomer()}");
|
||||
logger.LogInformation($"ComputerName:{configuration.GetComputerName()}");
|
||||
}
|
||||
|
||||
public static void LogStartError(Exception ex) {
|
||||
var logDir = Path.Combine(AppContext.BaseDirectory, "logs");
|
||||
if (!Directory.Exists(logDir))
|
||||
Directory.CreateDirectory(logDir);
|
||||
var logFile = Path.Combine(logDir, "start_error.txt");
|
||||
File.AppendAllText(logFile, DateTime.Now.ToString() + ": " + ex.ToString() + Environment.NewLine);
|
||||
}
|
||||
|
||||
public static void ChangeCurrentDirToProjectDir() {
|
||||
var currentDir = Directory.GetCurrentDirectory();
|
||||
var ix = currentDir.IndexOf("\\bin"); // goto project dir, if we are running from VS
|
||||
if (ix >= 0) {
|
||||
var newDir = currentDir.Substring(0, ix);
|
||||
Directory.SetCurrentDirectory(newDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
backend/app/app.Configuration/app.Configuration.csproj
Normal file
11
backend/app/app.Configuration/app.Configuration.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0"/>
|
||||
<PackageReference Include="NLog" Version="4.7.13"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user