123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System.Collections.Generic;
- using System.Linq;
- using Aitex.Core.RT.Routine;
- using MECF.Framework.Common.Equipment;
- namespace VirgoRT.Modules
- {
- public class EntityTaskBase
- {
- protected Queue<IRoutine> QueueRoutine
- {
- get { return _routine; }
- }
- private Queue<IRoutine> _routine = new Queue<IRoutine>();
- public Result Start(IRoutine routine)
- {
- QueueRoutine.Clear();
- QueueRoutine.Enqueue(routine);
- return QueueRoutine.Peek().Start();
- }
- public Result TaskStart()
- {
- if (_routine.Count == 0)
- return Result.DONE;
- Result ret = Result.DONE;
- var lst = _routine.ToList();
- for (int i = 0; i < lst.Count; i++)
- {
- ret = lst[i].Start();
- if (ret == Result.DONE)
- {
- _routine.Dequeue();
- continue;
- }
- else
- {
- break;
- }
- }
- return Result.RUN;
- }
- public Result TaskMonitor()
- {
- if (_routine.Count == 0)
- return Result.DONE;
- IRoutine routine = _routine.Peek();
- Result ret = routine.Monitor();
- if (ret == Result.DONE)
- {
- _routine.Dequeue();
- var lst = _routine.ToList();
- for (int i = 0; i < lst.Count; i++)
- {
- ret = lst[i].Start();
- if (ret == Result.DONE)
- {
- _routine.Dequeue();
- continue;
- }
- else
- {
- break;
- }
- }
- }
- return ret;
- }
- public void Abort()
- {
- if (_routine != null)
- {
- _routine.Peek().Abort();
- _routine.Clear();
- }
- }
- }
- }
- namespace VirgoRT
- {
- abstract class ActionBase
- {
- private static ushort _id = 100;
- //---------------------------------Properties------------------------------------
- //
- public ushort ID { get; }
- public ModuleName Module { get; protected set; }
- public virtual ActionStatus Status { get; set; }
- public virtual bool IsReady { get; set; }
- public bool IsBackground { get; set; }
- //--------------------------------Constructor------------------------------------
- //
- protected ActionBase(ModuleName mod)
- {
- this.ID = _id++;
- this.Module = mod;
- this.Status = ActionStatus.Pending;
- }
- public virtual void Execute()
- {
- this.Status = ActionStatus.SendCmd;
- }
- protected virtual void OnPreWork() { }
- public virtual void OnPostWork(string data = null) { }
- public virtual void OnError(string data = null) { }
- }
- }
|