Browse Source

Adding more microservices for tenantA and tenantB

pull/1240/head
espent1004 5 years ago
parent
commit
7e246bd7c3
28 changed files with 495 additions and 247 deletions
  1. +0
    -49
      src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/CustomisationEventHandler.cs
  2. +0
    -60
      src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs
  3. +0
    -62
      src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs
  4. +34
    -0
      src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs
  5. +38
    -0
      src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs
  6. +0
    -0
      src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/IShippingService.cs
  7. +0
    -0
      src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/MockedShippingService.cs
  8. +0
    -34
      src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs
  9. +13
    -12
      src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs
  10. +0
    -30
      src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs
  11. +0
    -0
      src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs
  12. +12
    -0
      src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs
  13. +12
    -0
      src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs
  14. +17
    -0
      src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs
  15. +31
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs
  16. +28
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs
  17. +59
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile
  18. +9
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs
  19. +20
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs
  20. +28
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs
  21. +12
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs
  22. +33
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs
  23. +69
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs
  24. +34
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs
  25. +18
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs
  26. +7
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs
  27. +7
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs
  28. +14
    -0
      src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs

+ 0
- 49
src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/CustomisationEventHandler.cs View File

@ -1,49 +0,0 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Ordering.API.Application.IntegrationEvents.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TenantACustomisations.Services;
namespace TenantACustomisations.IntegrationEvents.EventHandling
{
public class CustomisationEventHandler : IIntegrationEventHandler<CustomisationEvent>
{
private readonly ILogger<CustomisationEventHandler> _logger;
private readonly IEventBus _eventBus;
private readonly IValidationService validationService;
public CustomisationEventHandler(ILogger<CustomisationEventHandler> logger, IEventBus eventBus)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
validationService = new ValidationService();
}
public async Task Handle(CustomisationEvent @event)
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
IntegrationEvent integrationEvent = @event.@event;
switch (integrationEvent.GetType().Name)
{
case "UserCheckoutAcceptedIntegrationEvent":
if (validationService.Validate((UserCheckoutAcceptedIntegrationEvent)integrationEvent))
{
integrationEvent.CheckForCustomisation = false;
_eventBus.Publish(integrationEvent);
}
break;
default:
integrationEvent.CheckForCustomisation = false;
_eventBus.Publish(integrationEvent);
break;
}
}
}
}

+ 0
- 60
src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/TenantAUserCheckoutAcceptedIntegrationEventHandler.cs View File

@ -1,60 +0,0 @@
using MediatR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Behaviors;
using Serilog.Context;
using System.Threading.Tasks;
using System;
using System.Diagnostics;
using TenantACustomisations.IntegrationEvents.Events;
using TenantACustomisations.ExternalServices;
using TenantACustomisations.Database;
namespace TenantACustomisations.IntegrationEvents.EventHandling
{
public class TenantAUserCheckoutAcceptedIntegrationEventHandler :
IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
{
private readonly IMediator _mediator;
private readonly IEventBus _eventBus;
private readonly ILogger<TenantAUserCheckoutAcceptedIntegrationEventHandler> _logger;
//private readonly TenantAContext _context;
//private readonly IShippingService _shippingService;
public TenantAUserCheckoutAcceptedIntegrationEventHandler(
IMediator mediator,
ILogger<TenantAUserCheckoutAcceptedIntegrationEventHandler> logger,
IEventBus eventBus
)
{
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
}
/// <summary>
/// Integration event handler which starts the create order process
/// </summary>
/// <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 @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantA- ({@IntegrationEvent})", @event.Id, @event);
_logger.LogInformation("Hello");
//TODO
Debug.WriteLine(@event);
//Save shipping info
//Hard code view comp
//Retrieve shipping info and show
}
}
}
}

+ 0
- 62
src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs View File

