private async Task SignUpAsync() { HasActiveTask = true; try { _terminator = new CancellationTokenSource(); var token = new SignUpToken { ID = _tuple.ID, Key = _tuple.Key, Name = _name }; var user = await _client.SignUpAsync(_tuple.Server, token, _terminator.Token); await _storage.StoreDataAsync("signin", new[] { _tuple }); var parameters = new Dictionary<string, object> { { NavigationParameters.UserID, user.ID } }; NavigationService.Navigate(NavigationRegistry.HomePage, parameters); } catch (TaskCanceledException) { } catch (Exception ex) { var template = new DialogTemplate { Title = "Something went wrong", Content = $"There is a problem signing you up. Inquiring minds may find this information helpful: {ex.Message}", PrimaryButtonText = "Close" }; await _dialogService.ShowAsync(template); } finally { _terminator = null; } HasActiveTask = false; }
public async Task<User> SignUpAsync(string server, SignUpToken token, CancellationToken terminator) { if (server == null) throw new ArgumentNullException(nameof(server)); if (token == null) throw new ArgumentNullException(nameof(token)); _server = server; var uri = new Uri(FormattableString.Invariant($"{_server}/api/signup")); var content = JsonObjectContent.Create(token); using (var response = await _client.PostAsync(uri, content, terminator).ConfigureAwait(false)) { await VerifyResponseAsync(response); return await response.Content.ReadAsJsonObjectAsync<User>().ConfigureAwait(false); } }