Adding
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
||||
using LCU.WebApps.Internal.DispatcherManager.Configurations;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.WebApps.Internal.DispatcherManager.Services;
|
||||
|
||||
public class CleanUpJobSettingService
|
||||
{
|
||||
private readonly DispatcherApiConfiguration _dispatcherApiConfiguration;
|
||||
private readonly IGetRequest _getRequest;
|
||||
|
||||
public CleanUpJobSettingService(IGetRequest getRequest,
|
||||
DispatcherApiConfiguration dispatcherApiConfiguration)
|
||||
{
|
||||
_getRequest = getRequest;
|
||||
_dispatcherApiConfiguration = dispatcherApiConfiguration;
|
||||
}
|
||||
|
||||
public async Task<List<CleanUpJobSetting>> GetAllCleanUpJobSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _getRequest.AsyncWithNewton<List<CleanUpJobSetting>>(_dispatcherApiConfiguration.GetAllCleanUpJobSettingEndpointUrl);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error getting CleanUpJobSettings.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
||||
using LCU.Library.Internal.Security.Service;
|
||||
using LCU.WebApps.Internal.DispatcherManager.Configurations;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.WebApps.Internal.DispatcherManager.Services;
|
||||
|
||||
public class ExecutionMessageService
|
||||
{
|
||||
private readonly DispatcherApiConfiguration _dispatcherApiConfiguration;
|
||||
private readonly IAzureAdAuthorizationService _azureAdAuthorizationService;
|
||||
private readonly IPostRequest _postRequest;
|
||||
|
||||
public ExecutionMessageService(IAzureAdAuthorizationService azureAdAuthorizationService,
|
||||
DispatcherApiConfiguration dispatcherApiConfiguration,
|
||||
IPostRequest postRequest)
|
||||
{
|
||||
_dispatcherApiConfiguration = dispatcherApiConfiguration;
|
||||
_azureAdAuthorizationService = azureAdAuthorizationService;
|
||||
_postRequest = postRequest;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveExecutionMessages(List<ExecutionMessage> executionMessages)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = _dispatcherApiConfiguration.ExecutionMessageControllerEndpointUrl + "?request=" + executionMessages;
|
||||
|
||||
await _postRequest.Async<List<ExecutionMessage>>(new Uri(url), executionMessages);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error saving execution messaging.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> SaveExecutionMessages(int workItemExecutionId, string ExecutionMessageType)
|
||||
{
|
||||
var messageList = BuildWorkItemExecutionMessages(workItemExecutionId, ExecutionMessageType);
|
||||
return await SaveExecutionMessages(messageList);
|
||||
}
|
||||
|
||||
public async Task<bool> SaveExecutionMessages(Job job, string ExecutionMessageType)
|
||||
{
|
||||
var workItemExecution = job.WorkItems.FirstOrDefault((WorkItem workItem) => workItem.CurrentWorkItemExecution != null);
|
||||
|
||||
//if there is not a current work item execution do not write a message
|
||||
if (workItemExecution?.CurrentWorkItemExecution == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var messageList = BuildWorkItemExecutionMessages(workItemExecution.CurrentWorkItemExecution.WorkItemExecutionId, ExecutionMessageType);
|
||||
return await SaveExecutionMessages(messageList);
|
||||
}
|
||||
|
||||
private List<ExecutionMessage> BuildWorkItemExecutionMessages(int workItemExecutionId, string ExecutionMessageType)
|
||||
{
|
||||
var messageList = new List<ExecutionMessage>()
|
||||
{
|
||||
new ExecutionMessage(workItemExecutionId, ExecutionMessageType)
|
||||
{
|
||||
User = _azureAdAuthorizationService.GetUserName(),
|
||||
MessageDate = DateTime.Now,
|
||||
}
|
||||
};
|
||||
return messageList;
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Blazored.LocalStorage;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
|
||||
namespace LCU.WebApps.Internal.DispatcherManager.Services;
|
||||
|
||||
public class FilterService
|
||||
{
|
||||
private readonly ILocalStorageService _localStorageService;
|
||||
private const string StorageItemName = "JobFilter";
|
||||
|
||||
public FilterService(ILocalStorageService localStorageService)
|
||||
{
|
||||
_localStorageService = localStorageService;
|
||||
}
|
||||
|
||||
public async Task<Filter> GetFilterItemAsync()
|
||||
{
|
||||
return await _localStorageService.GetItemAsync<Filter>(StorageItemName);
|
||||
}
|
||||
|
||||
public async Task SetFilter(Filter jobFilter)
|
||||
{
|
||||
await _localStorageService.SetItemAsync(StorageItemName, jobFilter);
|
||||
}
|
||||
|
||||
public Filter AddTagFiltering(Filter filter, IList<Tag> tags)
|
||||
{
|
||||
if (tags == null || !tags.Any())
|
||||
{
|
||||
filter.TagIdFilters = null;
|
||||
return filter;
|
||||
}
|
||||
|
||||
filter.TagIdFilters = new List<int>();
|
||||
List<int> tagIds = tags.Select(Tag => Tag.TagId).ToList();
|
||||
filter.TagIdFilters.AddRange(tagIds);
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
public Filter AddStatusFiltering(Filter filter, IList<JobStatus> statuses)
|
||||
{
|
||||
if (statuses == null || !statuses.Any())
|
||||
{
|
||||
filter.StatusFilters = null;
|
||||
return filter;
|
||||
}
|
||||
|
||||
var statusFilterList = new List<StatusFilter>();
|
||||
foreach (var type in statuses)
|
||||
{
|
||||
var status = new StatusFilter()
|
||||
{
|
||||
JobStatus = type,
|
||||
IsEnabled = true
|
||||
};
|
||||
statusFilterList.Add(status);
|
||||
};
|
||||
|
||||
filter.StatusFilters = statusFilterList;
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
public List<JobStatus> AddDefaultStatusFiltering(Filter filter)
|
||||
{
|
||||
if (filter == null || filter.StatusFilters == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var statusTypeList = new List<JobStatus>();
|
||||
foreach (var type in filter.StatusFilters)
|
||||
{
|
||||
statusTypeList.Add(type.JobStatus);
|
||||
};
|
||||
|
||||
return statusTypeList;
|
||||
}
|
||||
|
||||
public List<Tag> AddDefaultTags(List<Tag> tags, Filter filter)
|
||||
{
|
||||
if (filter == null || filter.TagIdFilters == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var tagList = new List<Tag>();
|
||||
foreach (var tagId in filter.TagIdFilters)
|
||||
{
|
||||
var tagName = tags.Where(t => t.TagId == tagId).FirstOrDefault();
|
||||
tagList.Add(tagName);
|
||||
};
|
||||
|
||||
return tagList;
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
||||
using LCU.WebApps.Internal.DispatcherManager.Configurations;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
namespace LCU.WebApps.Internal.DispatcherManager.Services;
|
||||
|
||||
public class JobService
|
||||
{
|
||||
private readonly DispatcherApiConfiguration _dispatcherApiConfiguration;
|
||||
private readonly IPostRequest _postRequest;
|
||||
private readonly IGetRequest _getRequest;
|
||||
private readonly IPutRequest _putRequest;
|
||||
private readonly IDeleteRequest _deleteRequest;
|
||||
|
||||
public JobService(DispatcherApiConfiguration dispatcherApiConfiguration,
|
||||
IPostRequest postRequest,
|
||||
IGetRequest getRequest,
|
||||
IPutRequest putRequest,
|
||||
IDeleteRequest deleteRequest)
|
||||
{
|
||||
_dispatcherApiConfiguration = dispatcherApiConfiguration;
|
||||
_postRequest = postRequest;
|
||||
_getRequest = getRequest;
|
||||
_putRequest = putRequest;
|
||||
_deleteRequest = deleteRequest;
|
||||
}
|
||||
|
||||
public async Task<PagedResponse<Job>> GetFilteredJobs(Filter filter)
|
||||
{
|
||||
var jobs = new PagedResponse<Job>();
|
||||
try
|
||||
{
|
||||
jobs = await _postRequest.AsyncWithNewton<Filter, PagedResponse<Job>>(new Uri(_dispatcherApiConfiguration.GetFilteredJobsEndpointUrl), filter);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error getting jobs.");
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
public async Task<List<Job>> GetJobs()
|
||||
{
|
||||
var jobs = new List<Job>();
|
||||
try
|
||||
{
|
||||
jobs = await _getRequest.AsyncWithNewton<List<Job>>(_dispatcherApiConfiguration.JobControllerEndpointUrl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error getting jobs.");
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
public async Task<Job> RunJobNow(Job job)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _putRequest.AsyncWithNewton<Job, Job>(_dispatcherApiConfiguration.RunJobNowEndpointUrl, job);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error Setting Job to Now.");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<Job> DeactivateJob(Job job)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _putRequest.AsyncWithNewton<Job, Job>(_dispatcherApiConfiguration.DeactivateJobEndpointUrl, job);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error Deactivating Job.");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<Job> RescheduleJob(Job job)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _putRequest.AsyncWithNewton<Job, Job>(_dispatcherApiConfiguration.RescheduleJobEndpointUrl, job);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error Rescheduling Job.");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteJob(int jobId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = _dispatcherApiConfiguration.JobControllerEndpointUrl + "?jobId=" + jobId;
|
||||
|
||||
await _deleteRequest.Async(url);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error deleting job.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
using LCU.WebApps.Internal.DispatcherManager.Helpers;
|
||||
using LCU.WebApps.Internal.DispatcherManager.Models;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.DispatcherModels.Enums;
|
||||
using LCU.Api.Internal.DispatcherSharedLib.BuilderServices;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Library.Internal.Security.Service;
|
||||
namespace LCU.WebApps.Internal.DispatcherManager.Services;
|
||||
|
||||
public class JobStateService
|
||||
{
|
||||
private readonly IRequestBuilderService _requestBuilderService;
|
||||
private readonly IAzureAdAuthorizationService AzureAdAuthorizationService;
|
||||
private const string DispatcherManager = "Dispatcher Manager";
|
||||
private int KeyCount;
|
||||
public event Action OnChange;
|
||||
public JobDetails JobDetails { get; set; }
|
||||
public bool Scheduled { get; set; }
|
||||
public bool SkipHolidays { get; set; }
|
||||
public string ActionTypeSelected { get; set; }
|
||||
public IList<Tag> TagSelectedList { get; set; }
|
||||
public List<WorkItemComponent> WorkItemComponents { get; set; }
|
||||
public Job EditingJob { get; set; }
|
||||
|
||||
public JobStateService(IRequestBuilderService requestBuilderService,
|
||||
IAzureAdAuthorizationService azureAdAuthorizationService)
|
||||
{
|
||||
WorkItemComponents = new List<WorkItemComponent>();
|
||||
JobDetails = new JobDetails();
|
||||
KeyCount = 0;
|
||||
ActionTypeSelected = "";
|
||||
Scheduled = false;
|
||||
EditingJob = null;
|
||||
_requestBuilderService = requestBuilderService;
|
||||
AzureAdAuthorizationService = azureAdAuthorizationService;
|
||||
}
|
||||
|
||||
private void NotifyStateChanged() => OnChange?.Invoke();
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
JobDetails = new JobDetails
|
||||
{
|
||||
ErrorRecipients = new List<string>()
|
||||
};
|
||||
WorkItemComponents = new List<WorkItemComponent>();
|
||||
TagSelectedList = new List<Tag>();
|
||||
ActionTypeSelected = "";
|
||||
Scheduled = false;
|
||||
SkipHolidays = false;
|
||||
KeyCount = 0;
|
||||
EditingJob = null;
|
||||
NotifyStateChanged();
|
||||
}
|
||||
|
||||
public void MapJobToJobState()
|
||||
{
|
||||
if (EditingJob == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MapEditingJobToJobDetails();
|
||||
|
||||
foreach (var workItem in EditingJob.WorkItems.OrderBy(wi => wi.Order))
|
||||
{
|
||||
AddExistingWorkItem(workItem);
|
||||
}
|
||||
|
||||
ActionTypeSelected = "";
|
||||
Scheduled = !string.IsNullOrEmpty(JobDetails.CronSchedule);
|
||||
SkipHolidays = JobDetails.SkipHolidays;
|
||||
NotifyStateChanged();
|
||||
}
|
||||
|
||||
public void MapEditingJobToJobDetails()
|
||||
{
|
||||
JobDetails.JobId = EditingJob.JobId;
|
||||
JobDetails.Name = EditingJob.Name;
|
||||
JobDetails.RequestingApplication = EditingJob.RequestingApplication;
|
||||
JobDetails.Description = EditingJob.Description;
|
||||
JobDetails.CronSchedule = EditingJob.CronSchedule;
|
||||
JobDetails.NextRunTime = EditingJob.NextRunTime;
|
||||
JobDetails.SkipHolidays = EditingJob.SkipHolidays;
|
||||
JobDetails.CreatedBy = EditingJob.CreatedBy;
|
||||
JobDetails.CreatedAt = EditingJob.CreatedAt;
|
||||
JobDetails.ModifiedBy = EditingJob.ModifiedBy;
|
||||
JobDetails.ModifiedDate = EditingJob.ModifiedDate;
|
||||
JobDetails.ErrorRecipients = EditingJob.JobErrorRecipients.Select(jer => jer.Recipient).ToList();
|
||||
JobDetails.JobTags = EditingJob.JobTags.ToList();
|
||||
}
|
||||
|
||||
public void AddExistingWorkItem(WorkItem workItem)
|
||||
{
|
||||
ActionTypeSelected = Enum.GetName(typeof(ActionType), workItem.ActionType);
|
||||
var request = JsonConvert.DeserializeObject(workItem.SerializedPayload,
|
||||
_requestBuilderService.GetDispatcherTypeByString(ActionTypeSelected));
|
||||
|
||||
var workItemComponent = new WorkItemComponent(KeyCount, ActionTypeSelected, request)
|
||||
{
|
||||
WorkItemDetails = new WorkItemDetails()
|
||||
};
|
||||
workItemComponent.WorkItemDetails.WorkItemId = workItem.WorkItemId;
|
||||
workItemComponent.WorkItemDetails.Name = workItem.Name;
|
||||
workItemComponent.WorkItemDetails.Description = workItem.Description;
|
||||
workItemComponent.WorkItemDetails.CancelJobOnFailure = workItem.CancelJobOnFailure;
|
||||
workItemComponent.WorkItemDetails.CancelJobLimit = workItem.CancelJobLimit;
|
||||
WorkItemComponents.Add(workItemComponent);
|
||||
KeyCount++;
|
||||
}
|
||||
|
||||
public void Add()
|
||||
{
|
||||
var type = _requestBuilderService.GetDispatcherTypeByString(ActionTypeSelected);
|
||||
var request = Activator.CreateInstance(type);
|
||||
AddWorkItemState(request);
|
||||
}
|
||||
|
||||
private void AddWorkItemState(object item)
|
||||
{
|
||||
var workItemComponent = new WorkItemComponent(KeyCount, ActionTypeSelected, item)
|
||||
{
|
||||
WorkItemDetails = new WorkItemDetails()
|
||||
};
|
||||
WorkItemComponents.Add(workItemComponent);
|
||||
KeyCount++;
|
||||
NotifyStateChanged();
|
||||
}
|
||||
|
||||
private List<JobTag> BuildJobTags()
|
||||
{
|
||||
var jobTagList = new List<JobTag>();
|
||||
foreach (var tag in TagSelectedList)
|
||||
{
|
||||
var jobTag = new JobTag
|
||||
{
|
||||
Tag = null,
|
||||
TagId = tag.TagId,
|
||||
JobId = JobDetails.JobId
|
||||
};
|
||||
jobTagList.Add(jobTag);
|
||||
}
|
||||
return jobTagList;
|
||||
}
|
||||
|
||||
public void Remove(WorkItemComponent toRemove)
|
||||
{
|
||||
WorkItemComponents.Remove(toRemove);
|
||||
NotifyStateChanged();
|
||||
}
|
||||
|
||||
public int GetIndex(WorkItemComponent item)
|
||||
{
|
||||
return WorkItemComponents.FindIndex(a => a == item);
|
||||
}
|
||||
|
||||
public bool ValidateWorkItems()
|
||||
{
|
||||
bool itemsAreValid = WorkItemComponents.Any();
|
||||
foreach (var component in WorkItemComponents)
|
||||
{
|
||||
component.IsValid = component.EditContext.Validate() && component.WorkItemDetailsEditContext.Validate();
|
||||
if (!component.IsValid)
|
||||
{
|
||||
itemsAreValid = component.IsValid;
|
||||
component.IsCollapsed = false;
|
||||
}
|
||||
}
|
||||
|
||||
return itemsAreValid;
|
||||
}
|
||||
|
||||
public async Task<bool> SendJob()
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateJobDetails();
|
||||
_requestBuilderService.CreateJob(JobDetails);
|
||||
|
||||
foreach (var component in WorkItemComponents)
|
||||
{
|
||||
AddWorkitem(component);
|
||||
}
|
||||
|
||||
//bool result = Task.Run(() => _requestBuilderService.SendDispatcherRequest()).Result;
|
||||
bool result = await _requestBuilderService.SendDispatcherRequest();
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Failure sending job to dispatcher.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateJobDetails()
|
||||
{
|
||||
if (Scheduled)
|
||||
{
|
||||
JobDetails.NextRunTime = null;
|
||||
}
|
||||
|
||||
var isNewJob = EditingJob == null;
|
||||
JobDetails.RequestingApplication = isNewJob ? DispatcherManager : EditingJob.RequestingApplication;
|
||||
JobDetails.CreatedBy = isNewJob ? AzureAdAuthorizationService.GetUserName() : EditingJob.CreatedBy;
|
||||
JobDetails.CreatedAt = isNewJob ? DateTime.Now : EditingJob.CreatedAt;
|
||||
JobDetails.ModifiedBy = isNewJob ? JobDetails.ModifiedBy : AzureAdAuthorizationService.GetUserName();
|
||||
JobDetails.ModifiedDate = isNewJob ? JobDetails.ModifiedDate : DateTime.Now;
|
||||
JobDetails.SkipHolidays = isNewJob ? JobDetails.SkipHolidays : SkipHolidays;
|
||||
JobDetails.JobTags = BuildJobTags();
|
||||
}
|
||||
|
||||
public void AddWorkitem(WorkItemComponent component)
|
||||
{
|
||||
component.WorkItemDetails.Name = string.IsNullOrEmpty(component.WorkItemDetails.Name) ? component.Type : component.WorkItemDetails.Name;
|
||||
component.WorkItemDetails.JobId = EditingJob == null ? 0 : EditingJob.JobId;
|
||||
component.WorkItemDetails.Order = GetIndex(component);
|
||||
_requestBuilderService.AddWorkItem(component.Item, component.WorkItemDetails, component.Type);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
||||
using LCU.WebApps.Internal.DispatcherManager.Configurations;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.WebApps.Internal.DispatcherManager.Services;
|
||||
|
||||
public class JobTagService
|
||||
{
|
||||
private readonly DispatcherApiConfiguration _dispatcherApiConfiguration;
|
||||
private readonly IGetRequest _getRequest;
|
||||
|
||||
public JobTagService(DispatcherApiConfiguration dispatcherApiConfiguration,
|
||||
IGetRequest getRequest)
|
||||
{
|
||||
_dispatcherApiConfiguration = dispatcherApiConfiguration;
|
||||
_getRequest = getRequest;
|
||||
}
|
||||
|
||||
public async Task<List<JobTag>> GetJobTagsByTagId(int tagId)
|
||||
{
|
||||
List<JobTag> tags = new List<JobTag>();
|
||||
try
|
||||
{
|
||||
var url = _dispatcherApiConfiguration.GetJobTagsByTagIdEndpointUrl + "?tagId=" + tagId;
|
||||
|
||||
return await _getRequest.AsyncWithNewton<List<JobTag>>(url);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error getting job tags.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
||||
using LCU.WebApps.Internal.DispatcherManager.Configurations;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.WebApps.Internal.DispatcherManager.Services;
|
||||
|
||||
public class QueueService
|
||||
{
|
||||
DispatcherApiConfiguration _dispatcherApiConfiguration;
|
||||
private readonly IPostRequest _postRequest;
|
||||
|
||||
public QueueService(DispatcherApiConfiguration dispatcherApiConfiguration,
|
||||
IPostRequest postRequest)
|
||||
{
|
||||
_dispatcherApiConfiguration = dispatcherApiConfiguration;
|
||||
_postRequest = postRequest;
|
||||
}
|
||||
|
||||
public async Task<bool> QueueRetryExecution(WorkItemExecution workItemExecution)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _postRequest.Async<WorkItemExecution>(new Uri(_dispatcherApiConfiguration.QueueExecutionControllerEndpointUrl), workItemExecution);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error Queueing Work Item Execution.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> QueueCompletion(int workItemId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dispatcherReturnResponse = new DispatcherReturnResponse()
|
||||
{
|
||||
WorkItemId = workItemId
|
||||
};
|
||||
|
||||
await _postRequest.Async<DispatcherReturnResponse>(new Uri(_dispatcherApiConfiguration.QueueCompletionControllerEndpointUrl), dispatcherReturnResponse);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error Queueing Work Item.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
using LCU.Library.Internal.LcuHttpClient.HttpRequest;
|
||||
using LCU.WebApps.Internal.DispatcherManager.Configurations;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.WebApps.Internal.DispatcherManager.Services;
|
||||
|
||||
public class TagService
|
||||
{
|
||||
private readonly DispatcherApiConfiguration _dispatcherApiConfiguration;
|
||||
private readonly IGetRequest _getRequest;
|
||||
private readonly IPostRequest _postRequest;
|
||||
private readonly IPutRequest _putRequest;
|
||||
private readonly IDeleteRequest _deleteRequest;
|
||||
|
||||
public TagService(DispatcherApiConfiguration dispatcherApiConfiguration,
|
||||
IGetRequest getRequest,
|
||||
IPostRequest postRequest,
|
||||
IPutRequest putRequest,
|
||||
IDeleteRequest deleteRequest)
|
||||
{
|
||||
_dispatcherApiConfiguration = dispatcherApiConfiguration;
|
||||
_getRequest = getRequest;
|
||||
_postRequest = postRequest;
|
||||
_putRequest = putRequest;
|
||||
_deleteRequest = deleteRequest;
|
||||
}
|
||||
|
||||
public async Task<List<Tag>> GetTags()
|
||||
{
|
||||
List<Tag> tags = new List<Tag>();
|
||||
try
|
||||
{
|
||||
tags = await _getRequest.AsyncWithNewton<List<Tag>>(_dispatcherApiConfiguration.TagControllerEndpointUrl);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error getting tags.");
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
public async Task DeleteTag(int tagId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = _dispatcherApiConfiguration.TagControllerEndpointUrl + "?tagId=" + tagId;
|
||||
|
||||
await _deleteRequest.Async(url);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error deleting tag.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveTag(Tag tag)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = _dispatcherApiConfiguration.TagControllerEndpointUrl + "?request=" + tag;
|
||||
|
||||
var result = await _postRequest.Async<Tag, Tag>(new Uri(url), tag);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error saving tag.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateTag(Tag tag)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = _dispatcherApiConfiguration.TagControllerEndpointUrl + "?request=" + tag;
|
||||
|
||||
await _putRequest.Async<Tag>(new Uri(url), tag, null);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error(exception, "Error updating tag.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user