Skip to content

Commit

Permalink
Reconstructs the BaseContext
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Nov 12, 2023
1 parent 1a88f09 commit 15d73b6
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 26 deletions.
127 changes: 102 additions & 25 deletions src/c#/GeneralUpdate.Core/Pipelines/Context/BaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,122 @@

namespace GeneralUpdate.Core.Pipelines.Context
{
/// <summary>
/// Pipeline common content.
/// </summary>
//public class BaseContext
//{
// public VersionInfo Version { get; set; }

// public string Name { get; set; }

// public string ZipfilePath { get; set; }

// public string TargetPath { get; set; }

// public string SourcePath { get; set; }

// public string Format { get; set; }

// public Encoding Encoding { get; set; }

// /// <summary>
// /// Blacklist file list.
// /// </summary>
// public List<string> BlackFiles { get; set; }

// /// <summary>
// /// Blacklist File suffix list.
// /// </summary>
// public List<string> BlackFileFormats { get; set; }

// public BaseContext(VersionInfo version, string zipfilePath, string targetPath, string sourcePath, string format, Encoding encoding, List<string> files, List<string> fileFormats)
// {
// Version = version ?? throw new ArgumentNullException($"{nameof(VersionInfo)} Cannot be empty");
// ZipfilePath = string.IsNullOrWhiteSpace(zipfilePath) ? throw new ArgumentNullException($"{nameof(zipfilePath)} Cannot be empty") : zipfilePath;
// TargetPath = string.IsNullOrWhiteSpace(targetPath) ? throw new ArgumentNullException($"{nameof(targetPath)} Cannot be empty") : targetPath; ;
// SourcePath = string.IsNullOrWhiteSpace(sourcePath) ? throw new ArgumentNullException($"{nameof(sourcePath)} Cannot be empty") : sourcePath; ;
// Format = string.IsNullOrWhiteSpace(format) ? throw new ArgumentNullException($"{nameof(format)} Cannot be empty") : format;
// Encoding = encoding;
// BlackFiles = files;
// BlackFileFormats = fileFormats;
// }
//}

/// <summary>
/// Pipeline common content.
/// </summary>
public class BaseContext
{
public VersionInfo Version { get; set; }
public VersionInfo Version { get; private set; }
public string Name { get; private set; }
public string ZipfilePath { get; private set; }
public string TargetPath { get; private set; }
public string SourcePath { get; private set; }
public string Format { get; private set; }
public Encoding Encoding { get; private set; }
public List<string> BlackFiles { get; private set; }
public List<string> BlackFileFormats { get; private set; }

public string Name { get; set; }
private BaseContext() { }

public string ZipfilePath { get; set; }
public class Builder
{
private readonly BaseContext _context = new BaseContext();

public string TargetPath { get; set; }
public Builder SetVersion(VersionInfo version)
{
_context.Version = version ?? throw new ArgumentNullException($"{nameof(VersionInfo)} Cannot be empty");
return this;
}

public string SourcePath { get; set; }
public Builder SetZipfilePath(string zipfilePath)
{
_context.ZipfilePath = string.IsNullOrWhiteSpace(zipfilePath) ? throw new ArgumentNullException($"{nameof(zipfilePath)} Cannot be empty") : zipfilePath;
return this;
}

public string Format { get; set; }
public Builder SetTargetPath(string targetPath)
{
_context.TargetPath = string.IsNullOrWhiteSpace(targetPath) ? throw new ArgumentNullException($"{nameof(targetPath)} Cannot be empty") : targetPath;
return this;
}

public Encoding Encoding { get; set; }
public Builder SetSourcePath(string sourcePath)
{
_context.SourcePath = string.IsNullOrWhiteSpace(sourcePath) ? throw new ArgumentNullException($"{nameof(sourcePath)} Cannot be empty") : sourcePath;
return this;
}

/// <summary>
/// Blacklist file list.
/// </summary>
public List<string> BlackFiles { get; set; }
public Builder SetFormat(string format)
{
_context.Format = string.IsNullOrWhiteSpace(format) ? throw new ArgumentNullException($"{nameof(format)} Cannot be empty") : format;
return this;
}

/// <summary>
/// Blacklist File suffix list.
/// </summary>
public List<string> BlackFileFormats { get; set; }
public Builder SetEncoding(Encoding encoding)
{
_context.Encoding = encoding;
return this;
}

public BaseContext(VersionInfo version, string zipfilePath, string targetPath, string sourcePath, string format, Encoding encoding, List<string> files, List<string> fileFormats)
{
Version = version ?? throw new ArgumentNullException($"{nameof(VersionInfo)} Cannot be empty");
ZipfilePath = string.IsNullOrWhiteSpace(zipfilePath) ? throw new ArgumentNullException($"{nameof(zipfilePath)} Cannot be empty") : zipfilePath;
TargetPath = string.IsNullOrWhiteSpace(targetPath) ? throw new ArgumentNullException($"{nameof(targetPath)} Cannot be empty") : targetPath; ;
SourcePath = string.IsNullOrWhiteSpace(sourcePath) ? throw new ArgumentNullException($"{nameof(sourcePath)} Cannot be empty") : sourcePath; ;
Format = string.IsNullOrWhiteSpace(format) ? throw new ArgumentNullException($"{nameof(format)} Cannot be empty") : format;
Encoding = encoding;
BlackFiles = files;
BlackFileFormats = fileFormats;
public Builder SetBlackFiles(List<string> files)
{
_context.BlackFiles = files;
return this;
}

public Builder SetBlackFileFormats(List<string> fileFormats)
{
_context.BlackFileFormats = fileFormats;
return this;
}

public BaseContext Build()
{
return _context;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneralUpdate.Core.Strategys.PlatformWindows
Expand Down Expand Up @@ -45,7 +46,19 @@ public override void Execute()
{
var patchPath = FileUtil.GetTempDirectory(PATCHS);

Check warning on line 47 in src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type 'FileUtil' in 'D:\a\GeneralUpdate\GeneralUpdate\src\c#\GeneralUpdate.Core\Utils\FileUtil.cs' conflicts with the imported type 'FileUtil' in 'GeneralUpdate.Differential, Version=1.4.3.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'D:\a\GeneralUpdate\GeneralUpdate\src\c#\GeneralUpdate.Core\Utils\FileUtil.cs'.
var zipFilePath = $"{Packet.TempPath}{version.Name}{Packet.Format}";
var pipelineBuilder = new PipelineBuilder<BaseContext>(new BaseContext(version, zipFilePath, patchPath, Packet.InstallPath, Packet.Format, Packet.Encoding, Packet.BlackFiles, Packet.BlackFormats)).

var context = new BaseContext.Builder()
.SetVersion(version)
.SetZipfilePath(zipFilePath)
.SetTargetPath(patchPath)
.SetSourcePath(Packet.InstallPath)
.SetFormat(Packet.Format)
.SetEncoding(Packet.Encoding)
.SetBlackFiles(Packet.BlackFiles)
.SetBlackFileFormats(Packet.BlackFormats)
.Build();

var pipelineBuilder = new PipelineBuilder<BaseContext>(context).
UseMiddleware<MD5Middleware>().
UseMiddleware<ZipMiddleware>().
UseMiddleware<PatchMiddleware>();
Expand Down

0 comments on commit 15d73b6

Please sign in to comment.