Separation of change processors.
This commit is contained in:
@@ -49,15 +49,6 @@ namespace Wino.Core.Domain.Interfaces
|
|||||||
/// <param name="allFolders">Folders to update.</param>
|
/// <param name="allFolders">Folders to update.</param>
|
||||||
Task BulkUpdateFolderStructureAsync(Guid accountId, List<MailItemFolder> allFolders);
|
Task BulkUpdateFolderStructureAsync(Guid accountId, List<MailItemFolder> allFolders);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates Folder's delta synchronization identifier.
|
|
||||||
/// Only used in Outlook since it does per-folder sync.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="folderId">Folder id</param>
|
|
||||||
/// <param name="synchronizationIdentifier">New synchronization identifier.</param>
|
|
||||||
/// <returns>New identifier if success.</returns>
|
|
||||||
Task<string> UpdateFolderDeltaSynchronizationIdentifierAsync(Guid folderId, string synchronizationIdentifier);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes the folder for the given account by remote folder id.
|
/// Deletes the folder for the given account by remote folder id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -87,6 +78,12 @@ namespace Wino.Core.Domain.Interfaces
|
|||||||
/// <returns>True if Inbox exists, False if not.</returns>
|
/// <returns>True if Inbox exists, False if not.</returns>
|
||||||
Task<bool> IsInboxAvailableForAccountAsync(Guid accountId);
|
Task<bool> IsInboxAvailableForAccountAsync(Guid accountId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates folder's LastSynchronizedDate to now.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderId">Folder to update.</param>
|
||||||
|
Task UpdateFolderLastSyncDateAsync(Guid folderId);
|
||||||
|
|
||||||
Task TestAsync();
|
Task TestAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ namespace Wino.Core.Domain.Interfaces
|
|||||||
/// <param name="newMailCopyId"></param>
|
/// <param name="newMailCopyId"></param>
|
||||||
/// <param name="newDraftId"></param>
|
/// <param name="newDraftId"></param>
|
||||||
/// <param name="newThreadId"></param>
|
/// <param name="newThreadId"></param>
|
||||||
/// <returns></returns>
|
|
||||||
Task MapLocalDraftAsync(string newMailCopyId, string newDraftId, string newThreadId);
|
Task MapLocalDraftAsync(string newMailCopyId, string newDraftId, string newThreadId);
|
||||||
|
|
||||||
Task<MimeMessage> CreateDraftMimeMessageAsync(Guid accountId, DraftCreationOptions options);
|
Task<MimeMessage> CreateDraftMimeMessageAsync(Guid accountId, DraftCreationOptions options);
|
||||||
|
|||||||
@@ -22,8 +22,10 @@ namespace Wino.Core
|
|||||||
services.AddSingleton<IThreadingStrategyProvider, ThreadingStrategyProvider>();
|
services.AddSingleton<IThreadingStrategyProvider, ThreadingStrategyProvider>();
|
||||||
services.AddSingleton<IMimeFileService, MimeFileService>();
|
services.AddSingleton<IMimeFileService, MimeFileService>();
|
||||||
|
|
||||||
services.AddTransient<IDefaultChangeProcessor, DefaultChangeProcessor>();
|
services.AddTransient<IGmailChangeProcessor, GmailChangeProcessor>();
|
||||||
|
services.AddTransient<IImapChangeProcessor, ImapChangeProcessor>();
|
||||||
services.AddTransient<IOutlookChangeProcessor, OutlookChangeProcessor>();
|
services.AddTransient<IOutlookChangeProcessor, OutlookChangeProcessor>();
|
||||||
|
|
||||||
services.AddTransient<ITokenService, TokenService>();
|
services.AddTransient<ITokenService, TokenService>();
|
||||||
services.AddTransient<IProviderService, ProviderService>();
|
services.AddTransient<IProviderService, ProviderService>();
|
||||||
services.AddTransient<IFolderService, FolderService>();
|
services.AddTransient<IFolderService, FolderService>();
|
||||||
|
|||||||
@@ -14,43 +14,31 @@ namespace Wino.Core.Integration.Processors
|
|||||||
/// Database change processor that handles common operations for all synchronizers.
|
/// Database change processor that handles common operations for all synchronizers.
|
||||||
/// When a synchronizer detects a change, it should call the appropriate method in this class to reflect the change in the database.
|
/// When a synchronizer detects a change, it should call the appropriate method in this class to reflect the change in the database.
|
||||||
/// Different synchronizers might need additional implementations.
|
/// Different synchronizers might need additional implementations.
|
||||||
/// <see cref="IGmailChangeProcessor"/> and <see cref="IOutlookChangeProcessor"/>
|
/// <see cref="IGmailChangeProcessor"/>, <see cref="IOutlookChangeProcessor"/> and <see cref="IImapChangeProcessor"/>
|
||||||
/// None of the synchronizers can directly change anything in the database.
|
/// None of the synchronizers can directly change anything in the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDefaultChangeProcessor
|
public interface IDefaultChangeProcessor
|
||||||
{
|
{
|
||||||
Task<string> UpdateAccountDeltaSynchronizationIdentifierAsync(Guid accountId, string deltaSynchronizationIdentifier);
|
Task<string> UpdateAccountDeltaSynchronizationIdentifierAsync(Guid accountId, string deltaSynchronizationIdentifier);
|
||||||
Task<string> UpdateFolderDeltaSynchronizationIdentifierAsync(Guid folderId, string deltaSynchronizationIdentifier);
|
|
||||||
|
|
||||||
Task CreateAssignmentAsync(Guid accountId, string mailCopyId, string remoteFolderId);
|
Task CreateAssignmentAsync(Guid accountId, string mailCopyId, string remoteFolderId);
|
||||||
Task DeleteAssignmentAsync(Guid accountId, string mailCopyId, string remoteFolderId);
|
Task DeleteAssignmentAsync(Guid accountId, string mailCopyId, string remoteFolderId);
|
||||||
|
|
||||||
Task ChangeMailReadStatusAsync(string mailCopyId, bool isRead);
|
Task ChangeMailReadStatusAsync(string mailCopyId, bool isRead);
|
||||||
Task ChangeFlagStatusAsync(string mailCopyId, bool isFlagged);
|
Task ChangeFlagStatusAsync(string mailCopyId, bool isFlagged);
|
||||||
|
|
||||||
Task<bool> CreateMailAsync(Guid AccountId, NewMailItemPackage package);
|
Task<bool> CreateMailAsync(Guid AccountId, NewMailItemPackage package);
|
||||||
Task DeleteMailAsync(Guid accountId, string mailId);
|
Task DeleteMailAsync(Guid accountId, string mailId);
|
||||||
|
|
||||||
Task<bool> MapLocalDraftAsync(Guid accountId, Guid localDraftCopyUniqueId, string newMailCopyId, string newDraftId, string newThreadId);
|
|
||||||
Task MapLocalDraftAsync(string mailCopyId, string newDraftId, string newThreadId);
|
|
||||||
|
|
||||||
Task<List<MailCopy>> GetDownloadedUnreadMailsAsync(Guid accountId, IEnumerable<string> downloadedMailCopyIds);
|
Task<List<MailCopy>> GetDownloadedUnreadMailsAsync(Guid accountId, IEnumerable<string> downloadedMailCopyIds);
|
||||||
|
|
||||||
Task SaveMimeFileAsync(Guid fileId, MimeMessage mimeMessage, Guid accountId);
|
Task SaveMimeFileAsync(Guid fileId, MimeMessage mimeMessage, Guid accountId);
|
||||||
|
|
||||||
// For gmail.
|
|
||||||
Task UpdateFolderStructureAsync(Guid accountId, List<MailItemFolder> allFolders);
|
Task UpdateFolderStructureAsync(Guid accountId, List<MailItemFolder> allFolders);
|
||||||
|
|
||||||
Task DeleteFolderAsync(Guid accountId, string remoteFolderId);
|
Task DeleteFolderAsync(Guid accountId, string remoteFolderId);
|
||||||
Task<List<MailItemFolder>> GetSynchronizationFoldersAsync(SynchronizationOptions options);
|
Task<List<MailItemFolder>> GetSynchronizationFoldersAsync(SynchronizationOptions options);
|
||||||
Task InsertFolderAsync(MailItemFolder folder);
|
Task InsertFolderAsync(MailItemFolder folder);
|
||||||
|
Task<bool> MapLocalDraftAsync(Guid accountId, Guid localDraftCopyUniqueId, string newMailCopyId, string newDraftId, string newThreadId);
|
||||||
Task<IList<uint>> GetKnownUidsForFolderAsync(Guid folderId);
|
Task UpdateFolderLastSyncDateAsync(Guid folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IGmailChangeProcessor : IDefaultChangeProcessor
|
public interface IGmailChangeProcessor : IDefaultChangeProcessor
|
||||||
{
|
{
|
||||||
|
Task MapLocalDraftAsync(string mailCopyId, string newDraftId, string newThreadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IOutlookChangeProcessor : IDefaultChangeProcessor
|
public interface IOutlookChangeProcessor : IDefaultChangeProcessor
|
||||||
@@ -62,6 +50,24 @@ namespace Wino.Core.Integration.Processors
|
|||||||
/// <param name="messageId">MailCopyId of the message.</param>
|
/// <param name="messageId">MailCopyId of the message.</param>
|
||||||
/// <returns>Whether the mime has b</returns>
|
/// <returns>Whether the mime has b</returns>
|
||||||
Task<bool> IsMailExistsAsync(string messageId);
|
Task<bool> IsMailExistsAsync(string messageId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates Folder's delta synchronization identifier.
|
||||||
|
/// Only used in Outlook since it does per-folder sync.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderId">Folder id</param>
|
||||||
|
/// <param name="synchronizationIdentifier">New synchronization identifier.</param>
|
||||||
|
/// <returns>New identifier if success.</returns>
|
||||||
|
Task UpdateFolderDeltaSynchronizationIdentifierAsync(Guid folderId, string deltaSynchronizationIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IImapChangeProcessor : IDefaultChangeProcessor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all known uids for the given folder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderId">Folder id to retrieve uIds for.</param>
|
||||||
|
Task<IList<uint>> GetKnownUidsForFolderAsync(Guid folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DefaultChangeProcessor(IDatabaseService databaseService,
|
public class DefaultChangeProcessor(IDatabaseService databaseService,
|
||||||
@@ -72,7 +78,7 @@ namespace Wino.Core.Integration.Processors
|
|||||||
{
|
{
|
||||||
protected IMailService MailService = mailService;
|
protected IMailService MailService = mailService;
|
||||||
|
|
||||||
private readonly IFolderService _folderService = folderService;
|
protected IFolderService FolderService = folderService;
|
||||||
private readonly IAccountService _accountService = accountService;
|
private readonly IAccountService _accountService = accountService;
|
||||||
private readonly IMimeFileService _mimeFileService = mimeFileService;
|
private readonly IMimeFileService _mimeFileService = mimeFileService;
|
||||||
|
|
||||||
@@ -99,33 +105,31 @@ namespace Wino.Core.Integration.Processors
|
|||||||
|
|
||||||
// Folder methods
|
// Folder methods
|
||||||
public Task UpdateFolderStructureAsync(Guid accountId, List<MailItemFolder> allFolders)
|
public Task UpdateFolderStructureAsync(Guid accountId, List<MailItemFolder> allFolders)
|
||||||
=> _folderService.BulkUpdateFolderStructureAsync(accountId, allFolders);
|
=> FolderService.BulkUpdateFolderStructureAsync(accountId, allFolders);
|
||||||
|
|
||||||
public Task<bool> MapLocalDraftAsync(Guid accountId, Guid localDraftCopyUniqueId, string newMailCopyId, string newDraftId, string newThreadId)
|
public Task<bool> MapLocalDraftAsync(Guid accountId, Guid localDraftCopyUniqueId, string newMailCopyId, string newDraftId, string newThreadId)
|
||||||
=> MailService.MapLocalDraftAsync(accountId, localDraftCopyUniqueId, newMailCopyId, newDraftId, newThreadId);
|
=> MailService.MapLocalDraftAsync(accountId, localDraftCopyUniqueId, newMailCopyId, newDraftId, newThreadId);
|
||||||
|
|
||||||
public Task MapLocalDraftAsync(string mailCopyId, string newDraftId, string newThreadId)
|
|
||||||
=> MailService.MapLocalDraftAsync(mailCopyId, newDraftId, newThreadId);
|
|
||||||
|
|
||||||
public Task<List<MailItemFolder>> GetSynchronizationFoldersAsync(SynchronizationOptions options)
|
public Task<List<MailItemFolder>> GetSynchronizationFoldersAsync(SynchronizationOptions options)
|
||||||
=> _folderService.GetSynchronizationFoldersAsync(options);
|
=> FolderService.GetSynchronizationFoldersAsync(options);
|
||||||
|
|
||||||
public Task<string> UpdateFolderDeltaSynchronizationIdentifierAsync(Guid folderId, string deltaSynchronizationIdentifier)
|
|
||||||
=> _folderService.UpdateFolderDeltaSynchronizationIdentifierAsync(folderId, deltaSynchronizationIdentifier);
|
|
||||||
|
|
||||||
public Task DeleteFolderAsync(Guid accountId, string remoteFolderId)
|
public Task DeleteFolderAsync(Guid accountId, string remoteFolderId)
|
||||||
=> _folderService.DeleteFolderAsync(accountId, remoteFolderId);
|
=> FolderService.DeleteFolderAsync(accountId, remoteFolderId);
|
||||||
|
|
||||||
public Task InsertFolderAsync(MailItemFolder folder)
|
public Task InsertFolderAsync(MailItemFolder folder)
|
||||||
=> _folderService.InsertFolderAsync(folder);
|
=> FolderService.InsertFolderAsync(folder);
|
||||||
|
|
||||||
public Task<List<MailCopy>> GetDownloadedUnreadMailsAsync(Guid accountId, IEnumerable<string> downloadedMailCopyIds)
|
public Task<List<MailCopy>> GetDownloadedUnreadMailsAsync(Guid accountId, IEnumerable<string> downloadedMailCopyIds)
|
||||||
=> MailService.GetDownloadedUnreadMailsAsync(accountId, downloadedMailCopyIds);
|
=> MailService.GetDownloadedUnreadMailsAsync(accountId, downloadedMailCopyIds);
|
||||||
|
|
||||||
public Task<IList<uint>> GetKnownUidsForFolderAsync(Guid folderId)
|
|
||||||
=> _folderService.GetKnownUidsForFolderAsync(folderId);
|
|
||||||
|
|
||||||
public Task SaveMimeFileAsync(Guid fileId, MimeMessage mimeMessage, Guid accountId)
|
public Task SaveMimeFileAsync(Guid fileId, MimeMessage mimeMessage, Guid accountId)
|
||||||
=> _mimeFileService.SaveMimeMessageAsync(fileId, mimeMessage, accountId);
|
=> _mimeFileService.SaveMimeMessageAsync(fileId, mimeMessage, accountId);
|
||||||
|
|
||||||
|
public Task UpdateFolderLastSyncDateAsync(Guid folderId)
|
||||||
|
=> FolderService.UpdateFolderLastSyncDateAsync(folderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
Wino.Core/Integration/Processors/GmailChangeProcessor.cs
Normal file
16
Wino.Core/Integration/Processors/GmailChangeProcessor.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Wino.Core.Domain.Interfaces;
|
||||||
|
using Wino.Core.Services;
|
||||||
|
|
||||||
|
namespace Wino.Core.Integration.Processors
|
||||||
|
{
|
||||||
|
public class GmailChangeProcessor : DefaultChangeProcessor, IGmailChangeProcessor
|
||||||
|
{
|
||||||
|
public GmailChangeProcessor(IDatabaseService databaseService, IFolderService folderService, IMailService mailService, IAccountService accountService, IMimeFileService mimeFileService) : base(databaseService, folderService, mailService, accountService, mimeFileService)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task MapLocalDraftAsync(string mailCopyId, string newDraftId, string newThreadId)
|
||||||
|
=> MailService.MapLocalDraftAsync(mailCopyId, newDraftId, newThreadId);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
Wino.Core/Integration/Processors/ImapChangeProcessor.cs
Normal file
22
Wino.Core/Integration/Processors/ImapChangeProcessor.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Wino.Core.Domain.Interfaces;
|
||||||
|
using Wino.Core.Services;
|
||||||
|
|
||||||
|
namespace Wino.Core.Integration.Processors
|
||||||
|
{
|
||||||
|
public class ImapChangeProcessor : DefaultChangeProcessor, IImapChangeProcessor
|
||||||
|
{
|
||||||
|
public ImapChangeProcessor(IDatabaseService databaseService,
|
||||||
|
IFolderService folderService,
|
||||||
|
IMailService mailService,
|
||||||
|
IAccountService accountService,
|
||||||
|
IMimeFileService mimeFileService) : base(databaseService, folderService, mailService, accountService, mimeFileService)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IList<uint>> GetKnownUidsForFolderAsync(Guid folderId)
|
||||||
|
=> FolderService.GetKnownUidsForFolderAsync(folderId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Threading.Tasks;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Wino.Core.Domain.Interfaces;
|
using Wino.Core.Domain.Interfaces;
|
||||||
using Wino.Core.Services;
|
using Wino.Core.Services;
|
||||||
|
|
||||||
@@ -12,5 +13,8 @@ namespace Wino.Core.Integration.Processors
|
|||||||
{
|
{
|
||||||
public Task<bool> IsMailExistsAsync(string messageId)
|
public Task<bool> IsMailExistsAsync(string messageId)
|
||||||
=> MailService.IsMailExistsAsync(messageId);
|
=> MailService.IsMailExistsAsync(messageId);
|
||||||
|
|
||||||
|
public Task UpdateFolderDeltaSynchronizationIdentifierAsync(Guid folderId, string synchronizationIdentifier)
|
||||||
|
=> Connection.ExecuteAsync("UPDATE MailItemFolder SET DeltaToken = ? WHERE Id = ?", synchronizationIdentifier, folderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -513,23 +513,7 @@ namespace Wino.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> UpdateFolderDeltaSynchronizationIdentifierAsync(Guid folderId, string synchronizationIdentifier)
|
|
||||||
{
|
|
||||||
var folder = await GetFolderAsync(folderId).ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (folder == null)
|
|
||||||
{
|
|
||||||
_logger.Warning("Folder with id {FolderId} does not exist.", folderId);
|
|
||||||
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
folder.DeltaToken = synchronizationIdentifier;
|
|
||||||
|
|
||||||
await UpdateFolderAsync(folder).ConfigureAwait(false);
|
|
||||||
|
|
||||||
return synchronizationIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task DeleteFolderAsync(Guid accountId, string remoteFolderId)
|
public async Task DeleteFolderAsync(Guid accountId, string remoteFolderId)
|
||||||
{
|
{
|
||||||
@@ -588,5 +572,8 @@ namespace Wino.Core.Services
|
|||||||
=> (await Connection.Table<MailItemFolder>()
|
=> (await Connection.Table<MailItemFolder>()
|
||||||
.Where(a => a.SpecialFolderType == SpecialFolderType.Inbox && a.MailAccountId == accountId)
|
.Where(a => a.SpecialFolderType == SpecialFolderType.Inbox && a.MailAccountId == accountId)
|
||||||
.CountAsync()) == 1;
|
.CountAsync()) == 1;
|
||||||
|
|
||||||
|
public Task UpdateFolderLastSyncDateAsync(Guid folderId)
|
||||||
|
=> Connection.ExecuteAsync("UPDATE MailItemFolder SET LastSynchronizedDate = ? WHERE Id = ?", DateTime.UtcNow, folderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ namespace Wino.Core.Synchronizers
|
|||||||
private readonly ConfigurableHttpClient _gmailHttpClient;
|
private readonly ConfigurableHttpClient _gmailHttpClient;
|
||||||
private readonly GmailService _gmailService;
|
private readonly GmailService _gmailService;
|
||||||
private readonly IAuthenticator _authenticator;
|
private readonly IAuthenticator _authenticator;
|
||||||
private readonly IDefaultChangeProcessor _gmailChangeProcessor;
|
private readonly IGmailChangeProcessor _gmailChangeProcessor;
|
||||||
private readonly ILogger _logger = Log.ForContext<GmailSynchronizer>();
|
private readonly ILogger _logger = Log.ForContext<GmailSynchronizer>();
|
||||||
|
|
||||||
public GmailSynchronizer(MailAccount account,
|
public GmailSynchronizer(MailAccount account,
|
||||||
IAuthenticator authenticator,
|
IAuthenticator authenticator,
|
||||||
IDefaultChangeProcessor gmailChangeProcessor) : base(account)
|
IGmailChangeProcessor gmailChangeProcessor) : base(account)
|
||||||
{
|
{
|
||||||
var messageHandler = new GmailClientMessageHandler(() => _authenticator.GetTokenAsync(Account));
|
var messageHandler = new GmailClientMessageHandler(() => _authenticator.GetTokenAsync(Account));
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace Wino.Core.Synchronizers
|
|||||||
|
|
||||||
private readonly ILogger _logger = Log.ForContext<ImapSynchronizer>();
|
private readonly ILogger _logger = Log.ForContext<ImapSynchronizer>();
|
||||||
private readonly ImapClientPool _clientPool;
|
private readonly ImapClientPool _clientPool;
|
||||||
private readonly IDefaultChangeProcessor _imapChangeProcessor;
|
private readonly IImapChangeProcessor _imapChangeProcessor;
|
||||||
|
|
||||||
// Minimum summary items to Fetch for mail synchronization from IMAP.
|
// Minimum summary items to Fetch for mail synchronization from IMAP.
|
||||||
private readonly MessageSummaryItems mailSynchronizationFlags =
|
private readonly MessageSummaryItems mailSynchronizationFlags =
|
||||||
@@ -61,7 +61,7 @@ namespace Wino.Core.Synchronizers
|
|||||||
public override uint BatchModificationSize => 1000;
|
public override uint BatchModificationSize => 1000;
|
||||||
public override uint InitialMessageDownloadCountPerFolder => 500;
|
public override uint InitialMessageDownloadCountPerFolder => 500;
|
||||||
|
|
||||||
public ImapSynchronizer(MailAccount account, IDefaultChangeProcessor imapChangeProcessor) : base(account)
|
public ImapSynchronizer(MailAccount account, IImapChangeProcessor imapChangeProcessor) : base(account)
|
||||||
{
|
{
|
||||||
_clientPool = new ImapClientPool(Account.ServerInformation);
|
_clientPool = new ImapClientPool(Account.ServerInformation);
|
||||||
|
|
||||||
@@ -830,10 +830,9 @@ namespace Wino.Core.Synchronizers
|
|||||||
await _imapChangeProcessor.InsertFolderAsync(folder);
|
await _imapChangeProcessor.InsertFolderAsync(folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update last synchronization identifier.
|
// Update last synchronization date for the folder..
|
||||||
// This will update last sync date for the folder.
|
|
||||||
|
|
||||||
await _imapChangeProcessor.UpdateFolderDeltaSynchronizationIdentifierAsync(folder.Id, string.Empty).ConfigureAwait(false);
|
await _imapChangeProcessor.UpdateFolderLastSyncDateAsync(folder.Id).ConfigureAwait(false);
|
||||||
|
|
||||||
return downloadedMessageIds;
|
return downloadedMessageIds;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ namespace Wino.Core.Synchronizers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
options.ProgressListener?.AccountProgressUpdated(Account.Id, 1);
|
options.ProgressListener?.AccountProgressUpdated(Account.Id, 1);
|
||||||
|
|
||||||
await SynchronizeFoldersAsync(cancellationToken).ConfigureAwait(false);
|
await SynchronizeFoldersAsync(cancellationToken).ConfigureAwait(false);
|
||||||
@@ -102,6 +101,9 @@ namespace Wino.Core.Synchronizers
|
|||||||
{
|
{
|
||||||
var synchronizationFolders = await _outlookChangeProcessor.GetSynchronizationFoldersAsync(options).ConfigureAwait(false);
|
var synchronizationFolders = await _outlookChangeProcessor.GetSynchronizationFoldersAsync(options).ConfigureAwait(false);
|
||||||
|
|
||||||
|
_logger.Information("Found {Count} folders to synchronize.", synchronizationFolders.Count);
|
||||||
|
_logger.Information(string.Format("Folders: {0}", string.Join(",", synchronizationFolders.Select(a => a.FolderName))));
|
||||||
|
|
||||||
for (int i = 0; i < synchronizationFolders.Count; i++)
|
for (int i = 0; i < synchronizationFolders.Count; i++)
|
||||||
{
|
{
|
||||||
var folder = synchronizationFolders[i];
|
var folder = synchronizationFolders[i];
|
||||||
@@ -149,6 +151,8 @@ namespace Wino.Core.Synchronizers
|
|||||||
|
|
||||||
if (isInitialSync)
|
if (isInitialSync)
|
||||||
{
|
{
|
||||||
|
_logger.Debug("No sync identifier for Folder {FolderName}. Performing initial sync.", folder.FolderName);
|
||||||
|
|
||||||
// No delta link. Performing initial sync.
|
// No delta link. Performing initial sync.
|
||||||
|
|
||||||
messageCollectionPage = await _graphClient.Me.MailFolders[folder.RemoteFolderId].Messages.Delta.GetAsDeltaGetResponseAsync((config) =>
|
messageCollectionPage = await _graphClient.Me.MailFolders[folder.RemoteFolderId].Messages.Delta.GetAsDeltaGetResponseAsync((config) =>
|
||||||
@@ -162,6 +166,9 @@ namespace Wino.Core.Synchronizers
|
|||||||
{
|
{
|
||||||
var currentDeltaToken = folder.DeltaToken;
|
var currentDeltaToken = folder.DeltaToken;
|
||||||
|
|
||||||
|
_logger.Debug("Sync identifier found for Folder {FolderName}. Performing delta sync.", folder.FolderName);
|
||||||
|
_logger.Debug("Current delta token: {CurrentDeltaToken}", currentDeltaToken);
|
||||||
|
|
||||||
var requestInformation = _graphClient.Me.MailFolders[folder.RemoteFolderId].Messages.Delta.ToGetRequestInformation((config) =>
|
var requestInformation = _graphClient.Me.MailFolders[folder.RemoteFolderId].Messages.Delta.ToGetRequestInformation((config) =>
|
||||||
{
|
{
|
||||||
config.QueryParameters.Top = (int)InitialMessageDownloadCountPerFolder;
|
config.QueryParameters.Top = (int)InitialMessageDownloadCountPerFolder;
|
||||||
@@ -186,6 +193,14 @@ namespace Wino.Core.Synchronizers
|
|||||||
|
|
||||||
latestDeltaLink = messageIteratorAsync.Deltalink;
|
latestDeltaLink = messageIteratorAsync.Deltalink;
|
||||||
|
|
||||||
|
if (downloadedMessageIds.Any())
|
||||||
|
{
|
||||||
|
_logger.Debug("Downloaded {Count} messages for folder {FolderName}", downloadedMessageIds.Count, folder.FolderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Iterator completed for folder {FolderName}", folder.FolderName);
|
||||||
|
_logger.Debug("Extracted latest delta link is {LatestDeltaLink}", latestDeltaLink);
|
||||||
|
|
||||||
//Store delta link for tracking new changes.
|
//Store delta link for tracking new changes.
|
||||||
if (!string.IsNullOrEmpty(latestDeltaLink))
|
if (!string.IsNullOrEmpty(latestDeltaLink))
|
||||||
{
|
{
|
||||||
@@ -196,6 +211,8 @@ namespace Wino.Core.Synchronizers
|
|||||||
await _outlookChangeProcessor.UpdateFolderDeltaSynchronizationIdentifierAsync(folder.Id, deltaToken).ConfigureAwait(false);
|
await _outlookChangeProcessor.UpdateFolderDeltaSynchronizationIdentifierAsync(folder.Id, deltaToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _outlookChangeProcessor.UpdateFolderLastSyncDateAsync(folder.Id).ConfigureAwait(false);
|
||||||
|
|
||||||
return downloadedMessageIds;
|
return downloadedMessageIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ namespace Wino.Core
|
|||||||
private readonly ISignatureService _signatureService;
|
private readonly ISignatureService _signatureService;
|
||||||
private readonly IDatabaseService _databaseService;
|
private readonly IDatabaseService _databaseService;
|
||||||
private readonly IMimeFileService _mimeFileService;
|
private readonly IMimeFileService _mimeFileService;
|
||||||
private readonly IDefaultChangeProcessor _defaultChangeProcessor;
|
|
||||||
private readonly IOutlookChangeProcessor _outlookChangeProcessor;
|
private readonly IOutlookChangeProcessor _outlookChangeProcessor;
|
||||||
|
private readonly IGmailChangeProcessor _gmailChangeProcessor;
|
||||||
|
private readonly IImapChangeProcessor _imapChangeProcessor;
|
||||||
|
|
||||||
public WinoSynchronizerFactory(INativeAppService nativeAppService,
|
public WinoSynchronizerFactory(INativeAppService nativeAppService,
|
||||||
ITokenService tokenService,
|
ITokenService tokenService,
|
||||||
@@ -49,8 +50,9 @@ namespace Wino.Core
|
|||||||
ISignatureService signatureService,
|
ISignatureService signatureService,
|
||||||
IDatabaseService databaseService,
|
IDatabaseService databaseService,
|
||||||
IMimeFileService mimeFileService,
|
IMimeFileService mimeFileService,
|
||||||
IDefaultChangeProcessor defaultChangeProcessor,
|
IOutlookChangeProcessor outlookChangeProcessor,
|
||||||
IOutlookChangeProcessor outlookChangeProcessor)
|
IGmailChangeProcessor gmailChangeProcessor,
|
||||||
|
IImapChangeProcessor imapChangeProcessor)
|
||||||
{
|
{
|
||||||
_contactService = contactService;
|
_contactService = contactService;
|
||||||
_notificationBuilder = notificationBuilder;
|
_notificationBuilder = notificationBuilder;
|
||||||
@@ -61,8 +63,9 @@ namespace Wino.Core
|
|||||||
_signatureService = signatureService;
|
_signatureService = signatureService;
|
||||||
_databaseService = databaseService;
|
_databaseService = databaseService;
|
||||||
_mimeFileService = mimeFileService;
|
_mimeFileService = mimeFileService;
|
||||||
_defaultChangeProcessor = defaultChangeProcessor;
|
|
||||||
_outlookChangeProcessor = outlookChangeProcessor;
|
_outlookChangeProcessor = outlookChangeProcessor;
|
||||||
|
_gmailChangeProcessor = gmailChangeProcessor;
|
||||||
|
_imapChangeProcessor = imapChangeProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBaseSynchronizer GetAccountSynchronizer(Guid accountId)
|
public IBaseSynchronizer GetAccountSynchronizer(Guid accountId)
|
||||||
@@ -80,13 +83,13 @@ namespace Wino.Core
|
|||||||
case Domain.Enums.MailProviderType.Gmail:
|
case Domain.Enums.MailProviderType.Gmail:
|
||||||
var gmailAuthenticator = new GmailAuthenticator(_tokenService, _nativeAppService);
|
var gmailAuthenticator = new GmailAuthenticator(_tokenService, _nativeAppService);
|
||||||
|
|
||||||
return new GmailSynchronizer(mailAccount, gmailAuthenticator, _defaultChangeProcessor);
|
return new GmailSynchronizer(mailAccount, gmailAuthenticator, _gmailChangeProcessor);
|
||||||
case Domain.Enums.MailProviderType.Office365:
|
case Domain.Enums.MailProviderType.Office365:
|
||||||
break;
|
break;
|
||||||
case Domain.Enums.MailProviderType.Yahoo:
|
case Domain.Enums.MailProviderType.Yahoo:
|
||||||
break;
|
break;
|
||||||
case Domain.Enums.MailProviderType.IMAP4:
|
case Domain.Enums.MailProviderType.IMAP4:
|
||||||
return new ImapSynchronizer(mailAccount, _defaultChangeProcessor);
|
return new ImapSynchronizer(mailAccount, _imapChangeProcessor);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user