Beispiel #1
0
        public static void AssertResetInventoryQuantityReserveAndHold(RealTimeInventory inventory, int toUpdate, int toReserve, int toHold, IInventoryServiceCompletedMessage r)
        {
            if ((toUpdate - toReserve >= 0) || toReserve <= 0)
            {
                if (toUpdate - toHold >= 0)
                {
                    Assert.True(r.Successful);
                    var newReserved = Math.Max(0, toReserve);
                    Assert.Equal(r.RealTimeInventory.Reserved, newReserved);
                    Assert.Equal(r.RealTimeInventory.Holds, toHold);
                }
                else
                {
                    Assert.False(r.Successful);
                }
            }
            else
            {
                Assert.False(r.Successful);
            }

            if (r.Successful)
            {
                return;
            }
            //else things remain same
            Assert.Equal(r.RealTimeInventory.Quantity, inventory.Quantity);
            Assert.Equal(r.RealTimeInventory.Reserved, inventory.Reserved);
            Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds);
        }
        public void ETag_Test(RealTimeInventory existingRealTimeInventory, int quantity, int reserve, int hold)
        {
            var newRealTimeInventory = new RealTimeInventory(existingRealTimeInventory.ProductId, existingRealTimeInventory.Quantity, existingRealTimeInventory.Reserved, existingRealTimeInventory.Holds);

            var first  = new RealTimeInventory(existingRealTimeInventory.ProductId, 0, 0, 0);
            var second = new RealTimeInventory(existingRealTimeInventory.ProductId, 0, 0, 0);
            var third  = new RealTimeInventory("ticketsections-" + quantity, quantity, reserve, hold);
            var forth  = new RealTimeInventory("ticketsections-" + quantity, quantity, reserve, hold);

            Assert.False(existingRealTimeInventory.IsMostRecentThan(newRealTimeInventory));
            Assert.False(existingRealTimeInventory.IsMostRecentThan(new RealTimeInventory(null, 0, 0, 0)));
            Assert.False(newRealTimeInventory.IsMostRecentThan(new RealTimeInventory(null, 0, 0, 0)));

            var mostRecentEtag = forth.ETag.GetMostRecentEtag(
                newRealTimeInventory.ETag,
                existingRealTimeInventory.ETag,
                first.ETag,
                second.ETag,
                third.ETag,
                forth.ETag
                );

            Assert.False(newRealTimeInventory.IsMostRecentThan(first));
            Assert.False(first.IsMostRecentThan(second));
            Assert.False(second.IsMostRecentThan(third));
            Assert.False(third.IsMostRecentThan(forth));
            Assert.Equal(mostRecentEtag, forth.ETag);
        }
        public static async Task <OperationResult <IRealTimeInventory> > PurchaseFromHoldsAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int quantity)
        {
            if (quantity < 0)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.NEGATIVE_PURCHASE_FOR_PURCHASEFROMHOLD, realTimeInventory, quantity).ToFailedOperationResult(realTimeInventory, productId));
            }
            var newQuantity = realTimeInventory.Quantity - quantity;
            var newHolds    = realTimeInventory.Holds - quantity;

            if (newQuantity < 0 || newHolds < 0)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.PURCHASE_EXCEED_QUANTITY_FOR_PURCHASEFROMHOLD, realTimeInventory, quantity).ToFailedOperationResult(realTimeInventory, productId));
            }

            var newrealTimeInventory = new RealTimeInventory(productId, newQuantity, realTimeInventory.Reserved,
                                                             newHolds);

            var result = await inventoryStorage.WriteInventoryAsync(newrealTimeInventory).ConfigureAwait(false);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, quantity, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newrealTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public static async Task <OperationResult <IRealTimeInventory> > PurchaseAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int quantity)
        {
            if (quantity < 0)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.NEGATIVE_PURCHASE_FOR_PURCHASEFROMRESERVATION, realTimeInventory, quantity).ToFailedOperationResult(realTimeInventory, productId));
            }
            var newQuantity = realTimeInventory.Quantity - quantity;

            var newReserved = Math.Max(0, realTimeInventory.Reserved - quantity);

            //todo we still want to sell even though there is reservation
            //var newReserved = realTimeInventory.Reserved - quantity;
            //if(newReserved<0) throw new Exception("provided " + quantity + ", available reservations must be less than or equal to quantity for product " + productId);

            if (newQuantity - realTimeInventory.Holds < 0)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.PURCHASE_EXCEED_QUANTITY_FOR_PURCHASEFROMRESERVATION, realTimeInventory, quantity).ToFailedOperationResult(realTimeInventory, productId));
            }

            var newrealTimeInventory = new RealTimeInventory(productId, newQuantity, newReserved, realTimeInventory.Holds);
            var result = await inventoryStorage.WriteInventoryAsync(newrealTimeInventory);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, quantity, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newrealTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public void Holds_Test(RealTimeInventory inventory, int toHold)
        {
            IInventoryServiceCompletedMessage response;

            using (var testHelper = CreateInventoryServiceServer(inventory))
                response = testHelper.PlaceHoldAsync(inventory, toHold).WaitAndGetOperationResult();

            InventoryServiceSpecificationHelper.AssertHolds(inventory, toHold, response);
        }
        public void UpdateQuantity_Test(RealTimeInventory inventory, int toUpdate)
        {
            IInventoryServiceCompletedMessage response;

            using (var testHelper = CreateInventoryServiceServer(inventory))
                response = testHelper.UpdateQuantityAsync(inventory, toUpdate).WaitAndGetOperationResult();

            InventoryServiceSpecificationHelper.AssertUpdateQuantity(inventory, toUpdate, response);
        }
        public void PurchaseFromHolds_Test(RealTimeInventory inventory, uint toPurchase)
        {
            IInventoryServiceCompletedMessage response;

            using (var testHelper = CreateInventoryServiceServer(inventory))
                response = testHelper.PurchaseFromHoldsAsync(inventory, (int)toPurchase).WaitAndGetOperationResult();

            InventoryServiceSpecificationHelper.AssertPurchaseFromHolds(inventory, toPurchase, response);
        }
        public void Reservation_Test(RealTimeInventory inventory, int toReserve)
        {
            IInventoryServiceCompletedMessage response = null;

            using (var testHelper = CreateInventoryServiceServer(inventory))
                response = testHelper.ReserveAsync(inventory, toReserve).WaitAndGetOperationResult();

            InventoryServiceSpecificationHelper.AssertReservations(inventory, toReserve, response);
        }
Beispiel #9
0
        public Task <IInventoryServiceCompletedMessage> PurchaseAsync(RealTimeInventory product, int purchaseQuantity)
        {
            var request = new PurchaseMessage(product.ProductId, purchaseQuantity);

            if (DontUseActorSystem)
            {
                return(PerformOperation(request, product.PurchaseAsync(TestInventoryStorage, request.ProductId, request.Update), TestInventoryStorage.ReadInventoryAsync(request.ProductId).Result.Result));
            }
            return(inventoryActor.Ask <IInventoryServiceCompletedMessage>(request, GENERAL_WAIT_TIME));
        }
        public void ResetInventoryQuantityReserveAndHold_Test(RealTimeInventory inventory, int toUpdate, int toReserve, int toHold)
        {
            IInventoryServiceCompletedMessage response;

            using (var testHelper = CreateInventoryServiceServer(inventory))
            {
                response = testHelper.ResetInventoryQuantityReserveAndHoldAsync(inventory, toUpdate, toReserve, toHold).WaitAndGetOperationResult();
            }

            InventoryServiceSpecificationHelper.AssertResetInventoryQuantityReserveAndHold(inventory, toUpdate, toReserve, toHold, response);
        }
Beispiel #11
0
        public void TestMethod1()
        {
            var initialInventory = new RealTimeInventory("ticketsections-100", 10, 0, 0);
            var serverOptions    = new InventoryServerOptions()
            {
                InitialInventory        = initialInventory,
                InventoryActorAddress   = "akka.tcp://InventoryService-Server@localhost:10000/user/InventoryActor",
                ServerEndPoint          = "http://*:10088/",
                StorageType             = typeof(InMemory),
                ServerActorSystemName   = "InventoryService-Server",
                ServerActorSystemConfig = @"
                  akka.actor{provider= ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""}
                  akka.remote.helios.tcp {
                      transport-class =""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
                      port = 10000
                      transport-protocol = tcp
                      hostname = ""localhost""
                  }
              "
            };

            using (var server = new InventoryServiceServer(new TestPerformanceService(), new NullBackUp(), serverOptions))
            {
                var mySystem       = Akka.Actor.ActorSystem.Create("mySystem", ConfigurationFactory.ParseString(@"
                  akka.actor{provider= ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""}
                  akka.remote.helios.tcp {
                      transport-class =""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
                      port = 0
                      transport-protocol = tcp
                      hostname = ""localhost""
                  }
              "));
                var inventoryActor = mySystem.ActorSelection(serverOptions.InventoryActorAddress);

                var result =
                    server.inventoryActor.Ask <IInventoryServiceCompletedMessage>(new ReserveMessage(
                                                                                      initialInventory.ProductId, 20));

                result.ConfigureAwait(false);

                Task.WaitAll(result);

                if (result.Result.Successful)
                {
                    Console.WriteLine(result.Result.RealTimeInventory);
                }
                else
                {
                    Console.WriteLine(result.Result.RealTimeInventory);
                }
            }
        }
        public static RealTimeInventory InitializeFromStorage(this RealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string id)
        {
            var initTask = inventoryStorage.ReadInventoryAsync(id);

            Task.WaitAll(initTask);
            var inventory = initTask.Result.Result;

            if (!initTask.Result.IsSuccessful)
            {
                throw initTask.Result.Errors.Flatten();
            }
            return(new RealTimeInventory(id, inventory.Quantity, inventory.Reserved, inventory.Holds));
        }
        public static async Task <OperationResult <IRealTimeInventory> > UpdateQuantityAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int quantity)
        {
            var newQuantity = realTimeInventory.Quantity + quantity;

            var newRealTimeInventory = new RealTimeInventory(productId, newQuantity, realTimeInventory.Reserved, realTimeInventory.Holds);
            var result = await inventoryStorage.WriteInventoryAsync(newRealTimeInventory);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, quantity, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newRealTimeInventory.ToOperationResult(isSuccessful: true));
        }
 public InventoryServiceServer CreateInventoryServiceServer(RealTimeInventory inventory)
 {
     /*
      * TODO USE THESE
      #if !FULL_INTEGRATION
      *    return new InventoryServiceServer(new InventoryServerOptions() { InitialInventory = inventory, DontUseActorSystem = true });
      #else
      *         return new InventoryServiceServer(new InventoryServerOptions() { InitialInventory = inventory });
      #endif
      */
     // return new InventoryServiceServer(new InventoryServerOptions() { InitialInventory = inventory });
     return(new InventoryServiceServer(new TestPerformanceService(), new NullBackUp(), new InventoryServerOptions()
     {
         InitialInventory = inventory, DontUseActorSystem = true
     }));
 }
 public void Holds_Reservation_PurchaseFromHold_And_Purchase_Test(RealTimeInventory inventory, int toUpdate)
 {
     using (var testHelper = CreateInventoryServiceServer(inventory))
     {
         const int looplength       = 5;
         var       operations       = InventoryServiceSpecificationHelper.GetOperations(testHelper);
         var       assertions       = InventoryServiceSpecificationHelper.GetAssertions();
         var       updatedInventory = inventory;
         for (var i = 0; i < looplength; i++)
         {
             var selection = new Random().Next(1, operations.Count);
             var updatedInventoryMessage = operations[selection](updatedInventory, toUpdate).WaitAndGetOperationResult();
             assertions[selection](updatedInventory, toUpdate, updatedInventoryMessage);
             updatedInventory = updatedInventoryMessage.RealTimeInventory as RealTimeInventory;
         }
     }
 }
