public IDisposable Subscribe(IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }
            Exception ex = null;

            ReplaySubject <T> .Subscription subscription = null;
            object obj = this.observerLock;

            lock (obj)
            {
                this.ThrowIfDisposed();
                if (!this.isStopped)
                {
                    ListObserver <T> listObserver = this.outObserver as ListObserver <T>;
                    if (listObserver != null)
                    {
                        this.outObserver = listObserver.Add(observer);
                    }
                    else
                    {
                        IObserver <T> observer2 = this.outObserver;
                        if (observer2 is EmptyObserver <T> )
                        {
                            this.outObserver = observer;
                        }
                        else
                        {
                            this.outObserver = new ListObserver <T>(new ImmutableList <IObserver <T> >(new IObserver <T>[]
                            {
                                observer2,
                                observer
                            }));
                        }
                    }
                    subscription = new ReplaySubject <T> .Subscription(this, observer);
                }
                ex = this.lastError;
                this.Trim();
                foreach (TimeInterval <T> timeInterval in this.queue)
                {
                    observer.OnNext(timeInterval.Value);
                }
            }
            if (subscription != null)
            {
                return(subscription);
            }
            if (ex != null)
            {
                observer.OnError(ex);
            }
            else
            {
                observer.OnCompleted();
            }
            return(Disposable.Empty);
        }
            public void Dispose()
            {
                object obj = this.gate;

                lock (obj)
                {
                    if (this.parent != null)
                    {
                        object observerLock = this.parent.observerLock;
                        lock (observerLock)
                        {
                            ListObserver <T> listObserver = this.parent.outObserver as ListObserver <T>;
                            if (listObserver != null)
                            {
                                this.parent.outObserver = listObserver.Remove(this.unsubscribeTarget);
                            }
                            else
                            {
                                this.parent.outObserver = new EmptyObserver <T>();
                            }
                            this.unsubscribeTarget = null;
                            this.parent            = null;
                        }
                    }
                }
            }
Example #3
0
			public UnexplodeTileCommand(IImageBox imageBox, object unexplodeMemento, NotifyRemoveUnexplodedTileCommand remove)
			{
				_imageBox = imageBox;
				_unexplodeMemento = unexplodeMemento;
				_remove = remove;
				_listObserver = new ListObserver<ITile>(imageBox.Tiles, OnTilesChanged);
			}
Example #4
0
        public void RemoveObserverTest()
        {
            RegistrationUpdate regUpdate = new RegistrationUpdate("Registered", "3", "10/13/2017 10:00:00 PM", "Matt", "Morris", "M", "24");
            Athlete            athlete1  = new Athlete(regUpdate.Status, regUpdate.BibNumber, regUpdate.Timestamp.ToString(), regUpdate.LastName, regUpdate.Gender, regUpdate.Age);

            ConsoleObserver           consoleobserver     = new ConsoleObserver();
            _1DLineObserver           onedobserver        = new _1DLineObserver();
            AthleteComparisonObserver athletecompobserver = new AthleteComparisonObserver();
            ListObserver listobserver = new ListObserver();

            athlete1.RegisterObserver(consoleobserver);
            athlete1.RegisterObserver(onedobserver);
            athlete1.RegisterObserver(athletecompobserver);
            athlete1.RegisterObserver(listobserver);

            // test to see if observers are successfully removed
            try
            {
                athlete1.RemoveObserver(consoleobserver);
                athlete1.RemoveObserver(onedobserver);
                athlete1.RemoveObserver(athletecompobserver);
                athlete1.RemoveObserver(listobserver);
            }
            catch
            {
                Assert.Fail();
            }
        }
Example #5
0
        public void ListObserver_ArgumentChecking()
        {
            //Assert.ThrowsException<ArgumentNullException>(() => new ListObserver<int>(default(IObserver<int>[])));

            var lo = new ListObserver <int>();

            Assert.ThrowsException <ArgumentNullException>(() => lo.Add(default));
Example #6
0
        public IDisposable Subscribe(IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }

            Exception    ex           = default(Exception);
            Subscription subscription = default(Subscription);

            lock (observerLock)
            {
                ThrowIfDisposed();
                if (!isStopped)
                {
                    ListObserver <T> listObserver = outObserver as ListObserver <T>;
                    if (listObserver != null)
                    {
                        outObserver = listObserver.Add(observer);
                    }
                    else
                    {
                        IObserver <T> current = outObserver;
                        if (current is EmptyObserver <T> )
                        {
                            outObserver = observer;
                        }
                        else
                        {
                            outObserver = new ListObserver <T>(new ImmutableList <IObserver <T> >(new[] { current, observer }));
                        }
                    }

                    subscription = new Subscription(this, observer);
                }

                ex = lastError;
                Trim();
                foreach (TimeInterval <T> item in queue)
                {
                    observer.OnNext(item.Value);
                }
            }

            if (subscription != null)
            {
                return(subscription);
            }
            else if (ex != null)
            {
                observer.OnError(ex);
            }
            else
            {
                observer.OnCompleted();
            }

            return(Disposable.Empty);
        }
