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; } } } }
public UnexplodeTileCommand(IImageBox imageBox, object unexplodeMemento, NotifyRemoveUnexplodedTileCommand remove) { _imageBox = imageBox; _unexplodeMemento = unexplodeMemento; _remove = remove; _listObserver = new ListObserver<ITile>(imageBox.Tiles, OnTilesChanged); }
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(); } }
public void ListObserver_ArgumentChecking() { //Assert.ThrowsException<ArgumentNullException>(() => new ListObserver<int>(default(IObserver<int>[]))); var lo = new ListObserver <int>(); Assert.ThrowsException <ArgumentNullException>(() => lo.Add(default));
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); }
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); }
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); }
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); }
public override void Initialize() { base.Initialize(); Tools[ImageViewer] = this; _imageBoxesObserver = new ListObserver<IImageBox>(ImageViewer.PhysicalWorkspace.ImageBoxes, OnImageBoxesChanged); UpdateEnabled(); }
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); }
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); }
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); }
public override void Initialize() { base.Initialize(); _imageBoxesObserver = new ListObserver<IImageBox>(ImageViewer.PhysicalWorkspace.ImageBoxes, OnImageBoxesChanged); _imageBoxesObserver.SuppressChangedEvent = true; }
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(); }
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(); }