private void AddWorker <T>(T w) where T : IWorker { string wprefix = $"{w.ToString()}-"; WorkerContainer wc = new WorkerContainer(); wc.Name = wprefix + UI.Prompt($"What should we call this worker? Give a name {wprefix}"); wc.Worker = w; UI.Log($"Creating {wc.Name}"); w.PromptParameters(); RegisterWorkerToWC(w, wc); }
public void RegisterReusableWorker <T>(T WOriginal, string Name) where T : IWorker { IWorker w = Core.FromJSON <T>(Core.ToJSON(WOriginal)); w.UI = UI; WorkerContainer wc = new WorkerContainer(); wc.Name = $"{w.ToString()}"; wc.Worker = w; UI.Log($"Creating {wc.Name}"); RegisterWorkerToWC(w, wc); }
public void ShowMenu() { ProgramBegin: UI.Log(""); UI.Log("-----------------------------------"); UI.Log("|| ... ||"); UI.Log("|| Methane ||"); UI.Log("|| Automating Lab ||"); UI.Log("|| ... ||"); UI.Log("-----------------------------------"); UI.Log(""); UI.Log(""); ShowPipes(); UI.Log(""); if (Services.Count > 0) { string in1 = UI.Prompt("[Enter] to add a new worker | Input the index of Service worker to Run it | [E] to Exit").ToLower().Trim(); if (in1 == "e") { return; } else if (int.TryParse(in1, out int ini) && ini < Services.Count) { WorkerContainer wc = Services[ini]; UI.Log($"Building {wc.Name}"); wc.Worker.BuildFromParameters(); UI.Log($"Running {wc.Name}"); wc.Worker.RunService(); } else { ShowAddMenu(); } } else { ShowAddMenu(); } goto ProgramBegin; }
private void ShowPipes() { if (Pipes.Count > 0) { UI.Log(""); UI.Log(""); UI.Log($"{Pipes.Count} Pipes"); for (int i = 0; i < Pipes.Count; i++) { WorkerContainer iwc = Pipes[i]; UI.Log($"{i}. {iwc.Name} \t \t {iwc.Worker?.WorkerType} {(iwc.Used ? " Used " : "")}"); } } if (Services.Count > 0) { UI.Log(""); UI.Log(""); UI.Log($"{Services.Count} Services"); for (int i = 0; i < Services.Count; i++) { WorkerContainer iwc = Services[i]; UI.Log($"{i}. {iwc.Name} \t \t {iwc.Worker?.WorkerType} {(iwc.Used ? " Used " : "")}"); } } // if (RWorkers.Count > 0) // { // UI.Log(""); // UI.Log(""); // UI.Log($"{RWorkers.Count} Reusable workers"); // for (int i = 0; i < RWorkers.Count; i++) // { // WorkerContainer iwc = RWorkers[i]; // UI.Log($"{i}. {iwc.Name} \t \t {iwc.Worker?.WorkerType}"); // } // } UI.Log(""); if (Services.Count == 0 && Pipes.Count == 0) { UI.Log("Let's create some Workers!"); } }
private void RegisterWorkerToWC <T>(T w, WorkerContainer wc) where T : IWorker { if ((w.WorkerType & IWorkerType.Reusable) != 0) { wc.Copy = Core.ToJSON(w); // RWorkers.Add(wc); UI.Log($"Saved reusable {wc.Name}"); } if ((w.WorkerType & IWorkerType.Pipe) != 0) { Pipes.Add(wc); UI.Log($"Added Pipe {wc.Name}"); } else if ((w.WorkerType & IWorkerType.Service) != 0) { Services.Add(wc); UI.Log($"Added Service {wc.Name}"); } else { UI.LogError(new Exception(), $"{wc.Name} does not fall into either Pipe or Service"); } }
public T Request <T>() where T : IWorker { List <WorkerContainer> Matches = new List <WorkerContainer>(); UI.Log(""); UI.Log(""); if (Pipes.Count > 0) { for (int i = 0; i < Pipes.Count; i++) { WorkerContainer iwc = Pipes[i]; if (iwc.Worker is T && (((iwc.Worker.WorkerType & IWorkerType.Reusable) != 0) || !iwc.Used)) { int mi = Matches.Count; Matches.Add(iwc); UI.Log($"{mi}. {iwc.Name} \t \t {iwc.Worker?.WorkerType} "); } } } int MatchedPipes = Matches.Count; if (Services.Count > 0) { UI.Log(""); for (int i = 0; i < Services.Count; i++) { WorkerContainer iwc = Services[i]; if (iwc.Worker is T && (((iwc.Worker.WorkerType & IWorkerType.Reusable) != 0) || !iwc.Used)) { int mi = Matches.Count; Matches.Add(iwc); UI.Log($"{i}. {iwc.Name} \t \t {iwc.Worker?.WorkerType} "); } } } UI.Log(""); if (Matches.Count == 0) { return(RequestNew <T>()); } else { PrompIndex: string r = UI.Prompt("[Enter] to create a new worker OR input index to use").Trim().ToLower(); if (string.IsNullOrEmpty(r)) { return(RequestNew <T>()); } else { if (int.TryParse(r, out int ri) && ri < Matches.Count) { WorkerContainer workerContainer = Matches[ri]; if ((workerContainer.Worker.WorkerType & IWorkerType.Reusable) == 0) { workerContainer.Used = true; Pipes.Remove(workerContainer); Services.Remove(workerContainer); } return((T)workerContainer.Worker); } else { UI.Log("What?"); goto PrompIndex; } } } }