Ejemplo n.º 1
0
        public static Dictionary <int, Func <RealTimeInventory, int, Task <IInventoryServiceCompletedMessage> > > GetOperations(InventoryServiceServer testHelper)
        {
            var operations = new Dictionary <int, Func <RealTimeInventory, int, Task <IInventoryServiceCompletedMessage> > >
            {
                {
                    1, (product, update) =>
                    {
                        var reservationResult = testHelper.ReserveAsync(product, update);
                        return(reservationResult);
                    }
                },
                {
                    2, (product, update) =>
                    {
                        var reservationResult = testHelper.UpdateQuantityAsync(product, update);
                        return(reservationResult);
                    }
                },
                {
                    3, (product, update) =>
                    {
                        var reservationResult = testHelper.PlaceHoldAsync(product, update);
                        return(reservationResult);
                    }
                },
                {
                    4, (product, update) =>
                    {
                        var reservationResult = testHelper.UpdateQuantityAndHoldAsync(product, update);
                        return(reservationResult);
                    }
                },
                {
                    5, (product, update) =>
                    {
                        var reservationResult = testHelper.PurchaseAsync(product, update);
                        return(reservationResult);
                    }
                },
                {
                    6, (product, update) =>
                    {
                        var reservationResult = testHelper.PurchaseFromHoldsAsync(product, update);
                        return(reservationResult);
                    }
                }
            };

            return(operations);
        }
Ejemplo n.º 2
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            try
            {
                var productName = "productName";
                var inventory   = new RealTimeInventory(
                    productName,
                    Convert.ToInt32(InitialQuantity.Text),
                    Convert.ToInt32(InitialReservation.Text),
                    Convert.ToInt32(InitialHold.Text));
                InventoryServiceServer helper = new InventoryServiceServer(new TestPerformanceService(), new NullBackUp(), new InventoryServerOptions()
                {
                    StorageType       = typeof(Storage.InMemoryLib.InMemory),
                    InitialInventory  = inventory,
                    ClientActorSystem = ActorSystem
                });

                var t = helper.ReserveAsync(ActorSystem.ActorSelection(textBox1.Text), 1);

                var task = ActorSystem.ActorSelection(textBox1.Text).ResolveOne(TimeSpan.FromSeconds(5));
                // task.ConfigureAwait(false);

                task.ContinueWith(r =>
                {
                    IInventoryServiceCompletedMessage result = null;
                    var newUpdate = Convert.ToInt32(NewQuantity.Text);
                    switch (cmbOoperation.SelectedItem.ToString())
                    {
                    case "ReadInventory":
                        result = helper.GetInventoryAsync(productName).WaitAndGetOperationResult();
                        break;

                    case "Reserve":
                        result = helper.ReserveAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "UpdateQuantity":
                        result = helper.UpdateQuantityAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "UpdateQuantityAndHold":
                        result = helper.UpdateQuantityAndHoldAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "PlaceHold":
                        result = helper.PlaceHoldAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "Purchase":
                        result = helper.PurchaseAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "PurchaseFromHolds":
                        result = helper.PurchaseFromHoldsAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;
                    }

                    if (result != null)
                    {
                        ResultQuantity.Text    = result.RealTimeInventory.Quantity.ToString();
                        ResultHold.Text        = result.RealTimeInventory.Holds.ToString();
                        ResultReservation.Text = result.RealTimeInventory.Reserved.ToString();

                        if (!result.Successful)
                        {
                            var errorMessage       = result as InventoryOperationErrorMessage;
                            var list               = new List <string>();
                            var aggregateException = errorMessage?.Error;
                            if (aggregateException != null)
                            {
                                list.Add(aggregateException.ErrorMessage);
                            }
                            richTextBox1.Text = errorMessage?.Error?.ErrorMessage + " - " + string.Join(" ", list);
                        }
                        else
                        {
                            richTextBox1.Text = "";
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                richTextBox1.Text = ex.Message + ex?.InnerException?.Message;
            }
        }