Beispiel #16
0
        public Task <IInventoryServiceCompletedMessage> ResetInventoryQuantityReserveAndHoldAsync(
            RealTimeInventory product,
            int quantity,
            int reserveQuantity,
            int holdsQuantity)
        {
            var request = new ResetInventoryQuantityReserveAndHoldMessage(product.ProductId, quantity, reserveQuantity, holdsQuantity);

            if (DontUseActorSystem)
            {
                return(PerformOperation(request, product.ResetInventoryQuantityReserveAndHoldAsync(TestInventoryStorage, request.ProductId, request.Update, request.Reservations, request.Holds),
                                        TestInventoryStorage
                                        .ReadInventoryAsync(request.ProductId)
                                        .Result.Result));
            }
            return(inventoryActor.Ask <IInventoryServiceCompletedMessage>(request, GENERAL_WAIT_TIME));
        }
        public static async Task <OperationResult <IRealTimeInventory> > PlaceHoldAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int toHold)
        {
            var newHolds = realTimeInventory.Holds + toHold;

            if (newHolds > realTimeInventory.Quantity)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.HOLD_EXCEED_QUANTITY_FOR_HOLD, realTimeInventory, toHold).ToFailedOperationResult(realTimeInventory, productId));
            }
            var newRealTimeInventory = new RealTimeInventory(productId, realTimeInventory.Quantity, realTimeInventory.Reserved, newHolds);

            var result = await inventoryStorage.WriteInventoryAsync(newRealTimeInventory);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, toHold, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newRealTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public static async Task <OperationResult <IRealTimeInventory> > ReserveAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int reservationQuantity)
        {
            var newReserved = Math.Max(0, realTimeInventory.Reserved + reservationQuantity);

            if ((reservationQuantity > 0) && (newReserved > realTimeInventory.Quantity - realTimeInventory.Holds))
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.RESERVATION_EXCEED_QUANTITY, realTimeInventory, reservationQuantity).ToFailedOperationResult(realTimeInventory, productId));
            }

            var newRealTimeInventory = new RealTimeInventory(productId, realTimeInventory.Quantity, newReserved, realTimeInventory.Holds);

            var result = await inventoryStorage.WriteInventoryAsync(newRealTimeInventory);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, reservationQuantity, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newRealTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public static async Task <OperationResult <IRealTimeInventory> > ResetInventoryQuantityReserveAndHoldAsync(this IRealTimeInventory currentInventory, IInventoryStorage inventoryStorage, string productId, int quantity, int reserve, int hold)
        {
            IRealTimeInventory realTimeInventory = new RealTimeInventory(currentInventory.ProductId, 0, 0, 0);

            var result = await realTimeInventory.UpdateQuantityAsync(inventoryStorage, productId, quantity);

            if (result.IsSuccessful)
            {
                result = await result.Data.ReserveAsync(inventoryStorage, productId, reserve);

                if (result.IsSuccessful)
                {
                    result = await result.Data.PlaceHoldAsync(inventoryStorage, productId, hold);

                    if (result.IsSuccessful)
                    {
                        return(result.Data.ToOperationResult(isSuccessful: true));
                    }
                }
            }
            result.Data = currentInventory;
            return(result);
        }
