Skip to content

Commit c5b8877

Browse files
committed
More work on improving perf and reinstating real-time sync.
1 parent 5aa0134 commit c5b8877

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

SFTPSyncLib/Logger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ private static void Log(string message)
4040
switch (_mode)
4141
{
4242
case LoggerMode.Console:
43-
Console.WriteLine($"{DateTime.Now.ToString()} {message}");
43+
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} {message}");
4444
break;
4545

4646
case LoggerMode.RaiseEvent:
47-
LogUpdated?.Invoke($"{DateTime.Now.ToString()} {message}");
47+
LogUpdated?.Invoke($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} {message}");
4848
break;
4949
}
5050
}

SFTPSyncLib/RemoteSync.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public RemoteSync(string host, string username, string password,
3939
_director = director;
4040
_excludedFolders = excludedFolders ?? new List<string>();
4141
_sftp = new SftpClient(host, username, password);
42-
_sftp.Connect();
4342

4443
//Our first instance is responsible for creating all of the the directories
4544
//Subsequent instances will not be created until this is done
@@ -69,7 +68,6 @@ public RemoteSync(string host, string username, string password,
6968
_director = director;
7069
_excludedFolders = excludedFolders ?? new List<string>();
7170
_sftp = new SftpClient(host, username, password);
72-
_sftp.Connect();
7371

7472
DoneMakingFolders = Task.CompletedTask;
7573
DoneInitialSync = initialSyncTask;
@@ -424,6 +422,11 @@ private bool EnsureConnectedSafe()
424422
}
425423
}
426424

425+
public Task<bool> ConnectAsync()
426+
{
427+
return Task.Run(() => EnsureConnectedSafe());
428+
}
429+
427430

428431
private async void Fsw_Changed(object? sender, FileSystemEventArgs arg)
429432
{

SFTPSyncUI/SFTPSyncUI.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,18 @@ await Task.Run(async () =>
264264
}
265265
}
266266

267+
var connectTasks = new List<Task>();
268+
269+
Logger.LogInfo($"Establishing SFTP connections for {RemoteSyncWorkers.Count} workers");
270+
271+
for (int i = 0; i < RemoteSyncWorkers.Count; i++)
272+
{
273+
connectTasks.Add(RemoteSyncWorkers[i].ConnectAsync());
274+
}
275+
await Task.WhenAll(connectTasks);
276+
267277
Task runInitialSyncTask;
278+
268279
try
269280
{
270281
runInitialSyncTask = RemoteSync.RunSharedInitialSyncAsync(
@@ -284,7 +295,7 @@ await Task.Run(async () =>
284295
return;
285296
}
286297

287-
runInitialSyncTask.ContinueWith(t =>
298+
await runInitialSyncTask.ContinueWith(t =>
288299
{
289300
if (t.IsFaulted && t.Exception != null)
290301
{
@@ -301,6 +312,7 @@ await Task.Run(async () =>
301312
}, TaskScheduler.Default);
302313

303314
//Wait for all sync workers to finish initial sync then tell the user
315+
304316
try
305317
{
306318
await runInitialSyncTask;

0 commit comments

Comments
 (0)