From 2f7b4b3875342d02d82115f33c82a3c4dacb9fa0 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 26 Aug 2019 01:54:38 +0100 Subject: [PATCH] some cleaning --- src/Yavsc.Abstract/IT/CiBuildSettings.cs | 4 +- src/Yavsc.Abstract/IT/Command.cs | 6 ++ src/Yavsc.Abstract/IT/CommandPipe.cs | 92 ++++++++++++------------ version.txt | 2 +- 4 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/Yavsc.Abstract/IT/CiBuildSettings.cs b/src/Yavsc.Abstract/IT/CiBuildSettings.cs index b5754636..4663c8f9 100644 --- a/src/Yavsc.Abstract/IT/CiBuildSettings.cs +++ b/src/Yavsc.Abstract/IT/CiBuildSettings.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using Newtonsoft.Json; +namespace Yavsc.Abstract.IT { public class CiBuildSettings { @@ -46,4 +47,5 @@ public class CiBuildSettings [JsonPropertyAttribute("emails")] public string[] Emails { get; set; } -} \ No newline at end of file +} +} diff --git a/src/Yavsc.Abstract/IT/Command.cs b/src/Yavsc.Abstract/IT/Command.cs index 1feeb444..6d299b05 100644 --- a/src/Yavsc.Abstract/IT/Command.cs +++ b/src/Yavsc.Abstract/IT/Command.cs @@ -2,6 +2,10 @@ using System.ComponentModel.DataAnnotations; using System.Diagnostics; using Newtonsoft.Json; + +namespace Yavsc.Abstract.IT +{ + /// /// A command specification (a system command), /// in order to reference some trusted server-side process @@ -34,3 +38,5 @@ public class Command } } +} + diff --git a/src/Yavsc.Abstract/IT/CommandPipe.cs b/src/Yavsc.Abstract/IT/CommandPipe.cs index 293cb3b6..c57b74bf 100644 --- a/src/Yavsc.Abstract/IT/CommandPipe.cs +++ b/src/Yavsc.Abstract/IT/CommandPipe.cs @@ -4,61 +4,65 @@ using System.Diagnostics; using System.Threading.Tasks; using Newtonsoft.Json; -public class CommandPipe +namespace Yavsc.Abstract.IT { + public class CommandPipe + { - [JsonPropertyAttribute("pipe")] - public Command[] Pipe { get; set; } + [JsonPropertyAttribute("pipe")] + public Command[] Pipe { get; set; } - [JsonPropertyAttribute("working_dir")] - public string WorkingDir { get; set; } + [JsonPropertyAttribute("working_dir")] + public string WorkingDir { get; set; } - public virtual int Run() - { - Process latest = null; - Queue runQueue = new Queue(); - Queue joints = new Queue(); - if (Pipe.Length == 0) return -1; - if (Pipe.Length == 1) + public virtual int Run() { - latest = Pipe[0].Start(); - latest.WaitForExit(); - return latest.ExitCode; - } - - for (int i = 0; i < Pipe.Length; i++) - { - Process newProcess = null; - var cmd = Pipe[i]; - bool isNotLast = (i + 1) >= Pipe.Length; + Process latest = null; + Queue runQueue = new Queue(); + Queue joints = new Queue(); + if (Pipe.Length == 0) return -1; + if (Pipe.Length == 1) + { + latest = Pipe[0].Start(); + latest.WaitForExit(); + return latest.ExitCode; + } - if (latest != null) // i.e. isNotFirst + for (int i = 0; i < Pipe.Length; i++) { - newProcess = cmd.Start(WorkingDir, true, isNotLast); - var jt = Task.Run(async () => + Process newProcess = null; + var cmd = Pipe[i]; + bool isNotLast = (i + 1) >= Pipe.Length; + + if (latest != null) // i.e. isNotFirst { - while (!latest.HasExited && !newProcess.HasExited) + newProcess = cmd.Start(WorkingDir, true, isNotLast); + var jt = Task.Run(async () => { - string line = await latest.StandardOutput.ReadLineAsync(); - if (line != null) - await newProcess.StandardInput.WriteLineAsync(line); - } - }); - joints.Enqueue(jt); - } - else - { - newProcess = cmd.Start(WorkingDir, false, isNotLast); - Task ending = Task.Run(() => { latest.WaitForExit(); }); - joints.Enqueue(ending); + while (!latest.HasExited && !newProcess.HasExited) + { + string line = await latest.StandardOutput.ReadLineAsync(); + if (line != null) + await newProcess.StandardInput.WriteLineAsync(line); + } + }); + joints.Enqueue(jt); + } + else + { + newProcess = cmd.Start(WorkingDir, false, isNotLast); + Task ending = Task.Run(() => { latest.WaitForExit(); }); + joints.Enqueue(ending); + } + latest = newProcess; + runQueue.Enqueue(latest); } - latest = newProcess; - runQueue.Enqueue(latest); + while (runQueue.Count > 0) + (latest = runQueue.Dequeue()).WaitForExit(); + return latest.ExitCode; } - while (runQueue.Count > 0) - (latest = runQueue.Dequeue()).WaitForExit(); - return latest.ExitCode; } -} \ No newline at end of file +} + diff --git a/version.txt b/version.txt index 724e9bb5..0fd042b8 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.6-rc05 +1.0.6-rc06