Beispiel #20
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;
            }
        }
        private List <Tuple <int, RealTimeInventory, int> > CreateInventoryOperationEvents(RealTimeInventory inventory, int toUpdate, int looplength)
        {
            List <Tuple <int, RealTimeInventory, int> > events = new List <Tuple <int, RealTimeInventory, int> >();
            var operations       = InventoryServiceSpecificationHelper.GetOperations(null);
            var updatedInventory = inventory;

            for (var i = 0; i < looplength; i++)
            {
                var selection = new Random().Next(1, operations.Count);
                events.Add(new Tuple <int, RealTimeInventory, int>(selection, new RealTimeInventory(updatedInventory.ProductId, updatedInventory.Quantity, updatedInventory.Reserved, updatedInventory.Holds), toUpdate));
            }
            return(events);
        }
        public void Concurrent_Holds_Reservation_PurchaseFromHold_And_Purchase_Async_Test(RealTimeInventory inventory, int toUpdate)
        {
            const int looplength = 5;

            var events = CreateInventoryOperationEvents(inventory, toUpdate, looplength);

            RealTimeInventory currentInventoryAfterFirstOperation;

            using (var testHelper = CreateInventoryServiceServer(inventory))
                currentInventoryAfterFirstOperation = RunSomeInventoryOperationUsingEventsSync(events, testHelper);

            RealTimeInventory currentInventoryAfterLastOperation;

            using (var testHelper = CreateInventoryServiceServer(inventory))
                currentInventoryAfterLastOperation = RunSomeInventoryOperationUsingEventsAsync(events, testHelper);

            Assert.Equal(currentInventoryAfterFirstOperation.Quantity, currentInventoryAfterLastOperation.Quantity);
            Assert.Equal(currentInventoryAfterFirstOperation.Reserved, currentInventoryAfterLastOperation.Reserved);
            Assert.Equal(currentInventoryAfterFirstOperation.Holds, currentInventoryAfterLastOperation.Holds);
        }
 public RealTimeInventoryFinalResult(RealTimeInventory realTimeInventory, IInventoryServiceCompletedMessage inventoryServiceCompletedMessage, OperationResult <IRealTimeInventory> result)
 {
     RealTimeInventory = realTimeInventory;
     InventoryServiceCompletedMessage = inventoryServiceCompletedMessage;
     Result = result;
 }
