Refactoring project

parent 5e824dba
......@@ -11,72 +11,91 @@ using RouteHandler = IntegrationKSSS.WebService.Infrastructure.RouteHandlers.Rou
using IRouteHandler = IntegrationKSSS.WebService.Infrastructure.RouteHandlers.IRouteHandler;
using NLog.Config;
using ILogger = NLog.ILogger;
using System.Reflection;
using Microsoft.AspNetCore.Authorization;
namespace IntegrationKSSS.WebService.Infrastructure.Configurations
namespace IntegrationKSSS.WebService.Infrastructure.Configurations;
/// <summary>
/// Configuration of the WEB API
/// </summary>
public static class ApplicationConfiguration
{
public static class ApplicationConfiguration
#region Methods
/// <summary>
/// Getting a logger
/// </summary>
/// <returns>Logger</returns>
private static ILogger GetLogger()
{
public static ILogger GetLogger()
{
string fileName = string.Empty;
string fileName = string.Empty;
#if DEBUG
fileName = Path.GetFullPath(@"../../IntegrationKSSS/IntegrationKSSS.WebService/NLog.config");
fileName = Path.GetFullPath(@"../../IntegrationKSSS/IntegrationKSSS.WebService/NLog.config");
#endif
#if !DEBUG
fileName = $"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}/NLog.config";
#endif
LogManager.Configuration = new XmlLoggingConfiguration(fileName);
return LogManager.GetCurrentClassLogger();
}
LogManager.Configuration = new XmlLoggingConfiguration(fileName);
return LogManager.GetCurrentClassLogger();
}
/// <summary>
/// Adding middleware, services and functions
/// </summary>
/// <param name="webApplicationBuilder"></param>
public static void RegisterBuilder(WebApplicationBuilder webApplicationBuilder)
{
var logger = GetLogger();
public static void RegisterBuilder(WebApplicationBuilder webApplicationBuilder)
try
{
var logger = GetLogger();
webApplicationBuilder.Services.AddEndpointsApiExplorer();
webApplicationBuilder.Logging.ClearProviders();
webApplicationBuilder.Host.UseNLog();
webApplicationBuilder.Services.AddSwaggerGen();
webApplicationBuilder.Services.AddSingleton(logger);
try
var connectionString = webApplicationBuilder.Configuration["ConnectionStrings:MicrosoftSqlServer"]
.DecryptString(AesConfiguration.Key, AesConfiguration.IV);
webApplicationBuilder.Services.AddDbContext<RDnLDbContext>(options =>
options.UseSqlServer(connectionString));
webApplicationBuilder.Services.AddScoped<IAuthService, AuthService>();
webApplicationBuilder.Services.AddScoped<IKsssRepository, KsssRepository>();
webApplicationBuilder.Services.AddTransient<IRouteHandler, RouteHandler>();
webApplicationBuilder.Services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", options => { });
webApplicationBuilder.Services.AddAuthorization(options =>
{
webApplicationBuilder.Services.AddEndpointsApiExplorer();
webApplicationBuilder.Logging.ClearProviders();
webApplicationBuilder.Host.UseNLog();
webApplicationBuilder.Services.AddSwaggerGen();
webApplicationBuilder.Services.AddSingleton(logger);
webApplicationBuilder.Services.AddAuthorization();
webApplicationBuilder.Services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
var connectionString = webApplicationBuilder.Configuration["ConnectionStrings:MicrosoftSqlServer"]
.DecryptString(AesConfiguration.Key, AesConfiguration.IV);
webApplicationBuilder.Services.AddDbContext<RDnLDbContext>(options =>
options.UseSqlServer(connectionString));
webApplicationBuilder.Services.AddScoped<IAuthService, AuthService>();
webApplicationBuilder.Services.AddScoped<IKsssRepository, KsssRepository>();
webApplicationBuilder.Services.AddTransient<IRouteHandler, RouteHandler>();
}
catch (Exception ex)
{
logger.Error(ex, "Stopped web api because of exception");
throw;
}
finally
{
LogManager.Shutdown();
}
options.AddPolicy("BasicAuthentication", new AuthorizationPolicyBuilder("BasicAuthentication").RequireAuthenticatedUser().Build());
});
}
public static void RegisterApplication(WebApplication webApplication)
catch (Exception ex)
{
if (webApplication.Environment.IsDevelopment())
{
webApplication.UseSwagger();
webApplication.UseSwaggerUI();
}
webApplication.UseAuthorization();
webApplication.UseAuthentication();
webApplication.Services.GetServices<IRouteHandler>().ToList().ForEach(c => c.Register(webApplication));
logger.Error(ex, "Stopped web api because of exception");
throw;
}
finally
{
LogManager.Shutdown();
}
}
/// <summary>
/// Using middleware, services and functions
/// </summary>
/// <param name="webApplication"></param>
public static void RegisterApplication(WebApplication webApplication)
{
if (webApplication.Environment.IsDevelopment())
{
webApplication.UseSwagger();
webApplication.UseSwaggerUI();
}
webApplication.UseAuthentication();
webApplication.UseAuthorization();
webApplication.Services.GetServices<IRouteHandler>().ToList().ForEach(c => c.Register(webApplication));
}
#endregion
}
namespace IntegrationKSSS.WebService.Infrastructure.Cryptography;
internal static class AesConfiguration
{
#region Variables
public const string Key = "da983189246a4520a94764a751fa466a";
public static byte[] IV = new byte[16];
#endregion
}
using System.Security.Cryptography;
using System.Text;
namespace IntegrationKSSS.WebService.Infrastructure.Cryptography
namespace IntegrationKSSS.WebService.Infrastructure.Cryptography;
internal static class AesExtension
{
public static class AesConfiguration
#region Methods
internal static string DecryptString(this string cipherText, string key, byte[] IV)
{
public const string Key = "da983189246a4520a94764a751fa466a";
public static byte[] IV = new byte[16];
}
public static class AesExtension
{
public static string DecryptString(this string cipherText, string key, byte[] IV)
if (cipherText == null || cipherText.Length <= 0) throw new ArgumentNullException(nameof(cipherText));
if (key == null || key.Length <= 0) throw new ArgumentNullException(nameof(key));
if (IV == null || IV.Length <= 0) throw new ArgumentNullException(nameof(IV));
string plaintext = null;
using (Aes aesAlg = Aes.Create())
{
if (cipherText == null || cipherText.Length <= 0) throw new ArgumentNullException(nameof(cipherText));
if (key == null || key.Length <= 0) throw new ArgumentNullException(nameof(key));
if (IV == null || IV.Length <= 0) throw new ArgumentNullException(nameof(IV));
string plaintext = null;
using (Aes aesAlg = Aes.Create())
{
aesAlg.Key = Encoding.UTF8.GetBytes(key);
aesAlg.IV = IV;
aesAlg.Key = Encoding.UTF8.GetBytes(key);
aesAlg.IV = IV;
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(cipherText)))
using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(cipherText)))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
plaintext = srDecrypt.ReadToEnd();
}
plaintext = srDecrypt.ReadToEnd();
}
}
}
return plaintext;
}
}
}
return plaintext;
}
#endregion
}
\ No newline at end of file
using IntegrationKSSS.WebService.Infrastructure.Models;
using Microsoft.EntityFrameworkCore;
namespace IntegrationKSSS.WebService.Infrastructure.Data
namespace IntegrationKSSS.WebService.Infrastructure.Data;
public class RDnLDbContext : DbContext
{
public class RDnLDbContext : DbContext
{
public RDnLDbContext(DbContextOptions dbContextOptions) : base(dbContextOptions) {}
#region Constructors
public RDnLDbContext(DbContextOptions dbContextOptions) : base(dbContextOptions) { }
#endregion
public DbSet<RndtSp> RndtSp => Set<RndtSp>();
public DbSet<RndtSpIc> RndtSpIc => Set<RndtSpIc>();
public DbSet<RndtSpIi> RndtSpIi => Set<RndtSpIi>();
#region Properties
public DbSet<RndtSp> RndtSp => Set<RndtSp>();
public DbSet<RndtSpIc> RndtSpIc => Set<RndtSpIc>();
public DbSet<RndtSpIi> RndtSpIi => Set<RndtSpIi>();
public DbSet<RndtIpIeAu> RndtIpIeAu => Set<RndtIpIeAu>();
#endregion
#region Methods
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("RndSuite");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("RndSuite");
modelBuilder.Entity<RndtSp>()
.HasKey(c => new { c.SP, c.SP_VERSION });
modelBuilder.Entity<RndtSp>()
.HasKey(c => new { c.SP, c.SP_VERSION });
modelBuilder.Entity<RndtSpIc>()
.HasKey(c => new { c.SP, c.SP_VERSION, c.IC, c.ICNODE });
modelBuilder.Entity<RndtSpIc>()
.HasKey(c => new { c.SP, c.SP_VERSION, c.IC, c.ICNODE});
modelBuilder.Entity<RndtSpIi>()
.HasKey(c => new { c.SP, c.SP_VERSION, c.IC, c.ICNODE, c.IINODE });
modelBuilder.Entity<RndtSpIi>()
.HasKey(c => new {c.SP, c.SP_VERSION, c.IC, c.ICNODE, c.IINODE});
}
}
}
modelBuilder.Entity<RndtIpIeAu>()
.HasKey(c => new { c.IP, c.SEQ, c.AUSEQ, c.AU, c.VERSION, c.IE });
}
#endregion
}
\ No newline at end of file
......@@ -7,56 +7,61 @@ using System.Text.Encodings.Web;
using System.Text;
using IntegrationKSSS.WebService.Infrastructure.Services;
namespace IntegrationKSSS.WebService.Infrastructure.Handlers
namespace IntegrationKSSS.WebService.Infrastructure.Handlers;
/// <summary>
/// Basic authorization handler
/// </summary>
public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
public class BasicAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
private readonly IAuthService _authService;
#region Consturctors
public BasicAuthenticationHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock,
IAuthService authService)
: base(options, logger, encoder, clock)
{
_authService = authService;
}
#endregion
#region Methods
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
private readonly IAuthService _authService;
public BasicAuthenticationHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock,
IAuthService authService)
: base(options, logger, encoder, clock)
var endpoint = Context.GetEndpoint();
if (endpoint?.Metadata?.GetMetadata<IAllowAnonymous>() != null)
return AuthenticateResult.NoResult();
if (!Request.Headers.ContainsKey("Authorization"))
return AuthenticateResult.Fail("Missing Authorization Header");
bool authResult = false;
try
{
_authService = authService;
var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
var credentialBytes = Convert.FromBase64String(authHeader.Parameter);
var credentials = Encoding.UTF8.GetString(credentialBytes).Split(new[] { ':' }, 2);
var username = credentials[0];
var password = credentials[1];
authResult = await _authService.Auth(username, password);
}
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
catch
{
// skip authentication if endpoint has [AllowAnonymous] attribute
var endpoint = Context.GetEndpoint();
if (endpoint?.Metadata?.GetMetadata<IAllowAnonymous>() != null)
return AuthenticateResult.NoResult();
if (!Request.Headers.ContainsKey("Authorization"))
return AuthenticateResult.Fail("Missing Authorization Header");
bool authResult = false;
try
{
var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
var credentialBytes = Convert.FromBase64String(authHeader.Parameter);
var credentials = Encoding.UTF8.GetString(credentialBytes).Split(new[] { ':' }, 2);
var username = credentials[0];
var password = credentials[1];
authResult = await _authService.Auth(username, password);
}
catch
{
return AuthenticateResult.Fail("Invalid Authorization Header");
}
if (authResult == false)
return AuthenticateResult.Fail("Invalid Username or Password");
List<Claim> claims = new List<Claim>();
var identity = new ClaimsIdentity(claims, Scheme.Name);
var principal = new ClaimsPrincipal(identity);
var ticket = new AuthenticationTicket(principal, Scheme.Name);
return AuthenticateResult.Success(ticket);
return AuthenticateResult.Fail("Invalid Authorization Header");
}
if (authResult == false)
return AuthenticateResult.Fail("Invalid Username or Password");
List<Claim> claims = new List<Claim>();
var identity = new ClaimsIdentity(claims, Scheme.Name);
var principal = new ClaimsPrincipal(identity);
var ticket = new AuthenticationTicket(principal, Scheme.Name);
return AuthenticateResult.Success(ticket);
}
#endregion
}
namespace IntegrationKSSS.WebService.Infrastructure.Models;
/// <summary>
/// List of internal messages
/// </summary>
internal static class MessageList
{
#region Variables
public const string SpecificationNotFound = "Specification not found";
public const string KsssInfoCardNotFound = "KSSS info card not found";
public const string KsssInfoCardEmpty = "There are no info fields on the KSSS info card";
public const string SuccessfullyKsssInfoCardRecord = "Successfully recorded data on the KSSS info card";
public const string AcceptedDataPackage = "The data package has been accepted for processing";
#endregion
}
\ No newline at end of file
namespace IntegrationKSSS.WebService.Infrastructure.Models;
public class RndtIpIeAu
{
#region Properties
public decimal IP { get; set; }
public decimal VERSION { get; set; }
public decimal IE { get; set; }
public decimal SEQ { get; set; }
public decimal AU { get; set; }
public decimal AUSEQ { get; set; }
public string? VALUE { get; set; }
#endregion
}
\ No newline at end of file
namespace IntegrationKSSS.WebService.Infrastructure.Models
namespace IntegrationKSSS.WebService.Infrastructure.Models;
public class RndtSp
{
public class RndtSp
{
public decimal SP { get; set; }
public decimal SP_VERSION { get; set; }
public string DESCRIPTION { get; set; }
public decimal? SS { get; set; }
public char? ALLOW_MODIFY { get; set; }
public char? ACTIVE { get; set; }
public string? LAST_COMMENT { get; set; }
#region Properties
public decimal SP { get; set; }
public decimal SP_VERSION { get; set; }
public string DESCRIPTION { get; set; }
public decimal? SS { get; set; }
public char? ALLOW_MODIFY { get; set; }
public char? ACTIVE { get; set; }
public string? LAST_COMMENT { get; set; }
#endregion
}
}
}
\ No newline at end of file
namespace IntegrationKSSS.WebService.Infrastructure.Models
namespace IntegrationKSSS.WebService.Infrastructure.Models;
public class RndtSpIc
{
public class RndtSpIc
{
public decimal SP { get; set; }
public decimal SP_VERSION { get; set; }
public decimal IC { get; set; }
public string? IC_SHORT_DESC { get; set; }
public decimal ICNODE { get; set; }
public decimal? IP_VERSION { get; set; }
public decimal? SS { get; set; }
}
}
#region Properties
public decimal SP { get; set; }
public decimal SP_VERSION { get; set; }
public decimal IC { get; set; }
public string? IC_SHORT_DESC { get; set; }
public decimal ICNODE { get; set; }
public decimal? IP_VERSION { get; set; }
public decimal? SS { get; set; }
#endregion
}
\ No newline at end of file
namespace IntegrationKSSS.WebService.Infrastructure.Models
namespace IntegrationKSSS.WebService.Infrastructure.Models;
public class RndtSpIi
{
public class RndtSpIi
{
public decimal SP { get; set; }
public decimal SP_VERSION { get; set; }
public decimal IC { get; set; }
public decimal ICNODE { get; set; }
public decimal II { get; set; }
public string? II_SHORT_DESC { get; set; }
public decimal IINODE { get; set; }
public decimal? IE_VERSION { get; set; }
public string? IIVALUE { get; set; }
public decimal? SS { get; set; }
}
}
#region Properties
public decimal SP { get; set; }
public decimal SP_VERSION { get; set; }
public decimal IC { get; set; }
public decimal ICNODE { get; set; }
public decimal II { get; set; }
public string? II_SHORT_DESC { get; set; }
public decimal IINODE { get; set; }
public decimal? IE_VERSION { get; set; }
public string? IIVALUE { get; set; }
public decimal? SS { get; set; }
#endregion
}
\ No newline at end of file
namespace IntegrationKSSS.WebService.Infrastructure.Repositories
namespace IntegrationKSSS.WebService.Infrastructure.Repositories;
/// <summary>
/// A set of repository functions
/// </summary>
public interface IKsssRepository
{
public interface IKsssRepository
{
Task<string> WriteKsssData(Dictionary<string, string> ksss);
}
}
Task WriteKsssData(Dictionary<string, string> ksss);
}
\ No newline at end of file
using IntegrationKSSS.Models;
using IntegrationKSSS.WebService.Infrastructure.Data;
using IntegrationKSSS.WebService.Infrastructure.Data;
using IntegrationKSSS.WebService.Infrastructure.Models;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using ILogger = NLog.ILogger;
namespace IntegrationKSSS.WebService.Infrastructure.Repositories
namespace IntegrationKSSS.WebService.Infrastructure.Repositories;
/// <summary>
/// A set of repository function implementations
/// </summary>
public class KsssRepository : KsssRepositoryBase, IKsssRepository
{
public class KsssRepository : KsssRepositoryBase, IKsssRepository
{
public KsssRepository(RDnLDbContext rDnLDbContext, ILogger logger) : base(rDnLDbContext, logger) { }
#region Constructors
public KsssRepository(RDnLDbContext rDnLDbContext, ILogger logger) : base(rDnLDbContext, logger) { }
#endregion
public async Task<string> WriteKsssData(Dictionary<string, string> ksssDictionary)
#region Methods
/// <summary>
/// Data recording on the specification infocard
/// </summary>
/// <param name="ksssDictionary"></param>
/// <returns></returns>
public async Task WriteKsssData(Dictionary<string, string> ksssDictionary)
{
try
{
decimal specificationId = 0;
decimal.TryParse(ksssDictionary["SP"], out specificationId);
if(specificationId == 0)
if (specificationId == 0)
{
Logger.Info("Not found specification id");
return "Not found specification id";
Logger.Info(MessageList.SpecificationNotFound);
return;
}
decimal ssDev = 1000012;
string nameInfoCard = "KSSS_Data";
......@@ -23,12 +38,10 @@ namespace IntegrationKSSS.WebService.Infrastructure.Repositories
var specification = RDnLDbContext.RndtSp.FirstOrDefault(c => c.SP == specificationId &&
c.ALLOW_MODIFY == '1' &&
c.SS == ssDev);
if (specification == null)
{
Logger.Info($"Not found specification {specificationId}");
return $"Not found specification {specificationId}";
Logger.Info(MessageList.SpecificationNotFound);
return;
}
......@@ -36,40 +49,77 @@ namespace IntegrationKSSS.WebService.Infrastructure.Repositories
infoCard.IC_SHORT_DESC == nameInfoCard &&
infoCard.SP_VERSION == specification.SP_VERSION);
if(infoCardKsss == null)
if (infoCardKsss == null)
{
Logger.Info($"Not found info card {nameInfoCard}");
return $"Not found info card {nameInfoCard}";
Logger.Info(MessageList.KsssInfoCardNotFound);
return;
}
var infoFields = RDnLDbContext.RndtSpIi.Where(infoField => infoField.IC == infoCardKsss.IC &&
infoField.SP == specificationId);
if(infoFields.Count() == 0)
if (infoFields.Count() == 0)
{
Logger.Info($"There are no info fields on the info card {nameInfoCard}");
return $"There are no info fields on the info card {nameInfoCard}";
Logger.Info(MessageList.KsssInfoCardEmpty);
return;
}
foreach (var ksssValuePair in ksssDictionary)
{
if(ksssValuePair.Key == "SP")
if (ksssValuePair.Key == "SP")
{
continue;
}
var foundedInfoField = infoFields.FirstOrDefault(infoField => infoField.II_SHORT_DESC == ksssValuePair.Key);
if(foundedInfoField == null)
if (foundedInfoField == null)
{
continue;
}
foundedInfoField.IIVALUE = ksssValuePair.Value;
var relationValue = GetRelationValue(foundedInfoField, ksssValuePair.Value);
if (string.IsNullOrEmpty(relationValue))
{
foundedInfoField.IIVALUE = ksssValuePair.Value;
}
else
{
foundedInfoField.IIVALUE = relationValue;
}
}
await RDnLDbContext.SaveChangesAsync();
Logger.Info($"Successfully recorded data on the info card {nameInfoCard}");
return $"Successfully recorded data on the info card {nameInfoCard}";
Logger.Info(MessageList.SuccessfullyKsssInfoCardRecord);
}
catch (Exception ex)
{
Logger.Error(ex);
}
}
/// <summary>
/// Getting the value relation
/// </summary>
/// <param name="rndtSpIi"></param>
/// <param name="tableValue"></param>
/// <returns></returns>
private string GetRelationValue(RndtSpIi rndtSpIi, string tableValue)
{
string result = string.Empty;
var rndvIpIeAu = RDnLDbContext.RndtIpIeAu.Where(c => c.IE == rndtSpIi.II)
.OrderByDescending(c => c.VERSION)
.FirstOrDefault();
var tableName = rndvIpIeAu?.VALUE;
if (!string.IsNullOrEmpty(tableName) && !string.IsNullOrEmpty(tableValue))
{
var sqlQuery = $"SELECT Name FROM [RndSuite].[{tableName}] WHERE [Id] = @TableId";
var tableId = new SqlParameter("@TableId", tableValue);
result = RDnLDbContext.Database.SqlQueryRaw<string>(sqlQuery, tableId)
.ToList()
.FirstOrDefault();
}
return result;
}
#endregion
}
using IntegrationKSSS.WebService.Infrastructure.Data;
using ILogger = NLog.ILogger;
namespace IntegrationKSSS.WebService.Infrastructure.Repositories
namespace IntegrationKSSS.WebService.Infrastructure.Repositories;
/// <summary>
/// A set of variables repository
/// </summary>
public class KsssRepositoryBase
{
public class KsssRepositoryBase
#region Variables
internal readonly RDnLDbContext RDnLDbContext;
internal readonly ILogger Logger;
#endregion
#region Constructors
public KsssRepositoryBase(RDnLDbContext rDnLDbContext, ILogger logger)
{
internal readonly RDnLDbContext RDnLDbContext;
internal readonly ILogger Logger;
public KsssRepositoryBase(RDnLDbContext rDnLDbContext, ILogger logger)
{
RDnLDbContext = rDnLDbContext;
Logger = logger;
}
}
}
RDnLDbContext = rDnLDbContext;
Logger = logger;
}
#endregion
}
\ No newline at end of file
using IntegrationKSSS.WebService.Infrastructure.Repositories;
using IntegrationKSSS.WebService.Infrastructure.Models;
using IntegrationKSSS.WebService.Infrastructure.Repositories;
using Microsoft.AspNetCore.Authorization;
namespace IntegrationKSSS.WebService.Infrastructure.RequestHandlers
namespace IntegrationKSSS.WebService.Infrastructure.RequestHandlers;
internal static class RequestHandler
{
internal static class KsssFunctions
/// <summary>
/// KSSS data recording function
/// </summary>
/// <returns></returns>
#region Methods
internal static Func<IKsssRepository, Dictionary<string, string>, Task<IResult>> WriteKsssData()
{
internal static Func<IKsssRepository, Dictionary<string, string>, Task<IResult>> WriteKsssData()
return [Authorize] async (IKsssRepository ksssRepository, Dictionary<string, string> ksss) =>
{
return /*[Authorize] */async (IKsssRepository ksssRepository, Dictionary<string,string> ksss) =>
{
var message = await ksssRepository.WriteKsssData(ksss)/*.ConfigureAwait(false)*/;
if(message.Contains("Successfully"))
{
return Results.Ok(message);
}
else
{
return Results.BadRequest(message);
}
};
}
}
}
await ksssRepository.WriteKsssData(ksss);
return Results.Accepted("/api/ksss", MessageList.AcceptedDataPackage);
};
}
#endregion
}
\ No newline at end of file
namespace IntegrationKSSS.WebService.Infrastructure.RouteHandlers;
public interface IRouteHandler
{
#region Methods
void Register(WebApplication webApplication);
#endregion
}
\ No newline at end of file
using IntegrationKSSS.WebService.Infrastructure.RequestHandlers;
namespace IntegrationKSSS.WebService.Infrastructure.RouteHandlers
namespace IntegrationKSSS.WebService.Infrastructure.RouteHandlers;
public class RouteHandler : RouteHandlerBase, IRouteHandler
{
public interface IRouteHandler
{
void Register(WebApplication webApplication);
}
public abstract class KsssRouteHandlerBase
#region Methods
public void Register(WebApplication webApplication)
{
internal WebApplication WebApplication { get; set; }
WebApplication = webApplication;
Creators();
}
public class RouteHandler : KsssRouteHandlerBase, IRouteHandler
private void Creators()
{
public void Register(WebApplication webApplication)
{
WebApplication = webApplication;
Creators();
}
private void Creators()
{
WebApplication.MapPost("/api/ksss", KsssFunctions.WriteKsssData());
}
}
WebApplication.MapPost("/api/ksss", RequestHandler.WriteKsssData());
}
#endregion
}
namespace IntegrationKSSS.WebService.Infrastructure.RouteHandlers;
public abstract class RouteHandlerBase
{
#region Properties
internal WebApplication WebApplication { get; set; }
#endregion
}
\ No newline at end of file
using IntegrationKSSS.WebService.Infrastructure.Cryptography;
namespace IntegrationKSSS.WebService.Infrastructure.Services
namespace IntegrationKSSS.WebService.Infrastructure.Services;
public class AuthService : IAuthService
{
public interface IAuthService
#region Methods
public async Task<bool> Auth(string login, string password)
{
Task<bool> Auth(string login, string password);
}
public class AuthService : IAuthService
{
public async Task<bool> Auth(string login, string password)
{
string _login = "5WndfpUBeL21vPl1T52S2w==",
_password = "wK/ZViL6VAYL1FNYO10vLg==";
string _login = "5WndfpUBeL21vPl1T52S2w==",
_password = "wK/ZViL6VAYL1FNYO10vLg==";
return await Task.Run(() =>
(_login.DecryptString(AesConfiguration.Key, AesConfiguration.IV) == login &&
_password.DecryptString(AesConfiguration.Key, AesConfiguration.IV) == password) ?
true :
false);
}
}
}
return await Task.Run(() =>
(_login.DecryptString(AesConfiguration.Key, AesConfiguration.IV) == login &&
_password.DecryptString(AesConfiguration.Key, AesConfiguration.IV) == password) ?
true :
false);
}
#endregion
}
\ No newline at end of file
namespace IntegrationKSSS.WebService.Infrastructure.Services;
public interface IAuthService
{
#region Methods
Task<bool> Auth(string login, string password);
#endregion
}
......@@ -29,6 +29,12 @@
<ProjectReference Include="..\IntegrationKSSS\IntegrationKSSS.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="RnD.Model.EF">
<HintPath>..\..\..\..\Distr\OpcenterRDnL_9.1.0.0.3\Implementation\ABP\Opcenter_RDnL_V9.1.0.3_applied_best_practices\OpcenterRDnLLibrary_Builds\Siemens.OpcenterRDnLLibrary.Dependencies\RnD.Model.EF.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
......
......@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2023-01-26T11:17:24.0239724Z;True|2023-01-25T14:06:16.9243865+03:00;True|2023-01-25T14:00:39.9266437+03:00;True|2023-01-25T12:51:23.5799247+03:00;True|2023-01-25T12:35:08.8563117+03:00;False|2023-01-25T12:34:04.6686340+03:00;False|2023-01-25T12:33:57.8005398+03:00;False|2023-01-25T12:33:39.5203110+03:00;</History>
<History>True|2023-02-10T11:33:33.5625719Z;True|2023-02-09T18:01:25.0874999+03:00;True|2023-02-09T16:04:11.0766065+03:00;True|2023-01-26T14:17:24.0239724+03:00;True|2023-01-25T14:06:16.9243865+03:00;True|2023-01-25T14:00:39.9266437+03:00;True|2023-01-25T12:51:23.5799247+03:00;True|2023-01-25T12:35:08.8563117+03:00;False|2023-01-25T12:34:04.6686340+03:00;False|2023-01-25T12:33:57.8005398+03:00;False|2023-01-25T12:33:39.5203110+03:00;</History>
<LastFailureDetails />
<_PublishTargetUrl>C:\Bryzgalov\Projects\IntegrationKSSS\IntegrationKSSS.WebService\bin\Release\net6.0\publish\</_PublishTargetUrl>
</PropertyGroup>
......
......@@ -17,7 +17,8 @@
"NLog.Config": "4.7.15",
"NLog.Web.AspNetCore": "5.2.0",
"Newtonsoft.Json": "13.0.2",
"Swashbuckle.AspNetCore": "6.2.3"
"Swashbuckle.AspNetCore": "6.2.3",
"RnD.Model.EF": "9.1.0.0"
},
"runtime": {
"IntegrationKSSS.WebService.dll": {}
......@@ -804,6 +805,30 @@
"runtime": {
"IntegrationKSSS.dll": {}
}
},
"RnD.Model.EF/9.1.0.0": {
"runtime": {
"RnD.Model.EF.dll": {
"assemblyVersion": "9.1.0.0",
"fileVersion": "901.0.300.11"
}
}
},
"RnD.Common/9.1.0.0": {
"runtime": {
"RnD.Common.dll": {
"assemblyVersion": "9.1.0.0",
"fileVersion": "901.0.300.11"
}
}
},
"RDnL.Logger/9.1.0.0": {
"runtime": {
"RDnL.Logger.dll": {
"assemblyVersion": "9.1.0.0",
"fileVersion": "901.0.300.11"
}
}
}
}
},
......@@ -1377,6 +1402,21 @@
"type": "project",
"serviceable": false,
"sha512": ""
},
"RnD.Model.EF/9.1.0.0": {
"type": "reference",
"serviceable": false,
"sha512": ""
},
"RnD.Common/9.1.0.0": {
"type": "reference",
"serviceable": false,
"sha512": ""
},
"RDnL.Logger/9.1.0.0": {
"type": "reference",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment