/// <summary>
 /// 给规约增加任务
 /// </summary>
 /// <param name="task">要添加的任务。</param>
 public virtual void AddTask(ConnectionTask task)
 {
     if (task == null)
     {
         return;
     }
     lock (this.taskDocker)
     {
         if (!this.taskDocker.TaskList.Contains(task))
         {
             this.taskDocker.AddTask(task);
             ((EventWaitHandle)protocolEvents[(int)ProtocolEvents.TaskArrived]).Set();
         }
     }
 }
 /// <summary>
 /// 异步执行任务
 /// </summary>
 /// <param name="task"></param>
 /// <param name="asyncCallback"></param>
 /// <param name="timeout"></param>
 public virtual void ExecuteTaskAsync(ConnectionTask task, AsyncCallback asyncCallback, int timeout)
 {
     if (this.ProtocolThreadIsAlive)
     {
         task.AsyncInvokeSetup(asyncCallback, task, timeout);
         AddTask(task);
     }
     else
     {
         if (asyncCallback != null)
         {
             task.AsyncInvokeSetup(asyncCallback, task, timeout);
             task.Complete(TaskState.NewTask);
         }
     }
 }
 /// <summary>
 /// 执行任务
 /// </summary>
 /// <param name="task"></param>
 /// <param name="timeout"></param>
 /// <returns></returns>
 public virtual bool ExecuteTaskSync(ConnectionTask task, int timeout)
 {
     //if (!this.ProtocolIsRunning)
     //    return false;
     task.InitSynchObject();
     this.taskDocker.AddTask(task);
     task.WaitBeCompleted(timeout);
     if (task.TaskState != TaskState.Completed)
     {
         task.SetAsOvertime();
         if (task.Result == null)
         {
             task.Result = new TaskResult(false, "", new object());
         }
         this.taskDocker.RemoveTask(task);
         return(false);
     }
     return(true);
 }
Esempio n. 4
0
        /// <summary>
        /// 任务过期
        /// </summary>
        /// <param name="task"></param>
        internal void SetCaseAsDead(ConnectionTask task)
        {
            IConnection csObj = null;

            lock (caseList)
            {
                foreach (IConnection cs in caseList)
                {
                    if (cs == task.GetRelatedProtocol())
                    {
                        csObj = cs;
                        break;
                    }
                }
            }
            if (csObj != null)
            {
                csObj.Dead = true;
            }
        }
 /// <summary>
 /// 移除任务
 /// </summary>
 /// <param name="connectionTask"></param>
 /// <returns></returns>
 public virtual bool RemoveTask(ConnectionTask connectionTask)
 {
     return(this.taskDocker.RemoveTask(connectionTask));
 }
 /// <summary>
 /// 协议一收到任务,此函数将被调用。
 /// </summary>
 /// <param name="newTask">收到的任务。</param>
 protected virtual void ProcessTask(ConnectionTask connectionTask)
 {
 }