protected async void GeneratePasswordCommandHandler(object p) { // Get data context var field = p as FieldModel; // Prompt only if there is something in the field var prompt = !string.IsNullOrWhiteSpace(field.Value); // If we don't need to prompt, then show the dialog var result = !prompt; // Prompt only if we need to if (prompt) { await DialogHelper.Confirm( "This will replace your existing password with a new one. Are you sure?", (c) => { result = true; }); } // If the result is true, then show the dialog if (result) { // Show the add field dialog var d = new PasswordGeneratorDialog(); // Show the dialog var action = await d.ShowAsync(); if (action == ContentDialogResult.Primary) { // Set the password field to the new value field.Value = (d.DataContext as PasswordGeneratorDialogViewModel)?.Password; } } }
protected async void DeleteFieldCommandHandler(object p) { // Get data context var field = p as FieldModel; // Prompt user to delete the field var promptResp = await DialogHelper.Confirm( "This action cannot be undone. Are you sure you want to delete this field?", async (c) => { try { // Call api to delete the field from the item await KryptPadApi.DeleteFieldAsync(Category.Id, Item.Id, field.Id); // Remove the field Fields.Remove(field); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }); }
private async void DeleteAccountCommandHandlerAsync(object obj) { IsBusy = true; try { await DialogHelper.Confirm( "Are you sure you want to delete your account? ALL OF YOUR DATA WILL BE DELETED! THIS ACTION CANNOT BE UNDONE.", async (p) => { // Log in and get access token await KryptPadApi.DeleteAccountAsync(); // Create instance to credential locker var locker = new PasswordVault(); try { // Clear out the saved credential for the resource var creds = locker.FindAllByResource(Constants.LOCKER_RESOURCE); foreach (var cred in creds) { // Remove only the credentials for the given resource locker.Remove(cred); } } catch { /* Nothing to see here */ } // Navigate to the login page NavigationHelper.Navigate(typeof(LoginPage), null, NavigationHelper.NavigationType.Root); } ); } catch (WebException ex) { await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } IsBusy = false; }
private void ExecuteDelete(object obj) { try { if (DialogHelper.Confirm("Are you sure you want to delete selected task?", "Confirm Delete Task")) { var dataRequest = new DataRequest(Id); ServiceManager.Invoke(sc => sc.DeleteTask(RequestResponseUtils.SendData(dataRequest))); var taskListViewModel = PageNavigatorHelper.GetMainContentViewModel <TaskListViewModel>(); if (taskListViewModel != null) { taskListViewModel.RemoveTask(this); } } } catch (Exception ex) { Logger.Error("Delete Task Error: " + ex.Message, ex); } }
private async void DeleteCategoryCommandHandler(object p) { // Confirm delete var res = await DialogHelper.Confirm("All items under this category will be deleted. Are you sure you want to delete this category?", async (ap) => { var category = p as ApiCategory; // Get the selected items and delete them if (category != null) { try { // Delete the item var success = await KryptPadApi.DeleteCategoryAsync(category.Id); // If sucessful, remove item from the list if (success) { // Refresh the view await RefreshCategoriesAsync(); } } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } } } ); }
/// <summary> /// Clears any saved passphrases /// </summary> private async void ClearAllSavedPassphrases() { var command = await DialogHelper.Confirm( ResourceHelper.GetString("ConfirmClearAllPassphrases"), ResourceHelper.GetString("Confirm"), (c) => { try { // Create instance to credential locker var locker = new PasswordVault(); // Clear out the saved credential for the resource var logins = locker.FindAllByResource(KryptPadApi.Username); foreach (var login in logins) { if (login.Resource != Constants.LOCKER_RESOURCE) { locker.Remove(login); } } // Reset flag on all profiles foreach (var profile in Profiles) { profile.WindowsHelloEnabled = false; } } catch { } }); if ((int)command.Id == 2) { // User chose to cancel, so re-enable SavePassphraseEnabled = true; } }
/// <summary> /// Registers commands for UI elements /// </summary> private void RegisterCommands() { // Handle add category AddCategoryCommand = new Command(async(p) => { // Prompt for name await DialogHelper.ShowClosableDialog <NamePromptDialog>(async(d) => { try { //create new category var category = new ApiCategory() { Name = d.Value, Items = new ApiItem[] { } }; // Send the category to the api var resp = await KryptPadApi.SaveCategoryAsync(category); // Set the id of the newly created category category.Id = resp.Id; // Add the category to the list Categories.Add(category); // Add view to the ItemsView object ItemsView.Source = Categories; // Refresh OnPropertyChanged(nameof(ItemsView)); // Hide empty message EmptyMessageVisibility = Visibility.Collapsed; } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }, "Add Category"); }); // Handle add new item AddItemCommand = new Command(AddItemCommandHandler); // Handle item click ItemClickCommand = new Command((p) => { var item = p as ApiItem; var category = (from c in Categories where c.Items.Contains(item) select c).FirstOrDefault(); // Navigate to edit NavigationHelper.Navigate(typeof(NewItemPage), new EditItemPageParams() { Category = category, Item = item }); }); // Handle change passphrase command ChangePassphraseCommand = new Command(async(p) => { var dialog = new ChangePassphraseDialog(); await dialog.ShowAsync(); }); // Handle rename command RenameProfileCommand = new Command(async(p) => { // Prompt for name await DialogHelper.GetValueAsync(async(d) => { try { // Set new name var profile = KryptPadApi.CurrentProfile; profile.Name = d.Value; // Send the category to the api var resp = await KryptPadApi.SaveProfileAsync(profile); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }, "RENAME PROFILE", KryptPadApi.CurrentProfile.Name); }); // Handle delete command DeleteProfileCommand = new Command(async(p) => { var res = await DialogHelper.Confirm( "All of your data in this profile will be deleted permanently. THIS ACTION CANNOT BE UNDONE. Are you sure you want to delete this entire profile?", "WARNING - CONFIRM DELETE", async(ap) => { try { // Delete the selected profile await KryptPadApi.DeleteProfileAsync(KryptPadApi.CurrentProfile); // Navigate back to the profiles list NavigationHelper.Navigate(typeof(SelectProfilePage), null); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } } ); }); // Download profile handler DownloadProfileCommand = new Command(async(prop) => { try { // Prompt for a place to save the file var sfd = new FileSavePicker() { SuggestedFileName = KryptPadApi.CurrentProfile.Name, }; //sfd.FileTypeChoices.Add("KryptPad Document Format", new List<string>(new[] { ".kdf" })); sfd.FileTypeChoices.Add("KryptPad Document Format", new[] { ".kdf" }); // Show the picker var file = await sfd.PickSaveFileAsync(); if (file != null) { // Get profile var profileData = await KryptPadApi.DownloadCurrentProfileAsync(); // Save profile to file using (var fs = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite)) using (var sw = new StreamWriter(fs.AsStreamForWrite())) { // Write the data sw.Write(profileData); } await DialogHelper.ShowMessageDialogAsync("Profile downloaded successfully"); } } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }); // Handle category rename RenameCategoryCommand = new Command(RenameCategoryCommandHandler); // Handle category delete DeleteCategoryCommand = new Command(DeleteCategoryCommandHandler); // Handle selection mode SelectModeCommand = new Command(SelectModeCommandHandler); // Handle the move command MoveItemsCommand = new Command(MoveItemsCommandHandler, CanMoveItems); // Handle setting favorites SetFavoriteCommand = new Command(SetFavoriteCommandHandler); }
/// <summary> /// Registers commands for UI elements /// </summary> private void RegisterCommands() { // Handle add new field AddFieldCommand = new Command(async(p) => { // Show the add field dialog var res = await DialogHelper.ShowClosableDialog <AddFieldDialog>(async(d) => { try { var m = (d.DataContext as AddFieldDialogViewModel); var field = new FieldModel(new ApiField() { Name = m.FieldName, FieldType = m.SelectedFieldType.Id }); // Send the field to the API to be stored under the item var resp = await KryptPadApi.SaveFieldAsync(Category.Id, Item.Id, field.Field); field.Id = resp.Id; // Add field to the list AddFieldToCollection(field); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }); }); // Handle item delete DeleteItemCommand = new Command(async(p) => { // Prompt user to delete the item var promptResp = await DialogHelper.Confirm( "This action cannot be undone. All data associated with this item will be deleted. Are you sure you want to delete this item?", async(c) => { try { // Delete the item await KryptPadApi.DeleteItemAsync(Category.Id, Item.Id); // Navigate back to items page NavigationHelper.Navigate(typeof(ItemsPage), null); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }); }); // Handle copy field value CopyFieldValueCommand = new Command(async(p) => { try { var field = p as FieldModel; // Check if field value is null if (!string.IsNullOrWhiteSpace(field.Value)) { // Create a data package var package = new DataPackage(); package.SetText(field.Value); // Set the value of the field to the clipboard Clipboard.SetContent(package); } } catch (Exception) { // Failed await DialogHelper.ShowMessageDialogAsync("Failed to copy text to clipboard."); } }); // Delete field DeleteFieldCommand = new Command(DeleteFieldCommandHandler); // Rename field RenameFieldCommand = new Command(RenameFieldCommandHandler); // Generate password GeneratePasswordCommand = new Command(GeneratePasswordCommandHandler); }