Example #7
0
        public IDisposable Subscribe(UniRx.IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }
            Exception    ex           = null;
            T            value        = default(T);
            Subscription subscription = null;

            lock (observerLock)
            {
                ThrowIfDisposed();
                if (!isStopped)
                {
                    ListObserver <T> listObserver = outObserver as ListObserver <T>;
                    if (listObserver != null)
                    {
                        outObserver = listObserver.Add(observer);
                    }
                    else
                    {
                        UniRx.IObserver <T> observer2 = outObserver;
                        if (observer2 is EmptyObserver <T> )
                        {
                            outObserver = observer;
                        }
                        else
                        {
                            outObserver = new ListObserver <T>(new ImmutableList <IObserver <T> >(new IObserver <T>[2]
                            {
                                observer2,
                                observer
                            }));
                        }
                    }
                    value        = lastValue;
                    subscription = new Subscription(this, observer);
                }
                else
                {
                    ex = lastError;
                }
            }
            if (subscription != null)
            {
                observer.OnNext(value);
                return(subscription);
            }
            if (ex != null)
            {
                observer.OnError(ex);
            }
            else
            {
                observer.OnCompleted();
            }
            return(Disposable.Empty);
        }
Example #8
0
        public IDisposable Subscribe(IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }

            Exception ex = default(Exception);
            T         v  = default(T);
            bool      hv = false;

            lock (observerLock)
            {
                ThrowIfDisposed();
                if (!isStopped)
                {
                    ListObserver <T> listObserver = outObserver as ListObserver <T>;
                    if (listObserver != null)
                    {
                        outObserver = listObserver.Add(observer);
                    }
                    else
                    {
                        IObserver <T> current = outObserver;
                        if (current is EmptyObserver <T> )
                        {
                            outObserver = observer;
                        }
                        else
                        {
                            outObserver = new ListObserver <T>(new ImmutableList <IObserver <T> >(new[] { current, observer }));
                        }
                    }

                    return(new Subscription(this, observer));
                }

                ex = lastError;
                v  = lastValue;
                hv = hasValue;
            }

            if (ex != null)
            {
                observer.OnError(ex);
            }
            else if (hv)
            {
                observer.OnNext(v);
                observer.OnCompleted();
            }
            else
            {
                observer.OnCompleted();
            }

            return(Disposable.Empty);
        }
Example #9
0
        public IDisposable Subscribe(IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }
            Exception ex    = null;
            T         value = default(T);
            bool      flag  = false;
            object    obj   = this.observerLock;

            lock (obj)
            {
                this.ThrowIfDisposed();
                if (!this.isStopped)
                {
                    ListObserver <T> listObserver = this.outObserver as ListObserver <T>;
                    if (listObserver != null)
                    {
                        this.outObserver = listObserver.Add(observer);
                    }
                    else
                    {
                        IObserver <T> observer2 = this.outObserver;
                        if (observer2 is EmptyObserver <T> )
                        {
                            this.outObserver = observer;
                        }
                        else
                        {
                            this.outObserver = new ListObserver <T>(new ImmutableList <IObserver <T> >(new IObserver <T>[]
                            {
                                observer2,
                                observer
                            }));
                        }
                    }
                    return(new AsyncSubject <T> .Subscription(this, observer));
                }
                ex    = this.lastError;
                value = this.lastValue;
                flag  = this.hasValue;
            }
            if (ex != null)
            {
                observer.OnError(ex);
            }
            else if (flag)
            {
                observer.OnNext(value);
                observer.OnCompleted();
            }
            else
            {
                observer.OnCompleted();
            }
            return(Disposable.Empty);
        }
Example #10
0
		public override void Initialize()
		{
			base.Initialize();
			Tools[ImageViewer] = this;

			_imageBoxesObserver = new ListObserver<IImageBox>(ImageViewer.PhysicalWorkspace.ImageBoxes, OnImageBoxesChanged);

			UpdateEnabled();
		}
Example #11
0
        public void DoObserver()
        {
            var observer = new ListObserver();

            Observable.Empty <int>().Do(observer).DefaultIfEmpty().Wait();
            observer.list.Is(1000);

            observer = new ListObserver();
            Observable.Range(1, 5).Do(observer).Wait();
            observer.list.Is(1, 2, 3, 4, 5, 1000);

            observer = new ListObserver();
            Observable.Range(1, 5).Concat(Observable.Throw <int>(new Exception())).Do(observer).Subscribe(_ => { }, _ => { }, () => { });
            observer.list.Is(1, 2, 3, 4, 5, 100);
        }
