Skip to content

Commit

Permalink
New feature "Import Behaviour" implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
fstueber committed Sep 9, 2024
1 parent 1b5f163 commit 01deadd
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 83 deletions.
8 changes: 4 additions & 4 deletions src/Enbrea.Cli.DaVinci/Export/ExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public async override Task Execute()
// Create command for DAVINCI CONSOLE
var cmd = _config.DataProvider == DataProvider.File ?
CliWrap.Cli.Wrap(ConsoleUtils.GetConsolePath())
.WithArguments(new[] {
.WithArguments([
"export", "-minimal-display",
"-s", "file",
"-o", GetEcfFolderName(),
"-fn", _config.DataFile
}) :
]) :
CliWrap.Cli.Wrap(ConsoleUtils.GetConsolePath())
.WithArguments(new[] {
.WithArguments([
"export", "-minimal-display",
"-s", "server",
"-o", GetEcfFolderName(),
Expand All @@ -63,7 +63,7 @@ public async override Task Execute()
"-un", _config.ServerUserName,
"-up", _config.ServerPassword,
"-sf", $"{{{_config.ServerFileId}}}"
});
]);

// Excecute DAVINCI CONSOLE
await foreach (var cmdEvent in cmd.ListenAsync(_cancellationToken))
Expand Down
8 changes: 4 additions & 4 deletions src/Enbrea.Cli.DaVinci/Import/ImportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public async override Task Execute()
// Create command for DAVINCI CONSOLE
var cmd = _config.DataProvider == DataProvider.File ?
CliWrap.Cli.Wrap(ConsoleUtils.GetConsolePath())
.WithArguments(new[] {
.WithArguments([
"import", "-minimal-display",
"-s", "file",
"-i", GetEcfFolderName(),
"-fn", _config.DataFile
}) :
]) :
CliWrap.Cli.Wrap(ConsoleUtils.GetConsolePath())
.WithArguments(new[] {
.WithArguments([
"import", "-minimal-display",
"-s", "server",
"-i", GetEcfFolderName(),
Expand All @@ -63,7 +63,7 @@ public async override Task Execute()
"-un", _config.ServerUserName,
"-up", _config.ServerPassword,
"-sf", $"{{{_config.ServerFileId}}}"
});
]);

