Work in progress
This commit is contained in:
parent
af3167ee83
commit
50bf07c8c0
@ -59,7 +59,6 @@ services:
|
||||
tenantmanager:
|
||||
environment:
|
||||
- ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.TenantManagerDb;User Id=sa;Password=Pass@word}
|
||||
|
||||
ports:
|
||||
- "5115:80"
|
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
{
|
||||
public abstract class AbstractIntegrationEventHandler<IIntegrationEvent>
|
||||
{
|
||||
private static String url = @"http://tenantmanager/";
|
||||
private readonly IEventBus _eventBus;
|
||||
|
||||
public async Task<bool> CheckIfCustomised(IntegrationEvent @event)
|
||||
{
|
||||
Boolean result = Get(@event);
|
||||
if (result)
|
||||
{
|
||||
CustomisationEvent customisationEvent = new CustomisationEvent(1, @event);
|
||||
try
|
||||
{
|
||||
//_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", eventMessage.Id, Program.AppName, eventMessage);
|
||||
|
||||
_eventBus.Publish(customisationEvent);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//_logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId} from {AppName}", eventMessage.Id, Program.AppName);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Boolean Get(IntegrationEvent @event)
|
||||
{
|
||||
//TODO return true/false
|
||||
Console.WriteLine("Making API Call...");
|
||||
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
|
||||
{
|
||||
client.BaseAddress = new Uri(url);
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = client.GetAsync("api/tenants").Result;
|
||||
response.EnsureSuccessStatusCode();
|
||||
string result = response.Content.ReadAsStringAsync().Result;
|
||||
Console.WriteLine("Result: " + result);
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -9,4 +9,10 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
|
||||
<HintPath>..\..\..\..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.logging.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
|
||||
{
|
||||
public class CustomisationEvent : IntegrationEvent
|
||||
{
|
||||
public CustomisationEvent(int tenantId, IntegrationEvent @event)
|
||||
{
|
||||
TenantId = tenantId;
|
||||
this.@event = @event;
|
||||
}
|
||||
|
||||
public int TenantId { get; set; }
|
||||
public IntegrationEvent @event { get; set; }
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ using System;
|
||||
|
||||
namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
{
|
||||
public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
|
||||
public class UserCheckoutAcceptedIntegrationEventHandler : AbstractIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ILogger<UserCheckoutAcceptedIntegrationEventHandler> _logger;
|
||||
@ -40,6 +40,9 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
{
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||
|
||||
var customised = await CheckIfCustomised(@event);
|
||||
if (!customised)
|
||||
{
|
||||
var result = false;
|
||||
|
||||
if (@event.RequestId != Guid.Empty)
|
||||
@ -80,3 +83,4 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user