Ejemplo n.º 1
0
        /// <summary>
        /// 发布消息
        /// </summary>
        public virtual Action <object[]> GetExecutionStrategy()
        {
            Action <MessageSender, TMessage> action = this.Action;
            Predicate <TMessage>             filter = this.Filter;

            if (action != null && filter != null)
            {
                return(arguments =>
                {
                    MessageSender argument1 = null;
                    TMessage argument2 = default(TMessage);
                    if (arguments != null && arguments.Length > 0 && arguments[0] != null && arguments[1] != null)
                    {
                        argument1 = (MessageSender)arguments[0];
                        argument2 = (TMessage)arguments[1];
                    }
                    if (filter(argument2))
                    {
                        InvokeAction(action, argument1, argument2);
                    }
                });
            }
            return(null);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 发布MessageEnvelope<TMessage>
 /// </summary>
 /// <param name="payload">传递给订阅者的消息对象</param>
 public virtual void Publish(MessageSender sender, TMessage message)
 {
     base.InternalPublish(sender, message);
 }
 /// <summary>
 /// 用线程池执行action
 /// </summary>
 /// <param name="action">Action</param>
 /// <param name="argument1">MessageSender</param>
 /// <param name="argument2">TMessage</param>
 public override void InvokeAction(Action <MessageSender, TMessage> action, MessageSender argument1, TMessage argument2)
 {
     ThreadPool.QueueUserWorkItem((o) => action(argument1, argument2));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 在UI线程上回调动作action
 /// </summary>
 /// <param name="action">动作action</param>
 /// <param name="argument1">MessageSender</param>
 /// <param name="argument2">TMessage</param>
 public override void InvokeAction(Action <MessageSender, TMessage> action, MessageSender argument1, TMessage argument2)
 {
     dispatcher.BeginInvoke(action, argument1, argument2);
 }