@ -1,62 +0,0 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Ordering.API.Application.Models;
using System;
namespace TenantACustomisations.IntegrationEvents.Events
{
public class UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
{
public string UserId { get; }
public string UserName { get; }
public string City { get; set; }
public string Street { get; set; }
public string State { get; set; }
public string Country { get; set; }
public string ZipCode { get; set; }
public string CardNumber { get; set; }
public string CardHolderName { get; set; }
public DateTime CardExpiration { get; set; }
public string CardSecurityNumber { get; set; }
public int CardTypeId { get; set; }
public string Buyer { get; set; }
public Guid RequestId { get; set; }
public CustomerBasket Basket { get; }
public UserCheckoutAcceptedIntegrationEvent(string userId, string userName, string city, string street,
string state, string country, string zipCode, string cardNumber, string cardHolderName,
DateTime cardExpiration, string cardSecurityNumber, int cardTypeId, string buyer, Guid requestId,
CustomerBasket basket)
{
UserId = userId;
City = city;
Street = street;
State = state;
Country = country;
ZipCode = zipCode;
CardNumber = cardNumber;
CardHolderName = cardHolderName;
CardExpiration = cardExpiration;
CardSecurityNumber = cardSecurityNumber;
CardTypeId = cardTypeId;
Buyer = buyer;
Basket = basket;
RequestId = requestId;
UserName = userName;
}
}
}

+ 34
- 0
src/Services/TenantCustomisations/TenantAShippingInformation/Database/DbInitializer.cs View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TenantACustomisations.ExternalServices;
namespace TenantACustomisations.Database
{
public class DbInitializer
{
public void Initialize(TenantAContext context)
{
context.Database.EnsureCreated();
if (context.ShippingInformation.Any())
{
return;
}
ShippingInformation shippingInformation = new ShippingInformation();
shippingInformation.ShippingTime = DateTime.Today;
shippingInformation.ArrivalTime = DateTime.Today.AddDays(2);
shippingInformation.FragilityLevel = Fragility.Medium;
shippingInformation.PriorityLevel = Priority.High;
shippingInformation.ShippingInformationId = 1;
shippingInformation.OrderNumber = "1";
context.ShippingInformation.Add(shippingInformation);
context.SaveChanges();
}
}
}

+ 38
- 0
src/Services/TenantCustomisations/TenantAShippingInformation/Database/TenantAContext.cs View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using TenantACustomisations.ExternalServices;
using TenantACustomisations.IntegrationEvents.Events;
namespace TenantACustomisations.Database
{
public class TenantAContext : DbContext
{
public TenantAContext(DbContextOptions<TenantAContext> options)
: base(options)
{
}
public DbSet<ShippingInformation> ShippingInformation { get; set; }
public DbSet<SavedEvent> SavedEvent
{
get;
set;
}
}
public class TenantAContextDesignFactory : IDesignTimeDbContextFactory<TenantAContext>
{
public TenantAContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<TenantAContext>()
.UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantADb;Integrated Security=true");
return new TenantAContext(optionsBuilder.Options);
}
}
}

src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/IShippingService.cs → src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/IShippingService.cs View File


src/Services/TenantCustomisations/TenantACustomisations/ExternalServices/MockedShippingService.cs → src/Services/TenantCustomisations/TenantAShippingInformation/ExternalServices/MockedShippingService.cs View File


+ 0
- 34
src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs View File

@ -1,34 +0,0 @@
using Microsoft.AspNetCore.SignalR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.Extensions.Logging;
using Serilog.Context;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using TenantAShippingInformation.IntegrationEvents.Events;
namespace TenantAShippingInformation.IntegrationEvents.EventHandling
{
public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent>
{
private readonly ILogger<OrderStatusChangedToAwaitingValidationIntegrationEventHandler> _logger;
public OrderStatusChangedToAwaitingValidationIntegrationEventHandler(ILogger<OrderStatusChangedToAwaitingValidationIntegrationEventHandler> logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA"))
{
//TODO
Debug.WriteLine(@event);
}
}
}
}

src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs → src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs View File

