private async void CreateButton_Click(object sender, RoutedEventArgs e) { ResourceLoader resourceLoader = new ResourceLoader(); EmailError.Visibility = Visibility.Collapsed; PasswordError.Visibility = Visibility.Collapsed; ErrorBorder.Visibility = Visibility.Collapsed; string errorText = ""; var email = Email.Text; var password = Password.Password; int expiresSeconds = 0; if (!NeverExpireCheckbox.IsChecked.Value) { var expireDate = ExpireDate.Date.Date; var expireTime = ExpireTime.Time; var expiresDateTime = expireDate.Add(expireTime); var expires = expiresDateTime - DateTime.Now; expiresSeconds = (int)expires.TotalSeconds; } if (string.IsNullOrWhiteSpace(email)) { errorText += resourceLoader.GetString("ErrorEmailIsRequired"); EmailError.Visibility = Visibility.Visible; } if (string.IsNullOrWhiteSpace(password)) { if (errorText.Length != 0) { errorText += "\n"; } errorText += resourceLoader.GetString("ErrorPasswordIsRequired"); PasswordError.Visibility = Visibility.Visible; } if (!NeverExpireCheckbox.IsChecked.Value) { if (expiresSeconds < 0) { if (errorText.Length != 0) { errorText += "\n"; } errorText += resourceLoader.GetString("TokenCreateExpireTimePast"); } else if (expiresSeconds < 60) { if (errorText.Length != 0) { errorText += "\n"; } errorText += resourceLoader.GetString("TokenCreateExpireTimeSoon"); } } if (errorText.Length != 0) { ErrorText.Text = errorText; ErrorBorder.Visibility = Visibility.Visible; return; } SetEnableState(false); var particleAuthentication = await ParticleCloud.SharedCloud.CreateTokenAsync(email, password, expiresSeconds); if (particleAuthentication != null) { NewTokenValue.Text = particleAuthentication.AccessToken; NewTokenFlyout.ShowAt(CreateButton); } else { ErrorText.Text = resourceLoader.GetString("AuthCredentialsError"); ErrorBorder.Visibility = Visibility.Visible; } SetEnableState(true); }
private void OkButton_click(object sender, RoutedEventArgs e) { NewTokenFlyout.Hide(); }