Add Application configuration #11
14
Endpoint/Configuration/General/GeneralConfig.cs
Normal file
14
Endpoint/Configuration/General/GeneralConfig.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.General;
|
||||
|
||||
public class GeneralConfig
|
||||
{
|
||||
public const string FilePath = "Settings.json";
|
||||
|
||||
public DbSettings? DbSettings { get; set; }
|
||||
public CacheSettings? CacheSettings { get; set; }
|
||||
public ScheduleSettings? ScheduleSettings { get; set; }
|
||||
public EmailSettings? EmailSettings { get; set; }
|
||||
public LogSettings? LogSettings { get; set; }
|
||||
}
|
23
Endpoint/Configuration/General/Settings/CacheSettings.cs
Normal file
23
Endpoint/Configuration/General/Settings/CacheSettings.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Mirea.Api.Endpoint.Configuration.General.Attributes;
|
||||
using Mirea.Api.Endpoint.Configuration.General.Interfaces;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||
|
||||
[RequiredSettings]
|
||||
public class CacheSettings : IIsConfigured
|
||||
{
|
||||
public enum CacheEnum
|
||||
{
|
||||
Memcached,
|
||||
Redis
|
||||
}
|
||||
|
||||
public CacheEnum TypeDatabase { get; set; }
|
||||
public string? ConnectionString { get; set; }
|
||||
|
||||
public bool IsConfigured()
|
||||
{
|
||||
return TypeDatabase == CacheEnum.Memcached ||
|
||||
!string.IsNullOrEmpty(ConnectionString);
|
||||
}
|
||||
}
|
22
Endpoint/Configuration/General/Settings/DbSettings.cs
Normal file
22
Endpoint/Configuration/General/Settings/DbSettings.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Mirea.Api.Endpoint.Configuration.General.Attributes;
|
||||
using Mirea.Api.Endpoint.Configuration.General.Interfaces;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||
|
||||
[RequiredSettings]
|
||||
public class DbSettings : IIsConfigured
|
||||
{
|
||||
public enum DatabaseEnum
|
||||
{
|
||||
Mysql,
|
||||
Sqlite,
|
||||
PostgresSql
|
||||
}
|
||||
public DatabaseEnum TypeDatabase { get; set; }
|
||||
public required string ConnectionStringSql { get; set; }
|
||||
|
||||
public bool IsConfigured()
|
||||
{
|
||||
return !string.IsNullOrEmpty(ConnectionStringSql);
|
||||
}
|
||||
}
|
23
Endpoint/Configuration/General/Settings/EmailSettings.cs
Normal file
23
Endpoint/Configuration/General/Settings/EmailSettings.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Mirea.Api.Endpoint.Configuration.General.Interfaces;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||
|
||||
public class EmailSettings : IIsConfigured
|
||||
{
|
||||
public string? Server { get; set; }
|
||||
public string? User { get; set; }
|
||||
public string? Password { get; set; }
|
||||
public string? From { get; set; }
|
||||
public int? Port { get; set; }
|
||||
public bool? Ssl { get; set; }
|
||||
|
||||
public bool IsConfigured()
|
||||
{
|
||||
return !string.IsNullOrEmpty(Server) &&
|
||||
!string.IsNullOrEmpty(User) &&
|
||||
!string.IsNullOrEmpty(Password) &&
|
||||
!string.IsNullOrEmpty(From) &&
|
||||
Port.HasValue &&
|
||||
Ssl.HasValue;
|
||||
}
|
||||
}
|
19
Endpoint/Configuration/General/Settings/LogSettings.cs
Normal file
19
Endpoint/Configuration/General/Settings/LogSettings.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Mirea.Api.Endpoint.Configuration.General.Attributes;
|
||||
using Mirea.Api.Endpoint.Configuration.General.Interfaces;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||
|
||||
[RequiredSettings]
|
||||
public class LogSettings : IIsConfigured
|
||||
{
|
||||
public bool EnableLogToFile { get; set; }
|
||||
public string? LogFilePath { get; set; }
|
||||
public string? LogFileName { get; set; }
|
||||
|
||||
public bool IsConfigured()
|
||||
{
|
||||
return !EnableLogToFile ||
|
||||
!string.IsNullOrEmpty(LogFilePath) &&
|
||||
!string.IsNullOrEmpty(LogFileName);
|
||||
}
|
||||
}
|
45
Endpoint/Configuration/General/Settings/ScheduleSettings.cs
Normal file
45
Endpoint/Configuration/General/Settings/ScheduleSettings.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Mirea.Api.Endpoint.Configuration.General.Attributes;
|
||||
using Mirea.Api.Endpoint.Configuration.General.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||
|
||||
[RequiredSettings]
|
||||
public class ScheduleSettings : IIsConfigured
|
||||
{
|
||||
public struct PairPeriodTime
|
||||
{
|
||||
public TimeOnly Start { get; set; }
|
||||
public TimeOnly End { get; set; }
|
||||
|
||||
public PairPeriodTime(TimeOnly t1, TimeOnly t2)
|
||||
{
|
||||
if (t1 > t2)
|
||||
{
|
||||
Start = t2;
|
||||
End = t1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Start = t1;
|
||||
End = t2;
|
||||
}
|
||||
}
|
||||
|
||||
public PairPeriodTime(Dto.Common.PairPeriodTime time) : this(time.Start, time.End) { }
|
||||
}
|
||||
|
||||
public required string CronUpdateSchedule { get; set; }
|
||||
public DateOnly StartTerm { get; set; }
|
||||
public required IDictionary<int, PairPeriodTime> PairPeriod { get; set; }
|
||||
|
||||
public bool IsConfigured()
|
||||
{
|
||||
return !string.IsNullOrEmpty(CronUpdateSchedule) &&
|
||||
StartTerm != default &&
|
||||
PairPeriod.Count != 0 &&
|
||||
PairPeriod.Any();
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using Mirea.Api.DataAccess.Persistence.Properties;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Properties;
|
||||
|
||||
public class EmailSettings
|
||||
{
|
||||
public string? Server { get; set; }
|
||||
public string? User { get; set; }
|
||||
public string? Password { get; set; }
|
||||
public string? From { get; set; }
|
||||
public int? Port { get; set; }
|
||||
public bool? Ssl { get; set; }
|
||||
}
|
||||
|
||||
public class LogSettings
|
||||
{
|
||||
public bool EnableLogToFile { get; set; }
|
||||
public string? LogFilePath { get; set; }
|
||||
public string? LogFileName { get; set; }
|
||||
}
|
||||
|
||||
public class ScheduleSettings
|
||||
{
|
||||
// Every 6 hours
|
||||
public string CronUpdateSchedule { get; set; } = "0 0 0/6 * * *";
|
||||
}
|
||||
|
||||
public class Settings
|
||||
{
|
||||
public const string FilePath = "Settings.json";
|
||||
|
||||
public EmailSettings? EmailSettings { get; set; }
|
||||
public LogSettings? LogSettings { get; set; }
|
||||
public DbSettings? DbSettings { get; set; }
|
||||
public ScheduleSettings? ScheduleSettings { get; set; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user