コード例 #1
0
        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;
            // }
        }
コード例 #2
0
 public static void UnSubscribe(IOperationObserver observer, BaseOperation operation)
 {
     if (AllObservers.Keys.Contains(operation.Name))
     {
         AllObservers[operation.Name].Remove(observer);
     }
 }
コード例 #3
0
        // 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);
            }
        }
コード例 #4
0
 /// <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;
 }
コード例 #5
0
        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);
                }
            }
        }
コード例 #6
0
        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);
                    }
                }
            }
        }
コード例 #7
0
        /// <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);
                }
            }
        }
コード例 #8
0
 // protected abstract List<OperationType> ParseOperationTypeOfObserver (IOperationObserver observer);
 protected abstract void NotifyObserver(OperationMessage message, IOperationObserver observer);
コード例 #9
0
ファイル: ObserverItem.cs プロジェクト: Darcy97/U3D_Libs
 public ObserverItem(IOperationObserver observer, OperationType type)
 {
     OpType   = type;
     Observer = observer;
 }
コード例 #10
0
ファイル: Operation.cs プロジェクト: techronin/virgil-sync
 public void AcceptProgress(IOperationObserver target)
 {
     this.observer = target;
 }