Skip to content

Commit

Permalink
Cleanup, update disabling
Browse files Browse the repository at this point in the history
  • Loading branch information
mormegil-cz committed Aug 30, 2024
1 parent 695d466 commit 69db90e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
36 changes: 18 additions & 18 deletions KdyPojedeVlak.Web/Engine/Djr/DataDownloader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
Expand All @@ -10,33 +9,34 @@

namespace KdyPojedeVlak.Web.Engine.Djr
{
public class DataDownloader
public partial class DataDownloader
{
private const string clientName = "KdyPojedeVlak/CoreFTP";
private static readonly Uri serverBaseUri = new Uri(@"ftp://ftp.cisjr.cz/draha/celostatni/szdc/");
private const string ClientName = "KdyPojedeVlak/CoreFTP";
private static readonly Uri serverBaseUri = new(@"ftp://ftp.cisjr.cz/draha/celostatni/szdc/");
private const int BuffSize = 10240;

private static readonly Regex reFilename = new Regex(@"^([^.]+)\.(XML\.)?ZIP$",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline);
private static readonly Regex reFilename = RegexFilename();
private static readonly Regex reDirectory = RegexDirectory();
private static readonly Regex reSubdirectory = RegexSubdirectory();

private static readonly Regex reDirectory = new Regex(@"^2[0-9]{3}$",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline);
[GeneratedRegex(@"^([^.]+)\.(XML\.)?ZIP$", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.CultureInvariant)]
private static partial Regex RegexFilename();

private static readonly Regex reSubdirectory = new Regex(@"^2[0-9]{3}-[0-9]{2}$",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline);
[GeneratedRegex(@"^2[0-9]{3}$", RegexOptions.Singleline | RegexOptions.CultureInvariant)]
private static partial Regex RegexDirectory();

private const int BUFF_SIZE = 10240;
[GeneratedRegex(@"^2[0-9]{3}-[0-9]{2}$", RegexOptions.Singleline | RegexOptions.CultureInvariant)]
private static partial Regex RegexSubdirectory();

private FtpClient ftp;

public bool ShouldExtractZip => false;

public async Task Connect()
{
if (ftp != null) throw new InvalidOperationException("Already connected");

ftp = new FtpClient(new FtpClientConfiguration { Host = serverBaseUri.GetLeftPart(UriPartial.Authority) });
await ftp.LoginAsync();
await ftp.SetClientName(clientName);
await ftp.SetClientName(ClientName);
await ftp.ChangeWorkingDirectoryAsync(serverBaseUri.AbsolutePath);
}

Expand Down Expand Up @@ -68,7 +68,7 @@ async Task AddListOfFilesAvailableInDir(Dictionary<string, long> dictionary, str
.Where(f => f.Match.Success)
.Select(f => f.Directory.Name)
.ToList();

var results = new Dictionary<string, long>();
foreach (var dir in directories)
{
Expand All @@ -86,7 +86,7 @@ async Task AddListOfFilesAvailableInDir(Dictionary<string, long> dictionary, str
await AddListOfFilesAvailableInDir(results, dir + "/" + subdir);
await ftp.ChangeWorkingDirectoryAsync("..");
}

await AddListOfFilesAvailableInDir(results, dir);

await ftp.ChangeWorkingDirectoryAsync("..");
Expand Down Expand Up @@ -135,9 +135,9 @@ public async Task<string> GetLatestVersionAvailable()
using (var receiveStream = await ftp.OpenFileReadStreamAsync(fileName))
{
using (var storeStream = new FileStream(destinationFilename, FileMode.Create, FileAccess.Write,
FileShare.Read))
FileShare.Read))
{
var buffer = new byte[BUFF_SIZE];
var buffer = new byte[BuffSize];
while (true)
{
var read = await receiveStream.ReadAsync(buffer, 0, buffer.Length);
Expand Down
3 changes: 2 additions & 1 deletion KdyPojedeVlak.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using KdyPojedeVlak.Web.Engine;
using KdyPojedeVlak.Web.Engine.DbStorage;
using KdyPojedeVlak.Web.Engine.Djr;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
throw;
}

if (EnableUpdates) UpdateManager.Initialize(@"App_Data\cisjrdata", serviceScopeFactory);
if (EnableUpdates && Configuration["DisableUpdates"] == null) UpdateManager.Initialize(Path.Combine("App_Data", "cisjrdata"), serviceScopeFactory);
}
}
}
1 change: 1 addition & 0 deletions KdyPojedeVlak.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"AdminPassword": "pass",
"DisableUpdates": "disable",
"Logging": {
"LogLevel": {
"Microsoft.EntityFrameworkCore.Database.Command": "Information"
Expand Down

0 comments on commit 69db90e

Please sign in to comment.