More abstraction for mail/calendar.

This commit is contained in:
Burak Kaan Köse
2024-12-24 18:30:25 +01:00
parent da2a58a88b
commit 1668dfcce6
28 changed files with 209 additions and 121 deletions

View File

@@ -0,0 +1,9 @@
namespace Wino.Core.Domain.Enums
{
public enum CalendarSynchronizationType
{
AllCalendars, // Sync all calendars.
SingleCalendar, // Sync only one calendar.
UpdateProfile // Update profile information only.
}
}

View File

@@ -1,17 +1,14 @@
namespace Wino.Core.Domain.Enums
{
public enum SynchronizationType
public enum MailSynchronizationType
{
// Shared
UpdateProfile, // Only update profile information
ExecuteRequests, // Run the queued requests, and then synchronize if needed.
// Wino Mail
FoldersOnly, // Only synchronize folder metadata.
InboxOnly, // Only Inbox, Sent and Draft folders.
CustomFolders, // Only sync folders that are specified in the options.
FullFolders, // Synchronize all folders. This won't update profile or alias information.
Alias, // Only update alias information
// Calendar
Events
}
}

View File

@@ -1,7 +0,0 @@
namespace Wino.Core.Domain.Interfaces
{
public interface IBaseCalendarSynchronizer : IBaseSynchronizer
{
}
}

View File

@@ -26,7 +26,7 @@ namespace Wino.Core.Domain.Interfaces
Task ChangeFolderSynchronizationStateAsync(Guid folderId, bool isSynchronizationEnabled);
Task ChangeFolderShowUnreadCountStateAsync(Guid folderId, bool showUnreadCount);
Task<List<MailItemFolder>> GetSynchronizationFoldersAsync(SynchronizationOptions options);
Task<List<MailItemFolder>> GetSynchronizationFoldersAsync(MailSynchronizationOptions options);
/// <summary>
/// Returns the folder - mail mapping for the given mail copy ids.

View File

@@ -5,7 +5,7 @@ namespace Wino.Core.Domain.Interfaces
{
public interface ISynchronizerFactory
{
Task<IBaseMailSynchronizer> GetAccountSynchronizerAsync(Guid accountId);
Task<IWinoSynchronizerBase> GetAccountSynchronizerAsync(Guid accountId);
Task InitializeAsync();
}
}

View File