@ -7,11 +7,12 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using TenantACustomisations.Database;
using TenantACustomisations.ExternalServices;
using TenantACustomisations.IntegrationEvents.Events;
using TenantAShippingInformation.Database;
using TenantAShippingInformation.ExternalServices;
using TenantAShippingInformation.IntegrationEvents.Events;
using TenantAShippingInformation.Models;
namespace TenantACustomisations.IntegrationEvents.EventHandling
namespace TenantAShippingInformation.IntegrationEvents.EventHandling
{
public class OrderStatusChangedToSubmittedIntegrationEventHandler :
IIntegrationEventHandler<OrderStatusChangedToSubmittedIntegrationEvent>
@ -31,14 +32,14 @@ namespace TenantACustomisations.IntegrationEvents.EventHandling
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantA - ({@IntegrationEvent})", @event.Id, @event);
_logger.LogInformation("Hello");
//TODO
Debug.WriteLine(@event);
ShippingInformation shippingInformation = _shippingService.CalculateShippingInformation(@event.OrderId);
_context.ShippingInformation.Add(shippingInformation);
_logger.LogInformation("----- Saving shipping information: {IntegrationEventId} at TenantA - ({@IntegrationEvent}) - {@ShippingInformation}", @event.Id, @event, shippingInformation);
_context.SaveChanges();
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at TenantA - ({@IntegrationEvent})", @event.Id, @event);
ShippingInformation shippingInformation = _shippingService.CalculateShippingInformation(@event.OrderId);
_context.ShippingInformation.Add(shippingInformation);
_logger.LogInformation("----- Saving shipping information: {IntegrationEventId} at TenantA - ({@IntegrationEvent}) - {@ShippingInformation}", @event.Id, @event, shippingInformation);
_context.SaveChanges();
}
}
}
}

+ 0
- 30
src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs View File

@ -1,30 +0,0 @@
using System.Collections.Generic;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
namespace TenantAShippingInformation.IntegrationEvents.Events
{
public class OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public IEnumerable<OrderStockItem> OrderStockItems { get; }
public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId,
IEnumerable<OrderStockItem> orderStockItems)
{
OrderId = orderId;
OrderStockItems = orderStockItems;
}
}
public class OrderStockItem
{
public int ProductId { get; }
public int Units { get; }
public OrderStockItem(int productId, int units)
{
ProductId = productId;
Units = units;
}
}
}

src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs → src/Services/TenantCustomisations/TenantAShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs View File


+ 12
- 0
src/Services/TenantCustomisations/TenantAShippingInformation/Models/Fragility.cs View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TenantACustomisations.ExternalServices
{
public enum Fragility
{
Low, Medium, High
}
}

+ 12
- 0
src/Services/TenantCustomisations/TenantAShippingInformation/Models/Priority.cs View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TenantACustomisations.ExternalServices
{
public enum Priority
{
Low, Medium, High
}
}

+ 17
- 0
src/Services/TenantCustomisations/TenantAShippingInformation/Models/ShippingInformation.cs View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TenantACustomisations.ExternalServices
{
public class ShippingInformation
{
public int ShippingInformationId { get; set; }
public DateTime ArrivalTime { get; set; }
public DateTime ShippingTime { get; set; }
public Priority PriorityLevel {get;set;}
public Fragility FragilityLevel { get; set; }
public String OrderNumber { get; set; }
}
}

+ 31
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Database/DbInitializer.cs View File

@ -0,0 +1,31 @@
using System;
using System.Linq;
using TenantAShippingInformation.Models;
namespace TenantAShippingInformation.Database
{
public class DbInitializer
{
public void Initialize(TenantAContext context)
{
context.Database.EnsureCreated();
if (context.ShippingInformation.Any())
{
return;
}
ShippingInformation shippingInformation = new ShippingInformation();
shippingInformation.ShippingTime = DateTime.Today;
shippingInformation.ArrivalTime = DateTime.Today.AddDays(2);
shippingInformation.FragilityLevel = Fragility.Medium;
shippingInformation.PriorityLevel = Priority.High;
shippingInformation.ShippingInformationId = 1;
shippingInformation.OrderNumber = "1";
context.ShippingInformation.Add(shippingInformation);
context.SaveChanges();
}
}
}

