Skip to content

Commit

Permalink
Merge pull request #275 from fiskaltrust/user/tsc/fcc-4.1.1
Browse files Browse the repository at this point in the history
Added support for FCC 4.1.1
  • Loading branch information
TSchmiedlechner committed Apr 15, 2024
2 parents 38081ec + a1fe1b5 commit 34a1dab
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ private void StartLocalFCC()

if (!_fccDownloadService.IsInstalled(_fccDirectory))
{
if (_fccDownloadService.DownloadFccAsync(_fccDirectory).Result)
if (_fccDownloadService.DownloadFccAsync(_fccDirectory, null).Result)
{
_fccInitializationService.Initialize(_fccDirectory);
_version = new Version(_configuration.FccVersion);
}
}
else if (!_fccDownloadService.IsLatestVersion(_fccDirectory, new Version(_configuration.FccVersion)))
{
if (_fccDownloadService.DownloadFccAsync(_fccDirectory).Result)
var currentlyInstalledVersion = _fccDownloadService.UsedFCCVersion;
if (_fccDownloadService.DownloadFccAsync(_fccDirectory, currentlyInstalledVersion).Result)
{
_fccInitializationService.Update(_fccDirectory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DeutscheFiskalSCUConfiguration
public bool DisplayCertificationIdAddition { get; set; } = true;
public string CertificationIdAddition { get; set; } = "USK ausgesetzt";
public string ServiceFolder { get; set; }
public string FccVersion { get; set; } = "4.0.8";
public string FccVersion { get; set; } = "4.1.1";
public string ProxyServer { get; set; }
public int? ProxyPort { get; set; }
public string ProxyUsername { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,28 @@ public bool IsPathInRunFccIdent(string path, string content, out string pathInFi
return string.Equals(path, pathInFile, StringComparison.OrdinalIgnoreCase);
}

public async Task<bool> DownloadFccAsync(string fccDirectory)
public async Task<bool> DownloadFccAsync(string fccDirectory, Version currentlyInstalledVersion)
{
_logger.LogWarning("Downloading and extracting FCC - this will take some time, depending on your internet connection.");
var tempZipPath = Path.GetTempFileName();
try
{
try
{
await DownloadAndExtractAsync(tempZipPath, fccDirectory).ConfigureAwait(false);
await DownloadAndExtractAsync(tempZipPath, fccDirectory, currentlyInstalledVersion).ConfigureAwait(false);
return true;
}
catch (Exception ex)
{
if(_configuration.FccRetry > _fccRetry)
if (_configuration.FccRetry > _fccRetry)
{
await Task.Delay(1000);
_fccRetry++;
_logger.LogWarning($"An error occured while downloading ({ex.InnerException?.Message ?? ex.Message}), retry {_fccRetry} from {_configuration.FccRetry}");
return await DownloadFccAsync(fccDirectory).ConfigureAwait(false);
return await DownloadFccAsync(fccDirectory, currentlyInstalledVersion).ConfigureAwait(false);
}
_logger.LogWarning($"An error occured while downloading ({ex.InnerException?.Message ?? ex.Message}), download aborted");
return false;
return false;
}
}
finally
Expand All @@ -137,10 +137,10 @@ public async Task<bool> DownloadFccAsync(string fccDirectory)
}
}
}

private string GetCloudConnectorPath(string fccDirectory) => Path.Combine(fccDirectory, "lib", "fiskal-cloud-connector-service.jar");

private async Task DownloadAndExtractAsync(string tempZipPath, string fccDirectory)
private async Task DownloadAndExtractAsync(string tempZipPath, string fccDirectory, Version currentlyInstalledVersion)
{
var downloadUri = string.IsNullOrEmpty(_configuration.FccDownloadUri) ? GetDownloadUriByCurrentPlatform() : _configuration.FccDownloadUri;
_logger.LogDebug("Downloading FCC from {FccDownloadUrl}...", downloadUri);
Expand All @@ -159,6 +159,14 @@ private async Task DownloadAndExtractAsync(string tempZipPath, string fccDirecto
var baseDir = new DirectoryInfo(fccDirectory);
if (fccdataDir.Exists)
{
// FCC version 4.1.1 requires to delete the existing Java files prior to extracting the new ones
var versionRequiresJavaUpdate = new Version(4, 1, 1);
if (currentlyInstalledVersion != null && currentlyInstalledVersion < versionRequiresJavaUpdate && new Version(_configuration.FccVersion) >= versionRequiresJavaUpdate)
{
CleanExistingJavaFiles(fccDirectory);
_logger.LogInformation("Cleaned up previous Java installation from /bin folder, as required when updating to FCC >= 4.1.1.");
}

UpdateFCCFiles(tempZipPath, fccDirectory, baseDir);
}
else
Expand All @@ -178,6 +186,15 @@ private async Task DownloadAndExtractAsync(string tempZipPath, string fccDirecto
}
}

private void CleanExistingJavaFiles(string fccDirectory)
{
var binDirectory = Path.Combine(fccDirectory, "bin");
if (Directory.Exists(binDirectory))
{
Directory.Delete(binDirectory, true);
}
}

private void UpdateFCCFiles(string tempZipPath, string fccDirectory, DirectoryInfo baseDir)
{
var runningProcess = DeutscheFiskalFccProcessHost.GetProcessIfRunning(fccDirectory, _logger);
Expand Down Expand Up @@ -210,6 +227,11 @@ private void UpdateFCCFiles(string tempZipPath, string fccDirectory, DirectoryIn

protected virtual string GetDownloadUriByCurrentPlatform()
{
if (RuntimeInformation.OSArchitecture == Architecture.X86)
{
throw new Exception("Starting from version 4.1.1, the FCC does not support x86 Operating Systems anymore. Only x64, arm32 and arm64 are supported.");
}

var operatingSystem = RuntimeInformation.OSArchitecture switch
{
Architecture.X64 => "x64",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace fiskaltrust.Middleware.SCU.DE.DeutscheFiskal.Services.Interfaces
public interface IFccDownloadService
{
Version UsedFCCVersion { get; }
Task<bool> DownloadFccAsync(string fccDirectory);
Task<bool> DownloadFccAsync(string fccDirectory, Version currentlyInstalledVersion);
bool IsInstalled(string fccDirectory);
bool IsLatestVersion(string fccDirectory, Version latestVersion);
bool IsLatestVersionDat(string fccDirectory, Version latestVersion);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.3.55",
"version": "1.3.56",
"releaseBranches": [
"^refs/tags/scu-de/deutschefiskal/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.3.55",
"version": "1.3.56",
"releaseBranches": [
"^refs/tags/scu-de/swissbitcloud/v\\d+(?:\\.\\d+)*(?:-.*)?$"
]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task DownloadAsync_Should_DownloadFileDependingOnPlatform()
};
DeleteNotExistingFolder(notExistingPath);
var sut = new DeutscheFiskalFccDownloadService(config, Mock.Of<ILogger<DeutscheFiskalFccDownloadService>>());
await sut.DownloadFccAsync(config.FccDirectory);
await sut.DownloadFccAsync(config.FccDirectory, null);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public FccDownloaderTests(SwissbitCloudFixture fixture)
public async Task DownloadAsync_Should_DownloadFileDependingOnPlatform()
{
var sut = new DeutscheFiskalFccDownloadService(_fixture.Configuration, Mock.Of<ILogger<IFccDownloadService>>());
await sut.DownloadFccAsync(_fixture.Configuration.FccDirectory);
await sut.DownloadFccAsync(_fixture.Configuration.FccDirectory, null);
}
}
}

0 comments on commit 34a1dab

Please sign in to comment.