Example #1
0
        /// <summary>
        ///   Stores an order as a final order which has completed submission.
        /// </summary>
        ///
        /// <param name="log">The logging instance to use for emitting information.</param>
        /// <param name="storage">The storage to use for the order.</param>
        /// <param name="createOrderMessage">The CreateOrderMessage representing the order.</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 interacting with storage.</param>
        ///
        /// <returns>The result of the operation.</returns>
        ///
        protected virtual async Task <OperationResult> StoreOrderAsCompletedAsync(ILogger log,
                                                                                  IOrderStorage storage,
                                                                                  CreateOrderMessage order,
                                                                                  string correlationId           = null,
                                                                                  OperationResult emulatedResult = null)
        {
            OperationResult result;

            try
            {
                if (emulatedResult != null)
                {
                    result = emulatedResult;
                }
                else
                {
                    var key = await storage.SaveCompletedOrderAsync(order);

                    result = new OperationResult
                    {
                        Outcome     = Outcome.Success,
                        Reason      = String.Empty,
                        Recoverable = Recoverability.Final,
                        Payload     = key
                    };
                }

                log.Information("Order details for {Partner}//{Order} have been saved as final.  Emulated: {Emulated}.  Result: {Result}",
                                order?.Identity?.PartnerCode,
                                order?.Identity?.PartnerOrderId,
                                (emulatedResult != null),
                                result);
            }

            catch (Exception ex)
            {
                log.Error(ex, "An error occured while saving {Partner}//{Order} as completed submission.", order.Identity.PartnerCode, order.Identity.PartnerOrderId);
                return(OperationResult.ExceptionResult);
            }

            return(result);
        }