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 QueueRoutine { get { return _routine; } } private Queue _routine = new Queue(); 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) { } } }