Batches
[Release 1.0.5-rc20-alpha7] deploying a batch abstraction
This commit is contained in:
@ -14,15 +14,28 @@ namespace Yavsc.Server.Models.IT
|
||||
public string OwnerId { get; set; }
|
||||
|
||||
public string LocalRepo { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Version { get; set; }
|
||||
|
||||
public string[] Configurations { get; set; }
|
||||
|
||||
[ForeignKey("LocalRepo")]
|
||||
public virtual GitRepositoryReference Repository { get; set; }
|
||||
|
||||
List<IBillItem> bill = new List<IBillItem> ();
|
||||
public void AddBillItem(IBillItem item)
|
||||
{
|
||||
bill.Add(item);
|
||||
|
||||
}
|
||||
public override List<IBillItem> GetBillItems()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
return bill;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public override string GetDescription()
|
||||
@ -30,6 +43,8 @@ namespace Yavsc.Server.Models.IT
|
||||
return Description;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Project()
|
||||
{
|
||||
|
||||
|
14
Yavsc.Server/Models/IT/SourceCode/Batch.cs
Normal file
14
Yavsc.Server/Models/IT/SourceCode/Batch.cs
Normal 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);
|
||||
}
|
||||
}
|
73
Yavsc.Server/Models/IT/SourceCode/GitBatch.cs
Normal file
73
Yavsc.Server/Models/IT/SourceCode/GitBatch.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user