+ 28
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Database/TenantAContext.cs View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using TenantAShippingInformation.Models;
namespace TenantAShippingInformation.Database
{
public class TenantAContext : DbContext
{
public TenantAContext(DbContextOptions<TenantAContext> options)
: base(options)
{
}
public DbSet<ShippingInformation> ShippingInformation { get; set; }
}
public class TenantAContextDesignFactory : IDesignTimeDbContextFactory<TenantAContext>
{
public TenantAContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<TenantAContext>()
.UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.TenantAShippingInformationDb;Integrated Security=true");
return new TenantAContext(optionsBuilder.Options);
}
}
}

+ 59
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Dockerfile View File

@ -0,0 +1,59 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
# Keep the project list and command dotnet restore identical in all Dockfiles to maximize image cache utilization
COPY eShopOnContainers-ServicesAndWebApps.sln .
COPY docker-compose.dcproj /src/
COPY src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj src/ApiGateways/ApiGw-Base/
COPY src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj src/ApiGateways/Mobile.Bff.Shopping/aggregator/
COPY src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj src/ApiGateways/Web.Bff.Shopping/aggregator/
COPY src/BuildingBlocks/Devspaces.Support/Devspaces.Support.csproj src/BuildingBlocks/Devspaces.Support/
COPY src/BuildingBlocks/EventBus/EventBus/EventBus.csproj src/BuildingBlocks/EventBus/EventBus/
COPY src/BuildingBlocks/EventBus/EventBus.Tests/EventBus.Tests.csproj src/BuildingBlocks/EventBus/EventBus.Tests/
COPY src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj src/BuildingBlocks/EventBus/EventBusRabbitMQ/
COPY src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj src/BuildingBlocks/EventBus/EventBusServiceBus/
COPY src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj src/BuildingBlocks/EventBus/IntegrationEventLogEF/
COPY src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj src/BuildingBlocks/WebHostCustomization/WebHost.Customization/
COPY src/Services/Basket/Basket.API/Basket.API.csproj src/Services/Basket/Basket.API/
COPY src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj src/Services/Basket/Basket.FunctionalTests/
COPY src/Services/Basket/Basket.UnitTests/Basket.UnitTests.csproj src/Services/Basket/Basket.UnitTests/
COPY src/Services/Catalog/Catalog.API/Catalog.API.csproj src/Services/Catalog/Catalog.API/
COPY src/Services/Catalog/Catalog.FunctionalTests/Catalog.FunctionalTests.csproj src/Services/Catalog/Catalog.FunctionalTests/
COPY src/Services/Catalog/Catalog.UnitTests/Catalog.UnitTests.csproj src/Services/Catalog/Catalog.UnitTests/
COPY src/Services/Identity/Identity.API/Identity.API.csproj src/Services/Identity/Identity.API/
COPY src/Services/Location/Locations.API/Locations.API.csproj src/Services/Location/Locations.API/
COPY src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj src/Services/Location/Locations.FunctionalTests/
COPY src/Services/Marketing/Marketing.API/Marketing.API.csproj src/Services/Marketing/Marketing.API/
COPY src/Services/Marketing/Marketing.FunctionalTests/Marketing.FunctionalTests.csproj src/Services/Marketing/Marketing.FunctionalTests/
COPY src/Services/Ordering/Ordering.API/Ordering.API.csproj src/Services/Ordering/Ordering.API/
COPY src/Services/Ordering/Ordering.BackgroundTasks/Ordering.BackgroundTasks.csproj src/Services/Ordering/Ordering.BackgroundTasks/
COPY src/Services/Ordering/Ordering.Domain/Ordering.Domain.csproj src/Services/Ordering/Ordering.Domain/
COPY src/Services/Ordering/Ordering.FunctionalTests/Ordering.FunctionalTests.csproj src/Services/Ordering/Ordering.FunctionalTests/
COPY src/Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.csproj src/Services/Ordering/Ordering.Infrastructure/
COPY src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj src/Services/Ordering/Ordering.SignalrHub/
COPY src/Services/Ordering/Ordering.UnitTests/Ordering.UnitTests.csproj src/Services/Ordering/Ordering.UnitTests/
COPY src/Services/Payment/Payment.API/Payment.API.csproj src/Services/Payment/Payment.API/
COPY src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj src/Services/Webhooks/Webhooks.API/
COPY src/Web/WebhookClient/WebhookClient.csproj src/Web/WebhookClient/
COPY src/Web/WebMVC/WebMVC.csproj src/Web/WebMVC/
COPY src/Web/WebSPA/WebSPA.csproj src/Web/WebSPA/
COPY src/Web/WebStatus/WebStatus.csproj src/Web/WebStatus/
COPY test/ServicesTests/Application.FunctionalTests/Application.FunctionalTests.csproj test/ServicesTests/Application.FunctionalTests/
COPY test/ServicesTests/LoadTest/LoadTest.csproj test/ServicesTests/LoadTest/
RUN dotnet restore eShopOnContainers-ServicesAndWebApps.sln
COPY . .
WORKDIR /src/src/Services/TenantCustomisations/TenantAShippingInformation
RUN dotnet publish --no-restore -c Release -o /app
FROM build AS publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TenantAShippingInformation.dll"]

