some cleaning

main
Paul Schneider 6 years ago
parent 9a669ea5fb
commit 2f7b4b3875
4 changed files with 58 additions and 46 deletions

@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Yavsc.Abstract.IT {
public class CiBuildSettings public class CiBuildSettings
{ {
@ -47,3 +48,4 @@ public class CiBuildSettings
public string[] Emails { get; set; } public string[] Emails { get; set; }
} }
}

@ -2,6 +2,10 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Diagnostics; using System.Diagnostics;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Yavsc.Abstract.IT
{
/// <summary> /// <summary>
/// A command specification (a system command), /// A command specification (a system command),
/// in order to reference some trusted server-side process /// in order to reference some trusted server-side process
@ -34,3 +38,5 @@ public class Command
} }
} }
}

@ -4,61 +4,65 @@ using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
public class CommandPipe namespace Yavsc.Abstract.IT
{ {
public class CommandPipe
{
[JsonPropertyAttribute("pipe")] [JsonPropertyAttribute("pipe")]
public Command[] Pipe { get; set; } public Command[] Pipe { get; set; }
[JsonPropertyAttribute("working_dir")] [JsonPropertyAttribute("working_dir")]
public string WorkingDir { get; set; } public string WorkingDir { get; set; }
public virtual int Run() public virtual int Run()
{
Process latest = null;
Queue<Process> runQueue = new Queue<Process>();
Queue<Task> joints = new Queue<Task>();
if (Pipe.Length == 0) return -1;
if (Pipe.Length == 1)
{ {
latest = Pipe[0].Start(); Process latest = null;
latest.WaitForExit(); Queue<Process> runQueue = new Queue<Process>();
return latest.ExitCode; Queue<Task> joints = new Queue<Task>();
} if (Pipe.Length == 0) return -1;
if (Pipe.Length == 1)
for (int i = 0; i < Pipe.Length; i++) {
{ latest = Pipe[0].Start();
Process newProcess = null; latest.WaitForExit();
var cmd = Pipe[i]; return latest.ExitCode;
bool isNotLast = (i + 1) >= Pipe.Length; }
if (latest != null) // i.e. isNotFirst for (int i = 0; i < Pipe.Length; i++)
{ {
newProcess = cmd.Start(WorkingDir, true, isNotLast); Process newProcess = null;
var jt = Task.Run(async () => 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(); while (!latest.HasExited && !newProcess.HasExited)
if (line != null) {
await newProcess.StandardInput.WriteLineAsync(line); string line = await latest.StandardOutput.ReadLineAsync();
} if (line != null)
}); await newProcess.StandardInput.WriteLineAsync(line);
joints.Enqueue(jt); }
} });
else joints.Enqueue(jt);
{ }
newProcess = cmd.Start(WorkingDir, false, isNotLast); else
Task ending = Task.Run(() => { latest.WaitForExit(); }); {
joints.Enqueue(ending); newProcess = cmd.Start(WorkingDir, false, isNotLast);
Task ending = Task.Run(() => { latest.WaitForExit(); });
joints.Enqueue(ending);
}
latest = newProcess;
runQueue.Enqueue(latest);
} }
latest = newProcess; while (runQueue.Count > 0)
runQueue.Enqueue(latest); (latest = runQueue.Dequeue()).WaitForExit();
return latest.ExitCode;
} }
while (runQueue.Count > 0)
(latest = runQueue.Dequeue()).WaitForExit();
return latest.ExitCode;
} }
} }

@ -1 +1 @@
1.0.6-rc05 1.0.6-rc06

Loading…