Esempio n. 1
0
        private void Handle(AddProduct command)
        {
            var domainEvent = new ProductAdded(command.ProductName);

            //TODO: Handle persistence errors https://getakka.net/articles/persistence/event-sourcing.html#persistence-status-handling
            Persist(domainEvent, Apply);
        }
        public void ReceiveTest()
        {
            var message = new ProductAdded
            {
                ProductId = 5,
                Msgs      = new List <TestMsg>()
                {
                    new TestMsg()
                    {
                        Type  = Int32.MaxValue,
                        Type1 = "asas"
                    },
                    new TestMsg()
                    {
                        Type  = Int32.MinValue,
                        Type1 = "asdasd"
                    }
                }
            };

            var builder = new AgreementBuilder();

            builder.Consumer("Message.Reciever")
            .HasAgreementWith("Message.Publisher")
            .ExpectsMessage(message)
            .Build();
        }
        public void AddProduct(Guid productId)
        {
            var e = new ProductAdded(productId);

            Apply(e);
            AddEvent(e);
        }
 public void EditProduct(Product product, string newName, string newDescription)
 {
     product.Name        = newName;
     product.Description = newDescription;
     ProductAdded?.Invoke(product);
     _logger.Log($"Внесены изменения в продукт {product.Name}");
     SaveData();
 }
Esempio n. 5
0
        private void HandleProductAddedEvent(ProductAdded productAdded)
        {
            var entry = this.mostSeenProducts.GetValueOrDefault(productAdded.ProductId);

            entry = entry != null?entry.Add(productAdded.Quantity) : new ReadModel.Product(productAdded.ProductId, "", 0.0M, productAdded.Quantity);

            this.mostSeenProducts[productAdded.ProductId] = entry;
        }
 private void HandleEvent(Customer customer, ProductAdded @event)
 {
     customer.Cart.Products.Add(new Product
     {
         Id    = @event.ProductId,
         Name  = @event.ProductName,
         Price = @event.ProductPrice
     });
 }
Esempio n. 7
0
        public async Task Handle(ProductAdded notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var collection = _mongoClient.GetDatabase(_settings.Database).GetCollection <CategoryAggregate>(nameof(CategoryAggregate));
            await collection.UpdateOneAsync(Builders <CategoryAggregate> .Filter.Eq(p => p.OriginalId, notification.SourceId), Builders <CategoryAggregate> .Update.Inc(p => p.ProductCount, 1));
        }
Esempio n. 8
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            var product = GetProduct();
            var @event  = new ProductAdded()
            {
                ProductId = this.ProductId,
                UnitPrice = product.UnitPrice.Value
            };

            Bus.Send(@event);
        }
        public void AddProduct(Product product, Category category)
        {
            if (category.Products.Exists(p => p.Name == product.Name))
            {
                throw new Exception("Такой продукт уже существует!");
            }

            category.Products.Add(product);
            ProductAdded?.Invoke(product);
            _logger.Log($"Добавлен новый продукт {product.Name}");
            SaveData();
        }
Esempio n. 10
0
        public void StoringCartAggregateEmitEvent()
        {
            var cart = Cart.CreateEmptyFor(user);

            var itemId1 = cart.AddProduct(shampoo, 1);
            var itemId2 = cart.AddProduct(soap, 1);

            Assert.That(cart.GetUncommittedEvents(), Is.EqualTo(new[] {
                ProductAdded.For(cart, itemId1, shampoo, 1),
                ProductAdded.For(cart, itemId2, soap, 1)
            }));
        }
Esempio n. 11
0
        /// <summary>
        /// Add a product to the list
        /// </summary>
        /// <param name="product"></param>
        void IProductStore.AddProduct(IProduct product)
        {
            Thread.Sleep(5000);//DO NOT REMOVE; TO SIMULATE A BUGGY/SLOW SERVICE

            // Use the lock object to avoid concurrency issues
            lock (_productsLock)
            {
                _products.Add(product);
            }

            ProductAdded?.Invoke(product);
        }
Esempio n. 12
0
        public void AddItem(Product product)
        {
            products.Add(product);
            System.Console.WriteLine($"Product {product.Name} added to Cart");

            // Option 1 : Using IObserver/IObservable pattern
            foreach (var observer in observers)
            {
                observer.OnNext(product);
            }

            // Option 2: Using Event Handler Pattern
            ProductAdded?.Invoke(this, new ProductAddedEventArgs(product));
        }
Esempio n. 13
0
        public async Task HandleAsync(ProductAdded @event)
        {
            var product = await productRepository.GetByIdAsync(@event.ProductId.IdAsString());

            var cart = await orderRepository.GetByIdAsync(@event.AggregateId.IdAsString());

            var cartItem = OrderItemReadModel.CreateFor(@event.AggregateId.IdAsString(), @event.ProductId.IdAsString());

            cartItem.ProductName = product.Name;
            cartItem.Quantity    = @event.Quantity;
            cart.TotalItems     += @event.Quantity;
            await orderRepository.UpdateAsync(cart);

            await orderItemRepository.InsertAsync(cartItem);
        }
