files tree made better.

This commit is contained in:
Paul Schneider 2019-01-01 16:28:47 +00:00
commit ccc91bbf19
1630 changed files with 18209 additions and 41860 deletions

View file

@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Attributes.Validation;
namespace Yavsc.Models.IT.Evolution
{
public class Feature
{
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[YaStringLength(256,MinLen=3)]
public string ShortName { get; set; }
[YaStringLength(10*1024,MinLen=3)]
public string Description { get; set; }
public FeatureStatus Status { get; set; }
}
}

View file

@ -0,0 +1,18 @@
namespace Yavsc.Models.IT.Evolution
{
/// <summary>
/// A Feature status
/// <c>Ko</c>: A Bug has just been discovered
/// <c>InSane</c>: This feature is not correctly integrating its ecosystem
/// <c>Obsolete</c>: This will be replaced in a short future, or yet has been replaced
/// with a better solution.
/// <c>Ok</c> : nothing to say
/// </summary>
public enum FeatureStatus: int
{
Requested,
Accepted,
Rejected,
Implemented
}
}

View file

@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Attributes.Validation;
using Yavsc.Models.IT.Evolution;
namespace Yavsc.Models.IT.Fixing
{
public class Bug
{
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[ForeignKey("FeatureId")]
public virtual Feature False { get; set; }
public long? FeatureId { get; set; }
[YaStringLength(1024)]
public string Title { get; set; }
[YaStringLength(4096)]
public string Description { get; set; }
public BugStatus Status { get; set; }
}
}

View file

@ -0,0 +1,17 @@
namespace Yavsc.Models.IT.Fixing
{
/// <summary>
/// Bug status:
/// * Inserted -> Confirmed|FeatureRequest|Feature|Rejected
/// * Confirmed -> Fixed
/// * FeatureRequest -> Implemented
/// </summary>
public enum BugStatus : int
{
Inserted,
Confirmed,
Rejected,
Feature,
Fixed
}
}

View file

@ -0,0 +1,67 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Yavsc.Abstract.IT;
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>
[Required]
public string Name { get; set; }
public string Version { get; set; }
[InverseProperty("TargetProject")]
public virtual List<ProjectBuildConfiguration> Configurations { get; set; }
[Required]
public long GitId { get; set; }
[ForeignKey("GitId")]
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()
{
return bill;
}
public IEnumerable<string> GetConfigurations()
{
return Configurations.Select(c => c.Name);
}
string description;
public override string Description
{
get { return description; }
set { description = value; }
}
}
}

View file

@ -0,0 +1,24 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Yavsc.Server.Models.IT
{
public class ProjectBuildConfiguration
{
/// <summary>
/// A Numerical Id
/// </summary>
/// <value></value>
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Required]
public string Name { get; set; }
public long ProjectId { get; set; }
[ForeignKey("ProjectId")]
public virtual Project TargetProject { get; set; }
}
}

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 LogPath { 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,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());
}
}
if (ResultHandler!=null) ResultHandler(true);
}
}
}

View file

@ -0,0 +1,32 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Models;
namespace Yavsc.Server.Models.IT.SourceCode
{
public class GitRepositoryReference
{
[Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Required]
public string Path { get; set; }
[StringLength(2048)]
public string Url { get; set; }
[StringLength(512)]
public string Branch { get; set; }
[StringLength(1024)]
public string OwnerId { get; set; }
[ForeignKey("OwnerId")]
public virtual ApplicationUser Owner { get; set; }
public override string ToString()
{
return $"[Git ref {Path} {Branch} {Url}]";
}
}
}

View file

@ -0,0 +1,50 @@
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 args = string.Join(" ", Args);
var cloneStart = new ProcessStartInfo
( _cmdPath, args )
{
WorkingDirectory = prjPath,
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 announce ...
while (!process.HasExited)
{
if (process.StandardOutput.Peek() > -1)
writer.WriteLine(process.StandardOutput.ReadLine());
}
}
if (ResultHandler!=null) ResultHandler(true);
}
}
}

View file

@ -0,0 +1,21 @@
using System;
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.");
}
}
}