コード例 #1
0
 public DispatcherMessageMatcher(DispatcherMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     _message = message;
 }
コード例 #2
0
 public AppDispatcher()
 {
     _callbacks          = new Dictionary <DispatchToken, Action <DispatcherMessage> >();
     _executingCallbacks = new HashSet <DispatchToken>();
     _finishedCallbacks  = new HashSet <DispatchToken>();
     _isDispatching      = false;
     _currentMessage     = null;
 }
コード例 #3
0
#pragma warning disable CS0618 // Type or member is obsolete
        private void Dispatch(DispatcherMessage message)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (_isDispatching)
            {
                throw new InvalidOperationException("Cannot dispatch while already dispatching");
            }

            _isDispatching  = true;
            _currentMessage = message;
            _executingCallbacks.Clear();
            _finishedCallbacks.Clear();
            try
            {
                foreach (var callback in _callbacks)
                {
                    // Skip over callbacks that have already been called (by an earlier callback that used WaitFor)
                    if (_finishedCallbacks.Contains(callback.Key))
                    {
                        continue;
                    }

                    _executingCallbacks.Add(callback.Key);
                    callback.Value(_currentMessage);
                    _executingCallbacks.Remove(callback.Key);
                    _finishedCallbacks.Add(callback.Key);
                }
            }
            finally
            {
                _isDispatching  = false;
                _currentMessage = null;
                _executingCallbacks.Clear();
                _finishedCallbacks.Clear();
            }
        }
コード例 #4
0
		private void Dispatch(DispatcherMessage message)
		{
			if (message == null)
				throw new ArgumentNullException("message");

			// Dispatching a message during the handling of another is not allowed, in order to be consistent with the Facebook Dispatcher
			// (see https://github.com/facebook/flux/blob/master/src/Dispatcher.js#L183)
			if (_dispatcher != null)
			{
				if (_currentDispatching)
					throw new Exception("Cannot dispatch in the middle of a dispatch.");
				_currentDispatching = true;
				try
				{
					_dispatcher(message);
				}
				finally
				{
					_currentDispatching = false;
				}
			}
		}
コード例 #5
0
 /// <summary>
 /// This will execute the specified callback with a non-null reference if the current DispatcherMessage action matches type T and
 /// if that instance of T meets the specified conditions. It will never call the work action with a null reference and it will never
 /// return a null reference. It will throw an exception for a null DispatcherMessage, null condition or null work reference.
 /// </summary>
 public static IMatchDispatcherMessages If <T>(this DispatcherMessage message, Func <T, bool> condition, Action <T> work) where T : class, IDispatcherAction
 {
     return(new DispatcherMessageMatcher(message).Else(condition, work));
 }
コード例 #6
0
 /// <summary>
 /// This will execute the specified callback with a non-null reference if the current DispatcherMessage action matches type T.
 /// It will never call the work action with a null reference and it will never return a null reference. It will throw an exception
 /// for a null DispatcherMessage or null work reference.
 /// </summary>
 public static IMatchDispatcherMessages If <T>(this DispatcherMessage message, Action <T> work) where T : class, IDispatcherAction
 {
     return(new DispatcherMessageMatcher(message).Else(work));
 }