[Release 1.0.5-rc20-alpha7]

deploying a batch abstraction
This commit is contained in:
Paul Schneider 2018-06-17 23:34:17 +02:00
commit aeebf8bea9
10 changed files with 642 additions and 7 deletions

View file

@ -0,0 +1,14 @@
using System;
using Yavsc.Abstract.Interfaces;
namespace Yavsc.Server.Models.IT.SourceCode
{
public abstract class Batch<TInput> : IBatch<TInput, bool>
{
public string WorkingDir { get; set; }
public string HtmlLogPath { get; set; }
public Action<bool> ResultHandler { get; private set; }
public string []Args { get; set; }
public abstract void Launch(TInput Input);
}
}

View file

@ -0,0 +1,73 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Yavsc.Abstract.Interfaces;
namespace Yavsc.Server.Models.IT.SourceCode
{
public abstract class GitBatch : Batch<GitRepositoryReference>
{
public GitBatch()
{
// git -c color.status=always status
// | ~/bin/ansi2html.sh --bg=dark --palette=xterm > ../test.html
}
ProcessStartInfo CreateAnsiFilter
(GitRepositoryReference input, params string [] args )
{
var pStart = new ProcessStartInfo("git", string.Join(" ", args));
if (args[0]=="clone")
pStart.WorkingDirectory = WorkingDir;
else
pStart.WorkingDirectory = Path.Combine( WorkingDir, input.Path);
return pStart;
}
protected ProcessStartInfo CreateProcessStart(string args)
{
return new ProcessStartInfo("git", args)
{ WorkingDirectory = WorkingDir };
}
bool Clone (GitRepositoryReference input)
{
var pStart = CreateProcessStart( $"clone -b {input.Branch} {input.Url} {input.Path}");
pStart.WorkingDirectory = WorkingDir;
var proc = Process.Start(pStart);
proc.WaitForExit();
return proc.ExitCode == 0;
}
bool Pull (GitRepositoryReference input)
{
HtmlLogPath = Path.Combine( WorkingDir, "git.log");
var pStart = new ProcessStartInfo("git", "pull");
pStart.WorkingDirectory = Path.Combine(WorkingDir,input.Path);
pStart.RedirectStandardOutput = true;
HtmlLogPath = Path.Combine( WorkingDir, "git.log");
using (var mem = new MemoryStream())
{
using (var memWriter = new StreamWriter(mem))
{
var proc = Process.Start(pStart);
using (var memReader = new StreamReader(mem)) {
while (!proc.StandardOutput.EndOfStream)
memWriter.Write(proc.StandardOutput.Read());
proc.WaitForExit();
}
bool ok = proc.ExitCode==0;
ResultHandler(ok);
return ok;
}
}
}
}
}