+ 9
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/IShippingService.cs View File

@ -0,0 +1,9 @@
using TenantAShippingInformation.Models;
namespace TenantAShippingInformation.ExternalServices
{
public interface IShippingService
{
ShippingInformation CalculateShippingInformation(int orderId);
}
}

+ 20
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/ExternalServices/MockedShippingService.cs View File

@ -0,0 +1,20 @@
using System;
using TenantAShippingInformation.Models;
namespace TenantAShippingInformation.ExternalServices
{
public class MockedShippingService : IShippingService
{
public ShippingInformation CalculateShippingInformation(int orderId)
{
ShippingInformation shippingInformation = new ShippingInformation();
shippingInformation.ShippingTime = DateTime.Today;
shippingInformation.ArrivalTime = DateTime.Today.AddDays(2);
shippingInformation.FragilityLevel = Fragility.Medium;
shippingInformation.PriorityLevel = Priority.High;
shippingInformation.OrderNumber = orderId.ToString();
return shippingInformation;
}
}
}

+ 28
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/ApplicationModule.cs View File

@ -0,0 +1,28 @@
using Autofac;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using System.Reflection;
using TenantAShippingInformation.IntegrationEvents.EventHandling;
namespace TenantAShippingInformation.Infrastructure.AutofacModules
{
public class ApplicationModule
:Autofac.Module
{
public string QueriesConnectionString { get; }
public ApplicationModule(string qconstr)
{
QueriesConnectionString = qconstr;
}
protected override void Load(ContainerBuilder builder)
{
builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEventHandler).GetTypeInfo().Assembly)
.AsClosedTypesOf(typeof(IIntegrationEventHandler<>));
}
}
}

+ 12
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/AutofacModules/MediatorModule.cs View File

@ -0,0 +1,12 @@
using Autofac;
namespace TenantAShippingInformation.Infrastructure.AutofacModules
{
public class MediatorModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
//TODO
}
}
}

+ 33
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs View File

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Authorization;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TenantAShippingInformation.Infrastructure.Filters
{
public class AuthorizeCheckOperationFilter : IOperationFilter
{
public void Apply(Operation operation, OperationFilterContext context)
{
// Check for authorize attribute
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
if (!hasAuthorize) return;
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
{
new Dictionary<string, IEnumerable<string>>
{
{ "oauth2", new [] { "orderingapi" } }
}
};
}
}
}

+ 69
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Infrastructure/Filters/HttpGlobalExceptionFilter.cs View File

