some cleaning

This commit is contained in:
2019-08-26 01:54:38 +01:00
parent 9a669ea5fb
commit 2f7b4b3875
4 changed files with 66 additions and 54 deletions

View File

@ -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; }
}
}
}

View File

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

View File

@ -4,61 +4,65 @@ using System.Diagnostics;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class CommandPipe
namespace Yavsc.Abstract.IT
{
[JsonPropertyAttribute("pipe")]
public Command[] Pipe { get; set; }
[JsonPropertyAttribute("working_dir")]
public string WorkingDir { get; set; }
public virtual int Run()
public class CommandPipe
{
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)
[JsonPropertyAttribute("pipe")]
public Command[] Pipe { get; set; }
[JsonPropertyAttribute("working_dir")]
public string WorkingDir { get; set; }
public virtual int Run()
{
latest = Pipe[0].Start();
latest.WaitForExit();
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();
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;
if (latest != null) // i.e. isNotFirst
{
newProcess = cmd.Start(WorkingDir, true, isNotLast);
var jt = Task.Run(async () =>
{
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);
}
while (runQueue.Count > 0)
(latest = runQueue.Dequeue()).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;
if (latest != null) // i.e. isNotFirst
{
newProcess = cmd.Start(WorkingDir, true, isNotLast);
var jt = Task.Run(async () =>
{
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);
}
while (runQueue.Count > 0)
(latest = runQueue.Dequeue()).WaitForExit();
return latest.ExitCode;
}
}
}

View File

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