using Ease.NetCore.DataAccess;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace OnlineSalesAutoCrop.CoreAPI.Models.Global
{
///
/// AppSettings
///
public class AppSettings
{
///
/// Default Database Connection to be used
///
[Required]
public string DefaultDB { get; set; }
///
/// Used to dec from User info got over http
///
public string CipherSecretKey { get; set; }
///
/// Gets or sets a value that indicates whether a cookie is inaccessible by client-side script.
///
public bool CookieHttpOnly { get; set; }
///
/// Gets or sets a value that indicates whether to transmit the cookie using Secure Sockets Layer (SSL)--that is, over HTTPS only.
///
public bool CookieSecure { get; set; }
///
/// Gets or sets the max-age for the cookie in minutes.
///
public int CookieLifeTime { get; set; } = 360;
///
/// Gets or sets the value for the SameSite attribute of the cookie.
/// -1: No SameSite field will be set, the client should follow its default cookie policy.
/// 0: Indicates the client should disable same-site restrictions.
/// 1: Indicates the client should send the cookie with "same-site" requests, and with "cross-site" top-level navigations.
/// 2: Indicates the client should only send the cookie with "same-site" requests.
///
public int CookieSameSite { get; set; }
///
/// For Jwt Token
///
public string JwtCryptoKey { get; set; }
public string JwtIssuer { get; set; }
public string JwtAudience { get; set; }
public bool JwtValidateIssuer { get; set; }
public bool JwtValidateAudience { get; set; }
///
/// Folder management
///
public string UploadFolder { get; set; }
public string ProfileImageFolder { get; set; }
public string ReportFolder { get; set; }
public string FileProcessFolder { get; set; }
///
/// For user password
///
[Required]
public string PwdSecretKey { get; set; }
///
/// For SMS Management
///
public string SmsSecretKey { get; set; }
public string SmsApiUrl { get; set; }
public string SmsAccessInfo { get; set; }
///
/// Email management
///
public int EmailPort { get; set; }
public bool EmailEnableSsl { get; set; }
public string EmailHost { get; set; }
public string EmailSenderName { get; set; }
public string EmailSenderIp { get; set; }
public string EmailSenderId { get; set; }
private string _emailSenderPwd;
public string EmailSenderPwd
{
get
{
if (string.IsNullOrEmpty(_emailSenderPwd) || string.IsNullOrEmpty(PwdSecretKey))
return string.Empty;
string secretKey = GlobalFunctions.ConvertFromBase64String(PwdSecretKey);
return Ease.NetCore.Utility.Global.CipherFunctions.DecryptByAES(privateKey: secretKey, publicKey: secretKey, data: _emailSenderPwd, input: 2);
}
set { _emailSenderPwd = value; }
}
public string EmailBcc { get; set; }
public string EmailErrorLogPath { get; set; }
public bool EmailUseDefaultCredentials { get; set; }
public int EmailTlsVersion { get; set; }
///
/// CORS CorsHeaders
///
public string CorsHeaders { get; set; }
///
/// CORS CorsMethods
///
public string CorsMethods { get; set; }
///
/// CORS CorsOrigins
///
public string CorsOrigins { get; set; }
///
/// Logger enabled if the is there is value
///
public string LoggerPath { get; set; }
public int LoggerMinLevel { get; set; }
///
/// Database connection Hangfire
///
private string _hangfireDb;
public string HangfireDb
{
get
{
if (string.IsNullOrEmpty(_hangfireDb) || string.IsNullOrEmpty(PwdSecretKey))
return string.Empty;
string secretKey = GlobalFunctions.ConvertFromBase64String(PwdSecretKey);
return Ease.NetCore.Utility.Global.CipherFunctions.DecryptByAES(privateKey: secretKey, publicKey: secretKey, data: _hangfireDb, input: 2);
}
set { _hangfireDb = value; }
}
//
/// Use for caching
///
public EnumCacheType CacheType { get; set; } = EnumCacheType.InMemory;
public string CacheUrl { get; set; }
public string CacheSchemaName { get; set; }
public string CacheTableName { get; set; }
///
/// What's app messaging
///
public string WaSenderId { get; set; }
public string WaAuthToken { get; set; }
public string WaAccountSid { get; set; }
public string WaMsgSvcSid { get; set; }
///
/// Rabbit MQ Information
///
public string RabbitMQHost { get; set; }
public string RabbitMQUser { get; set; }
private string _rabbitMQPwd;
public string RabbitMQPwd
{
get
{
if (string.IsNullOrEmpty(_rabbitMQPwd) || string.IsNullOrEmpty(PwdSecretKey))
return string.Empty;
string secretKey = GlobalFunctions.ConvertFromBase64String(PwdSecretKey);
return Ease.NetCore.Utility.Global.CipherFunctions.DecryptByAES(privateKey: secretKey, publicKey: secretKey, data: _rabbitMQPwd, input: 2);
}
set { _rabbitMQPwd = value; }
}
public int RabbitMQPort { get; set; }
///
/// Rate Limit by Ip Address
///
public string RLName { get; set; }
public int RLQueueLimit { get; set; }
public int RLPermitLimit { get; set; }
public int RLWindowInSecond { get; set; }
public bool RLAutoReplenishment { get; set; }
public int RLQueueProcessingOrder { get; set; }
///
/// AI Service Information
///
private string _apiKeyOpenAI;
public string ApiKeyOpenAI
{
get
{
if (string.IsNullOrEmpty(_apiKeyOpenAI) || string.IsNullOrEmpty(PwdSecretKey))
return string.Empty;
string secretKey = GlobalFunctions.ConvertFromBase64String(PwdSecretKey);
return Ease.NetCore.Utility.Global.CipherFunctions.DecryptByAES(privateKey: secretKey, publicKey: secretKey, data: _apiKeyOpenAI, input: 2);
}
set { _apiKeyOpenAI = value; }
}
public string AIModel { get; set; }
public string AICustomBaseUrl { get; set; }
///
/// Google API Key
///
private string _apiKeyGoogle;
public string ApiKeyGoogle
{
get
{
if (string.IsNullOrEmpty(_apiKeyGoogle) || string.IsNullOrEmpty(PwdSecretKey))
return string.Empty;
string secretKey = GlobalFunctions.ConvertFromBase64String(PwdSecretKey);
return Ease.NetCore.Utility.Global.CipherFunctions.DecryptByAES(privateKey: secretKey, publicKey: secretKey, data: _apiKeyGoogle, input: 2);
}
set { _apiKeyGoogle = value; }
}
///
/// Product Hierarchy Maximum Level
///
public int PHMaxLevel { get; set; }
///
/// Channel Hierarchy Maximum Level
///
public int CHMaxLevel { get; set; }
///
/// Market Hierarchy Maximum Level
///
public int MHMaxLevel { get; set; }
///
/// Market Hierarchy Maximum Level
///
public int EPMaxLevel { get; set; }
///
/// Use to view payslip
///
public string PayslipPath { get; set; }
///
/// AD ie Active Domain Settings
///
public ADSettings ADConfig { get; set; }
///
/// Api Settings
///
[Required]
public ApiSettings API { get; set; }
///
/// Swagger Setting
///
[Required]
public Swagger Swagger { get; set; }
///
/// DB Connection Node
///
[Required]
public List DbConfig { get; set; }
///
/// Default DB Connection Node
///
public DbConnectionNode DefaultConnection => GetConnectionNode(DefaultDB);
///
/// DB Connection Node by name
///
/// Connection node name
///
public DbConnectionNode GetConnectionNode(string key)
{
if (string.IsNullOrEmpty(key))
key = DefaultDB;
if (DbConfig == null || DbConfig.Count <= 0 || string.IsNullOrEmpty(key))
return null;
return DbConfig.FirstOrDefault(x => x.ConnectionNode.Key == key);
}
}
///
///
///
public class DbConnectionNode
{
public ConnectionNode ConnectionNode { get; set; }
}
///
///
///
public class ADSettings
{
public bool Enabled { get; set; }
public string Domain { get; set; }
public string Path { get; set; }
}
///
///
///
public class ApiSettings
{
[Required]
public string Title { get; set; }
public string Description { get; set; }
public ApiContact Contact { get; set; }
public string TermsOfServiceUrl { get; set; }
public ApiLicense License { get; set; }
}
///
///
///
public class ApiContact
{
public string Name { get; set; }
public string Email { get; set; }
public string Url { get; set; }
}
///
///
///
public class ApiLicense
{
public string Name { get; set; }
public string Url { get; set; }
}
///
///
///
public class Swagger
{
[Required]
public bool Enabled { get; set; }
}
}