예제 #1
0
        public bool BuyProduct(string productName)
        {
            foreach (Product product in productsList)
            {
                if (product.Name == productName)
                {
                    if (product.Stock > 0)
                    {
                        // New order for the last task
                        Order newOrder = new Order(orderIdGenerator++, product.Name, DateTime.Now);
                        orderList.Add(newOrder);

                        product.Stock--;

                        // Instance of the current client
                        IWebshopEvents clientCallback = OperationContext.Current.GetCallbackChannel <IWebshopEvents>();
                        // We remove it to prevent dealock
                        StockChanged -= clientCallback.OnStockChanged;
                        // Add the new full course
                        StockChanged(GetAllProducts().ToArray());
                        // Add the current cliet back
                        StockChanged += clientCallback.OnStockChanged;

                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
        public void UnsubscribeEvent()
        {
            IWebshopEvents clientCallback = OperationContext.Current.GetCallbackChannel <IWebshopEvents>();

            StockChanged -= clientCallback.OnStockChanged;
        }