reorg
This commit is contained in:
parent
d000f77098
commit
40e8e08690
3487 changed files with 39 additions and 21 deletions
68
src/Yavsc.Server/Models/IT/Project.cs
Normal file
68
src/Yavsc.Server/Models/IT/Project.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using Yavsc.Abstract.IT;
|
||||
using Yavsc.Attributes.Validation;
|
||||
using Yavsc.Billing;
|
||||
using Yavsc.Models.Billing;
|
||||
using Yavsc.Server.Models.IT.SourceCode;
|
||||
|
||||
namespace Yavsc.Server.Models.IT
|
||||
{
|
||||
public class Project : NominativeServiceCommand, IProject
|
||||
{
|
||||
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public override long Id { get; set; }
|
||||
public string OwnerId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This field is something like a key,
|
||||
/// since it is required non null,
|
||||
/// and is the key of the foreign GitRepositoryReference entity.
|
||||
///
|
||||
/// As a side effect, there's no project without valid git reference in db.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[YaRequired]
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Version { get; set; }
|
||||
|
||||
[InverseProperty("TargetProject")]
|
||||
public virtual List<ProjectBuildConfiguration> Configurations { get; set; }
|
||||
|
||||
|
||||
[YaRequired]
|
||||
public long GitId { get; set; }
|
||||
|
||||
[ForeignKey("GitId")]
|
||||
public virtual GitRepositoryReference Repository { get; set; }
|
||||
|
||||
readonly List<IBillItem> bill = new List<IBillItem>();
|
||||
public void AddBillItem(IBillItem item)
|
||||
{
|
||||
bill.Add(item);
|
||||
|
||||
}
|
||||
public override List<IBillItem> GetBillItems()
|
||||
{
|
||||
return bill;
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetConfigurations()
|
||||
{
|
||||
return Configurations.Select(c => c.Name);
|
||||
}
|
||||
|
||||
string description;
|
||||
public override string Description
|
||||
{
|
||||
get { return description; }
|
||||
set { description = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
src/Yavsc.Server/Models/IT/ProjectBuildConfiguration.cs
Normal file
25
src/Yavsc.Server/Models/IT/ProjectBuildConfiguration.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Yavsc.Attributes.Validation;
|
||||
|
||||
namespace Yavsc.Server.Models.IT
|
||||
{
|
||||
public class ProjectBuildConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// A Numerical Id
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public long Id { get; set; }
|
||||
|
||||
[YaRequired]
|
||||
public string Name { get; set; }
|
||||
|
||||
public long ProjectId { get; set; }
|
||||
|
||||
[ForeignKey("ProjectId")]
|
||||
public virtual Project TargetProject { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
14
src/Yavsc.Server/Models/IT/SourceCode/Batch.cs
Normal file
14
src/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 LogPath { get; set; }
|
||||
public Action<bool> ResultHandler { get; private set; }
|
||||
public string []Args { get; set; }
|
||||
public abstract void Launch(TInput Input);
|
||||
}
|
||||
}
|
||||
53
src/Yavsc.Server/Models/IT/SourceCode/GitClone.cs
Normal file
53
src/Yavsc.Server/Models/IT/SourceCode/GitClone.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// // GitClone.cs
|
||||
// /*
|
||||
// paul 21/06/2018 11:27 20182018 6 21
|
||||
// */
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace Yavsc.Server.Models.IT.SourceCode
|
||||
{
|
||||
public class GitClone : SingleCmdProjectBatch
|
||||
{
|
||||
|
||||
public GitClone(string repo) : base(repo,"git")
|
||||
{
|
||||
|
||||
}
|
||||
public override void Launch(Project input)
|
||||
{
|
||||
if (input==null) throw new ArgumentNullException("input");
|
||||
LogPath = $"{input.Name}.git-clone.ansi.log";
|
||||
// TODO honor Args property
|
||||
// Model annotations => input.Repository!=null => input.Name == input.Repository.Path
|
||||
var prjPath = Path.Combine(WorkingDir, input.Name);
|
||||
var repoInfo = new DirectoryInfo(prjPath);
|
||||
var gitCmd = repoInfo.Exists ? "pull" : "clone --depth=1";
|
||||
|
||||
var cloneStart = new ProcessStartInfo
|
||||
( _cmdPath, $"{gitCmd} {input.Repository.Url} {input.Repository.Path}" )
|
||||
{
|
||||
WorkingDirectory = WorkingDir,
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
// TODO make `.ansi.log` a defined constant.
|
||||
var logFile = new FileInfo
|
||||
( Path.Combine
|
||||
( _repositoryRootPath, $"{input.Name}.ansi.log" ));
|
||||
using (var stream = logFile.Create())
|
||||
using (var writer = new StreamWriter(stream))
|
||||
{
|
||||
var process = Process.Start(cloneStart);
|
||||
// TODO publish the starting log url ...
|
||||
while (!process.HasExited)
|
||||
{
|
||||
if (process.StandardOutput.Peek() > -1)
|
||||
writer.WriteLine(process.StandardOutput.ReadLine());
|
||||
}
|
||||
}
|
||||
ResultHandler?.Invoke(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/Yavsc.Server/Models/IT/SourceCode/GitRepository.cs
Normal file
33
src/Yavsc.Server/Models/IT/SourceCode/GitRepository.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Yavsc.Attributes.Validation;
|
||||
using Yavsc.Models;
|
||||
|
||||
namespace Yavsc.Server.Models.IT.SourceCode
|
||||
{
|
||||
public class GitRepositoryReference
|
||||
{
|
||||
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public long Id { get; set; }
|
||||
|
||||
[YaRequired]
|
||||
public string Path { get; set; }
|
||||
|
||||
[YaStringLength(2048)]
|
||||
public string Url { get; set; }
|
||||
|
||||
[YaStringLength(512)]
|
||||
public string Branch { get; set; }
|
||||
|
||||
[YaStringLength(1024)]
|
||||
public string OwnerId { get; set; }
|
||||
|
||||
[ForeignKey("OwnerId")]
|
||||
public virtual ApplicationUser Owner { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[Git ref {Path} {Branch} {Url}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
43
src/Yavsc.Server/Models/IT/SourceCode/ProjectBuild.cs
Normal file
43
src/Yavsc.Server/Models/IT/SourceCode/ProjectBuild.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Yavsc.Server.Models.IT.SourceCode
|
||||
{
|
||||
public class ProjectBuild : SingleCmdProjectBatch
|
||||
{
|
||||
public ProjectBuild(string repoRoot): base(repoRoot, "make")
|
||||
{
|
||||
}
|
||||
|
||||
public override void Launch(Project input)
|
||||
{
|
||||
if (input==null) throw new ArgumentNullException("input");
|
||||
LogPath = $"{input.Name}.{_cmdPath}.ansi.log";
|
||||
|
||||
// TODO honor Args property
|
||||
// Model annotations => input.Repository!=null => input.Name == input.Repository.Path
|
||||
var prjPath = Path.Combine(WorkingDir, input.Name);
|
||||
var repoInfo = new DirectoryInfo(prjPath);
|
||||
var makeStart = CreateStartInfo(prjPath);
|
||||
|
||||
var args = string.Join(" ", Args);
|
||||
|
||||
// TODO make `.ansi.log` a defined constant.
|
||||
var logFile = new FileInfo(Path.Combine(_repositoryRootPath, LogPath));
|
||||
using (var stream = logFile.Create())
|
||||
using (var writer = new StreamWriter(stream))
|
||||
{
|
||||
var process = Process.Start(makeStart);
|
||||
// TODO announce ...
|
||||
while (!process.HasExited)
|
||||
{
|
||||
if (process.StandardOutput.Peek() > -1)
|
||||
writer.WriteLine(process.StandardOutput.ReadLine());
|
||||
}
|
||||
}
|
||||
ResultHandler?.Invoke(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Yavsc.Server.Models.IT.SourceCode
|
||||
{
|
||||
public abstract class SingleCmdProjectBatch : Batch<Project>
|
||||
{
|
||||
protected string _repositoryRootPath;
|
||||
protected string _cmdPath ;
|
||||
public SingleCmdProjectBatch (string repoRoot, string cmdPath)
|
||||
{
|
||||
_cmdPath = cmdPath;
|
||||
_repositoryRootPath = repoRoot;
|
||||
WorkingDir = _repositoryRootPath;
|
||||
var fie = new DirectoryInfo(WorkingDir);
|
||||
if (!fie.Exists)
|
||||
throw new Exception ($"This directory doesn't exist: {WorkingDir},\nand cannot be used as a repository.");
|
||||
}
|
||||
|
||||
public ProcessStartInfo CreateStartInfo(string workingDir)
|
||||
{
|
||||
var args = string.Join(" ", Args);
|
||||
var info = new ProcessStartInfo
|
||||
( _cmdPath, args )
|
||||
{
|
||||
WorkingDirectory = workingDir ?? WorkingDir,
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue