File scoped namespaces
This commit is contained in:
@@ -7,50 +7,49 @@ using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class AuthenticationHandler : ServerMessageHandler<AuthorizationRequested, TokenInformationEx>
|
||||
{
|
||||
public class AuthenticationHandler : ServerMessageHandler<AuthorizationRequested, TokenInformationEx>
|
||||
private readonly IAuthenticationProvider _authenticationProvider;
|
||||
|
||||
public override WinoServerResponse<TokenInformationEx> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<TokenInformationEx>.CreateErrorResponse(ex.Message);
|
||||
|
||||
public AuthenticationHandler(IAuthenticationProvider authenticationProvider)
|
||||
{
|
||||
private readonly IAuthenticationProvider _authenticationProvider;
|
||||
_authenticationProvider = authenticationProvider;
|
||||
}
|
||||
|
||||
public override WinoServerResponse<TokenInformationEx> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<TokenInformationEx>.CreateErrorResponse(ex.Message);
|
||||
protected override async Task<WinoServerResponse<TokenInformationEx>> HandleAsync(AuthorizationRequested message,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var authenticator = _authenticationProvider.GetAuthenticator(message.MailProviderType);
|
||||
|
||||
public AuthenticationHandler(IAuthenticationProvider authenticationProvider)
|
||||
// Some users are having issues with Gmail authentication.
|
||||
// Their browsers may never launch to complete authentication.
|
||||
// Offer to copy auth url for them to complete it manually.
|
||||
// Redirection will occur to the app and the token will be saved.
|
||||
|
||||
if (message.ProposeCopyAuthorizationURL && authenticator is IGmailAuthenticator gmailAuthenticator)
|
||||
{
|
||||
_authenticationProvider = authenticationProvider;
|
||||
gmailAuthenticator.ProposeCopyAuthURL = true;
|
||||
}
|
||||
|
||||
protected override async Task<WinoServerResponse<TokenInformationEx>> HandleAsync(AuthorizationRequested message,
|
||||
CancellationToken cancellationToken = default)
|
||||
TokenInformationEx generatedToken = null;
|
||||
|
||||
if (message.CreatedAccount != null)
|
||||
{
|
||||
var authenticator = _authenticationProvider.GetAuthenticator(message.MailProviderType);
|
||||
|
||||
// Some users are having issues with Gmail authentication.
|
||||
// Their browsers may never launch to complete authentication.
|
||||
// Offer to copy auth url for them to complete it manually.
|
||||
// Redirection will occur to the app and the token will be saved.
|
||||
|
||||
if (message.ProposeCopyAuthorizationURL && authenticator is IGmailAuthenticator gmailAuthenticator)
|
||||
{
|
||||
gmailAuthenticator.ProposeCopyAuthURL = true;
|
||||
}
|
||||
|
||||
TokenInformationEx generatedToken = null;
|
||||
|
||||
if (message.CreatedAccount != null)
|
||||
{
|
||||
generatedToken = await authenticator.GetTokenInformationAsync(message.CreatedAccount);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Initial authentication request.
|
||||
// There is no account to get token for.
|
||||
|
||||
generatedToken = await authenticator.GenerateTokenInformationAsync(message.CreatedAccount);
|
||||
}
|
||||
|
||||
return WinoServerResponse<TokenInformationEx>.CreateSuccessResponse(generatedToken);
|
||||
generatedToken = await authenticator.GetTokenInformationAsync(message.CreatedAccount);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Initial authentication request.
|
||||
// There is no account to get token for.
|
||||
|
||||
generatedToken = await authenticator.GenerateTokenInformationAsync(message.CreatedAccount);
|
||||
}
|
||||
|
||||
return WinoServerResponse<TokenInformationEx>.CreateSuccessResponse(generatedToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,34 +7,33 @@ using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class CalendarSynchronizationRequestHandler : ServerMessageHandler<NewCalendarSynchronizationRequested, CalendarSynchronizationResult>
|
||||
{
|
||||
public class CalendarSynchronizationRequestHandler : ServerMessageHandler<NewCalendarSynchronizationRequested, CalendarSynchronizationResult>
|
||||
public override WinoServerResponse<CalendarSynchronizationResult> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<CalendarSynchronizationResult>.CreateErrorResponse(ex.Message);
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
|
||||
public CalendarSynchronizationRequestHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
public override WinoServerResponse<CalendarSynchronizationResult> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<CalendarSynchronizationResult>.CreateErrorResponse(ex.Message);
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
protected override async Task<WinoServerResponse<CalendarSynchronizationResult>> HandleAsync(NewCalendarSynchronizationRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(message.Options.AccountId);
|
||||
|
||||
public CalendarSynchronizationRequestHandler(ISynchronizerFactory synchronizerFactory)
|
||||
try
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
var synchronizationResult = await synchronizer.SynchronizeCalendarEventsAsync(message.Options, cancellationToken);
|
||||
|
||||
return WinoServerResponse<CalendarSynchronizationResult>.CreateSuccessResponse(synchronizationResult);
|
||||
}
|
||||
|
||||
protected override async Task<WinoServerResponse<CalendarSynchronizationResult>> HandleAsync(NewCalendarSynchronizationRequested message, CancellationToken cancellationToken = default)
|
||||
catch (Exception ex)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(message.Options.AccountId);
|
||||
|
||||
try
|
||||
{
|
||||
var synchronizationResult = await synchronizer.SynchronizeCalendarEventsAsync(message.Options, cancellationToken);
|
||||
|
||||
return WinoServerResponse<CalendarSynchronizationResult>.CreateSuccessResponse(synchronizationResult);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,43 +8,42 @@ using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class ImapConnectivityTestHandler : ServerMessageHandler<ImapConnectivityTestRequested, ImapConnectivityTestResults>
|
||||
{
|
||||
public class ImapConnectivityTestHandler : ServerMessageHandler<ImapConnectivityTestRequested, ImapConnectivityTestResults>
|
||||
private readonly IImapTestService _imapTestService;
|
||||
|
||||
public override WinoServerResponse<ImapConnectivityTestResults> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<ImapConnectivityTestResults>.CreateErrorResponse(ex.Message);
|
||||
|
||||
public ImapConnectivityTestHandler(IImapTestService imapTestService)
|
||||
{
|
||||
private readonly IImapTestService _imapTestService;
|
||||
_imapTestService = imapTestService;
|
||||
}
|
||||
|
||||
public override WinoServerResponse<ImapConnectivityTestResults> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<ImapConnectivityTestResults>.CreateErrorResponse(ex.Message);
|
||||
|
||||
public ImapConnectivityTestHandler(IImapTestService imapTestService)
|
||||
protected override async Task<WinoServerResponse<ImapConnectivityTestResults>> HandleAsync(ImapConnectivityTestRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
_imapTestService = imapTestService;
|
||||
await _imapTestService.TestImapConnectionAsync(message.ServerInformation, message.IsSSLHandshakeAllowed);
|
||||
|
||||
return WinoServerResponse<ImapConnectivityTestResults>.CreateSuccessResponse(ImapConnectivityTestResults.Success());
|
||||
}
|
||||
|
||||
protected override async Task<WinoServerResponse<ImapConnectivityTestResults>> HandleAsync(ImapConnectivityTestRequested message, CancellationToken cancellationToken = default)
|
||||
catch (ImapTestSSLCertificateException sslTestException)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _imapTestService.TestImapConnectionAsync(message.ServerInformation, message.IsSSLHandshakeAllowed);
|
||||
|
||||
return WinoServerResponse<ImapConnectivityTestResults>.CreateSuccessResponse(ImapConnectivityTestResults.Success());
|
||||
}
|
||||
catch (ImapTestSSLCertificateException sslTestException)
|
||||
{
|
||||
// User must confirm to continue ignoring the SSL certificate.
|
||||
return WinoServerResponse<ImapConnectivityTestResults>.CreateSuccessResponse(ImapConnectivityTestResults.CertificateUIRequired(sslTestException.Issuer, sslTestException.ExpirationDateString, sslTestException.ValidFromDateString));
|
||||
}
|
||||
catch (ImapClientPoolException clientPoolException)
|
||||
{
|
||||
// Connectivity failed with protocol log.
|
||||
return WinoServerResponse<ImapConnectivityTestResults>.CreateSuccessResponse(ImapConnectivityTestResults.Failure(clientPoolException, clientPoolException.ProtocolLog));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Unknown error
|
||||
return WinoServerResponse<ImapConnectivityTestResults>.CreateSuccessResponse(ImapConnectivityTestResults.Failure(exception, string.Empty));
|
||||
}
|
||||
// User must confirm to continue ignoring the SSL certificate.
|
||||
return WinoServerResponse<ImapConnectivityTestResults>.CreateSuccessResponse(ImapConnectivityTestResults.CertificateUIRequired(sslTestException.Issuer, sslTestException.ExpirationDateString, sslTestException.ValidFromDateString));
|
||||
}
|
||||
catch (ImapClientPoolException clientPoolException)
|
||||
{
|
||||
// Connectivity failed with protocol log.
|
||||
return WinoServerResponse<ImapConnectivityTestResults>.CreateSuccessResponse(ImapConnectivityTestResults.Failure(clientPoolException, clientPoolException.ProtocolLog));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Unknown error
|
||||
return WinoServerResponse<ImapConnectivityTestResults>.CreateSuccessResponse(ImapConnectivityTestResults.Failure(exception, string.Empty));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,25 +6,24 @@ using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class KillAccountSynchronizerHandler : ServerMessageHandler<KillAccountSynchronizerRequested, bool>
|
||||
{
|
||||
public class KillAccountSynchronizerHandler : ServerMessageHandler<KillAccountSynchronizerRequested, bool>
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
|
||||
public KillAccountSynchronizerHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(KillAccountSynchronizerRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _synchronizerFactory.DeleteSynchronizerAsync(message.AccountId);
|
||||
|
||||
public KillAccountSynchronizerHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(KillAccountSynchronizerRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _synchronizerFactory.DeleteSynchronizerAsync(message.AccountId);
|
||||
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(true);
|
||||
}
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,99 +11,98 @@ using Wino.Messaging.Server;
|
||||
using Wino.Messaging.UI;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for NewMailSynchronizationRequested from the client.
|
||||
/// </summary>
|
||||
public class MailSynchronizationRequestHandler : ServerMessageHandler<NewMailSynchronizationRequested, MailSynchronizationResult>
|
||||
{
|
||||
/// <summary>
|
||||
/// Handler for NewMailSynchronizationRequested from the client.
|
||||
/// </summary>
|
||||
public class MailSynchronizationRequestHandler : ServerMessageHandler<NewMailSynchronizationRequested, MailSynchronizationResult>
|
||||
public override WinoServerResponse<MailSynchronizationResult> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<MailSynchronizationResult>.CreateErrorResponse(ex.Message);
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
private readonly INotificationBuilder _notificationBuilder;
|
||||
private readonly IFolderService _folderService;
|
||||
|
||||
public MailSynchronizationRequestHandler(ISynchronizerFactory synchronizerFactory,
|
||||
INotificationBuilder notificationBuilder,
|
||||
IFolderService folderService)
|
||||
{
|
||||
public override WinoServerResponse<MailSynchronizationResult> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<MailSynchronizationResult>.CreateErrorResponse(ex.Message);
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
_notificationBuilder = notificationBuilder;
|
||||
_folderService = folderService;
|
||||
}
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
private readonly INotificationBuilder _notificationBuilder;
|
||||
private readonly IFolderService _folderService;
|
||||
protected override async Task<WinoServerResponse<MailSynchronizationResult>> HandleAsync(NewMailSynchronizationRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(message.Options.AccountId);
|
||||
|
||||
public MailSynchronizationRequestHandler(ISynchronizerFactory synchronizerFactory,
|
||||
INotificationBuilder notificationBuilder,
|
||||
IFolderService folderService)
|
||||
// 1. Don't send message for sync completion when we execute requests.
|
||||
// People are usually interested in seeing the notification after they trigger the synchronization.
|
||||
|
||||
// 2. Don't send message for sync completion when we are synchronizing from the server.
|
||||
// It happens very common and there is no need to send a message for each synchronization.
|
||||
|
||||
bool shouldReportSynchronizationResult =
|
||||
message.Options.Type != MailSynchronizationType.ExecuteRequests &&
|
||||
message.Options.Type != MailSynchronizationType.IMAPIdle &&
|
||||
message.Source == SynchronizationSource.Client;
|
||||
|
||||
try
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
_notificationBuilder = notificationBuilder;
|
||||
_folderService = folderService;
|
||||
var synchronizationResult = await synchronizer.SynchronizeMailsAsync(message.Options, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (synchronizationResult.DownloadedMessages?.Any() ?? false || !synchronizer.Account.Preferences.IsNotificationsEnabled)
|
||||
{
|
||||
var accountInboxFolder = await _folderService.GetSpecialFolderByAccountIdAsync(message.Options.AccountId, SpecialFolderType.Inbox);
|
||||
|
||||
if (accountInboxFolder != null)
|
||||
{
|
||||
await _notificationBuilder.CreateNotificationsAsync(accountInboxFolder.Id, synchronizationResult.DownloadedMessages);
|
||||
}
|
||||
}
|
||||
|
||||
var isSynchronizationSucceeded = synchronizationResult.CompletedState == SynchronizationCompletedState.Success;
|
||||
|
||||
// IDLE requests might be canceled successfully.
|
||||
if (message.Options.Type == MailSynchronizationType.IMAPIdle && synchronizationResult.CompletedState == SynchronizationCompletedState.Canceled)
|
||||
{
|
||||
isSynchronizationSucceeded = true;
|
||||
}
|
||||
|
||||
// Update badge count of the notification task.
|
||||
if (isSynchronizationSucceeded)
|
||||
{
|
||||
await _notificationBuilder.UpdateTaskbarIconBadgeAsync();
|
||||
}
|
||||
|
||||
if (shouldReportSynchronizationResult)
|
||||
{
|
||||
var completedMessage = new AccountSynchronizationCompleted(message.Options.AccountId,
|
||||
isSynchronizationSucceeded ? SynchronizationCompletedState.Success : SynchronizationCompletedState.Failed,
|
||||
message.Options.GroupedSynchronizationTrackingId);
|
||||
|
||||
WeakReferenceMessenger.Default.Send(completedMessage);
|
||||
}
|
||||
|
||||
return WinoServerResponse<MailSynchronizationResult>.CreateSuccessResponse(synchronizationResult);
|
||||
}
|
||||
// TODO: Following cases might always be thrown from server. Handle them properly.
|
||||
|
||||
protected override async Task<WinoServerResponse<MailSynchronizationResult>> HandleAsync(NewMailSynchronizationRequested message, CancellationToken cancellationToken = default)
|
||||
//catch (AuthenticationAttentionException)
|
||||
//{
|
||||
// // TODO
|
||||
// // await SetAccountAttentionAsync(accountId, AccountAttentionReason.InvalidCredentials);
|
||||
//}
|
||||
//catch (SystemFolderConfigurationMissingException)
|
||||
//{
|
||||
// // TODO
|
||||
// // await SetAccountAttentionAsync(accountId, AccountAttentionReason.MissingSystemFolderConfiguration);
|
||||
//}
|
||||
catch (Exception)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(message.Options.AccountId);
|
||||
|
||||
// 1. Don't send message for sync completion when we execute requests.
|
||||
// People are usually interested in seeing the notification after they trigger the synchronization.
|
||||
|
||||
// 2. Don't send message for sync completion when we are synchronizing from the server.
|
||||
// It happens very common and there is no need to send a message for each synchronization.
|
||||
|
||||
bool shouldReportSynchronizationResult =
|
||||
message.Options.Type != MailSynchronizationType.ExecuteRequests &&
|
||||
message.Options.Type != MailSynchronizationType.IMAPIdle &&
|
||||
message.Source == SynchronizationSource.Client;
|
||||
|
||||
try
|
||||
{
|
||||
var synchronizationResult = await synchronizer.SynchronizeMailsAsync(message.Options, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (synchronizationResult.DownloadedMessages?.Any() ?? false || !synchronizer.Account.Preferences.IsNotificationsEnabled)
|
||||
{
|
||||
var accountInboxFolder = await _folderService.GetSpecialFolderByAccountIdAsync(message.Options.AccountId, SpecialFolderType.Inbox);
|
||||
|
||||
if (accountInboxFolder != null)
|
||||
{
|
||||
await _notificationBuilder.CreateNotificationsAsync(accountInboxFolder.Id, synchronizationResult.DownloadedMessages);
|
||||
}
|
||||
}
|
||||
|
||||
var isSynchronizationSucceeded = synchronizationResult.CompletedState == SynchronizationCompletedState.Success;
|
||||
|
||||
// IDLE requests might be canceled successfully.
|
||||
if (message.Options.Type == MailSynchronizationType.IMAPIdle && synchronizationResult.CompletedState == SynchronizationCompletedState.Canceled)
|
||||
{
|
||||
isSynchronizationSucceeded = true;
|
||||
}
|
||||
|
||||
// Update badge count of the notification task.
|
||||
if (isSynchronizationSucceeded)
|
||||
{
|
||||
await _notificationBuilder.UpdateTaskbarIconBadgeAsync();
|
||||
}
|
||||
|
||||
if (shouldReportSynchronizationResult)
|
||||
{
|
||||
var completedMessage = new AccountSynchronizationCompleted(message.Options.AccountId,
|
||||
isSynchronizationSucceeded ? SynchronizationCompletedState.Success : SynchronizationCompletedState.Failed,
|
||||
message.Options.GroupedSynchronizationTrackingId);
|
||||
|
||||
WeakReferenceMessenger.Default.Send(completedMessage);
|
||||
}
|
||||
|
||||
return WinoServerResponse<MailSynchronizationResult>.CreateSuccessResponse(synchronizationResult);
|
||||
}
|
||||
// TODO: Following cases might always be thrown from server. Handle them properly.
|
||||
|
||||
//catch (AuthenticationAttentionException)
|
||||
//{
|
||||
// // TODO
|
||||
// // await SetAccountAttentionAsync(accountId, AccountAttentionReason.InvalidCredentials);
|
||||
//}
|
||||
//catch (SystemFolderConfigurationMissingException)
|
||||
//{
|
||||
// // TODO
|
||||
// // await SetAccountAttentionAsync(accountId, AccountAttentionReason.MissingSystemFolderConfiguration);
|
||||
//}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,16 @@ using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class ServerTerminationModeHandler : ServerMessageHandler<ServerTerminationModeChanged, bool>
|
||||
{
|
||||
public class ServerTerminationModeHandler : ServerMessageHandler<ServerTerminationModeChanged, bool>
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
|
||||
protected override Task<WinoServerResponse<bool>> HandleAsync(ServerTerminationModeChanged message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
WeakReferenceMessenger.Default.Send(message);
|
||||
|
||||
protected override Task<WinoServerResponse<bool>> HandleAsync(ServerTerminationModeChanged message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(message);
|
||||
|
||||
return Task.FromResult(WinoServerResponse<bool>.CreateSuccessResponse(true));
|
||||
}
|
||||
return Task.FromResult(WinoServerResponse<bool>.CreateSuccessResponse(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,26 +6,25 @@ using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class SingleMimeDownloadHandler : ServerMessageHandler<DownloadMissingMessageRequested, bool>
|
||||
{
|
||||
public class SingleMimeDownloadHandler : ServerMessageHandler<DownloadMissingMessageRequested, bool>
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
public SingleMimeDownloadHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
public SingleMimeDownloadHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(DownloadMissingMessageRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(message.AccountId);
|
||||
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(DownloadMissingMessageRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(message.AccountId);
|
||||
// TODO: ITransferProgress support is lost.
|
||||
await synchronizer.DownloadMissingMimeMessageAsync(message.MailItem, null, cancellationToken);
|
||||
|
||||
// TODO: ITransferProgress support is lost.
|
||||
await synchronizer.DownloadMissingMimeMessageAsync(message.MailItem, null, cancellationToken);
|
||||
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(true);
|
||||
}
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,25 +6,24 @@ using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class SyncExistenceHandler : ServerMessageHandler<SynchronizationExistenceCheckRequest, bool>
|
||||
{
|
||||
public class SyncExistenceHandler : ServerMessageHandler<SynchronizationExistenceCheckRequest, bool>
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
|
||||
public SyncExistenceHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(SynchronizationExistenceCheckRequest message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(message.AccountId);
|
||||
|
||||
public SyncExistenceHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(SynchronizationExistenceCheckRequest message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(message.AccountId);
|
||||
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(synchronizer.State != Wino.Core.Domain.Enums.AccountSynchronizerState.Idle);
|
||||
}
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(synchronizer.State != Wino.Core.Domain.Enums.AccountSynchronizerState.Idle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,20 @@ using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class TerminateServerRequestHandler : ServerMessageHandler<TerminateServerRequested, bool>
|
||||
{
|
||||
public class TerminateServerRequestHandler : ServerMessageHandler<TerminateServerRequested, bool>
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
|
||||
protected override Task<WinoServerResponse<bool>> HandleAsync(TerminateServerRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
// This handler is only doing the logging right now.
|
||||
// Client will always expect success response.
|
||||
// Server will be terminated in the server context once the client gets the response.
|
||||
|
||||
protected override Task<WinoServerResponse<bool>> HandleAsync(TerminateServerRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// This handler is only doing the logging right now.
|
||||
// Client will always expect success response.
|
||||
// Server will be terminated in the server context once the client gets the response.
|
||||
Log.Information("Terminate server is requested by client. Killing server.");
|
||||
|
||||
Log.Information("Terminate server is requested by client. Killing server.");
|
||||
|
||||
return Task.FromResult(WinoServerResponse<bool>.CreateSuccessResponse(true));
|
||||
}
|
||||
return Task.FromResult(WinoServerResponse<bool>.CreateSuccessResponse(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,36 +6,35 @@ using Wino.Core.Domain.Models.Requests;
|
||||
using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
namespace Wino.Server.MessageHandlers;
|
||||
|
||||
public class UserActionRequestHandler : ServerMessageHandler<ServerRequestPackage, bool>
|
||||
{
|
||||
public class UserActionRequestHandler : ServerMessageHandler<ServerRequestPackage, bool>
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
|
||||
public UserActionRequestHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(ServerRequestPackage package, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(package.AccountId);
|
||||
synchronizer.QueueRequest(package.Request);
|
||||
|
||||
public UserActionRequestHandler(ISynchronizerFactory synchronizerFactory)
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
//if (package.QueueSynchronization)
|
||||
//{
|
||||
// var options = new SynchronizationOptions
|
||||
// {
|
||||
// AccountId = package.AccountId,
|
||||
// Type = Wino.Core.Domain.Enums.SynchronizationType.ExecuteRequests
|
||||
// };
|
||||
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(ServerRequestPackage package, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(package.AccountId);
|
||||
synchronizer.QueueRequest(package.Request);
|
||||
// WeakReferenceMessenger.Default.Send(new NewSynchronizationRequested(options));
|
||||
//}
|
||||
|
||||
//if (package.QueueSynchronization)
|
||||
//{
|
||||
// var options = new SynchronizationOptions
|
||||
// {
|
||||
// AccountId = package.AccountId,
|
||||
// Type = Wino.Core.Domain.Enums.SynchronizationType.ExecuteRequests
|
||||
// };
|
||||
|
||||
// WeakReferenceMessenger.Default.Send(new NewSynchronizationRequested(options));
|
||||
//}
|
||||
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(true);
|
||||
}
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user