Beispiel #24
0
        public ProductInventoryActor(IInventoryStorage inventoryStorage, IActorRef InventoryQueryActorRef, string id, bool withCache, IPerformanceService performanceService)
        {
            PerformanceService = performanceService;
            _id                  = id;
            _withCache           = withCache;
            InventoryStorage     = inventoryStorage;
            RealTimeInventory    = RealTimeInventory.InitializeFromStorage(InventoryStorage, id);
            NotificationActorRef = InventoryQueryActorRef;
            ReceiveAsync <GetInventoryMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }

                if (_withCache == false)
                {
                    var result        = await RealTimeInventory.ReadInventoryFromStorageAsync(InventoryStorage, message.ProductId);
                    RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
                }
                else
                {
                    RealTimeInventory = RealTimeInventory.ToSuccessOperationResult().ProcessAndSendResult(message, (rti) => new GetInventoryCompletedMessage(rti, true), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
                }
            });

            ReceiveAsync <ReserveMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.ReserveAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <UpdateQuantityMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.UpdateQuantityAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <UpdateAndHoldQuantityMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var updateandHoldResultesult = await RealTimeInventory.UpdateQuantityAndHoldAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory            = updateandHoldResultesult.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <PlaceHoldMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.PlaceHoldAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <PurchaseMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.PurchaseAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <PurchaseFromHoldsMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.PurchaseFromHoldsAsync(InventoryStorage, message.ProductId, message.Update).ConfigureAwait(false);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <FlushStreamsMessage>(async message =>
            {
                var result = await RealTimeInventory.InventoryStorageFlushAsync(InventoryStorage, _id);
                Sender.Tell(result.Data);
            });

            ReceiveAsync <ResetInventoryQuantityReserveAndHoldMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var updateandHoldResultesult = await RealTimeInventory.ResetInventoryQuantityReserveAndHoldAsync(InventoryStorage, message.ProductId, message.Update, message.Reservations, message.Holds);
                RealTimeInventory            = updateandHoldResultesult.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

#if DEBUG
            //            Context.System.Scheduler.ScheduleTellRepeatedly(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(5), Nobody.Instance, RealTimeInventory, Self);
#endif
        }
Beispiel #25
0
        protected override void PostStop()
        {
            Logger.Error(" I , the " + _id + " have been stopped. At the moment my inventory is " + RealTimeInventory.GetCurrentQuantitiesReport());
            Sender.Tell(new InventoryOperationErrorMessage(new RealTimeInventory(_id, 0, 0, 0), new RealTimeInventoryException()
            {
                ErrorMessage = "Actor " + _id + " has stopped"
            }));

            Context.Parent.Tell(new RemoveProductMessage(RealTimeInventory));
            base.PostStop();
        }
 public RemoveProductMessage(RealTimeInventory realTimeInventory, Exception reason = null)
 {
     RealTimeInventory = realTimeInventory;
     Reason            = reason;
 }