Removed Renci.SshNet
This commit is contained in:
parent
d9e394f446
commit
55adcb69aa
@ -1,7 +1,5 @@
|
|||||||
using DiscUtils.Iso9660;
|
using DiscUtils.Iso9660;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Renci.SshNet;
|
|
||||||
using Renci.SshNet.Sftp;
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
@ -15,7 +13,7 @@ internal static partial class Helper20241217
|
|||||||
|
|
||||||
private record Record(string Directory, Job? Job, string Path);
|
private record Record(string Directory, Job? Job, string Path);
|
||||||
private record Job(string AlternatePath, string Directory, string Extension, File[] Files, int FilesCount, double FilesTotalLength, int Keep, Target[] Targets);
|
private record Job(string AlternatePath, string Directory, string Extension, File[] Files, int FilesCount, double FilesTotalLength, int Keep, Target[] Targets);
|
||||||
private record SecureShell(string Host, string Key, string Path, bool Required, string User);
|
private record SecureShell();
|
||||||
private record ServerMessageBlock(string Path, bool Required);
|
private record ServerMessageBlock(string Path, bool Required);
|
||||||
private record Target(SecureShell? SecureShell, ServerMessageBlock? ServerMessageBlock);
|
private record Target(SecureShell? SecureShell, ServerMessageBlock? ServerMessageBlock);
|
||||||
private record File(long LastWriteTicks, long Length, string RelativePath);
|
private record File(long LastWriteTicks, long Length, string RelativePath);
|
||||||
@ -138,17 +136,25 @@ internal static partial class Helper20241217
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteISO(Record record, ReadOnlyCollection<File> files, string path, string directoryName)
|
private static void WriteISO(char destinationDriveLetter, Record record, ReadOnlyCollection<File> files, string path, string directoryName)
|
||||||
{
|
{
|
||||||
|
string checkFile = $"{destinationDriveLetter}{path[1..]}";
|
||||||
|
string checkDirectory = Path.GetDirectoryName(checkFile) ?? throw new Exception();
|
||||||
|
if (!Directory.Exists(checkDirectory))
|
||||||
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
CDBuilder builder = new() { UseJoliet = true, VolumeIdentifier = directoryName.Length < 25 ? directoryName : directoryName[..25] };
|
CDBuilder builder = new() { UseJoliet = true, VolumeIdentifier = directoryName.Length < 25 ? directoryName : directoryName[..25] };
|
||||||
foreach (File file in files)
|
foreach (File file in files)
|
||||||
_ = builder.AddFile(file.RelativePath, Path.Combine(record.Directory, file.RelativePath));
|
_ = builder.AddFile(file.RelativePath, Path.Combine(record.Directory, file.RelativePath));
|
||||||
builder.Build(path);
|
builder.Build(checkFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteZIP(Record record, ReadOnlyCollection<File> files, string path)
|
private static void WriteZIP(char destinationDriveLetter, Record record, ReadOnlyCollection<File> files, string path)
|
||||||
{
|
{
|
||||||
using ZipArchive zip = ZipFile.Open(path, ZipArchiveMode.Create);
|
string checkFile = $"{destinationDriveLetter}{path[1..]}";
|
||||||
|
string checkDirectory = Path.GetDirectoryName(checkFile) ?? throw new Exception();
|
||||||
|
if (!Directory.Exists(checkDirectory))
|
||||||
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
|
using ZipArchive zip = ZipFile.Open(checkFile, ZipArchiveMode.Create);
|
||||||
string directoryEntry;
|
string directoryEntry;
|
||||||
List<string> directoryEntries = [];
|
List<string> directoryEntries = [];
|
||||||
foreach (File file in files)
|
foreach (File file in files)
|
||||||
@ -163,39 +169,17 @@ internal static partial class Helper20241217
|
|||||||
_ = zip.CreateEntryFromFile(Path.Combine(record.Directory, file.RelativePath), file.RelativePath);
|
_ = zip.CreateEntryFromFile(Path.Combine(record.Directory, file.RelativePath), file.RelativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteExtension(Record record, Job job, ReadOnlyCollection<File> files, string path)
|
private static void WriteExtension(char destinationDriveLetter, Record record, Job job, ReadOnlyCollection<File> files, string path)
|
||||||
{
|
{
|
||||||
string directoryName = Path.GetFileName(record.Directory);
|
string directoryName = Path.GetFileName(record.Directory);
|
||||||
if (job.Extension.Equals(".iso", StringComparison.OrdinalIgnoreCase))
|
if (job.Extension.Equals(".iso", StringComparison.OrdinalIgnoreCase))
|
||||||
WriteISO(record, files, path, directoryName);
|
WriteISO(destinationDriveLetter, record, files, path, directoryName);
|
||||||
else if (job.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
|
else if (job.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
|
||||||
WriteZIP(record, files, path);
|
WriteZIP(destinationDriveLetter, record, files, path);
|
||||||
else
|
else
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PushTo(Job job, SecureShell secureShell, string path)
|
|
||||||
{
|
|
||||||
string remotePath = string.Concat(secureShell.Path, '/', Path.GetFileName(path));
|
|
||||||
using SftpClient client = new(secureShell.Host, secureShell.User, new PrivateKeyFile(secureShell.Key));
|
|
||||||
client.Connect();
|
|
||||||
if (job.Files.Length == 0)
|
|
||||||
{
|
|
||||||
string directoryName = Path.GetDirectoryName(secureShell.Path) ?? throw new Exception();
|
|
||||||
try
|
|
||||||
{ client.CreateDirectory(Path.GetDirectoryName(directoryName) ?? throw new Exception()); }
|
|
||||||
catch (Exception) { }
|
|
||||||
try
|
|
||||||
{ client.CreateDirectory(directoryName); }
|
|
||||||
catch (Exception) { }
|
|
||||||
try
|
|
||||||
{ client.CreateDirectory(secureShell.Path); }
|
|
||||||
catch (Exception) { }
|
|
||||||
}
|
|
||||||
using FileStream fileStream = System.IO.File.OpenRead(path);
|
|
||||||
client.UploadFile(fileStream, remotePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void PushTo(ServerMessageBlock serverMessageBlock, string path)
|
private static void PushTo(ServerMessageBlock serverMessageBlock, string path)
|
||||||
{
|
{
|
||||||
string remotePath = Path.Combine(serverMessageBlock.Path, Path.GetFileName(path));
|
string remotePath = Path.Combine(serverMessageBlock.Path, Path.GetFileName(path));
|
||||||
@ -214,15 +198,7 @@ internal static partial class Helper20241217
|
|||||||
foreach (Target target in job.Targets)
|
foreach (Target target in job.Targets)
|
||||||
{
|
{
|
||||||
if (target.SecureShell is not null)
|
if (target.SecureShell is not null)
|
||||||
{
|
continue;
|
||||||
try
|
|
||||||
{ PushTo(job, target.SecureShell, path); }
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
if (target.SecureShell.Required)
|
|
||||||
results.Add(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (target.ServerMessageBlock is not null)
|
else if (target.ServerMessageBlock is not null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -239,23 +215,6 @@ internal static partial class Helper20241217
|
|||||||
return results.AsReadOnly();
|
return results.AsReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DeleteOld(Job job, SecureShell secureShell, string path)
|
|
||||||
{
|
|
||||||
List<string> results = [];
|
|
||||||
using SftpClient client = new(secureShell.Host, secureShell.User, new PrivateKeyFile(secureShell.Key));
|
|
||||||
client.Connect();
|
|
||||||
foreach (ISftpFile file in client.ListDirectory(secureShell.Path))
|
|
||||||
{
|
|
||||||
if (file.Name == path)
|
|
||||||
continue;
|
|
||||||
if (!file.Name.EndsWith(job.Extension, StringComparison.OrdinalIgnoreCase))
|
|
||||||
continue;
|
|
||||||
results.Add(file.FullName);
|
|
||||||
}
|
|
||||||
for (int i = job.Keep - 1; i < results.Count; i++)
|
|
||||||
client.DeleteFile(results[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void DeleteOld(Job job, ServerMessageBlock serverMessageBlock, string path)
|
private static void DeleteOld(Job job, ServerMessageBlock serverMessageBlock, string path)
|
||||||
{
|
{
|
||||||
List<string> results = [];
|
List<string> results = [];
|
||||||
@ -276,15 +235,7 @@ internal static partial class Helper20241217
|
|||||||
foreach (Target target in job.Targets)
|
foreach (Target target in job.Targets)
|
||||||
{
|
{
|
||||||
if (target.SecureShell is not null)
|
if (target.SecureShell is not null)
|
||||||
{
|
continue;
|
||||||
try
|
|
||||||
{ DeleteOld(job, target.SecureShell, path); }
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
if (target.SecureShell.Required)
|
|
||||||
results.Add(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (target.ServerMessageBlock is not null)
|
else if (target.ServerMessageBlock is not null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -304,7 +255,7 @@ internal static partial class Helper20241217
|
|||||||
private static void Verify(string searchPattern, string[] ignoreFileNames)
|
private static void Verify(string searchPattern, string[] ignoreFileNames)
|
||||||
{
|
{
|
||||||
List<Target> targets = [
|
List<Target> targets = [
|
||||||
new(new SecureShell("free.file.sync.root", "C:/Users/phares/.ssh/id_ed25519", "\\home", true, "root"), null),
|
new(new SecureShell(), null),
|
||||||
new(null, new ServerMessageBlock("\\\\mesfs.infineon.com\\EC_APC\\DEV", true))
|
new(null, new ServerMessageBlock("\\\\mesfs.infineon.com\\EC_APC\\DEV", true))
|
||||||
];
|
];
|
||||||
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode", "helper");
|
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode", "helper");
|
||||||
@ -337,6 +288,7 @@ internal static partial class Helper20241217
|
|||||||
ReadOnlyCollection<Exception> exceptions;
|
ReadOnlyCollection<Exception> exceptions;
|
||||||
string[] ignoreFileNames = args[3].Split('|');
|
string[] ignoreFileNames = args[3].Split('|');
|
||||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||||
|
char destinationDriveLetter = args[4].Split(':')[0][0];
|
||||||
logger.LogInformation("Searching <{sourceDirectory}> with search pattern {searchPattern}", args[0], searchPattern);
|
logger.LogInformation("Searching <{sourceDirectory}> with search pattern {searchPattern}", args[0], searchPattern);
|
||||||
if (Debugger.IsAttached)
|
if (Debugger.IsAttached)
|
||||||
Verify(searchPattern, ignoreFileNames);
|
Verify(searchPattern, ignoreFileNames);
|
||||||
@ -353,7 +305,7 @@ internal static partial class Helper20241217
|
|||||||
directoryName = Path.GetFileName(record.Directory);
|
directoryName = Path.GetFileName(record.Directory);
|
||||||
path = Path.Combine(record.Directory, $"{directoryName}-{DateTime.Now:yyyy-MM-dd-HH-mm-ss-fff}{record.Job.Extension}");
|
path = Path.Combine(record.Directory, $"{directoryName}-{DateTime.Now:yyyy-MM-dd-HH-mm-ss-fff}{record.Job.Extension}");
|
||||||
logger.LogInformation("Writing <{directory}> extension", record.Directory);
|
logger.LogInformation("Writing <{directory}> extension", record.Directory);
|
||||||
WriteExtension(record, record.Job, files, path);
|
WriteExtension(destinationDriveLetter, record, record.Job, files, path);
|
||||||
logger.LogInformation("Pushing <{directory}> extension", record.Directory);
|
logger.LogInformation("Pushing <{directory}> extension", record.Directory);
|
||||||
exceptions = PushTo(record.Job, path);
|
exceptions = PushTo(record.Job, path);
|
||||||
if (exceptions.Count != 0)
|
if (exceptions.Count != 0)
|
||||||
|
@ -110,49 +110,51 @@ internal static partial class Helper20250204
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string[] GetTaskLines(string directory, string rootDirectory) =>
|
||||||
|
[
|
||||||
|
"{",
|
||||||
|
"\"version\": \"2.0.0\",",
|
||||||
|
"\"tasks\": [",
|
||||||
|
"{",
|
||||||
|
"\"label\": \"File-Folder-Helper AOT s X Day-Helper-2025-02-04\",",
|
||||||
|
"\"type\": \"shell\",",
|
||||||
|
"\"command\": \"L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe\",",
|
||||||
|
"\"args\": [",
|
||||||
|
"\"s\",",
|
||||||
|
"\"X\",",
|
||||||
|
$"\"{directory}\",",
|
||||||
|
"\"Day-Helper-2025-02-04\",",
|
||||||
|
$"\"{rootDirectory}\",",
|
||||||
|
"],",
|
||||||
|
"\"problemMatcher\": []",
|
||||||
|
"},",
|
||||||
|
"{",
|
||||||
|
"\"label\": \"File-Folder-Helper AOT s X Day-Helper-2024-06-23\",",
|
||||||
|
"\"type\": \"shell\",",
|
||||||
|
"\"command\": \"L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe\",",
|
||||||
|
"\"args\": [",
|
||||||
|
"\"s\",",
|
||||||
|
"\"X\",",
|
||||||
|
$"\"{directory}\",",
|
||||||
|
"\"Day-Helper-2024-06-23\",",
|
||||||
|
"\"*.md\",",
|
||||||
|
"\"##_Sub-tasks\",",
|
||||||
|
"\"-_[code-insiders](\",",
|
||||||
|
"\"index.md\",",
|
||||||
|
"\"-_[,](\",",
|
||||||
|
"\"##_Done\",",
|
||||||
|
"\".kan\",",
|
||||||
|
$"\"{rootDirectory}\",",
|
||||||
|
"\"316940400000\",",
|
||||||
|
"],",
|
||||||
|
"\"problemMatcher\": []",
|
||||||
|
"}",
|
||||||
|
"]",
|
||||||
|
"}",
|
||||||
|
];
|
||||||
|
|
||||||
private static string GetTaskText(string directory, string rootDirectory) =>
|
private static string GetTaskText(string directory, string rootDirectory) =>
|
||||||
string.Join(Environment.NewLine,
|
string.Join(Environment.NewLine, GetTaskLines(directory, rootDirectory));
|
||||||
[
|
|
||||||
"{",
|
|
||||||
"\"version\": \"2.0.0\",",
|
|
||||||
"\"tasks\": [",
|
|
||||||
"{",
|
|
||||||
"\"label\": \"File-Folder-Helper AOT s X Day-Helper-2025-02-04\",",
|
|
||||||
"\"type\": \"shell\",",
|
|
||||||
"\"command\": \"L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe\",",
|
|
||||||
"\"args\": [",
|
|
||||||
"\"s\",",
|
|
||||||
"\"X\",",
|
|
||||||
$"\"{directory}\",",
|
|
||||||
"\"Day-Helper-2025-02-04\",",
|
|
||||||
$"\"{rootDirectory}\",",
|
|
||||||
"],",
|
|
||||||
"\"problemMatcher\": []",
|
|
||||||
"},",
|
|
||||||
"{",
|
|
||||||
"\"label\": \"File-Folder-Helper AOT s X Day-Helper-2024-06-23\",",
|
|
||||||
"\"type\": \"shell\",",
|
|
||||||
"\"command\": \"L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe\",",
|
|
||||||
"\"args\": [",
|
|
||||||
"\"s\",",
|
|
||||||
"\"X\",",
|
|
||||||
$"\"{directory}\",",
|
|
||||||
"\"Day-Helper-2024-06-23\",",
|
|
||||||
"\"*.md\",",
|
|
||||||
"\"##_Sub-tasks\",",
|
|
||||||
"\"-_[code-insiders](\",",
|
|
||||||
"\"index.md\",",
|
|
||||||
"\"-_[,](\",",
|
|
||||||
"\"##_Done\",",
|
|
||||||
"\".kan\",",
|
|
||||||
$"\"{rootDirectory}\",",
|
|
||||||
"\"316940400000\",",
|
|
||||||
"],",
|
|
||||||
"\"problemMatcher\": []",
|
|
||||||
"}",
|
|
||||||
"]",
|
|
||||||
"}",
|
|
||||||
]);
|
|
||||||
|
|
||||||
private static void WriteTaskFile(string sourceDirectory, string rootDirectory)
|
private static void WriteTaskFile(string sourceDirectory, string rootDirectory)
|
||||||
{
|
{
|
||||||
@ -169,34 +171,36 @@ internal static partial class Helper20250204
|
|||||||
private static string GetFilter(ReadOnlyCollection<H1ParamCaseAndState> collection, string filter) =>
|
private static string GetFilter(ReadOnlyCollection<H1ParamCaseAndState> collection, string filter) =>
|
||||||
string.Join(Environment.NewLine, from l in collection where l.State == filter select $"- [{l.ParamCase}](tasks/{l.ParamCase}.md)");
|
string.Join(Environment.NewLine, from l in collection where l.State == filter select $"- [{l.ParamCase}](tasks/{l.ParamCase}.md)");
|
||||||
|
|
||||||
|
private static string[] GetIndexLines(WorkItem workItem, H1ParamCaseAndState h1ParamCaseAndState, ReadOnlyCollection<H1ParamCaseAndState> collection) =>
|
||||||
|
[
|
||||||
|
"---",
|
||||||
|
"startedColumns:",
|
||||||
|
" - 'In Progress'",
|
||||||
|
"completedColumns:",
|
||||||
|
" - Done",
|
||||||
|
"---",
|
||||||
|
string.Empty,
|
||||||
|
$"# {workItem.Id} - {h1ParamCaseAndState.H1}",
|
||||||
|
string.Empty,
|
||||||
|
"## Backlog",
|
||||||
|
string.Empty,
|
||||||
|
GetFilter(collection, "Backlog"),
|
||||||
|
string.Empty,
|
||||||
|
"## Todo",
|
||||||
|
string.Empty,
|
||||||
|
GetFilter(collection, "ToDo"),
|
||||||
|
string.Empty,
|
||||||
|
"## In Progress",
|
||||||
|
string.Empty,
|
||||||
|
GetFilter(collection, "In Progress"),
|
||||||
|
string.Empty,
|
||||||
|
"## Done",
|
||||||
|
string.Empty,
|
||||||
|
GetFilter(collection, "Done"),
|
||||||
|
string.Empty
|
||||||
|
];
|
||||||
private static string GetIndexText(WorkItem workItem, H1ParamCaseAndState h1ParamCaseAndState, ReadOnlyCollection<H1ParamCaseAndState> collection) =>
|
private static string GetIndexText(WorkItem workItem, H1ParamCaseAndState h1ParamCaseAndState, ReadOnlyCollection<H1ParamCaseAndState> collection) =>
|
||||||
string.Join(Environment.NewLine, [
|
string.Join(Environment.NewLine, GetIndexLines(workItem, h1ParamCaseAndState, collection));
|
||||||
"---",
|
|
||||||
"startedColumns:",
|
|
||||||
" - 'In Progress'",
|
|
||||||
"completedColumns:",
|
|
||||||
" - Done",
|
|
||||||
"---",
|
|
||||||
string.Empty,
|
|
||||||
$"# {workItem.Id} - {h1ParamCaseAndState.H1}",
|
|
||||||
string.Empty,
|
|
||||||
"## Backlog",
|
|
||||||
string.Empty,
|
|
||||||
GetFilter(collection, "Backlog"),
|
|
||||||
string.Empty,
|
|
||||||
"## Todo",
|
|
||||||
string.Empty,
|
|
||||||
GetFilter(collection, "ToDo"),
|
|
||||||
string.Empty,
|
|
||||||
"## In Progress",
|
|
||||||
string.Empty,
|
|
||||||
GetFilter(collection, "In Progress"),
|
|
||||||
string.Empty,
|
|
||||||
"## Done",
|
|
||||||
string.Empty,
|
|
||||||
GetFilter(collection, "Done"),
|
|
||||||
string.Empty
|
|
||||||
]);
|
|
||||||
|
|
||||||
private static string GetIndexMarkdown(FileInfo fileInfo, ReadOnlyCollection<WorkItem> workItems)
|
private static string GetIndexMarkdown(FileInfo fileInfo, ReadOnlyCollection<WorkItem> workItems)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
|
||||||
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.12" />
|
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.12" />
|
||||||
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
|
||||||
<PackageReference Include="System.Text.Json" Version="8.0.5" />
|
<PackageReference Include="System.Text.Json" Version="8.0.5" />
|
||||||
<PackageReference Include="TextCopy" Version="6.2.1" />
|
<PackageReference Include="TextCopy" Version="6.2.1" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user