示例#1
0
 /// <inheritdoc/>
 public IDisposable Subscribe(ISensorObserver observer)
 {
     if (observer == null)
     {
         throw new ArgumentNullException("observer");
     }
     lock (observerSync) {
         observers.Add(observer);
         return(new SensorSubscription(this, observer));
     }
 }
示例#2
0
 public SensorSubscription(SensorObservable observable, ISensorObserver observer)
 {
     if (observable == null)
     {
         throw new ArgumentNullException("observable");
     }
     if (observer == null)
     {
         throw new ArgumentNullException("observer");
     }
     this.observable = observable;
     this.observer   = observer;
 }
示例#3
0
 /// <summary>
 /// Unsubscribes the specified observer.
 /// </summary>
 /// <param name="observer">Observer to unsubscribe.</param>
 /// <returns>if the subscription was cancelled</returns>
 public bool Unsubscribe(ISensorObserver observer)
 {
     lock (observerSync) {
         int iObserver = observers.IndexOf(observer);
         if (iObserver < 0)
         {
             return(false);
         }
         // we receive an exception if an observer is removed while iterating through them
         // therefore we keep the original observer list untouched
         // by creating a new one that will be used for future operations
         int capacity      = observers.Count;
         var nextObservers = new List <ISensorObserver>(capacity);
         for (int i = 0; i < capacity; i++)
         {
             if (i != iObserver)
             {
                 nextObservers.Add(observers[iObserver]);
             }
         }
         observers = nextObservers;
         return(true);
     }
 }
示例#4
0
    public void subscribe(ISensorObserver iSensorObserver)
    {
//		observer += new EventHandler (iSensorObserver.Notify);
    }
 ///<inheritdoc/>
 public void RemoveObserver(ISensorObserver observer)
 {
     _sensorObservers.Remove(observer);
 }
 ///<inheritdoc/>
 public void RegisterObserver(ISensorObserver observer)
 {
     _sensorObservers.Add(observer);
 }
示例#7
0
 //Remove an observer front he list.
 public void removeObserver(ISensorObserver o)
 {
     observerList.Remove(o);
 }
示例#8
0
 //Addes and observer to  the observer list.
 public void addObserver(ISensorObserver o)
 {
     observerList.Add(o);
 }