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> 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 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 RunProfile(ImportProfile profile) { try { await channel.RunJobAsync(new RunJobRunJobRequest() { JobId = profile.JobId }); } catch (Exception ex) { logger.Error(ex); } } public async Task CreateProfile(ImportProfile profile) => await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Create); public async Task UpdateProfile(ImportProfile profile) => await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Update); public async Task DeleteProfile(ImportProfile profile) => await DoUpdateProfile(profile, UpdateProfileUpdateProfileRequest.UpdateProfileAction.Delete); private async Task 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; } } } }