Per-session ImapSynchronizer protocol log based on accounts.

This commit is contained in:
Burak Kaan Köse
2024-08-25 10:32:07 +02:00
parent d0b54ea44b
commit 43a51e5f2f
2 changed files with 25 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ namespace Wino.Core.Services
private bool isInitialized = false; private bool isInitialized = false;
private readonly IAccountService _accountService; private readonly IAccountService _accountService;
private readonly IApplicationConfiguration _applicationConfiguration;
private readonly IOutlookChangeProcessor _outlookChangeProcessor; private readonly IOutlookChangeProcessor _outlookChangeProcessor;
private readonly IGmailChangeProcessor _gmailChangeProcessor; private readonly IGmailChangeProcessor _gmailChangeProcessor;
private readonly IImapChangeProcessor _imapChangeProcessor; private readonly IImapChangeProcessor _imapChangeProcessor;
@@ -26,7 +27,8 @@ namespace Wino.Core.Services
IImapChangeProcessor imapChangeProcessor, IImapChangeProcessor imapChangeProcessor,
IOutlookAuthenticator outlookAuthenticator, IOutlookAuthenticator outlookAuthenticator,
IGmailAuthenticator gmailAuthenticator, IGmailAuthenticator gmailAuthenticator,
IAccountService accountService) IAccountService accountService,
IApplicationConfiguration applicationConfiguration)
{ {
_outlookChangeProcessor = outlookChangeProcessor; _outlookChangeProcessor = outlookChangeProcessor;
_gmailChangeProcessor = gmailChangeProcessor; _gmailChangeProcessor = gmailChangeProcessor;
@@ -34,6 +36,7 @@ namespace Wino.Core.Services
_outlookAuthenticator = outlookAuthenticator; _outlookAuthenticator = outlookAuthenticator;
_gmailAuthenticator = gmailAuthenticator; _gmailAuthenticator = gmailAuthenticator;
_accountService = accountService; _accountService = accountService;
_applicationConfiguration = applicationConfiguration;
} }
public async Task<IBaseSynchronizer> GetAccountSynchronizerAsync(Guid accountId) public async Task<IBaseSynchronizer> GetAccountSynchronizerAsync(Guid accountId)
@@ -67,7 +70,7 @@ namespace Wino.Core.Services
case Domain.Enums.MailProviderType.Gmail: case Domain.Enums.MailProviderType.Gmail:
return new GmailSynchronizer(mailAccount, _gmailAuthenticator, _gmailChangeProcessor); return new GmailSynchronizer(mailAccount, _gmailAuthenticator, _gmailChangeProcessor);
case Domain.Enums.MailProviderType.IMAP4: case Domain.Enums.MailProviderType.IMAP4:
return new ImapSynchronizer(mailAccount, _imapChangeProcessor); return new ImapSynchronizer(mailAccount, _imapChangeProcessor, _applicationConfiguration);
default: default:
break; break;
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -36,6 +37,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 IImapChangeProcessor _imapChangeProcessor; private readonly IImapChangeProcessor _imapChangeProcessor;
private readonly IApplicationConfiguration _applicationConfiguration;
// 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 =
@@ -63,14 +65,30 @@ namespace Wino.Core.Synchronizers
public override uint BatchModificationSize => 1000; public override uint BatchModificationSize => 1000;
public override uint InitialMessageDownloadCountPerFolder => 250; public override uint InitialMessageDownloadCountPerFolder => 250;
public ImapSynchronizer(MailAccount account, IImapChangeProcessor imapChangeProcessor) : base(account) public ImapSynchronizer(MailAccount account,
IImapChangeProcessor imapChangeProcessor,
IApplicationConfiguration applicationConfiguration) : base(account)
{ {
_clientPool = new ImapClientPool(Account.ServerInformation); // Create client pool with account protocol log.
_imapChangeProcessor = imapChangeProcessor; _imapChangeProcessor = imapChangeProcessor;
_applicationConfiguration = applicationConfiguration;
_clientPool = new ImapClientPool(Account.ServerInformation, CreateAccountProtocolLogFileStream());
idleDoneToken = new CancellationTokenSource(); idleDoneToken = new CancellationTokenSource();
} }
private Stream CreateAccountProtocolLogFileStream()
{
if (Account == null) throw new ArgumentNullException(nameof(Account));
var logFile = Path.Combine(_applicationConfiguration.ApplicationDataFolderPath, $"Protocol_{Account.Address}.log");
// Each session should start a new log.
if (File.Exists(logFile)) File.Delete(logFile);
return new FileStream(logFile, FileMode.CreateNew);
}
// TODO // TODO
// private async void NoOpTimerTriggered(object state) => await AwaitInboxIdleAsync(); // private async void NoOpTimerTriggered(object state) => await AwaitInboxIdleAsync();
@@ -265,7 +283,6 @@ namespace Wino.Core.Synchronizers
{ {
return CreateTaskBundle(async (ImapClient client) => return CreateTaskBundle(async (ImapClient client) =>
{ {
var remoteDraftFolder = await client.GetFolderAsync(request.DraftPreperationRequest.CreatedLocalDraftCopy.AssignedFolder.RemoteFolderId).ConfigureAwait(false); var remoteDraftFolder = await client.GetFolderAsync(request.DraftPreperationRequest.CreatedLocalDraftCopy.AssignedFolder.RemoteFolderId).ConfigureAwait(false);
await remoteDraftFolder.OpenAsync(FolderAccess.ReadWrite).ConfigureAwait(false); await remoteDraftFolder.OpenAsync(FolderAccess.ReadWrite).ConfigureAwait(false);