2025-04-11 02:31:29 -05:00
|
|
|
using AutoMapper;
|
2025-04-10 19:45:41 -05:00
|
|
|
using LANCommander.SDK.Enums;
|
2025-03-30 21:05:48 -05:00
|
|
|
using LANCommander.SDK.Models.Manifest;
|
2025-07-27 17:51:50 -05:00
|
|
|
using LANCommander.Server.ImportExport.Exceptions;
|
|
|
|
|
using LANCommander.Server.ImportExport.Models;
|
|
|
|
|
using LANCommander.Server.Services;
|
2025-03-30 21:05:48 -05:00
|
|
|
|
2025-07-27 17:51:50 -05:00
|
|
|
namespace LANCommander.Server.ImportExport.Importers;
|
2025-03-30 21:05:48 -05:00
|
|
|
|
2025-04-10 19:45:41 -05:00
|
|
|
public class ServerHttpPathImporter(
|
2025-04-11 02:31:29 -05:00
|
|
|
IMapper mapper,
|
2025-04-09 19:44:07 -05:00
|
|
|
ServerHttpPathService serverHttpPathService,
|
2025-07-19 17:39:55 -05:00
|
|
|
ServerService serverService) : BaseImporter<ServerHttpPath, Data.Models.ServerHttpPath>
|
2025-03-30 21:05:48 -05:00
|
|
|
{
|
2025-07-19 17:39:55 -05:00
|
|
|
public override async Task<ImportItemInfo> GetImportInfoAsync(ServerHttpPath record)
|
2025-04-12 02:37:14 -05:00
|
|
|
{
|
|
|
|
|
return new ImportItemInfo
|
|
|
|
|
{
|
2025-08-01 02:27:06 -05:00
|
|
|
Type = ImportExportRecordType.ServerHttpPath,
|
2025-04-12 02:37:14 -05:00
|
|
|
Name = record.Path,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
public override bool CanImport(ServerHttpPath record) => ImportContext.DataRecord is Data.Models.Server;
|
2025-03-30 21:05:48 -05:00
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
public override async Task<Data.Models.ServerHttpPath> AddAsync(ServerHttpPath record)
|
2025-04-09 19:44:07 -05:00
|
|
|
{
|
2025-03-30 21:05:48 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var serverHttpPath = new Data.Models.ServerHttpPath
|
|
|
|
|
{
|
|
|
|
|
LocalPath = record.LocalPath,
|
|
|
|
|
Path = record.Path,
|
2025-07-19 17:39:55 -05:00
|
|
|
Server = await serverService.FirstOrDefaultAsync(s => s.Name == (ImportContext.DataRecord as Data.Models.Server).Name),
|
2025-03-30 21:05:48 -05:00
|
|
|
};
|
|
|
|
|
|
2025-04-09 19:44:07 -05:00
|
|
|
serverHttpPath = await serverHttpPathService.AddAsync(serverHttpPath);
|
2025-03-30 21:05:48 -05:00
|
|
|
|
|
|
|
|
return serverHttpPath;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new ImportSkippedException<ServerHttpPath>(record, "An unknown error occured while importing server console", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
public override async Task<Data.Models.ServerHttpPath> UpdateAsync(ServerHttpPath record)
|
2025-03-30 21:05:48 -05:00
|
|
|
{
|
2025-04-09 19:44:07 -05:00
|
|
|
var existing = await serverHttpPathService.FirstOrDefaultAsync(p => p.Path == record.Path);
|
2025-03-30 21:05:48 -05:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
existing.LocalPath = record.LocalPath;
|
|
|
|
|
existing.Path = record.Path;
|
2025-04-09 19:44:07 -05:00
|
|
|
existing.Server =
|
|
|
|
|
await serverService.FirstOrDefaultAsync(
|
2025-07-19 17:39:55 -05:00
|
|
|
s => s.Name == (ImportContext.DataRecord as Data.Models.Server).Name);
|
2025-03-30 21:05:48 -05:00
|
|
|
|
2025-04-09 19:44:07 -05:00
|
|
|
existing = await serverHttpPathService.UpdateAsync(existing);
|
2025-03-30 21:05:48 -05:00
|
|
|
|
|
|
|
|
return existing;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new ImportSkippedException<ServerHttpPath>(record, "An unknown error occured while importing server console", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-19 17:39:55 -05:00
|
|
|
public override async Task<bool> ExistsAsync(ServerHttpPath record)
|
2025-03-30 21:05:48 -05:00
|
|
|
{
|
2025-04-09 19:44:07 -05:00
|
|
|
return await serverHttpPathService
|
|
|
|
|
.Include(p => p.Server)
|
2025-07-19 17:39:55 -05:00
|
|
|
.ExistsAsync(p => p.Path == record.Path && p.Server.Name == (ImportContext.DataRecord as Data.Models.Server).Name);
|
2025-03-30 21:05:48 -05:00
|
|
|
}
|
|
|
|
|
}
|