2023-06-01 12:30:38 +10:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using PARR.DAL.Context;
|
2023-08-14 15:24:57 +10:00
|
|
|
|
using PARR.DAL.Models;
|
2023-06-01 12:30:38 +10:00
|
|
|
|
using PARR.DAL.Services.Abstracts;
|
|
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PARR.DAL.Services.Implementations
|
|
|
|
|
|
{
|
2023-08-14 15:24:57 +10:00
|
|
|
|
internal class HostService : BaseService<Host>, IHostService
|
2023-06-01 12:30:38 +10:00
|
|
|
|
{
|
|
|
|
|
|
private readonly DataContext dataContext;
|
|
|
|
|
|
private readonly ILogger<HostService> logger;
|
|
|
|
|
|
|
2023-08-14 15:24:57 +10:00
|
|
|
|
protected override DbSet<Host> EntitySet => dataContext.Hosts;
|
2023-06-01 12:30:38 +10:00
|
|
|
|
|
|
|
|
|
|
protected override DataContext EntitiContext => dataContext;
|
|
|
|
|
|
public HostService(DataContext dataContext, ILogger<HostService> logger) : base(logger)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.dataContext = dataContext;
|
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
|
}
|
2023-06-05 16:28:36 +10:00
|
|
|
|
|
2023-08-14 15:24:57 +10:00
|
|
|
|
public async Task<Host?> GetHostWithAppsAsync(string IP)
|
2023-06-05 16:28:36 +10:00
|
|
|
|
{
|
2023-06-13 15:04:47 +10:00
|
|
|
|
|
|
|
|
|
|
//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)
|
2023-06-20 12:29:58 +10:00
|
|
|
|
.AsSplitQuery()
|
2023-08-14 15:24:57 +10:00
|
|
|
|
.FirstOrDefaultAsync(h => h.IP == IP);
|
2023-06-05 16:28:36 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-13 15:04:47 +10:00
|
|
|
|
//public async Task<Host?> GetHostByRegionalEKAsync(string RegionalEK)И
|
2023-06-05 16:28:36 +10:00
|
|
|
|
//{
|
|
|
|
|
|
// try
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var host = await EntitySet.FirstAsync(h => h.RegionalEK == RegionalEK);
|
|
|
|
|
|
// return host;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// catch
|
|
|
|
|
|
// {
|
|
|
|
|
|
// logger.LogInformation($"Не найден узел с региональным ЭК {RegionalEK}");
|
|
|
|
|
|
// return null;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//public async Task<bool> UpdateAsync(Host host)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var orig = await EntitySet.FirstAsync(h => h.IP == host.IP);
|
|
|
|
|
|
// if (orig == null)
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
|
|
|
|
// orig.DateModified = DateTimeOffset.UtcNow;
|
|
|
|
|
|
// orig.HostName = host.HostName;
|
|
|
|
|
|
// orig.RegionalEK = host.RegionalEK;
|
|
|
|
|
|
// orig.LinkEK = host.LinkEK;
|
|
|
|
|
|
// orig.Status = host.Status;
|
|
|
|
|
|
// orig.WorkGroup = host.WorkGroup;
|
|
|
|
|
|
// orig.Responsible = host.Responsible;
|
|
|
|
|
|
// orig.OS = host.OS;
|
|
|
|
|
|
// orig.DB = host.DB;
|
|
|
|
|
|
// orig.APP = host.APP;
|
|
|
|
|
|
|
|
|
|
|
|
// if (!await CommitAsync())
|
|
|
|
|
|
// {
|
|
|
|
|
|
// logger.LogError($"Ошибка обновления узла {host.IP}");
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// logger.LogInformation($"Обновлен узел {host.IP}");
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
2023-06-01 12:30:38 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|