51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.SelfService.Portal.Core.API.Context;
|
|
using Microsoft.SelfService.Portal.Core.API.Events.Interfaces;
|
|
using Microsoft.SelfService.Portal.Core.API.Helper;
|
|
using Microsoft.SelfService.Portal.Core.API.Models;
|
|
|
|
|
|
namespace Microsoft.SelfService.Portal.Core.API.Events
|
|
{
|
|
public class AbstractEventHandler : IEventHandlerInterface
|
|
{
|
|
private readonly DataContext _context;
|
|
|
|
public AbstractEventHandler(DataContext context)
|
|
{
|
|
_context = context;
|
|
new APIHelper();
|
|
}
|
|
|
|
public ICollection<EventModel> GetEvents(string Class, string Method)
|
|
{
|
|
return _context.Events
|
|
.Where(e => e.Class == Class && e.Method == Method)
|
|
.Include(r => r.Runbook)
|
|
.ToList();
|
|
}
|
|
|
|
public async void FireEvent(string Class, string Method, Guid parameters)
|
|
{
|
|
var events = GetEvents(Class, Method);
|
|
|
|
foreach (EventModel @event in events){
|
|
|
|
APIHelper.SetUrl(@event.RunbookId, @event.RestEndpointOperation);
|
|
APIHelper.SetRequestBody(parameters);
|
|
|
|
var response = await APIHelper.ApiClient.PostAsync(APIHelper.GetUrl(), APIHelper.SetRequestHeaders("application/json;odata=verbose;charset=utf-8"));
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
|
}
|
|
else
|
|
{
|
|
throw new HttpRequestException(response.ReasonPhrase);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|