public Task Handle(ProvisionDownloadResponse message, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Download for Order {OrderNumber} has been provisioned, Publishing Download ready event", message.OrderNumber);
        logger.Information("Downloads for Order {OrderNumber} is ready, publishing it.", message.OrderNumber);

        var downloadIsReady = new DownloadIsReady
        {
            OrderNumber = message.OrderNumber,
            ClientId    = message.ClientId,
            ProductUrls = new Dictionary <string, string>()
        };

        foreach (var productId in message.ProductIds)
        {
            downloadIsReady.ProductUrls.Add(productId, productIdToUrlMap[productId]);
        }
        return(context.Publish(downloadIsReady));
    }
Beispiel #2
0
    public Task Handle(HaveOrderCancelled message, IMessageHandlerContext context)
    {
        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Order for client {ClientId} was cancelled.", message.ClientId);

        return(ordersHubContext.Clients.Client(message.ClientId).SendAsync("orderCancelled",
                                                                           new
        {
            message.OrderNumber,
        }));
    }
    public Task Handle(ClientBecamePreferred message, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Handler WhenCustomerIsPreferredSendWelcomeEmail invoked for CustomerId: {ClientId}", message.ClientId);

        return(Task.CompletedTask);
    }
    public Task Handle(HaveOrderPlaced message, IMessageHandlerContext context)
    {
        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Order placed for customer {ClientId}.", message.ClientId);

        return(ordersHubContext.Clients.Client(message.ClientId).SendAsync("orderReceived",
                                                                           new
        {
            message.OrderNumber,
            message.ProductIds
        }));
    }
    public Task Handle(DownloadIsReady message, IMessageHandlerContext context)
    {
        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Order became ready. Sending product info.");

        return(ordersHubContext.Clients.Client(message.ClientId).SendAsync("orderReady",
                                                                           new
        {
            message.OrderNumber,
            ProductUrls = message.ProductUrls.Select(pair => new { Id = pair.Key, Url = pair.Value }).ToArray()
        }));
    }
    public Task Handle(SubmitHaveOrder message, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        Data.OrderNumber = message.OrderNumber;
        Data.ProductIds  = message.ProductIds;
        Data.ClientId    = message.ClientId;

        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Starting cool down period for order {OrderNumber}.", Data.OrderNumber);

        return(RequestTimeout(context, TimeSpan.FromSeconds(20), new BuyersRemorseIsOver()));
    }
    public Task Handle(HaveOrderAccepted message, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Customer: {ClientId} is now a preferred customer publishing for other service concerns", message.ClientId);

        // publish this event as an asynchronous event
        var clientBecamePreferred = new ClientBecamePreferred
        {
            ClientId = message.ClientId,
            PreferredStatusExpiresOn = DateTime.Now.AddMonths(2)
        };

        return(context.Publish(clientBecamePreferred));
    }
    public Task Handle(HaveOrderAccepted message, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Order {OrderNumber} has been accepted, Let's provision the download -- Sending ProvisionDownloadRequest to the Store.Operations endpoint", message.OrderNumber);

        // send out a request (a event will be published when the response comes back)
        var request = new ProvisionDownloadRequest
        {
            ClientId    = message.ClientId,
            OrderNumber = message.OrderNumber,
            ProductIds  = message.ProductIds
        };

        return(context.Send(request));
    }
    public Task Handle(CancelHaveOrder message, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Order {OrderNumber} was cancelled.", message.OrderNumber);

        MarkAsComplete();

        var orderCancelled = new HaveOrderCancelled
        {
            OrderNumber = message.OrderNumber,
            ClientId    = message.ClientId
        };

        return(context.Publish(orderCancelled));
    }
Beispiel #10
0
    public Task Handle(ProvisionDownloadRequest message, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        var products = string.Join(", ", message.ProductIds);

        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Provision the products and make the Urls available to the Content management for download ...{products} product(s) to provision", message.ProductIds);

        var response = new ProvisionDownloadResponse
        {
            OrderNumber = message.OrderNumber,
            ProductIds  = message.ProductIds,
            ClientId    = message.ClientId
        };

        return(context.Reply(response));
    }
    public Task Timeout(BuyersRemorseIsOver state, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        MarkAsComplete();

        var logger = context.GetOrderWorkflowLogger(Data);

        logger.Information("Cooling down period for order {OrderNumber} has elapsed.", Data.OrderNumber);

        var orderAccepted = new HaveOrderAccepted
        {
            OrderNumber = Data.OrderNumber,
            ProductIds  = Data.ProductIds,
            ClientId    = Data.ClientId
        };

        return(context.Publish(orderAccepted));
    }
    public Task Handle(SubmitHaveOrder message, IMessageHandlerContext context)
    {
        if (DebugFlagMutator.Debug)
        {
            Debugger.Break();
        }

        var logger = context.GetOrderWorkflowLogger(message);

        logger.Information("Received an order {OrderNumber} for {ProductIds} products(s).", message.OrderNumber, message.ProductIds);
        logger.Information("The credit card values will be encrypted when looking at the messages in the queues");
        logger.Information("CreditCard Number is {CreditCardNumber}", message.CreditCardNumber.EncryptedValue);
        logger.Information("CreditCard Expiration Date is {ExpirationDate}", message.ExpirationDate.EncryptedValue);

        // tell the client the order was received
        var orderPlaced = new HaveOrderPlaced
        {
            ClientId    = message.ClientId,
            OrderNumber = message.OrderNumber,
            ProductIds  = message.ProductIds
        };

        return(context.Publish(orderPlaced));
    }