/// <summary> /// 根据指定的接收者和 <c>Intent</c> 对象传递并执行任务 /// </summary> /// <param name="receiver"></param> /// <param name="intent"></param> private void Execute(string receiver, Intent intent) { if (Colleagues.ContainsKey(receiver)) { IWorker worker = Colleagues[receiver] as IWorker; if (worker != null) { worker.Trigger(intent); } } }
/// <summary> /// 中介者必须具备在同事之间处理逻辑、分配任务、促进交流的操作 /// </summary> /// <param name="receiver"></param> /// <param name="eventMessage"></param> public override void Trigger(string receiver, string eventMessage) { Intent intent = new Intent(receiver,eventMessage); Execute(intent); }
/// <summary> /// 根据指定的 <c>Intent</c> 对象传递并执行任务 /// </summary> /// <param name="intent"></param> public void Execute(Intent intent) { ThreadPool.QueueUserWorkItem(RunTask, intent); }
/// <summary> /// 执行工作任务 /// </summary> /// <param name="intent"></param> public void Trigger(Intent intent) { Action<Intent> action = _action; if (action != null) action(intent); }