Example #12
0
        public IDisposable Subscribe(IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }
            Exception ex = null;

            lock (observerLock)
            {
                ThrowIfDisposed();
                if (!isStopped)
                {
                    ListObserver <T> listObserver = outObserver as ListObserver <T>;
                    if (listObserver != null)
                    {
                        outObserver = listObserver.Add(observer);
                    }
                    else
                    {
                        IObserver <T> observer2 = outObserver;
                        if (observer2 is EmptyObserver <T> )
                        {
                            outObserver = observer;
                        }
                        else
                        {
                            outObserver = new ListObserver <T>(new ImmutableList <IObserver <T> >(new IObserver <T>[2]
                            {
                                observer2,
                                observer
                            }));
                        }
                    }
                    return(new Subscription(this, observer));
                }
                ex = lastError;
            }
            if (ex != null)
            {
                observer.OnError(ex);
            }
            else
            {
                observer.OnCompleted();
            }
            return(Disposable.Empty);
        }
Example #13
0
 public void Dispose()
 {
     lock (gate)
     {
         if (parent != null)
         {
             lock (parent.observerLock)
             {
                 ListObserver <T> listObserver = parent.outObserver as ListObserver <T>;
                 if (listObserver != null)
                 {
                     parent.outObserver = listObserver.Remove(unsubscribeTarget);
                 }
                 else
                 {
                     parent.outObserver = EmptyObserver <T> .Instance;
                 }
                 unsubscribeTarget = null;
                 parent            = null;
             }
         }
     }
 }
        public IDisposable Subscribe(IObserver <T> observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }
            Exception ex = null;

            ReplaySubject <T> .Subscription subscription = null;
            object obj = this.observerLock;

            lock (obj)
            {
                this.ThrowIfDisposed();
                if (!this.isStopped)
                {
                    ListObserver <T> listObserver = this.outObserver as ListObserver <T>;
                    if (listObserver != null)
                    {
                        this.outObserver = listObserver.Add(observer);
                    }
                    else
                    {
                        IObserver <T> observer2 = this.outObserver;
                        if (observer2 is EmptyObserver <T> )
                        {
                            this.outObserver = observer;
                        }
                        else
                        {
                            this.outObserver = new ListObserver <T>(new ImmutableList <IObserver <T> >(new IObserver <T>[]
                            {
                                observer2,
                                observer
                            }));
                        }
                    }
                    subscription = new ReplaySubject <T> .Subscription(this, observer);
                }
                ex = this.lastError;
                this.Trim();
                using (Queue <TimeInterval <T> > .Enumerator enumerator = this.queue.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        TimeInterval <T> current = enumerator.get_Current();
                        observer.OnNext(current.Value);
                    }
                }
            }
            if (subscription != null)
            {
                return(subscription);
            }
            if (ex != null)
            {
                observer.OnError(ex);
            }
            else
            {
                observer.OnCompleted();
            }
            return(Disposable.Empty);
        }
Example #15
0
		public override void Initialize()
		{
			base.Initialize();
			_imageBoxesObserver = new ListObserver<IImageBox>(ImageViewer.PhysicalWorkspace.ImageBoxes, OnImageBoxesChanged);
			_imageBoxesObserver.SuppressChangedEvent = true;
		}
Example #16
0
        public void DoObserver()
        {
            var observer = new ListObserver();
            Observable.Empty<int>().Do(observer).DefaultIfEmpty().Wait();
            observer.list.IsCollection(1000);

            observer = new ListObserver();
            Observable.Range(1, 5).Do(observer).Wait();
            observer.list.IsCollection(1, 2, 3, 4, 5, 1000);

            observer = new ListObserver();
            Observable.Range(1, 5).Concat(Observable.Throw<int>(new Exception())).Do(observer).Subscribe(_ => { }, _ => { }, () => { });
            observer.list.IsCollection(1, 2, 3, 4, 5, 100);
        }
		public override void Initialize()
		{
			base.Initialize();
            //Put a non-disposable object in so the tool doesn't get disposed 2x.
            ImageViewer.ExtensionData[typeof(ExtensionDataProxy)] = new ExtensionDataProxy(this);

			_imageBoxesObserver = new ListObserver<IImageBox>(ImageViewer.PhysicalWorkspace.ImageBoxes, OnImageBoxesChanged);

			UpdateEnabled();
		}
Example #18
0
 public void DoObserver()
 {
     SetScehdulerForImport();
     var observer = new ListObserver();
     Observable.Empty<int>().Do(observer).DefaultIfEmpty().Wait();
     observer.list.IsCollection(1000);
     observer = new ListObserver();
     Observable.Range(1, 5).Do(observer).Wait();
     observer.list.IsCollection(1, 2, 3, 4, 5, 1000);
     observer = new ListObserver();
     Observable.Range(1, 5).Concat(Observable.Throw<int>(new Exception())).Do(observer).Subscribe(_ => { }, _ => { }, () => { });
     observer.list.IsCollection(1, 2, 3, 4, 5, 100);
     UniRx.Scheduler.SetDefaultForUnity();
 }