Пример #1
0
        // Methods
        public static void Main(string[] args)
        {
            // Publisher
            using (var locationPublisher = new LocationPublisher())
            {
                // Observer
                var locationObserver = new LocationObserver();

                // Subscribe
                var locationObserverUnsubscriber = locationPublisher.Subscribe(locationObserver);
                locationPublisher.Write(new Location()
                {
                    X = 1, Y = 1
                });
                locationPublisher.Write(new Location()
                {
                    X = 2, Y = 2
                });

                // Unsubscribe
                locationObserverUnsubscriber.Dispose();
                locationPublisher.Write(new Location()
                {
                    X = 3, Y = 3
                });
            }
        }
Пример #2
0
        public override void Entry(IModHelper helper)
        {
            Logger.Init(this.Monitor);
            this.helper = helper;

            locationObserver = new LocationObserver(helper);

            helper.Events.GameLoop.SaveLoaded      += GameLoop_SaveLoaded;
            helper.Events.GameLoop.ReturnedToTitle += GameLoop_ReturnedToTitle;
        }
Пример #3
0
        public static void TestObserver()
        {
            Console.WriteLine("-- TEST OBSERVER IObservable Pattern --");
            LocationReporter reporter  = new LocationReporter();
            LocationObserver observer1 = new LocationObserver("observer1");
            LocationObserver observer2 = new LocationObserver("observer2");
            LocationObserver observer3 = new LocationObserver("observer3");

            observer1.Subscribe(reporter);
            observer2.Subscribe(reporter);
            observer3.Subscribe(reporter);

            reporter.TrackLocation(new Location(10, 10));
            observer3.Unsubscribe();

            reporter.TrackLocation(new Location(100, 333));

            reporter.TrackLocation(null);

            reporter.EndTransmission();
        }