@ -0,0 +1,69 @@
namespace TenantAShippingInformation.Infrastructure.Filters
{
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System.Net;
public class HttpGlobalExceptionFilter : IExceptionFilter
{
private readonly IHostingEnvironment env;
private readonly ILogger<HttpGlobalExceptionFilter> logger;
public HttpGlobalExceptionFilter(IHostingEnvironment env, ILogger<HttpGlobalExceptionFilter> logger)
{
this.env = env;
this.logger = logger;
}
public void OnException(ExceptionContext context)
{
logger.LogError(new EventId(context.Exception.HResult),
context.Exception,
context.Exception.Message);
if (1==2)//TODO
{
var problemDetails = new ValidationProblemDetails()
{
Instance = context.HttpContext.Request.Path,
Status = StatusCodes.Status400BadRequest,
Detail = "Please refer to the errors property for additional details."
};
problemDetails.Errors.Add("DomainValidations", new string[] { context.Exception.Message.ToString() });
context.Result = new BadRequestObjectResult(problemDetails);
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
else
{
var json = new JsonErrorResponse
{
Messages = new[] { "An error occur.Try it again." }
};
if (env.IsDevelopment())
{
json.DeveloperMessage = context.Exception;
}
// Result asigned to a result object but in destiny the response is empty. This is a known bug of .net core 1.1
// It will be fixed in .net core 1.1.2. See https://github.com/aspnet/Mvc/issues/5594 for more information
//TODO
//context.Result = new InternalServerErrorObjectResult(json);
context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
}
context.ExceptionHandled = true;
}
private class JsonErrorResponse
{
public string[] Messages { get; set; }
public object DeveloperMessage { get; set; }
}
}
}

+ 34
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/EventHandling/OrderStatusChangedToSubmittedIntegrationEventHandler.cs View File

@ -0,0 +1,34 @@
using Microsoft.AspNetCore.SignalR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.Extensions.Logging;
using Serilog.Context;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using TenantBShippingInformation.IntegrationEvents.Events;
namespace TenantBShippingInformation.IntegrationEvents.EventHandling
{
public class OrderStatusChangedToSubmittedIntegrationEventHandler :
IIntegrationEventHandler<OrderStatusChangedToSubmittedIntegrationEvent>
{
private readonly ILogger<OrderStatusChangedToSubmittedIntegrationEventHandler> _logger;
public OrderStatusChangedToSubmittedIntegrationEventHandler(ILogger<OrderStatusChangedToSubmittedIntegrationEventHandler> logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public async Task Handle(OrderStatusChangedToSubmittedIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}- TenantA"))
{
//TODO
Debug.WriteLine(@event);
}
}
}
}

+ 18
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/IntegrationEvents/Events/OrderStatusChangedToSubmittedIntegrationEvent.cs View File

@ -0,0 +1,18 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
namespace TenantBShippingInformation.IntegrationEvents.Events
{
public class OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public string OrderStatus { get; }
public string BuyerName { get; }
public OrderStatusChangedToSubmittedIntegrationEvent(int orderId, string orderStatus, string buyerName)
{
OrderId = orderId;
OrderStatus = orderStatus;
BuyerName = buyerName;
}
}
}

+ 7
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Models/Fragility.cs View File

@ -0,0 +1,7 @@
namespace TenantAShippingInformation.Models
{
public enum Fragility
{
Low, Medium, High
}
}

+ 7
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Models/Priority.cs View File

@ -0,0 +1,7 @@
namespace TenantAShippingInformation.Models
{
public enum Priority
{
Low, Medium, High
}
}

+ 14
- 0
src/Services/TenantCustomisations/TenantBShippingInformation/Models/ShippingInformation.cs View File

@ -0,0 +1,14 @@
using System;
namespace TenantAShippingInformation.Models
{
public class ShippingInformation
{
public int ShippingInformationId { get; set; }
public DateTime ArrivalTime { get; set; }
public DateTime ShippingTime { get; set; }
public Priority PriorityLevel {get;set;}
public Fragility FragilityLevel { get; set; }
public String OrderNumber { get; set; }
}
}

Loading…
Cancel
Save