16-12-2022
This commit is contained in:
93
ECM.JobRunner.Web/Data/ImportProfileService.cs
Normal file
93
ECM.JobRunner.Web/Data/ImportProfileService.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using DigitalData.Modules.Logging;
|
||||
using ECM.JobRunner.Common.JobRunnerReference;
|
||||
|
||||
|
||||
namespace ECM.JobRunner.Web.Data
|
||||
{
|
||||
public class ImportProfileService
|
||||
{
|
||||
private readonly Logger logger;
|
||||
private readonly IEDMIServiceChannel channel;
|
||||
|
||||
public ImportProfileService(LoggingService Logging, WcfService Wcf)
|
||||
{
|
||||
logger = Logging.LogConfig.GetLogger();
|
||||
channel = Wcf.Channel;
|
||||
}
|
||||
|
||||
public async Task<List<ImportProfile>> GetProfiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
var resp = await channel.GetJobConfigAsync();
|
||||
|
||||
if (resp == null) return new();
|
||||
if (resp.OK == false) return new();
|
||||
|
||||
var profiles = resp.ProfileDefinitions.ImportProfiles.ToList();
|
||||
return profiles;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return new();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ImportProfile?> GetProfile(int pProfileId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var resp = await channel.GetJobConfigAsync();
|
||||
|
||||
if (resp == null) return null;
|
||||
if (resp.OK == false) return null;
|
||||
|
||||
var jobs = resp.JobDefinitions.ToList();
|
||||
var profiles = resp.ProfileDefinitions.ImportProfiles.ToList();
|
||||
|
||||
return profiles.
|
||||
Where(p => p.Id == pProfileId).
|
||||
SingleOrDefault();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<bool> CreateProfile(ImportProfile profile) =>
|
||||
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Create);
|
||||
|
||||
public async Task<bool> UpdateProfile(ImportProfile profile) =>
|
||||
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Update);
|
||||
|
||||
public async Task<bool> DeleteProfile(ImportProfile profile) =>
|
||||
await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Delete);
|
||||
|
||||
private async Task<bool> DoUpdateProfile(ImportProfile profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction action)
|
||||
{
|
||||
try
|
||||
{
|
||||
var req = new UpdateProfileUpdateProfileRequest()
|
||||
{
|
||||
ImportProfile = profile,
|
||||
Action = action
|
||||
};
|
||||
var resp = await channel.UpdateProfileAsync(req);
|
||||
|
||||
if (resp == null) return false;
|
||||
if (resp.OK == false) return false;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user