Immidiate ui reflection for calendar events and some more error handling.

This commit is contained in:
Burak Kaan Köse
2026-04-07 16:48:46 +02:00
parent 3db54023a4
commit 71fc883e47
53 changed files with 1482 additions and 393 deletions
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
@@ -22,6 +24,13 @@ public class CalendarSynchronizationResult
public SynchronizationCompletedState CompletedState { get; set; }
public Exception Exception { get; set; }
public List<SynchronizationIssue> Issues { get; set; } = [];
[JsonIgnore]
public IEnumerable<SynchronizationIssue> AllIssues => Issues;
public static CalendarSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
// Mail synchronization
@@ -41,5 +50,48 @@ public class CalendarSynchronizationResult
};
public static CalendarSynchronizationResult Canceled => new() { CompletedState = SynchronizationCompletedState.Canceled };
public static CalendarSynchronizationResult Failed => new() { CompletedState = SynchronizationCompletedState.Failed };
public static CalendarSynchronizationResult Failed(Exception exception = null) => new()
{
CompletedState = SynchronizationCompletedState.Failed,
Exception = exception
};
public CalendarSynchronizationResult MergeIssues(IEnumerable<SynchronizationIssue> issues)
{
if (issues == null)
return this;
foreach (var issue in issues.Where(issue => issue != null))
{
if (!Issues.Any(existing => AreEquivalent(existing, issue)))
{
Issues.Add(issue);
}
}
if (CompletedState == SynchronizationCompletedState.Success && Issues.Any())
{
CompletedState = SynchronizationCompletedState.PartiallyCompleted;
}
if (Exception == null)
{
Exception = Issues.FirstOrDefault(issue => !string.IsNullOrWhiteSpace(issue?.Message)) is { } issue
? new Exception(issue.Message)
: null;
}
return this;
}
private static bool AreEquivalent(SynchronizationIssue left, SynchronizationIssue right)
=> string.Equals(left?.Message, right?.Message, StringComparison.Ordinal)
&& left?.ErrorCode == right?.ErrorCode
&& left?.Severity == right?.Severity
&& left?.Category == right?.Category
&& string.Equals(left?.OperationType, right?.OperationType, StringComparison.Ordinal)
&& string.Equals(left?.RequestType, right?.RequestType, StringComparison.Ordinal)
&& left?.FolderId == right?.FolderId
&& left?.CalendarId == right?.CalendarId
&& string.Equals(left?.ScopeName, right?.ScopeName, StringComparison.Ordinal);
}
@@ -26,6 +26,8 @@ public class MailSynchronizationResult
public Exception Exception { get; set; }
public List<SynchronizationIssue> Issues { 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.
@@ -75,6 +77,10 @@ public class MailSynchronizationResult
[JsonIgnore]
public IEnumerable<FolderSyncResult> FailedFolders => FolderResults.Where(f => !f.Success);
[JsonIgnore]
public IEnumerable<SynchronizationIssue> AllIssues
=> Issues.Concat(FailedFolders.Select(SynchronizationIssue.FromFolderResult).Where(issue => issue != null));
public static MailSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
// Mail synchronization
@@ -121,4 +127,43 @@ public class MailSynchronizationResult
CompletedState = SynchronizationCompletedState.Failed,
Exception = exception
};
public MailSynchronizationResult MergeIssues(IEnumerable<SynchronizationIssue> issues)
{
if (issues == null)
return this;
foreach (var issue in issues.Where(issue => issue != null))
{
if (!Issues.Any(existing => AreEquivalent(existing, issue)))
{
Issues.Add(issue);
}
}
if (CompletedState == SynchronizationCompletedState.Success && AllIssues.Any())
{
CompletedState = SynchronizationCompletedState.PartiallyCompleted;
}
if (Exception == null)
{
Exception = Issues.FirstOrDefault(issue => !string.IsNullOrWhiteSpace(issue?.Message)) is { } issue
? new Exception(issue.Message)
: null;
}
return this;
}
private static bool AreEquivalent(SynchronizationIssue left, SynchronizationIssue right)
=> string.Equals(left?.Message, right?.Message, StringComparison.Ordinal)
&& left?.ErrorCode == right?.ErrorCode
&& left?.Severity == right?.Severity
&& left?.Category == right?.Category
&& string.Equals(left?.OperationType, right?.OperationType, StringComparison.Ordinal)
&& string.Equals(left?.RequestType, right?.RequestType, StringComparison.Ordinal)
&& left?.FolderId == right?.FolderId
&& left?.CalendarId == right?.CalendarId
&& string.Equals(left?.ScopeName, right?.ScopeName, StringComparison.Ordinal);
}
@@ -0,0 +1,110 @@
using System;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.Domain.Models.Synchronization;
/// <summary>
/// Represents a user-visible synchronization issue collected during request execution or provider synchronization.
/// </summary>
public class SynchronizationIssue
{
public string Message { get; set; }
public int? ErrorCode { get; set; }
public SynchronizerErrorSeverity Severity { get; set; } = SynchronizerErrorSeverity.Fatal;
public SynchronizerErrorCategory Category { get; set; } = SynchronizerErrorCategory.Unknown;
public string OperationType { get; set; }
public string RequestType { get; set; }
public Guid? FolderId { get; set; }
public string FolderName { get; set; }
public Guid? CalendarId { get; set; }
public string CalendarName { get; set; }
public string ScopeName { get; set; }
public bool WasHandled { get; set; }
public string HandledBy { get; set; }
public bool CanContinueSync { get; set; }
public bool IsEntityNotFound { get; set; }
public string ExceptionType { get; set; }
public static SynchronizationIssue FromErrorContext(SynchronizerErrorContext errorContext)
{
if (errorContext == null)
return null;
return new SynchronizationIssue
{
Message = errorContext.ErrorMessage ?? errorContext.Exception?.Message,
ErrorCode = errorContext.ErrorCode,
Severity = errorContext.Severity,
Category = errorContext.Category,
OperationType = errorContext.OperationType,
RequestType = errorContext.Request?.GetType().Name,
FolderId = errorContext.FolderId,
FolderName = errorContext.FolderName,
CalendarId = errorContext.CalendarId,
CalendarName = errorContext.CalendarName,
ScopeName = GetScopeName(errorContext),
WasHandled = errorContext.WasHandled,
HandledBy = errorContext.HandledBy,
CanContinueSync = errorContext.CanContinueSync,
IsEntityNotFound = errorContext.IsEntityNotFound,
ExceptionType = errorContext.Exception?.GetType().Name
};
}
public static SynchronizationIssue FromException(
Exception exception,
string operationType = null,
SynchronizerErrorSeverity severity = SynchronizerErrorSeverity.Fatal,
SynchronizerErrorCategory category = SynchronizerErrorCategory.Unknown,
string scopeName = null)
{
if (exception == null)
return null;
return new SynchronizationIssue
{
Message = exception.Message,
Severity = severity,
Category = category,
OperationType = operationType,
ScopeName = scopeName,
CanContinueSync = severity == SynchronizerErrorSeverity.Recoverable,
ExceptionType = exception.GetType().Name
};
}
public static SynchronizationIssue FromFolderResult(FolderSyncResult folderResult)
{
if (folderResult == null || folderResult.Success)
return null;
return new SynchronizationIssue
{
Message = folderResult.ErrorMessage,
Severity = folderResult.ErrorSeverity ?? SynchronizerErrorSeverity.Fatal,
Category = folderResult.ErrorCategory ?? SynchronizerErrorCategory.Unknown,
OperationType = "FolderSync",
FolderId = folderResult.FolderId,
FolderName = folderResult.FolderName,
ScopeName = folderResult.FolderName
};
}
private static string GetScopeName(SynchronizerErrorContext errorContext)
{
if (!string.IsNullOrWhiteSpace(errorContext.CalendarName))
return errorContext.CalendarName;
if (!string.IsNullOrWhiteSpace(errorContext.FolderName))
return errorContext.FolderName;
return errorContext.Request switch
{
IFolderActionRequest folderRequest => folderRequest.Folder?.FolderName,
IMailActionRequest mailRequest => mailRequest.Item?.Subject,
ICalendarActionRequest calendarRequest => calendarRequest.Item?.Title,
_ => null
};
}
}
@@ -31,6 +31,11 @@ public class SynchronizerErrorContext
/// </summary>
public IRequestBundle RequestBundle { get; set; }
/// <summary>
/// Gets or sets the original request associated with the error when available.
/// </summary>
public IRequestBase Request { get; set; }
/// <summary>
/// Gets or sets additional data associated with the error
/// </summary>
@@ -76,6 +81,16 @@ public class SynchronizerErrorContext
/// </summary>
public string FolderName { get; set; }
/// <summary>
/// Gets or sets the calendar ID associated with the error for calendar sync issue tracking.
/// </summary>
public Guid? CalendarId { get; set; }
/// <summary>
/// Gets or sets the calendar name for display purposes.
/// </summary>
public string CalendarName { get; set; }
/// <summary>
/// Gets or sets the type of operation that failed.
/// Examples: "FolderSync", "MailSync", "RequestExecution", "Idle"
@@ -89,6 +104,16 @@ public class SynchronizerErrorContext
/// </summary>
public bool IsEntityNotFound { get; set; }
/// <summary>
/// Gets or sets whether a synchronizer error handler processed this error.
/// </summary>
public bool WasHandled { get; set; }
/// <summary>
/// Gets or sets the handler type that processed this error.
/// </summary>
public string HandledBy { get; set; }
/// <summary>
/// Gets whether this error should be retried based on severity and retry count.
/// </summary>