/// <summary> /// Submits an order to the order production service, signaling a request that it be produced. /// </summary> /// /// <param name="log">The logging instance to use for emitting information.</param> /// <param name="client">The client to use for interacting with the order production service.</param> /// <param name="createOrderMessage">The CreateOrderMessage representing the order to be produced.</param> /// <param name="correlationId">An optional identifier used to correlate activities across the disparate parts of processing, including external interations.</param> /// <param name="emulatedResult">An optional emulated result to use in place of querying the eCommerce service.</param> /// /// <returns>The result of the operation.</returns> /// /// <remarks> /// This method owns responsibility for logging the results of the operation and how /// it was produced. /// </remarks> /// protected virtual async Task <OperationResult> SendOrderToProductionAsync(ILogger log, IOrderProductionClient client, CreateOrderMessage order, string correlationId = null, OperationResult emulatedResult = null) { OperationResult result; try { result = emulatedResult ?? (await client.SubmitOrderForProductionAsync(order, correlationId)); log.Information("The order {Partner}//{Order} has been submitted for production. Emulated: {Emulated}. Result: {Result}", order?.Identity?.PartnerCode, order?.Identity?.PartnerOrderId, (emulatedResult != null), result); } catch (Exception ex) { log.Error(ex, "An error occured while submitting the order {Partner}//{Order}", order?.Identity?.PartnerCode, order?.Identity?.PartnerOrderId); return(OperationResult.ExceptionResult); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="OrderSubmitter"/> class. /// </summary> /// /// <param name="configuration">The configuration to use for influencing order submission behavior.</param> /// <param name="orderProductionClient">The client to use for interacting with the order production service.</param> /// <param name="orderStorage">The storage to use for orders.</param> /// <param name="logger">The logger to be used for emitting telemetry from the controller.</param> /// <param name="jsonSerializerSettings">The settings to use for JSON serializerion.</param> /// public OrderSubmitter(OrderSubmitterConfiguration configuration, IOrderProductionClient orderProductionClient, IOrderStorage orderStorage, ILogger logger, JsonSerializerSettings jsonSerializerSettings) { this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this.orderProductionClient = orderProductionClient ?? throw new ArgumentNullException(nameof(orderProductionClient)); this.orderStorage = orderStorage ?? throw new ArgumentNullException(nameof(orderStorage)); this.Log = logger ?? throw new ArgumentNullException(nameof(logger)); this.jsonSerializerSettings = jsonSerializerSettings ?? throw new ArgumentNullException(nameof(jsonSerializerSettings)); this.rng = new Random(); }