# Conflicts: # src/Services/Basket/Basket.API/Basket.API.csproj # src/Services/Basket/Basket.FunctionalTests/BasketScenarios.cs # src/Services/Catalog/Catalog.API/Catalog.API.csproj # src/Services/Identity/Identity.API/Identity.API.csproj # src/Services/Location/Locations.API/Locations.API.csproj # src/Services/Marketing/Marketing.API/Marketing.API.csproj # src/Services/Ordering/Ordering.API/Ordering.API.csproj # src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj # src/Services/Payment/Payment.API/Payment.API.csprojpull/965/head
@ -0,0 +1,32 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions | |||
{ | |||
public static class GenericTypeExtensions | |||
{ | |||
public static string GetGenericTypeName(this Type type) | |||
{ | |||
var typeName = string.Empty; | |||
if (type.IsGenericType) | |||
{ | |||
var genericTypes = string.Join(",", type.GetGenericArguments().Select(t => t.Name).ToArray()); | |||
typeName = $"{type.Name.Remove(type.Name.IndexOf('`'))}<{genericTypes}>"; | |||
} | |||
else | |||
{ | |||
typeName = type.Name; | |||
} | |||
return typeName; | |||
} | |||
public static string GetGenericTypeName(this object @object) | |||
{ | |||
return @object.GetType().GetGenericTypeName(); | |||
} | |||
} | |||
} |
@ -1,175 +0,0 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup> | |||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform> | |||
<ProjectGuid>{B68C2B56-7581-46AE-B55D-D25DDFD3BFE3}</ProjectGuid> | |||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | |||
<OutputType>Exe</OutputType> | |||
<RootNamespace>eShopOnContainers.TestRunner.iOS</RootNamespace> | |||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix> | |||
<AssemblyName>eShopOnContainers.TestRunner.iOS</AssemblyName> | |||
<NuGetPackageImportStamp> | |||
</NuGetPackageImportStamp> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' "> | |||
<DebugSymbols>true</DebugSymbols> | |||
<DebugType>full</DebugType> | |||
<Optimize>false</Optimize> | |||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath> | |||
<DefineConstants>DEBUG</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<ConsolePause>false</ConsolePause> | |||
<MtouchArch>x86_64</MtouchArch> | |||
<MtouchLink>SdkOnly</MtouchLink> | |||
<MtouchDebug>True</MtouchDebug> | |||
<MtouchSdkVersion>10.1</MtouchSdkVersion> | |||
<MtouchProfiling>False</MtouchProfiling> | |||
<MtouchFastDev>False</MtouchFastDev> | |||
<MtouchUseLlvm>False</MtouchUseLlvm> | |||
<MtouchUseThumb>False</MtouchUseThumb> | |||
<MtouchEnableBitcode>False</MtouchEnableBitcode> | |||
<MtouchUseSGen>False</MtouchUseSGen> | |||
<MtouchUseRefCounting>False</MtouchUseRefCounting> | |||
<OptimizePNGs>True</OptimizePNGs> | |||
<MtouchTlsProvider>Default</MtouchTlsProvider> | |||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler> | |||
<MtouchFloat32>False</MtouchFloat32> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' "> | |||
<DebugType>none</DebugType> | |||
<Optimize>true</Optimize> | |||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<MtouchLink>None</MtouchLink> | |||
<MtouchArch>x86_64</MtouchArch> | |||
<ConsolePause>false</ConsolePause> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' "> | |||
<DebugSymbols>true</DebugSymbols> | |||
<DebugType>full</DebugType> | |||
<Optimize>false</Optimize> | |||
<OutputPath>bin\iPhone\Debug</OutputPath> | |||
<DefineConstants>DEBUG</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<ConsolePause>false</ConsolePause> | |||
<MtouchArch>ARMv7, ARM64</MtouchArch> | |||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements> | |||
<CodesignKey>iPhone Developer</CodesignKey> | |||
<MtouchDebug>true</MtouchDebug> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' "> | |||
<DebugType>none</DebugType> | |||
<Optimize>true</Optimize> | |||
<OutputPath>bin\iPhone\Release</OutputPath> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements> | |||
<MtouchArch>ARMv7, ARM64</MtouchArch> | |||
<ConsolePause>false</ConsolePause> | |||
<CodesignKey>iPhone Developer</CodesignKey> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' "> | |||
<DebugType>none</DebugType> | |||
<Optimize>True</Optimize> | |||
<OutputPath>bin\iPhone\Ad-Hoc</OutputPath> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<ConsolePause>False</ConsolePause> | |||
<MtouchArch>ARMv7, ARM64</MtouchArch> | |||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements> | |||
<BuildIpa>True</BuildIpa> | |||
<CodesignProvision>Automatic:AdHoc</CodesignProvision> | |||
<CodesignKey>iPhone Distribution</CodesignKey> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' "> | |||
<DebugType>none</DebugType> | |||
<Optimize>True</Optimize> | |||
<OutputPath>bin\iPhone\AppStore</OutputPath> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
<ConsolePause>False</ConsolePause> | |||
<MtouchArch>ARMv7, ARM64</MtouchArch> | |||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements> | |||
<CodesignProvision>Automatic:AppStore</CodesignProvision> | |||
<CodesignKey>iPhone Distribution</CodesignKey> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Compile Include="Main.cs" /> | |||
<Compile Include="AppDelegate.cs" /> | |||
<None Include="app.config" /> | |||
<None Include="Info.plist" /> | |||
<Compile Include="Properties\AssemblyInfo.cs" /> | |||
<InterfaceDefinition Include="Resources\LaunchScreen.xib" /> | |||
<None Include="packages.config" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Reference Include="System" /> | |||
<Reference Include="System.Xml" /> | |||
<Reference Include="System.Core" /> | |||
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\Xamarin.Forms.2.3.3.166-pre4\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="Xamarin.Forms.Platform, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\Xamarin.Forms.2.3.3.166-pre4\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="Xamarin.Forms.Platform.iOS, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\Xamarin.Forms.2.3.3.166-pre4\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="Xamarin.Forms.Xaml, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\Xamarin.Forms.2.3.3.166-pre4\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="Xamarin.iOS" /> | |||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\xunit.abstractions.2.0.1\lib\netstandard1.0\xunit.abstractions.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="xunit.assert, Version=2.2.0.3444, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\xunit.assert.2.2.0-beta4-build3444\lib\netstandard1.0\xunit.assert.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="xunit.core, Version=2.2.0.3444, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\xunit.extensibility.core.2.2.0-beta4-build3444\lib\netstandard1.0\xunit.core.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="xunit.execution.dotnet, Version=2.2.0.3444, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\xunit.extensibility.execution.2.2.0-beta4-build3444\lib\netstandard1.0\xunit.execution.dotnet.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="xunit.runner.devices, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\xunit.runner.devices.2.1.0\lib\Xamarin.iOS\xunit.runner.devices.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
<Reference Include="xunit.runner.utility.dotnet, Version=2.2.0.3444, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | |||
<HintPath>..\..\packages\xunit.runner.utility.2.2.0-beta4-build3444\lib\netstandard1.1\xunit.runner.utility.dotnet.dll</HintPath> | |||
<Private>True</Private> | |||
</Reference> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Content Include="AppDelegate.cs.txt" /> | |||
<Content Include="Entitlements.plist" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\eShopOnContainers.UnitTests\eShopOnContainers.UnitTests.csproj"> | |||
<Project>{f7b6a162-bc4d-4924-b16a-713f9b0344e7}</Project> | |||
<Name>eShopOnContainers.UnitTests</Name> | |||
</ProjectReference> | |||
</ItemGroup> | |||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" /> | |||
<Import Project="..\..\packages\Xamarin.Forms.2.3.3.166-pre4\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.3.166-pre4\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" /> | |||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | |||
<PropertyGroup> | |||
<ErrorText>Este proyecto hace referencia a los paquetes NuGet que faltan en este equipo. Use la restauración de paquetes NuGet para descargarlos. Para obtener más información, consulte http://go.microsoft.com/fwlink/?LinkID=322105. El archivo que falta es {0}.</ErrorText> | |||
</PropertyGroup> | |||
<Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.3.3.166-pre4\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.2.3.3.166-pre4\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets'))" /> | |||
<Error Condition="!Exists('..\..\packages\xunit.runner.devices.2.1.0\build\Xamarin.iOS\xunit.runner.devices.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.devices.2.1.0\build\Xamarin.iOS\xunit.runner.devices.targets'))" /> | |||
</Target> | |||
<Import Project="..\..\packages\xunit.runner.devices.2.1.0\build\Xamarin.iOS\xunit.runner.devices.targets" Condition="Exists('..\..\packages\xunit.runner.devices.2.1.0\build\Xamarin.iOS\xunit.runner.devices.targets')" /> | |||
</Project> |
@ -1,11 +0,0 @@ | |||
using System.ComponentModel.DataAnnotations; | |||
namespace Microsoft.eShopOnContainers.Services.Identity.API.Models.AccountViewModels | |||
{ | |||
public class ExternalLoginConfirmationViewModel | |||
{ | |||
[Required] | |||
[EmailAddress] | |||
public string Email { get; set; } | |||
} | |||
} |
@ -1,13 +0,0 @@ | |||
using Microsoft.AspNetCore.Http.Authentication; | |||
using Microsoft.AspNetCore.Identity; | |||
using System.Collections.Generic; | |||
namespace Microsoft.eShopOnContainers.Services.Identity.API.Models.ManageViewModels | |||
{ | |||
public class ManageLoginsViewModel | |||
{ | |||
public IList<UserLoginInfo> CurrentLogins { get; set; } | |||
public IList<AuthenticationDescription> OtherLogins { get; set; } | |||
} | |||
} |
@ -1,8 +0,0 @@ | |||
namespace Microsoft.eShopOnContainers.Services.Identity.API.Models.ManageViewModels | |||
{ | |||
public class RemoveLoginViewModel | |||
{ | |||
public string LoginProvider { get; set; } | |||
public string ProviderKey { get; set; } | |||
} | |||
} |
@ -1,27 +1,49 @@ | |||
namespace Ordering.API.Application.IntegrationEvents.EventHandling | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions; | |||
using System.Threading.Tasks; | |||
using Events; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; | |||
using MediatR; | |||
using System; | |||
using Ordering.API.Application.Commands; | |||
using Microsoft.Extensions.Logging; | |||
using Serilog.Context; | |||
using Microsoft.eShopOnContainers.Services.Ordering.API; | |||
using Ordering.API.Application.Behaviors; | |||
public class OrderStockConfirmedIntegrationEventHandler : | |||
public class OrderStockConfirmedIntegrationEventHandler : | |||
IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent> | |||
{ | |||
private readonly IMediator _mediator; | |||
private readonly ILogger<OrderStockConfirmedIntegrationEventHandler> _logger; | |||
public OrderStockConfirmedIntegrationEventHandler(IMediator mediator) | |||
public OrderStockConfirmedIntegrationEventHandler( | |||
IMediator mediator, | |||
ILogger<OrderStockConfirmedIntegrationEventHandler> logger) | |||
{ | |||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); | |||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | |||
} | |||
public async Task Handle(OrderStockConfirmedIntegrationEvent @event) | |||
{ | |||
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId); | |||
await _mediator.Send(command); | |||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | |||
{ | |||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | |||
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId); | |||
_logger.LogInformation( | |||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", | |||
command.GetGenericTypeName(), | |||
nameof(command.OrderNumber), | |||
command.OrderNumber, | |||
command); | |||
await _mediator.Send(command); | |||
} | |||
} | |||
} | |||
} |
@ -1,31 +1,53 @@ | |||
namespace Ordering.API.Application.IntegrationEvents.EventHandling | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions; | |||
using System.Threading.Tasks; | |||
using Events; | |||
using System.Linq; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; | |||
using MediatR; | |||
using Ordering.API.Application.Commands; | |||
using Microsoft.Extensions.Logging; | |||
using Serilog.Context; | |||
using Microsoft.eShopOnContainers.Services.Ordering.API; | |||
using Ordering.API.Application.Behaviors; | |||
public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandler<OrderStockRejectedIntegrationEvent> | |||
{ | |||
private readonly IMediator _mediator; | |||
private readonly ILogger<OrderStockRejectedIntegrationEventHandler> _logger; | |||
public OrderStockRejectedIntegrationEventHandler(IMediator mediator) | |||
public OrderStockRejectedIntegrationEventHandler( | |||
IMediator mediator, | |||
ILogger<OrderStockRejectedIntegrationEventHandler> logger) | |||
{ | |||
_mediator = mediator; | |||
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); | |||
} | |||
public async Task Handle(OrderStockRejectedIntegrationEvent @event) | |||
{ | |||
var orderStockRejectedItems = @event.OrderStockItems | |||
.FindAll(c => !c.HasStock) | |||
.Select(c => c.ProductId) | |||
.ToList(); | |||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | |||
{ | |||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | |||
var command = new SetStockRejectedOrderStatusCommand(@event.OrderId, orderStockRejectedItems); | |||
await _mediator.Send(command); | |||
var orderStockRejectedItems = @event.OrderStockItems | |||
.FindAll(c => !c.HasStock) | |||
.Select(c => c.ProductId) | |||
.ToList(); | |||
var command = new SetStockRejectedOrderStatusCommand(@event.OrderId, orderStockRejectedItems); | |||
_logger.LogInformation( | |||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", | |||
command.GetGenericTypeName(), | |||
nameof(command.OrderNumber), | |||
command.OrderNumber, | |||
command); | |||
await _mediator.Send(command); | |||
} | |||
} | |||
} | |||
} |
@ -1,52 +1,82 @@ | |||
using System; | |||
using MediatR; | |||
using MediatR; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using System.Threading.Tasks; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions; | |||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; | |||
using Microsoft.eShopOnContainers.Services.Ordering.API; | |||
using Microsoft.Extensions.Logging; | |||
using Ordering.API.Application.Behaviors; | |||
using Ordering.API.Application.IntegrationEvents.Events; | |||
using Serilog.Context; | |||
using System.Threading.Tasks; | |||
using System; | |||
namespace Ordering.API.Application.IntegrationEvents.EventHandling | |||
{ | |||
public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent> | |||
{ | |||
private readonly IMediator _mediator; | |||
private readonly ILoggerFactory _logger; | |||
private readonly ILogger<UserCheckoutAcceptedIntegrationEventHandler> _logger; | |||
public UserCheckoutAcceptedIntegrationEventHandler(IMediator mediator, | |||
ILoggerFactory logger) | |||
public UserCheckoutAcceptedIntegrationEventHandler( | |||
IMediator mediator, | |||
ILogger<UserCheckoutAcceptedIntegrationEventHandler> logger) | |||
{ | |||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); | |||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | |||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | |||
} | |||
/// <summary> | |||
/// Integration event handler which starts the create order process | |||
/// </summary> | |||
/// <param name="eventMsg"> | |||
/// <param name="@event"> | |||
/// Integration event message which is sent by the | |||
/// basket.api once it has successfully process the | |||
/// order items. | |||
/// </param> | |||
/// <returns></returns> | |||
public async Task Handle(UserCheckoutAcceptedIntegrationEvent eventMsg) | |||
public async Task Handle(UserCheckoutAcceptedIntegrationEvent @event) | |||
{ | |||
var result = false; | |||
if (eventMsg.RequestId != Guid.Empty) | |||
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | |||
{ | |||
var createOrderCommand = new CreateOrderCommand(eventMsg.Basket.Items, eventMsg.UserId, eventMsg.UserName, eventMsg.City, eventMsg.Street, | |||
eventMsg.State, eventMsg.Country, eventMsg.ZipCode, | |||
eventMsg.CardNumber, eventMsg.CardHolderName, eventMsg.CardExpiration, | |||
eventMsg.CardSecurityNumber, eventMsg.CardTypeId); | |||
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(createOrderCommand, eventMsg.RequestId); | |||
result = await _mediator.Send(requestCreateOrder); | |||
} | |||
_logger.CreateLogger(nameof(UserCheckoutAcceptedIntegrationEventHandler)) | |||
.LogTrace(result ? $"UserCheckoutAccepted integration event has been received and a create new order process is started with requestId: {eventMsg.RequestId}" : | |||
$"UserCheckoutAccepted integration event has been received but a new order process has failed with requestId: {eventMsg.RequestId}"); | |||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | |||
var result = false; | |||
if (@event.RequestId != Guid.Empty) | |||
{ | |||
using (LogContext.PushProperty("IdentifiedCommandId", @event.RequestId)) | |||
{ | |||
var createOrderCommand = new CreateOrderCommand(@event.Basket.Items, @event.UserId, @event.UserName, @event.City, @event.Street, | |||
@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); | |||
} | |||
else | |||
{ | |||
_logger.LogWarning("CreateOrderCommand failed - RequestId: {RequestId}", @event.RequestId); | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
_logger.LogWarning("Invalid IntegrationEvent - RequestId is missing - {@IntegrationEvent}", @event); | |||
} | |||
} | |||
} | |||
} | |||
} |
@ -1,33 +1,75 @@ | |||
using Microsoft.AspNetCore; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.Logging; | |||
using Serilog; | |||
using System; | |||
using System.IO; | |||
namespace Ordering.BackgroundTasks | |||
{ | |||
public class Program | |||
{ | |||
public static void Main(string[] args) | |||
public static readonly string Namespace = typeof(Program).Namespace; | |||
public static readonly string AppName = Namespace; | |||
public static int Main(string[] args) | |||
{ | |||
BuildWebHost(args).Run(); | |||
var configuration = GetConfiguration(); | |||
Log.Logger = CreateSerilogLogger(configuration); | |||
try | |||
{ | |||
Log.Information("Configuring web host ({ApplicationContext})...", AppName); | |||
var host = BuildWebHost(configuration, args); | |||
Log.Information("Starting web host ({ApplicationContext})...", AppName); | |||
host.Run(); | |||
return 0; | |||
} | |||
catch (Exception ex) | |||
{ | |||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName); | |||
return 1; | |||
} | |||
finally | |||
{ | |||
Log.CloseAndFlush(); | |||
} | |||
} | |||
public static IWebHost BuildWebHost(string[] args) => | |||
private static IWebHost BuildWebHost(IConfiguration configuration, string[] args) => | |||
WebHost.CreateDefaultBuilder(args) | |||
.UseStartup<Startup>() | |||
.ConfigureLogging((hostingContext, builder) => | |||
{ | |||
builder.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); | |||
builder.AddDebug(); | |||
builder.AddConsole(); | |||
}) | |||
.UseSerilog((builderContext, config) => | |||
{ | |||
config | |||
.MinimumLevel.Information() | |||
.Enrich.FromLogContext() | |||
.WriteTo.Console(); | |||
}) | |||
.CaptureStartupErrors(false) | |||
.UseStartup<Startup>() | |||
.UseConfiguration(configuration) | |||
.UseSerilog() | |||
.Build(); | |||
private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) | |||
{ | |||
var seqServerUrl = configuration["Serilog:SeqServerUrl"]; | |||
return new LoggerConfiguration() | |||
.MinimumLevel.Verbose() | |||
.Enrich.WithProperty("ApplicationContext", AppName) | |||
.Enrich.FromLogContext() | |||
.WriteTo.Console() | |||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl) | |||
.ReadFrom.Configuration(configuration) | |||
.CreateLogger(); | |||
} | |||
private static IConfiguration GetConfiguration() | |||
{ | |||
var builder = new ConfigurationBuilder() | |||
.SetBasePath(Directory.GetCurrentDirectory()) | |||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | |||
.AddEnvironmentVariables(); | |||
return builder.Build(); | |||
} | |||
} | |||
} |