diff --git a/PARR.AIHIT/AIHIT/Syncher.cs b/PARR.AIHIT/AIHIT/Syncher.cs index 126636a6..5d128395 100644 --- a/PARR.AIHIT/AIHIT/Syncher.cs +++ b/PARR.AIHIT/AIHIT/Syncher.cs @@ -25,7 +25,7 @@ namespace PARR.AIHIT private readonly IApplicationTypeService appTypeService; private readonly IApplicationInHostService appInHostService; - public List AppTypes { get; private set; } + public List AppTypes { get; private set; } = new List(); public Syncher( ILogger logger, @@ -332,7 +332,7 @@ namespace PARR.AIHIT { if (string.IsNullOrEmpty(appName)) return null; - var existApp = await appService.GetByName(appName); + var existApp = await appService.GetByNameAsync(appName); if (existApp != null) return existApp; diff --git a/PARR.DAL/Extensions/GeneralExtesions.cs b/PARR.DAL/Extensions/GeneralExtesions.cs new file mode 100644 index 00000000..f9d106b6 --- /dev/null +++ b/PARR.DAL/Extensions/GeneralExtesions.cs @@ -0,0 +1,30 @@ +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Unicode; + +namespace PARR.DAL.Extensions +{ + public static class GeneralExtesions + { + /// + /// Преобразует объект в Json, с учетом Cyrillic + /// + /// + /// + public static string? ToJson(this object value) + { + if (value == null) + return null; + + try + { + return JsonSerializer.Serialize(value, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All, UnicodeRanges.Cyrillic) }); ; + } + catch// (Exception ex) + { + // todo: писать лог??? или и так пойдет + return null; + } + } + } +} diff --git a/PARR.DAL/Models/Application.cs b/PARR.DAL/Models/Application.cs index d060c032..9df7737b 100644 --- a/PARR.DAL/Models/Application.cs +++ b/PARR.DAL/Models/Application.cs @@ -1,11 +1,6 @@ using PARR.DAL.Models.Base; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PARR.DAL.Models { @@ -26,4 +21,3 @@ namespace PARR.DAL.Models public ICollection ApplicationsInHosts { get; set; } = new HashSet(); } } -} diff --git a/PARR.DAL/Models/ApplicationInHost.cs b/PARR.DAL/Models/ApplicationInHost.cs index deb6710d..0ca7c80a 100644 --- a/PARR.DAL/Models/ApplicationInHost.cs +++ b/PARR.DAL/Models/ApplicationInHost.cs @@ -1,10 +1,5 @@ using PARR.DAL.Models.Base; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PARR.DAL.Models { diff --git a/PARR.DAL/Models/Host.cs b/PARR.DAL/Models/Host.cs index fcc116ad..21b0940e 100644 --- a/PARR.DAL/Models/Host.cs +++ b/PARR.DAL/Models/Host.cs @@ -11,7 +11,7 @@ namespace PARR.DAL.Models public Guid Id { get; set; } public DateTimeOffset DateCreated { get; set; } public DateTimeOffset? DateModified { get; set; } - public string HostName { get; set; } + public string? HostName { get; set; } public required string IP { get; set; } public string? RegionalEK { get; set; } public string? LinkEK { get; set; } diff --git a/PARR.DAL/ParrDalInstaller.cs b/PARR.DAL/ParrDalInstaller.cs index b8e706fc..7a854d28 100644 --- a/PARR.DAL/ParrDalInstaller.cs +++ b/PARR.DAL/ParrDalInstaller.cs @@ -16,8 +16,10 @@ namespace PARR.DAL ); services.AddTransient(); - //services.AddTransient(); - //services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + //services.AddTransient(); } } diff --git a/PARR.DAL/Services/Implementations/ApplicationInHostService.cs b/PARR.DAL/Services/Implementations/ApplicationInHostService.cs new file mode 100644 index 00000000..52d87dd1 --- /dev/null +++ b/PARR.DAL/Services/Implementations/ApplicationInHostService.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using PARR.DAL.Context; +using PARR.DAL.Models; +using PARR.DAL.Services.Abstracts; +using PARR.DAL.Services.Interfaces; + +namespace PARR.DAL.Services.Implementations +{ + internal class ApplicationInHostService : BaseService, IApplicationInHostService + { + private readonly DataContext dataContext; + private readonly ILogger logger; + + public ApplicationInHostService(DataContext dataContext, ILogger logger) : base(logger) + { + this.dataContext = dataContext; + this.logger = logger; + } + + protected override DbSet EntitySet => dataContext.ApplicationsInHosts; + + protected override DataContext EntitiContext => dataContext; + } +} diff --git a/PARR.DAL/Services/Implementations/ApplicationService.cs b/PARR.DAL/Services/Implementations/ApplicationService.cs new file mode 100644 index 00000000..bdfae542 --- /dev/null +++ b/PARR.DAL/Services/Implementations/ApplicationService.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using PARR.DAL.Context; +using PARR.DAL.Models; +using PARR.DAL.Services.Abstracts; +using PARR.DAL.Services.Interfaces; + +namespace PARR.DAL.Services.Implementations +{ + internal class ApplicationService : BaseService, IApplicationService + { + private readonly DataContext dataContext; + private readonly ILogger logger; + + public ApplicationService(DataContext dataContext, ILogger logger) : base(logger) + { + this.dataContext = dataContext; + this.logger = logger; + } + + protected override DbSet EntitySet => dataContext.Applications; + + protected override DataContext EntitiContext => dataContext; + + public async Task GetByNameAsync(string appName) + { + return await EntitySet.FirstOrDefaultAsync(t => t.Name.ToLower() == appName.Trim().ToLower()); + } + } +} diff --git a/PARR.DAL/Services/Implementations/ApplicationTypeService.cs b/PARR.DAL/Services/Implementations/ApplicationTypeService.cs new file mode 100644 index 00000000..f0f73ad2 --- /dev/null +++ b/PARR.DAL/Services/Implementations/ApplicationTypeService.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using PARR.DAL.Context; +using PARR.DAL.Models; +using PARR.DAL.Services.Abstracts; +using PARR.DAL.Services.Interfaces; + +namespace PARR.DAL.Services.Implementations +{ + internal class ApplicationTypeService : BaseService, IApplicationTypeService + { + private readonly DataContext dataContext; + private readonly ILogger logger; + + public ApplicationTypeService(DataContext dataContext, ILogger logger) : base(logger) + { + this.dataContext = dataContext; + this.logger = logger; + } + + protected override DbSet EntitySet => dataContext.ApplicationTypes; + + protected override DataContext EntitiContext => dataContext; + } +} diff --git a/PARR.DAL/Services/Implementations/HostService.cs b/PARR.DAL/Services/Implementations/HostService.cs index 3bacc878..2d18e53d 100644 --- a/PARR.DAL/Services/Implementations/HostService.cs +++ b/PARR.DAL/Services/Implementations/HostService.cs @@ -21,21 +21,38 @@ namespace PARR.DAL.Services.Implementations this.logger = logger; } - public async Task GetHostWithAppsAsync(string IP, string RegionalEK)//TODO + public async Task GetHostWithAppsAsync(string IP, string RegionalEK) { - try - { - var host = await EntitySet.FirstAsync(h => h.IP == IP && h.RegionalEK == RegionalEK); - return host; - } - catch - { - logger.LogInformation($"Не найден узел с IP адресом {IP} и региональным ЭК {RegionalEK}"); - return null; - } + + //try + //{ + // var host = await EntitySet.FirstAsync(h => h.IP == IP && h.RegionalEK == RegionalEK); + // return host; + //} + //catch + //{ + // logger.LogInformation($"Не найден узел с IP адресом {IP} и региональным ЭК {RegionalEK}"); + // return null; + //} + return await EntitySet + .Include(t => t.ApplicationsInHosts).ThenInclude(a => a.Application).ThenInclude(t => t.ApplicationType) + .FirstOrDefaultAsync(h => h.IP == IP && h.RegionalEK == RegionalEK); } - //public async Task GetHostByRegionalEKAsync(string RegionalEK) + public async Task GetHostWithAppsAsync(string IP, string linkEK, string regionalEK) + { + return await EntitySet + .Include(t => t.ApplicationsInHosts).ThenInclude(a => a.Application).ThenInclude(t => t.ApplicationType) + .FirstOrDefaultAsync(h => h.IP == IP && h.LinkEK == linkEK && h.RegionalEK == regionalEK); + } + + + public async Task GetHostByIPAndRegionalEKAsync(string IP, string RegionalEK) + { + return await EntitySet.FirstOrDefaultAsync(h => h.IP == IP && h.RegionalEK == RegionalEK); + } + + //public async Task GetHostByRegionalEKAsync(string RegionalEK)И //{ // try // { diff --git a/PARR.DAL/Services/Interfaces/IApplicationInHostService.cs b/PARR.DAL/Services/Interfaces/IApplicationInHostService.cs new file mode 100644 index 00000000..c1dc02b3 --- /dev/null +++ b/PARR.DAL/Services/Interfaces/IApplicationInHostService.cs @@ -0,0 +1,9 @@ +using PARR.DAL.Models; +using PARR.DAL.Services.Interfaces.Base; + +namespace PARR.DAL.Services.Interfaces +{ + public interface IApplicationInHostService : IBaseService + { + } +} diff --git a/PARR.DAL/Services/Interfaces/IApplicationService.cs b/PARR.DAL/Services/Interfaces/IApplicationService.cs new file mode 100644 index 00000000..4834fc61 --- /dev/null +++ b/PARR.DAL/Services/Interfaces/IApplicationService.cs @@ -0,0 +1,10 @@ +using PARR.DAL.Models; +using PARR.DAL.Services.Interfaces.Base; + +namespace PARR.DAL.Services.Interfaces +{ + public interface IApplicationService : IBaseService + { + Task GetByNameAsync(string appName); + } +} diff --git a/PARR.DAL/Services/Interfaces/IApplicationTypeService.cs b/PARR.DAL/Services/Interfaces/IApplicationTypeService.cs new file mode 100644 index 00000000..93f6622e --- /dev/null +++ b/PARR.DAL/Services/Interfaces/IApplicationTypeService.cs @@ -0,0 +1,9 @@ +using PARR.DAL.Models; +using PARR.DAL.Services.Interfaces.Base; + +namespace PARR.DAL.Services.Interfaces +{ + public interface IApplicationTypeService : IBaseService + { + } +} diff --git a/PARR.DAL/Services/Interfaces/IHostService.cs b/PARR.DAL/Services/Interfaces/IHostService.cs index e1775b8e..fc7694c4 100644 --- a/PARR.DAL/Services/Interfaces/IHostService.cs +++ b/PARR.DAL/Services/Interfaces/IHostService.cs @@ -6,6 +6,7 @@ namespace PARR.DAL.Services.Interfaces public interface IHostService : IBaseService { Task GetHostByIPAndRegionalEKAsync(string IP, string RegionalEK); + Task GetHostWithAppsAsync(string IP, string linkEK, string regionalEK); //Task GetHostByRegionalEKAsync(string LinkEK); //Task UpdateAsync(Host host); }