Work in progress
This commit is contained in:
parent
af3167ee83
commit
50bf07c8c0
@ -59,7 +59,6 @@ services:
|
|||||||
tenantmanager:
|
tenantmanager:
|
||||||
environment:
|
environment:
|
||||||
- ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.TenantManagerDb;User Id=sa;Password=Pass@word}
|
- ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.TenantManagerDb;User Id=sa;Password=Pass@word}
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
- "5115:80"
|
- "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" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
</ItemGroup>
|
</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>
|
</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
|
namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||||
{
|
{
|
||||||
public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
|
public class UserCheckoutAcceptedIntegrationEventHandler : AbstractIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
|
||||||
{
|
{
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly ILogger<UserCheckoutAcceptedIntegrationEventHandler> _logger;
|
private readonly ILogger<UserCheckoutAcceptedIntegrationEventHandler> _logger;
|
||||||
@ -40,41 +40,45 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
|||||||
{
|
{
|
||||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
||||||
|
|
||||||
var result = false;
|
var customised = await CheckIfCustomised(@event);
|
||||||
|
if (!customised)
|
||||||
if (@event.RequestId != Guid.Empty)
|
|
||||||
{
|
{
|
||||||
using (LogContext.PushProperty("IdentifiedCommandId", @event.RequestId))
|
var result = false;
|
||||||
|
|
||||||
|
if (@event.RequestId != Guid.Empty)
|
||||||
{
|
{
|
||||||
var createOrderCommand = new CreateOrderCommand(@event.Basket.Items, @event.UserId, @event.UserName, @event.City, @event.Street,
|
using (LogContext.PushProperty("IdentifiedCommandId", @event.RequestId))
|
||||||
@event.State, @event.Country, @event.ZipCode,
|
|
||||||
@event.CardNumber, @event.CardHolderName, @event.CardExpiration,
|
|
||||||
@event.CardSecurityNumber, @event.CardTypeId);
|
|
||||||
|
|
||||||
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(createOrderCommand, @event.RequestId);
|
|
||||||
|
|
||||||
_logger.LogInformation(
|
|
||||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
|
||||||
requestCreateOrder.GetGenericTypeName(),
|
|
||||||
nameof(requestCreateOrder.Id),
|
|
||||||
requestCreateOrder.Id,
|
|
||||||
requestCreateOrder);
|
|
||||||
|
|
||||||
result = await _mediator.Send(requestCreateOrder);
|
|
||||||
|
|
||||||
if (result)
|
|
||||||
{
|
{
|
||||||
_logger.LogInformation("----- CreateOrderCommand suceeded - RequestId: {RequestId}", @event.RequestId);
|
var createOrderCommand = new CreateOrderCommand(@event.Basket.Items, @event.UserId, @event.UserName, @event.City, @event.Street,
|
||||||
}
|
@event.State, @event.Country, @event.ZipCode,
|
||||||
else
|
@event.CardNumber, @event.CardHolderName, @event.CardExpiration,
|
||||||
{
|
@event.CardSecurityNumber, @event.CardTypeId);
|
||||||
_logger.LogWarning("CreateOrderCommand failed - RequestId: {RequestId}", @event.RequestId);
|
|
||||||
|
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(createOrderCommand, @event.RequestId);
|
||||||
|
|
||||||
|
_logger.LogInformation(
|
||||||
|
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||||
|
requestCreateOrder.GetGenericTypeName(),
|
||||||
|
nameof(requestCreateOrder.Id),
|
||||||
|
requestCreateOrder.Id,
|
||||||
|
requestCreateOrder);
|
||||||
|
|
||||||
|
result = await _mediator.Send(requestCreateOrder);
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("----- CreateOrderCommand suceeded - RequestId: {RequestId}", @event.RequestId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("CreateOrderCommand failed - RequestId: {RequestId}", @event.RequestId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
_logger.LogWarning("Invalid IntegrationEvent - RequestId is missing - {@IntegrationEvent}", @event);
|
||||||
_logger.LogWarning("Invalid IntegrationEvent - RequestId is missing - {@IntegrationEvent}", @event);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user