protected override void NotifyObserver(OperationMessage message, IOperationObserver observer) { if (message == null) { return; } if (observer == null) { return; } observer.ObserverUpdate(message); // switch (opType) // { // case OperationType.Purchase: // var obPurchase = observer as IOperationObserverPurchase; // obPurchase.ObserverUpdatePurchase (message as OperationMessagePurchase); // break; // case OperationType.Spin: // var obSpin = observer as IOperationObserverSpin; // obSpin.ObserverUpdateSpin (message as OperationMessageSpin); // break; // } }
public static void UnSubscribe(IOperationObserver observer, BaseOperation operation) { if (AllObservers.Keys.Contains(operation.Name)) { AllObservers[operation.Name].Remove(observer); } }
// implementing subject interface public static void Subscribe(IOperationObserver observer, BaseOperation operation) { if (!AllObservers.Keys.Contains(operation.Name)) { AllObservers.Add(operation.Name, new List <IOperationObserver>()); } if (!AllObservers[operation.Name].Contains(observer)) { AllObservers[operation.Name].Add(observer); } }
/// <summary> /// Creates a new operation state with the provided callback /// </summary> public OperationState(Action <IRequestError, Response> callback, IRequest request, int timeoutMillis, IOperationObserver operationObserver) { Volatile.Write(ref _callback, (exception, response, timestamp) => { try { callback(exception, response); operationObserver.OnOperationReceive(exception, response, timestamp); } catch (Exception ex) { OperationState.Logger.Warning("Exception thrown inside an operation callback: {0}", ex.ToString()); } }); _operationObserver = operationObserver; Request = request; TimeoutMillis = timeoutMillis; }
public void RegisterObserver(IOperationObserver observer, List <OperationType> types) { if (observer == null) { return; } if (null == types) { return; } ObserverItem observerItem = null; foreach (var type in types) { observerItem = new ObserverItem(observer, type); if (!observerItems.Contains(observerItem)) { observerItems.Add(observerItem); } } }
public void RemoveObserver(IOperationObserver observer, OperationType type = OperationType.Default) { List <ObserverItem> obItems = new List <ObserverItem> (); foreach (var item in observerItems) { if (observer.Equals(item.Observer)) { obItems.Add(item); } } if (obItems != null) { foreach (var item in obItems) { if (type == OperationType.Default || item.OpType.Equals(type)) { observerItems.Remove(item); } } } }
/// <summary> /// 不传type时对 observer进行检查,实现了几种接口就监听几种 /// 传入type时 只监听对应接口 /// </summary> /// <param name="observer"></param> /// <param name="type"></param> public void RegisterObserver(IOperationObserver observer, OperationType type0, OperationType type1 = OperationType.Default, OperationType type2 = OperationType.Default) { if (observer == null) { return; } if (type0.Equals(OperationType.Default)) { return; } var observerItem = new ObserverItem(observer, type0); if (!observerItems.Contains(observerItem)) { observerItems.Add(observerItem); } if (!type1.Equals(OperationType.Default)) { observerItem = new ObserverItem(observer, type1); if (!observerItems.Contains(observerItem)) { observerItems.Add(observerItem); } } if (!type2.Equals(OperationType.Default)) { observerItem = new ObserverItem(observer, type2); if (!observerItems.Contains(observerItem)) { observerItems.Add(observerItem); } } }
// protected abstract List<OperationType> ParseOperationTypeOfObserver (IOperationObserver observer); protected abstract void NotifyObserver(OperationMessage message, IOperationObserver observer);
public ObserverItem(IOperationObserver observer, OperationType type) { OpType = type; Observer = observer; }
public void AcceptProgress(IOperationObserver target) { this.observer = target; }