initial commit
This commit is contained in:
50
Events/AbstractEventHandler.cs
Normal file
50
Events/AbstractEventHandler.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Events/Interfaces/IEventHandlerInterface.cs
Normal file
10
Events/Interfaces/IEventHandlerInterface.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Microsoft.SelfService.Portal.Core.API.Models;
|
||||
|
||||
namespace Microsoft.SelfService.Portal.Core.API.Events.Interfaces
|
||||
{
|
||||
public interface IEventHandlerInterface
|
||||
{
|
||||
ICollection<EventModel> GetEvents(string Class, string Method);
|
||||
void FireEvent(string Class, string Method, Guid parameters);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user