// Excecute DAVINCI CONSOLE
await foreach (var cmdEvent in cmd.ListenAsync(_cancellationToken))
Expand Down
12 changes: 6 additions & 6 deletions src/Enbrea.Cli.Untis/Utils/ConsoleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ static public async Task RunUntisBackup(

// Execute Untis
var result = await CliWrap.Cli.Wrap(GetUntisPath())
.WithArguments(new[] {
.WithArguments([
$"DB~{schoolNo}~{schoolYear}~{version}",
$"/backup={outputFile}",
$"/user={userName}",
$"/pwd={password}"
})
])
.WithValidation(CommandResultValidation.None)
.ExecuteAsync(cancellationToken);

Expand Down Expand Up @@ -148,10 +148,10 @@ static public async Task RunUntisSingleGpuExport(

// Execute Untis
var result = await CliWrap.Cli.Wrap(GetUntisPath())
.WithArguments(new[] {
.WithArguments([
$"{untisFile}",
$"/exp{outputType}={outputFile}"
})
])
.WithValidation(CommandResultValidation.None)
.ExecuteAsync(cancellationToken);

Expand Down Expand Up @@ -193,10 +193,10 @@ static public async Task RunUntisXmlExport(

// Execute Untis
var result = await CliWrap.Cli.Wrap(GetUntisPath())
.WithArguments(new[] {
.WithArguments([
$"{untisFile}",
$"/xml={outputFile}"
})
])
.WithValidation(CommandResultValidation.None)
.ExecuteAsync(cancellationToken);

Expand Down
75 changes: 40 additions & 35 deletions src/Enbrea.Cli/CommandDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public static Command Backup()
{
var command = new Command("backup-offline", "Creates and downloads an Enbrea database backup for offline use")
{
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
},
new Option<FileInfo>(new[] { "--out", "-o" }, "Path to output file")
new Option<FileInfo>(["--out", "-o"], "Path to output file")
{
IsRequired = true
}
Expand All @@ -53,15 +53,15 @@ public static Command CreateExportTask()
{
var command = new Command("create-export-task", "Schedules a task for a data export from an Enbrea instance")
{
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
},
new Option<ExportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ExportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
},
new Option<uint>(new[] { "--interval", "-i" }, delegate() { return 10; }, "Time interval in minutes")
new Option<uint>(["--interval", "-i"], delegate() { return 10; }, "Time interval in minutes")
{
IsRequired = true
}
Expand All @@ -79,15 +79,15 @@ public static Command CreateImportTask()
{
var command = new Command("create-import-task", "Schedules a task for a data import to an Enbrea instance")
{
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
},
new Option<ImportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ImportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
},
new Option<uint>(new[] { "--interval", "-i" }, delegate() { return 10; }, "Time interval in minutes")
new Option<uint>(["--interval", "-i"], delegate() { return 10; }, "Time interval in minutes")
{
IsRequired = true
}
Expand All @@ -105,7 +105,7 @@ public static Command CreateSnaphot()
{
var command = new Command("create-snapshot", "Create a Enbrea database snapshot")
{
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
}
Expand All @@ -131,7 +131,7 @@ public static Command DeleteExportTask()
{
var command = new Command("delete-export-task", "Deletes a scheduled export task for Enbrea")
{
new Option<ExportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ExportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
}
Expand All @@ -147,7 +147,7 @@ public static Command DeleteImportTask()
{
var command = new Command("delete-import-task", "Deletes a scheduled import task for Enbrea")
{
new Option<ImportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ImportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
}
Expand All @@ -162,11 +162,11 @@ public static Command DeleteImportTask()
public static Command DeleteSnaphot()
{
var command = new Command("delete-snapshot", "Delete an Enbrea database snapshot"){
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
},
new Option<Guid>(new[] { "--id", "-id" }, "Unique ID of the snapshot")
new Option<Guid>(["--id", "-id"], "Unique ID of the snapshot")
{
IsRequired = true
}
Expand All @@ -184,7 +184,7 @@ public static Command DisableExportTask()
{
var command = new Command("disable-export-task", "Deactivates a scheduled export task for Enbrea")
{
new Option<ExportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ExportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
}
Expand All @@ -200,7 +200,7 @@ public static Command DisableImportTask()
{
var command = new Command("disable-import-task", "Deactivates a scheduled import task for Enbrea")
{
new Option<ImportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ImportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
}
Expand All @@ -216,7 +216,7 @@ public static Command EnableExportTask()
{
var command = new Command("enable-export-task", "Activates a scheduled export task for Enbrea")
{
new Option<ExportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ExportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
}
Expand All @@ -232,7 +232,7 @@ public static Command EnableImportTask()
{
var command = new Command("enable-import-task", "Activates a scheduled import task for Enbrea")
{
new Option<ImportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ImportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
}
Expand All @@ -248,23 +248,23 @@ public static Command Export()
{
var command = new Command("export", "Exports data from an Enbrea instance to an external provider")
{
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
},
new Option<ExportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ExportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
},
new Option<bool>(new[] { "--skip-enbrea" }, delegate() { return false; }, "Skip export of ECF files from Enbrea")
new Option<bool>(["--skip-enbrea"], delegate() { return false; }, "Skip export of ECF files from Enbrea")
{
IsRequired = false
},
new Option<bool>(new[] { "--skip-provider" }, delegate() { return false; }, "Skip import of ECF files to external provider")
new Option<bool>(["--skip-provider"], delegate() { return false; }, "Skip import of ECF files to external provider")
{
IsRequired = false
},
new Option<string>(new[] { "--log", "-l" }, delegate () { return null; }, "Log file folder")
new Option<string>(["--log", "-l"], delegate () { return null; }, "Log file folder")
{
IsRequired = false
}
Expand All @@ -284,27 +284,31 @@ public static Command Import()
{
var command = new Command("import", "Imports data from external provider to an Enbrea instance")
{
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
},
new Option<ImportProvider>(new[] { "--provider", "-p" }, "Name of external data provider")
new Option<ImportProvider>(["--provider", "-p"], "Name of external data provider")
{
IsRequired = true
},
new Option<bool>(new[] { "--skip-provider" }, delegate() { return false; }, "Skip import of ECF files from external provider")
new Option<ImportBehaviour>(["--behaviour", "-b"], delegate() { return ImportBehaviour.diff; }, "Import behaviour")
{
IsRequired = false
},
new Option<bool>(new[] { "--skip-enbrea" }, delegate() { return false; }, "Skip import of ECF files to Enbrea")
new Option<bool>(["--skip-provider"], delegate() { return false; }, "Skip import of ECF files from external provider")
{
IsRequired = false
},
new Option<bool>(new[] { "--skip-snapshot" }, delegate() { return false; }, "Skip creating of a snapshot")
new Option<bool>(["--skip-enbrea"], delegate() { return false; }, "Skip import of ECF files to Enbrea")
{
IsRequired = false
},
new Option<string>(new[] { "--log", "-l" }, delegate () { return null; }, "Log file folder")
new Option<bool>(["--skip-snapshot"], delegate() { return false; }, "Skip creating of a snapshot")
{
IsRequired = false
},
new Option<string>(["--log", "-l"], delegate () { return null; }, "Log file folder")
{
IsRequired = false
}
Expand All @@ -313,10 +317,11 @@ public static Command Import()
command.SetHandler(CommandHandlers.Import,
command.Options[0] as Option<FileInfo>,
command.Options[1] as Option<ImportProvider>,
command.Options[2] as Option<bool>,
command.Options[2] as Option<ImportBehaviour>,
command.Options[3] as Option<bool>,
command.Options[4] as Option<bool>,
command.Options[5] as Option<string>);
command.Options[5] as Option<bool>,
command.Options[6] as Option<string>);

return command;
}
Expand All @@ -325,7 +330,7 @@ public static Command Init()
{
var command = new Command("init", "Create an Enbrea configuration file template")
{
new Option<FileInfo>(new[] { "--config", "-c" }, "Path for new JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path for new JSON configuration file")
{
IsRequired = true
}
Expand All @@ -350,7 +355,7 @@ public static Command ListAllTasks()
public static Command ListSchoolTerms()
{
var command = new Command("list-schoolterms", "Get list of Enbrea school terms"){
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
}
Expand All @@ -366,7 +371,7 @@ command.Options[0] as Option<FileInfo>
public static Command ListSnaphots()
{
var command = new Command("list-snapshots", "Get list of Enbrea database snapshots"){
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
}
Expand All @@ -382,11 +387,11 @@ command.Options[0] as Option<FileInfo>
public static Command RestoreSnaphot()
{
var command = new Command("restore-snapshot", "Restore an Enbrea database from an Enbrea snapshot"){
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(["--config", "-c"], "Path to existing JSON configuration file")
{
IsRequired = true
},
new Option<Guid>(new[] { "--id", "-id" }, "Unique ID of the snapshot")
new Option<Guid>(["--id", "-id"], "Unique ID of the snapshot")
{
IsRequired = true
}
Expand Down
4 changes: 2 additions & 2 deletions src/Enbrea.Cli/CommandHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ await Execute(async (cancellationEvent, cancellationToken) =>
});
}

public static async Task Import(FileInfo configFile, ImportProvider provider, bool skipProvider, bool skipEnbrea, bool skipSnapshot, string logFile)
public static async Task Import(FileInfo configFile, ImportProvider provider, ImportBehaviour behaviour, bool skipProvider, bool skipEnbrea, bool skipSnapshot, string logFile)
{
await Execute(async (cancellationEvent, cancellationToken) =>
{
Expand All @@ -379,7 +379,7 @@ await Execute(async (cancellationEvent, cancellationToken) =>

if (!skipEnbrea)
{
var importManager = ImportManagerFactory.CreateImportToEnbreaManager(provider, config, skipSnapshot, consoleWriter, cancellationEvent, cancellationToken);
var importManager = ImportManagerFactory.CreateImportToEnbreaManager(provider, config, behaviour, skipSnapshot, consoleWriter, cancellationEvent, cancellationToken);
if (importManager != null)
{
await importManager.Execute();
Expand Down
4 changes: 2 additions & 2 deletions src/Enbrea.Cli/Enbrea.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<PackageReference Include="Enbrea.Csv" Version="0.10.2" />
<PackageReference Include="Enbrea.Ecf" Version="0.2.1" />
<PackageReference Include="IdentityModel" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.7" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
Expand Down
Loading

0 comments on commit 01deadd

Please sign in to comment.