Skip to content

Commit e2f2b9f

Browse files
authored
fix(browser): status handling of multiple files/versions can cause crash (#352)
1 parent 36be93a commit e2f2b9f

File tree

5 files changed

+82
-5
lines changed

5 files changed

+82
-5
lines changed

src/BSH.Engine/Jobs/IJobReport.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using System.Collections.Generic;
1516
using System.Collections.ObjectModel;
1617
using Brightbits.BSH.Engine.Models;
1718

@@ -35,3 +36,59 @@ public interface IJobReport
3536

3637
void RequestShowErrorInsufficientDiskSpace();
3738
}
39+
40+
public class ForwardJobReport : IJobReport
41+
{
42+
private readonly IJobReport report;
43+
private List<FileExceptionEntry> files = new();
44+
45+
public ForwardJobReport(IJobReport report)
46+
{
47+
this.report = report;
48+
}
49+
50+
public void ReportAction(ActionType action, bool silent)
51+
{
52+
// not used
53+
}
54+
55+
public void ReportState(JobState jobState)
56+
{
57+
// not used
58+
}
59+
60+
public void ReportStatus(string title, string text)
61+
{
62+
this.report.ReportStatus(title, text);
63+
}
64+
65+
public void ReportProgress(int total, int current)
66+
{
67+
// not used
68+
}
69+
70+
public void ReportFileProgress(string file)
71+
{
72+
this.report.ReportFileProgress(file);
73+
}
74+
75+
public void ReportExceptions(Collection<FileExceptionEntry> files, bool silent)
76+
{
77+
this.files.AddRange(files);
78+
}
79+
80+
public RequestOverwriteResult RequestOverwrite(FileTableRow localFile, FileTableRow remoteFile)
81+
{
82+
return this.report.RequestOverwrite(localFile, remoteFile);
83+
}
84+
85+
public void RequestShowErrorInsufficientDiskSpace()
86+
{
87+
this.report.RequestShowErrorInsufficientDiskSpace();
88+
}
89+
90+
public void ForwardExceptions(bool silent)
91+
{
92+
this.report.ReportExceptions(new Collection<FileExceptionEntry>(this.files), silent);
93+
}
94+
}

src/BSH.Engine/Jobs/Job.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
using System;
1616
using System.Collections.Generic;
1717
using System.Collections.ObjectModel;
18-
using System.IO;
1918
using System.Threading.Tasks;
2019
using Brightbits.BSH.Engine.Contracts;
2120
using Brightbits.BSH.Engine.Contracts.Database;
22-
using Brightbits.BSH.Engine.Database;
2321
using Brightbits.BSH.Engine.Exceptions;
2422
using Brightbits.BSH.Engine.Models;
2523
using Brightbits.BSH.Engine.Storage;

src/BSH.Main/Dialogs/frmBrowser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,9 @@ private async void bgrWorkSearch_DoWork(object sender, System.ComponentModel.DoW
13601360
private void bgrWorkSearch_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
13611361
{
13621362
if (e.Result == null)
1363+
{
13631364
return;
1365+
}
13641366

13651367
// update UI
13661368
lvFiles.BeginUpdate();

src/BSH.Main/Modules/BackupController.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,19 @@ public async Task RestoreBackupAsync(string version, List<string> files, string
347347
// run restore job
348348
var fileOverwrite = FileOverwrite.Ask;
349349

350+
jobReportCallback.ReportAction(ActionType.Restore, !statusDialog);
351+
jobReportCallback.ReportState(JobState.RUNNING);
352+
353+
IJobReport forwardJobReport = new ForwardJobReport(jobReportCallback);
354+
350355
foreach (var file in files)
351356
{
352357
try
353358
{
354-
var task = backupService.StartRestore(version, file, destination, ref jobReportCallback, cancellationToken, fileOverwrite, !statusDialog);
359+
jobReportCallback.ReportProgress(files.Count, files.IndexOf(file) + 1);
360+
361+
// restore file
362+
var task = backupService.StartRestore(version, file, destination, ref forwardJobReport, cancellationToken, fileOverwrite, !statusDialog);
355363
await task.ConfigureAwait(true);
356364
}
357365
catch
@@ -373,6 +381,9 @@ public async Task RestoreBackupAsync(string version, List<string> files, string
373381
}
374382
}
375383

384+
((ForwardJobReport)forwardJobReport).ForwardExceptions(!statusDialog);
385+
jobReportCallback.ReportState(JobState.FINISHED);
386+
376387
// finish
377388
HandleFinishedStatusDialog(statusDialog);
378389
}
@@ -394,6 +405,7 @@ public async Task DeleteBackupAsync(string version, bool statusDialog = true)
394405
}
395406

396407
// run delete job
408+
397409
try
398410
{
399411
var task = backupService.StartDelete(version, ref jobReportCallback, cancellationToken, !statusDialog);
@@ -425,11 +437,16 @@ public async Task DeleteBackupsAsync(List<string> versions, bool statusDialog =
425437
}
426438

427439
// run delete job
440+
jobReportCallback.ReportAction(ActionType.Delete, !statusDialog);
441+
jobReportCallback.ReportState(JobState.RUNNING);
442+
443+
IJobReport forwardJobReport = new ForwardJobReport(jobReportCallback);
444+
428445
foreach (var version in versions)
429446
{
430447
try
431448
{
432-
var task = backupService.StartDelete(version, ref jobReportCallback, cancellationToken, !statusDialog);
449+
var task = backupService.StartDelete(version, ref forwardJobReport, cancellationToken, !statusDialog);
433450
await task.ConfigureAwait(true);
434451
}
435452
catch
@@ -443,6 +460,9 @@ public async Task DeleteBackupsAsync(List<string> versions, bool statusDialog =
443460
}
444461
}
445462

463+
((ForwardJobReport)forwardJobReport).ForwardExceptions(!statusDialog);
464+
jobReportCallback.ReportState(JobState.FINISHED);
465+
446466
// finish
447467
HandleFinishedStatusDialog(statusDialog);
448468
}

src/BSH.MainApp/BSH.MainApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
3434
<PackageReference Include="H.NotifyIcon.WinUI" Version="2.2.0" />
3535
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
36-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
36+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
3737
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.241114003" />
3838
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
3939
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

0 commit comments

Comments
 (0)