Full trust Wino Server implementation. (#295)
* Separation of messages. Introducing Wino.Messages library. * Wino.Server and Wino.Packaging projects. Enabling full trust for UWP and app service connection manager basics. * Remove debug code. * Enable generating assembly info to deal with unsupported os platform warnings. * Fix server-client connection. * UIMessage communication. Single instancing for server and re-connection mechanism on suspension. * Removed IWinoSynchronizerFactory from UWP project. * Removal of background task service from core. * Delegating changes to UI and triggering new background synchronization. * Fix build error. * Moved core lib messages to Messaging project. * Better client-server communication. Handling of requests in the server. New synchronizer factory in the server. * WAM broker and MSAL token caching for OutlookAuthenticator. Handling account creation for Outlook. * WinoServerResponse basics. * Delegating protocol activation for Gmail authenticator. * Adding margin to searchbox to match action bar width. * Move libraries into lib folder. * Storing base64 encoded mime on draft creation instead of MimeMessage object. Fixes serialization/deserialization issue with S.T.Json * Scrollbar adjustments * WınoExpander for thread expander layout ıssue. * Handling synchronizer state changes. * Double init on background activation. * FIxing packaging issues and new Wino Mail launcher protocol for activation from full thrust process. * Remove debug deserialization. * Remove debug code. * Making sure the server connection is established when the app is launched. * Thrust -> Trust string replacement... * Rename package to Wino Mail * Enable translated values in the server. * Fixed an issue where toast activation can't find the clicked mail after the folder is initialized. * Revert debug code. * Change server background sync to every 3 minute and Inbox only synchronization. * Revert google auth changes. * App preferences page. * Changing tray icon visibility on preference change. * Start the server with invisible tray icon if set to invisible. * Reconnect button on the title bar. * Handling of toast actions. * Enable x86 build for server during packaging. * Get rid of old background tasks and v180 migration. * Terminate client when Exit clicked in server. * Introducing SynchronizationSource to prevent notifying UI after server tick synchronization. * Remove confirmAppClose restricted capability and unused debug code in manifest. * Closing the reconnect info popup when reconnect is clicked. * Custom RetryHandler for OutlookSynchronizer and separating client/server logs. * Running server on Windows startup. * Fix startup exe. * Fix for expander list view item paddings. * Force full sync on app launch instead of Inbox. * Fix draft creation. * Fix an issue with custom folder sync logic. * Reporting back account sync progress from server. * Fix sending drafts and missing notifications for imap. * Changing imap folder sync requirements. * Retain file count is set to 3. * Disabled swipe gestures temporarily due to native crash with SwipeControl * Save all attachments implementation. * Localization for save all attachments button. * Fix logging dates for logs. * Fixing ARM64 build. * Add ARM64 build config to packaging project. * Comment out OutOfProcPDB for ARM64. * Hnadling GONE response for Outlook folder synchronization.
This commit is contained in:
34
Wino.Server/MessageHandlers/AuthenticationHandler.cs
Normal file
34
Wino.Server/MessageHandlers/AuthenticationHandler.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Domain.Entities;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
{
|
||||
public class AuthenticationHandler : ServerMessageHandler<AuthorizationRequested, TokenInformation>
|
||||
{
|
||||
private readonly IAuthenticationProvider _authenticationProvider;
|
||||
|
||||
public override WinoServerResponse<TokenInformation> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<TokenInformation>.CreateErrorResponse(ex.Message);
|
||||
|
||||
public AuthenticationHandler(IAuthenticationProvider authenticationProvider)
|
||||
{
|
||||
_authenticationProvider = authenticationProvider;
|
||||
}
|
||||
|
||||
protected override async Task<WinoServerResponse<TokenInformation>> HandleAsync(AuthorizationRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var authenticator = _authenticationProvider.GetAuthenticator(message.MailProviderType);
|
||||
|
||||
// Do not save the token here. Call is coming from account creation and things are atomic there.
|
||||
var generatedToken = await authenticator.GenerateTokenAsync(message.CreatedAccount, saveToken: false);
|
||||
|
||||
return WinoServerResponse<TokenInformation>.CreateSuccessResponse(generatedToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Wino.Server/MessageHandlers/ProtocolAuthActivationHandler.cs
Normal file
29
Wino.Server/MessageHandlers/ProtocolAuthActivationHandler.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Client.Authorization;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
{
|
||||
public class ProtocolAuthActivationHandler : ServerMessageHandler<ProtocolAuthorizationCallbackReceived, bool>
|
||||
{
|
||||
public override WinoServerResponse<bool> FailureDefaultResponse(Exception ex) => WinoServerResponse<bool>.CreateErrorResponse(ex.Message);
|
||||
|
||||
private readonly INativeAppService _nativeAppService;
|
||||
|
||||
public ProtocolAuthActivationHandler(INativeAppService nativeAppService)
|
||||
{
|
||||
_nativeAppService = nativeAppService;
|
||||
}
|
||||
|
||||
protected override Task<WinoServerResponse<bool>> HandleAsync(ProtocolAuthorizationCallbackReceived message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
_nativeAppService.ContinueAuthorization(message.AuthorizationResponseUri);
|
||||
|
||||
return Task.FromResult(WinoServerResponse<bool>.CreateSuccessResponse(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Wino.Server/MessageHandlers/ServerTerminationModeHandler.cs
Normal file
22
Wino.Server/MessageHandlers/ServerTerminationModeHandler.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
{
|
||||
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)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(message);
|
||||
|
||||
return Task.FromResult(WinoServerResponse<bool>.CreateSuccessResponse(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Wino.Server/MessageHandlers/SingleMimeDownloadHandler.cs
Normal file
31
Wino.Server/MessageHandlers/SingleMimeDownloadHandler.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
{
|
||||
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)
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return WinoServerResponse<bool>.CreateSuccessResponse(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Wino.Server/MessageHandlers/SyncExistenceHandler.cs
Normal file
30
Wino.Server/MessageHandlers/SyncExistenceHandler.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
{
|
||||
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)
|
||||
{
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Wino.Server/MessageHandlers/SynchronizationRequestHandler.cs
Normal file
96
Wino.Server/MessageHandlers/SynchronizationRequestHandler.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Messaging.Server;
|
||||
using Wino.Messaging.UI;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handler for NewSynchronizationRequested from the client.
|
||||
/// </summary>
|
||||
public class SynchronizationRequestHandler : ServerMessageHandler<NewSynchronizationRequested, SynchronizationResult>
|
||||
{
|
||||
public override WinoServerResponse<SynchronizationResult> FailureDefaultResponse(Exception ex)
|
||||
=> WinoServerResponse<SynchronizationResult>.CreateErrorResponse(ex.Message);
|
||||
|
||||
private readonly ISynchronizerFactory _synchronizerFactory;
|
||||
private readonly INotificationBuilder _notificationBuilder;
|
||||
private readonly IFolderService _folderService;
|
||||
|
||||
public SynchronizationRequestHandler(ISynchronizerFactory synchronizerFactory,
|
||||
INotificationBuilder notificationBuilder,
|
||||
IFolderService folderService)
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
_notificationBuilder = notificationBuilder;
|
||||
_folderService = folderService;
|
||||
}
|
||||
|
||||
protected override async Task<WinoServerResponse<SynchronizationResult>> HandleAsync(NewSynchronizationRequested message, CancellationToken cancellationToken = default)
|
||||
{
|
||||
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 != SynchronizationType.ExecuteRequests &&
|
||||
message.Source == SynchronizationSource.Client;
|
||||
|
||||
try
|
||||
{
|
||||
var synchronizationResult = await synchronizer.SynchronizeAsync(message.Options, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (synchronizationResult.DownloadedMessages.Any())
|
||||
{
|
||||
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;
|
||||
|
||||
if (shouldReportSynchronizationResult)
|
||||
{
|
||||
var completedMessage = new AccountSynchronizationCompleted(message.Options.AccountId,
|
||||
isSynchronizationSucceeded ? SynchronizationCompletedState.Success : SynchronizationCompletedState.Failed,
|
||||
message.Options.GroupedSynchronizationTrackingId);
|
||||
|
||||
WeakReferenceMessenger.Default.Send(completedMessage);
|
||||
}
|
||||
|
||||
return WinoServerResponse<SynchronizationResult>.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Wino.Server/MessageHandlers/UserActionRequestHandler.cs
Normal file
41
Wino.Server/MessageHandlers/UserActionRequestHandler.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Requests;
|
||||
using Wino.Core.Domain.Models.Server;
|
||||
using Wino.Server.Core;
|
||||
|
||||
namespace Wino.Server.MessageHandlers
|
||||
{
|
||||
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)
|
||||
{
|
||||
_synchronizerFactory = synchronizerFactory;
|
||||
}
|
||||
|
||||
protected override async Task<WinoServerResponse<bool>> HandleAsync(ServerRequestPackage package, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var synchronizer = await _synchronizerFactory.GetAccountSynchronizerAsync(package.AccountId);
|
||||
synchronizer.QueueRequest(package.Request);
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user