Beispiel #1
0
 /// <summary>
 /// 协议一收到任务,此函数将被调用。
 /// </summary>
 /// <param name="newTask">收到的任务。</param>
 protected virtual void ProcessTask(ConnectionTask task)
 {
     task.SetAsBeProccessing();
     try
     {
         string      cmdByte       = task.Name;
         IConnection commCase_Send = GetConnection(new FrameBase(cmdByte));
         if (commCase_Send != null && commCase_Send is RefactorRequestChannel)
         {
             task.SetRelatedProtocol(commCase_Send);
             ((RefactorRequestChannel)commCase_Send).ExecuteTaskSync(task);
         }
         else
         {
             string msg = String.Format("协议未实现。 TaskName:{0}; ", task.Name);
             Console.WriteLine(msg);
             task.Dead = true;
         }
     }
     catch (Exception ex)
     {
         string msg = String.Format("协议收到任务,此函数被调用。 TaskName:{0}; Message:{1}", task.Name, ex.Message);
         Console.WriteLine(msg);
         task.Dead = true;
     }
 }
Beispiel #2
0
        /// <summary>
        /// 移除任务
        /// </summary>
        /// <param name="connectionTask"></param>
        /// <returns></returns>
        public virtual bool RemoveTask(ConnectionTask connectionTask)
        {
            bool result = this.taskDocker.RemoveTask(connectionTask);

            this.connectionDocker.SetCaseAsDead(connectionTask);
            LogAgent.Info(String.Format("处理超时任务:{0}", connectionTask.ToString()));
            return(result);
        }
Beispiel #3
0
 /// <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();
         }
     }
 }
Beispiel #4
0
 /// <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);
         }
     }
 }
Beispiel #5
0
 /// <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();
     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);
 }
        /// <summary>
        /// 任务过期
        /// </summary>
        /// <param name="task"></param>
        internal void SetCaseAsDead(ConnectionTask task)
        {
            IConnection csObj = null;

            lock (caseDictionaryList)
            {
                foreach (IConnection cs in BusinessCaseList)
                {
                    if (cs == task.GetRelatedProtocol())
                    {
                        csObj = cs;
                        break;
                    }
                }
            }
            if (csObj != null && csObj.WasDisposed)
            {
                csObj.Dead = true;
            }
        }
Beispiel #7
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)
 {
 }