using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace StageController { public class Moveflow : List { public bool Done => this.All((e) => e.Done == true); public bool IsStoped = false; public bool IsPause = false; private bool Running = false; public event Action OnMoveflowDone; public void Start() { if (Done || IsStoped) throw new Exception("AlreadyDone"); if (Running) throw new Exception("AlreadyStart"); Running = true; new Task(() => { foreach (var workflow in this) { workflow.Process(); while ((!workflow.Judgement() || IsPause) && !IsStoped) { Thread.Sleep(50); } workflow.Done = true; if (IsStoped) return; } OnMoveflowDone?.Invoke(); }).Start(); } public void Stop() { IsStoped = true; } /// /// 暂停/继续 /// public void Pause() { IsPause = !IsPause; } public void Add(Action a = null, Func j = null) { var workflow = new Workflow(this); if (a != null) workflow.Process = a; if (j != null) workflow.Judgement = j; Add(workflow); } } //public interface IMoveFlow //{ // public static Moveflow ToCenter() // { // } // public static Moveflow OutStage() { } // public static Moveflow InStage() { } // public static Moveflow ResetStage() { } //} }