Beispiel #1
0
        static void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            Console.WriteLine($"Looking for dead cart items at {DateTime.Now.ToString()}.");

            CartItem[] cartItems = _cartManager.GetDeadCartItems();
            if (cartItems != null)
            {
                foreach (var item in cartItems)
                {
                    using (TransactionScope scope = new TransactionScope()) {
                        try { _cartManager.DeleteCartItem(item.CartItemId);
                              Console.WriteLine($"Deleting Cart Item ID: '{item.CartItemId}'");
                              scope.Complete(); }
                        catch (Exception ex) {
                            Console.WriteLine(
                                $"There was an exception when attempting to delete cart item ID: '{item.CartItemId}'.");
                        }
                    }
                }
            }
        }