Esempio n. 14
0
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnCollectionChanged(e);
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                ProductAdded?.Invoke((IProduct)e.NewItems[0]);

                Thread.Sleep(5000);    //DO NOT REMOVE; TO SIMULATE A BUGGY/SLOW SERVICE
                break;

            case NotifyCollectionChangedAction.Remove:
                Thread.Sleep(5000);
                break;
            }
        }
Esempio n. 15
0
    public void AddProduct(
        IProductPriceCalculator productPriceCalculator,
        ProductItem productItem)
    {
        if (Status != CartStatus.Pending)
        {
            throw new InvalidOperationException($"Adding product for the cart in '{Status}' status is not allowed.");
        }

        var pricedProductItem = productPriceCalculator.Calculate(productItem).Single();

        var @event = ProductAdded.Create(Id, pricedProductItem);

        Enqueue(@event);
        Apply(@event);
    }
Esempio n. 16
0
        private void Apply(ProductAdded @event)
        {
            Version++;

            var newProductItem = @event.ProductItem;

            var existingProductItem = FindProductItemMatchingWith(newProductItem);

            if (existingProductItem is null)
            {
                ProductItems.Add(newProductItem);
                return;
            }

            ProductItems.Replace(
                existingProductItem,
                existingProductItem.MergeWith(newProductItem)
                );
        }
Esempio n. 17
0
        private void Apply(ProductAdded domainEvent)
        {
            var cartLine = cartState.Lines.SingleOrDefault(line => line.ProductName == domainEvent.ProductName);

            if (cartLine == null)
            {
                //It didn't exist, so add it
                cartLine = new CartLine {
                    ProductName = domainEvent.ProductName, Quantity = 1
                };
                cartState.Lines.Add(cartLine);
            }
            else
            {
                //Just update its quantity
                cartLine.Quantity++;
            }
            Become(NonEmpty);
        }
        public async Task <AddProductToCartResponse> Handle(AddProductToCartCommand request, CancellationToken cancellationToken)
        {
            decimal totalPrice = _addProductToCartCommands.Sum(x => x.Product.Price) + request.Product.Price;

            if (totalPrice < 200)
            {
                ProductAdded?.Invoke(this, new AddProductToBasketEventArgs {
                    Product = request.Product
                });
                _addProductToCartCommands.Add(request);
                return(new AddProductToCartResponse {
                    Succeeded = true
                });
            }
            return(new AddProductToCartResponse
            {
                Succeeded = false,
                Message = $"{totalPrice} exceeds the limit of 200$"
            });
        }
        public void AddProducts()
        {
            try
            {
                if (Name != string.Empty && SKU != string.Empty && Type != null && Brand != null)
                {
                    Product prod = new Product(Name, SKU, PurchasePriceDKK, StockAmount, MinStock, Type, Brand, LeadTimeDays, IsActive);

                    controller.AddProduct(prod);

                    ProductAdded.Invoke(Name, null);
                    ClearAddProductTable();
                }
                else
                {
                    throw new Exception("Produktet blev ikke gemt - tjek din indstatning");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 20
0
 public void Apply(ProductAdded @event)
 {
     Id          = Guid.NewGuid();
     CartId      = @event.CartId;
     Description = $"Created tentative Cart with id {@event.CartId}";
 }
Esempio n. 21
0
        internal void ApplyProductAdded(IDomainEvent ev)
        {
            ProductAdded addedEvent = ev as ProductAdded;

            Items.Add(new OrderItem(addedEvent?.ProductId, addedEvent?.Quantity ?? 0));
        }
Esempio n. 22
0
 private void HandleEvent(ProductAdded @event)
 {
     this._products.Add(@event.Product);
 }
        void Button_Clicked(System.Object sender, System.EventArgs e)
        {
            var parent = (sender as Button).Parent as Grid;

            ProductAdded.Invoke(parent.BindingContext, new EventArgs());
        }
Esempio n. 24
0
 private void Apply(ProductAdded @event)
 {
     Products.Add(@event.ProductId);
 }
Esempio n. 25
0
 public void ProductControl_ProductChecked(products_in_shop item, int quantity)
 {
     ProductAdded?.Invoke(item, quantity);
 }
 public void Apply(ProductAdded @event)
 {
     TotalItemsCount += @event.ProductItem.Quantity;
 }
Esempio n. 27
0
 private void OnProductAdded(ProductAdded e)
 {
     _productIds.Add(e.ProductId);
 }
Esempio n. 28
0
        public void IncreaseCount()
        {
            ProductCount++;

            ProductAdded?.Invoke(this);
        }