Refactored all synchronizers to deal with some of the chronic issues.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Enums;
|
||||
@@ -25,6 +26,55 @@ public class MailSynchronizationResult
|
||||
|
||||
public Exception Exception { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the results for each folder that was synchronized.
|
||||
/// Enables partial failure tracking - some folders may succeed while others fail.
|
||||
/// </summary>
|
||||
public List<FolderSyncResult> FolderResults { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the synchronization had any partial failures.
|
||||
/// True if at least one folder failed but others succeeded.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool HasPartialFailures => FolderResults.Any(f => !f.Success) && FolderResults.Any(f => f.Success);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of folders that were successfully synchronized.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int SuccessfulFolderCount => FolderResults.Count(f => f.Success);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of folders that failed to synchronize.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int FailedFolderCount => FolderResults.Count(f => !f.Success);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of messages downloaded across all folders.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int TotalDownloadedCount => FolderResults.Sum(f => f.DownloadedCount);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of messages deleted across all folders.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int TotalDeletedCount => FolderResults.Sum(f => f.DeletedCount);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of messages updated across all folders.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int TotalUpdatedCount => FolderResults.Sum(f => f.UpdatedCount);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the folders that failed to sync for error reporting.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public IEnumerable<FolderSyncResult> FailedFolders => FolderResults.Where(f => !f.Success);
|
||||
|
||||
public static MailSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
|
||||
|
||||
// Mail synchronization
|
||||
@@ -43,6 +93,28 @@ public class MailSynchronizationResult
|
||||
CompletedState = SynchronizationCompletedState.Success
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Creates a completed result with folder-level results.
|
||||
/// </summary>
|
||||
public static MailSynchronizationResult CompletedWithFolderResults(
|
||||
IEnumerable<MailCopy> downloadedMessages,
|
||||
List<FolderSyncResult> folderResults)
|
||||
{
|
||||
var hasAnyFailure = folderResults.Any(f => !f.Success);
|
||||
var hasAnySuccess = folderResults.Any(f => f.Success);
|
||||
|
||||
return new()
|
||||
{
|
||||
DownloadedMessages = downloadedMessages,
|
||||
FolderResults = folderResults,
|
||||
CompletedState = hasAnyFailure && !hasAnySuccess
|
||||
? SynchronizationCompletedState.Failed
|
||||
: hasAnyFailure
|
||||
? SynchronizationCompletedState.PartiallyCompleted
|
||||
: SynchronizationCompletedState.Success
|
||||
};
|
||||
}
|
||||
|
||||
public static MailSynchronizationResult Canceled => new() { CompletedState = SynchronizationCompletedState.Canceled };
|
||||
public static MailSynchronizationResult Failed(Exception exception) => new()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user