@@ -6,7 +6,7 @@ using Wino.Core.Domain.Models.Synchronization;
namespace Wino.Core.Domain.Interfaces
{
public interface IBaseMailSynchronizer : IBaseSynchronizer
public interface IWinoSynchronizerBase : IBaseSynchronizer
{
/// <summary>
/// Performs a full synchronization with the server with given options.
@@ -17,7 +17,7 @@ namespace Wino.Core.Domain.Interfaces
/// <param name="options">Options for synchronization.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Result summary of synchronization.</returns>
Task<SynchronizationResult> SynchronizeAsync(SynchronizationOptions options, CancellationToken cancellationToken = default);
Task<MailSynchronizationResult> SynchronizeMailsAsync(MailSynchronizationOptions options, CancellationToken cancellationToken = default);
/// <summary>
/// Downloads a single MIME message from the server and saves it to disk.

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.Synchronization
{
public class CalendarSynchronizationOptions
{
/// <summary>
/// Unique id of synchronization.
/// </summary>
public Guid Id { get; } = Guid.NewGuid();
/// <summary>
/// Account to execute synchronization for.
/// </summary>
public Guid AccountId { get; set; }
/// <summary>
/// Type of the synchronization to be performed.
/// </summary>
public CalendarSynchronizationType Type { get; set; }
/// <summary>
/// Calendar ids to synchronize.
/// </summary>
public List<Guid> SynchronizationCalendarIds { get; set; }
public override string ToString() => $"Type: {Type}, Calendars: {(SynchronizationCalendarIds == null ? "All" : string.Join(",", SynchronizationCalendarIds))}";
}
}

View File

@@ -0,0 +1,46 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Accounts;
namespace Wino.Core.Domain.Models.Synchronization
{
public class CalendarSynchronizationResult
{
public CalendarSynchronizationResult() { }
/// <summary>
/// Gets the new downloaded events from synchronization.
/// Server will create notifications for these event.
/// It's ignored in serialization. Client should not react to this.
/// </summary>
[JsonIgnore]
public IEnumerable<ICalendarItem> DownloadedEvents { get; set; } = [];
public ProfileInformation ProfileInformation { get; set; }
public SynchronizationCompletedState CompletedState { get; set; }
public static CalendarSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
// Mail synchronization
public static CalendarSynchronizationResult Completed(IEnumerable<ICalendarItem> downloadedEvent)
=> new()
{
DownloadedEvents = downloadedEvent,
CompletedState = SynchronizationCompletedState.Success
};
// Profile synchronization
public static CalendarSynchronizationResult Completed(ProfileInformation profileInformation)
=> new()
{
ProfileInformation = profileInformation,
CompletedState = SynchronizationCompletedState.Success
};
public static CalendarSynchronizationResult Canceled => new() { CompletedState = SynchronizationCompletedState.Canceled };
public static CalendarSynchronizationResult Failed => new() { CompletedState = SynchronizationCompletedState.Failed };
}
}

View File

@@ -4,7 +4,7 @@ using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.Synchronization
{
public class SynchronizationOptions
public class MailSynchronizationOptions
{
/// <summary>
/// Unique id of synchronization.
@@ -19,7 +19,7 @@ namespace Wino.Core.Domain.Models.Synchronization
/// <summary>
/// Type of the synchronization to be performed.
/// </summary>
public SynchronizationType Type { get; set; }
public MailSynchronizationType Type { get; set; }
/// <summary>
/// Collection of FolderId to perform SynchronizationType.Custom type sync.
@@ -33,6 +33,6 @@ namespace Wino.Core.Domain.Models.Synchronization
/// </summary>
public Guid? GroupedSynchronizationTrackingId { get; set; }
public override string ToString() => $"Type: {Type}, Folders: {(SynchronizationFolderIds == null ? "None" : string.Join(",", SynchronizationFolderIds))}";
public override string ToString() => $"Type: {Type}, Folders: {(SynchronizationFolderIds == null ? "All" : string.Join(",", SynchronizationFolderIds))}";
}
}

View File

@@ -1,15 +1,14 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Accounts;
using Wino.Core.Domain.Models.MailItem;
namespace Wino.Core.Domain.Models.Synchronization
{
public class SynchronizationResult
public class MailSynchronizationResult
{
public SynchronizationResult() { }
public MailSynchronizationResult() { }
/// <summary>
/// Gets the new downloaded messages from synchronization.
@@ -19,22 +18,14 @@ namespace Wino.Core.Domain.Models.Synchronization
[JsonIgnore]
public IEnumerable<IMailItem> DownloadedMessages { get; set; } = [];
/// <summary>
/// Gets the new downloaded events from synchronization.
/// Server will create notifications for these events.
/// It's ignored in serialization. Client should not react to this.
/// </summary>
[JsonIgnore]
public IEnumerable<ICalendarItem> DownloadedEvents { get; set; } = [];
public ProfileInformation ProfileInformation { get; set; }
public SynchronizationCompletedState CompletedState { get; set; }
public static SynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
public static MailSynchronizationResult Empty => new() { CompletedState = SynchronizationCompletedState.Success };
// Mail synchronization
public static SynchronizationResult Completed(IEnumerable<IMailItem> downloadedMessages)
public static MailSynchronizationResult Completed(IEnumerable<IMailItem> downloadedMessages)
=> new()
{
DownloadedMessages = downloadedMessages,
@@ -42,14 +33,14 @@ namespace Wino.Core.Domain.Models.Synchronization
};
// Profile synchronization
public static SynchronizationResult Completed(ProfileInformation profileInformation)
public static MailSynchronizationResult Completed(ProfileInformation profileInformation)
=> new()
{
ProfileInformation = profileInformation,
CompletedState = SynchronizationCompletedState.Success
};
public static SynchronizationResult Canceled => new() { CompletedState = SynchronizationCompletedState.Canceled };
public static SynchronizationResult Failed => new() { CompletedState = SynchronizationCompletedState.Failed };
public static MailSynchronizationResult Canceled => new() { CompletedState = SynchronizationCompletedState.Canceled };
public static MailSynchronizationResult Failed => new() { CompletedState = SynchronizationCompletedState.Failed };
}
}