예제 #1
0
        static void Main(string[] args)
        {
            WebAppInventory.InventoryService service = new WebAppInventory.InventoryService();
            InventoryServiceMonitor          monitor = new InventoryServiceMonitor();

            monitor.Subscribe(service);
            service.AddItem("orange", DateTime.Now.AddSeconds(30), WebAppInventory.InventoryItemType.Solid);
            service.AddItem("apple", DateTime.Now, WebAppInventory.InventoryItemType.Solid); // expect getting item expired notification
            System.Threading.Thread.Sleep(2000);
            service.RemoveItem("apple");                                                     // expect getting item removed notification
            System.Threading.Thread.Sleep(65000);                                            // after sleep expect getting item expired notification for orange
            monitor.Unsubscribe();
            service.RemoveItem("orange");                                                    // expect not getting item removed notification, because the monitor already unsubscribed
            System.Threading.Thread.Sleep(65000);
        }
예제 #2
0
 public virtual void Subscribe(WebAppInventory.InventoryService provider)
 {
     cancellation = provider.Subscribe(this);
 }