Canceling authentication and Outlook improvements (#367)
* Cancellation support for getting responses from the server. * Adding cancel button for account creation dialog initialization. * Prevent invalid outlook message types like contact, calendar event or todo item. * Remove debug launcher options.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Nito.AsyncEx;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Foundation.Metadata;
|
||||
using Windows.Security.Authentication.Web;
|
||||
@@ -9,10 +11,10 @@ using Windows.Storage;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.System;
|
||||
using Windows.UI.Shell;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Exceptions;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Authorization;
|
||||
using Wino.Core.Domain.Exceptions;
|
||||
using Wino.Core.Domain;
|
||||
|
||||
|
||||
|
||||
@@ -126,7 +128,7 @@ namespace Wino.Services
|
||||
await Launcher.LaunchFileAsync(file);
|
||||
}
|
||||
|
||||
public Task LaunchUriAsync(Uri uri) => Launcher.LaunchUriAsync(uri).AsTask();
|
||||
public Task<bool> LaunchUriAsync(Uri uri) => Launcher.LaunchUriAsync(uri).AsTask();
|
||||
|
||||
public string GetFullAppVersion()
|
||||
{
|
||||
@@ -154,7 +156,7 @@ namespace Wino.Services
|
||||
await taskbarManager.RequestPinCurrentAppAsync();
|
||||
}
|
||||
|
||||
public async Task<Uri> GetAuthorizationResponseUriAsync(IAuthenticator authenticator, string authorizationUri)
|
||||
public async Task<Uri> GetAuthorizationResponseUriAsync(IAuthenticator authenticator, string authorizationUri, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (authorizationCompletedTaskSource != null)
|
||||
{
|
||||
@@ -164,9 +166,12 @@ namespace Wino.Services
|
||||
|
||||
authorizationCompletedTaskSource = new TaskCompletionSource<Uri>();
|
||||
|
||||
await LaunchUriAsync(new Uri(authorizationUri));
|
||||
bool isLaunched = await Launcher.LaunchUriAsync(new Uri(authorizationUri)).AsTask(cancellationToken);
|
||||
|
||||
return await authorizationCompletedTaskSource.Task;
|
||||
if (!isLaunched)
|
||||
throw new WinoServerException("Failed to launch Google Authentication dialog.");
|
||||
|
||||
return await authorizationCompletedTaskSource.Task.WaitAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public void ContinueAuthorization(Uri authorizationResponseUri)
|
||||
|
||||
@@ -275,10 +275,12 @@ namespace Wino.Core.UWP.Services
|
||||
queueResponse.ThrowIfFailed();
|
||||
}
|
||||
|
||||
public Task<WinoServerResponse<TResponse>> GetResponseAsync<TResponse, TRequestType>(TRequestType message) where TRequestType : IClientMessage
|
||||
=> GetResponseInternalAsync<TResponse, TRequestType>(message);
|
||||
public Task<WinoServerResponse<TResponse>> GetResponseAsync<TResponse, TRequestType>(TRequestType message, CancellationToken cancellationToken = default) where TRequestType : IClientMessage
|
||||
=> GetResponseInternalAsync<TResponse, TRequestType>(message, cancellationToken: cancellationToken);
|
||||
|
||||
private async Task<WinoServerResponse<TResponse>> GetResponseInternalAsync<TResponse, TRequestType>(TRequestType message, Dictionary<string, object> parameters = null)
|
||||
private async Task<WinoServerResponse<TResponse>> GetResponseInternalAsync<TResponse, TRequestType>(TRequestType message,
|
||||
Dictionary<string, object> parameters = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (Status != WinoServerConnectionStatus.Connected)
|
||||
await ConnectAsync();
|
||||
@@ -315,7 +317,11 @@ namespace Wino.Core.UWP.Services
|
||||
}
|
||||
}
|
||||
|
||||
response = await Connection.SendMessageAsync(valueSet);
|
||||
response = await Connection.SendMessageAsync(valueSet).AsTask(cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return WinoServerResponse<TResponse>.CreateErrorResponse($"Request is canceled by client.");
|
||||
}
|
||||
catch (Exception serverSendException)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user