/// <summary> /// Updates the field /// </summary> /// <param name="field"></param> private async void UpdateField(FieldModel field) { if (_isLoading) { return; } // Set main window busy state //(Window.Current.Content as MainPage).SetIsBusy(true); try { // Send the field to the API to be stored under the item await KryptPadApi.SaveFieldAsync(Category.Id, Item.Id, field.Field); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } // Set main window busy state //(Window.Current.Content as MainPage).SetIsBusy(false); }
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 RenameCategoryCommandHandler(object p) { //create new category var category = p as ApiCategory; // Prompt for name await DialogHelper.GetValueAsync(async (d) => { try { // Set new name category.Name = d.Value; // Send the category to the api var resp = await KryptPadApi.SaveCategoryAsync(category); // 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); } }, "RENAME CATEGORY", category.Name); }
/// <summary> /// Saves details about an item /// </summary> private async void SaveItemAsync() { // If we are loading, do not save the item if (_isLoading) { return; } try { // Set item properties Item.Name = ItemName; Item.Notes = Notes; Item.Background = SelectedColor; var oldCategoryId = Item.CategoryId; Item.CategoryId = Category.Id; // Update the item await KryptPadApi.SaveItemAsync(oldCategoryId, Item); } 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 SetFavoriteCommandHandler(object obj) { var item = obj as ApiItem; try { // Remove favorite await KryptPadApi.DeleteItemFromFavoritesAsync(item); // Remove from list Items.Remove(item); // Update empty message if (Items.Count == 0) { EmptyMessageVisibility = Visibility.Visible; } } 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 SetFavoriteCommandHandler(object obj) { var item = obj as ApiItem; try { // Set / remove favorite if (!item.IsFavorite) { await KryptPadApi.AddItemToFavoritesAsync(item); } else { await KryptPadApi.DeleteItemFromFavoritesAsync(item); } } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }
/// <summary> /// Register commands /// </summary> private void RegisterCommands() { CreateAccountCommand = new Command(async(p) => { IsBusy = true; try { // Log in and get access token var response = await KryptPadApi.CreateAccountAsync(Email, Password, ConfirmPassword); // The account was created await DialogHelper.ShowMessageDialogAsync("Your account has been successfully created."); // Go to login page NavigationHelper.Navigate(typeof(LoginPage), null); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } IsBusy = false; }, CanSignUp); }
private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { // Disable the primary button IsPrimaryButtonEnabled = false; // Force the dialog to stay open until the operation completes. // We will call Hide() when the api calls are done. args.Cancel = true; try { // Change the passphrase await KryptPadApi.ChangePassphraseAsync(OldPassphrase, NewPassphrase); // Done await DialogHelper.ShowMessageDialogAsync("Profile passphrase changed successfully."); // Hide dialog Hide(); } catch (WarningException ex) { // Operation failed await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (WebException ex) { // Operation failed await DialogHelper.ShowMessageDialogAsync(ex.Message); } // Restore the button IsPrimaryButtonEnabled = CanChangePassphrase; }
/// <summary> /// Performs login /// </summary> /// <returns></returns> private async Task LoginAsync() { IsBusy = true; try { //log in and get access token await KryptPadApi.AuthenticateAsync(Email, Password); //save credentials SaveCredentialsIfAutoSignIn(); //navigate to the select profile page NavigationHelper.Navigate(typeof(SelectProfilePage), null); } catch (WebException ex) { await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { Debug.WriteLine(ex.Message); // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } IsBusy = false; }
/// <summary> /// Decrypts the user's profile and logs in /// </summary> /// <returns></returns> private async Task EnterProfile(ProfileModel profile, string passphrase) { try { // Check the profile and determine if the passphrase is correct await KryptPadApi.LoadProfileAsync(profile.Profile, passphrase); // Success, tell the app we are signed in (App.Current as App).SignInStatus = SignInStatus.SignedInWithProfile; // Check if Windows hellow is supported and save the passphrase var supported = await KeyCredentialManager.IsSupportedAsync(); if (supported && SavePassphraseEnabled) { // Prompt to save profile passphrase if Windows Hello is enabled StorePassphrase(profile.Id.ToString(), passphrase); } // When a profile is selected, navigate to main page NavigationHelper.Navigate(typeof(ItemsPage), null, NavigationHelper.NavigationType.Main); } catch (WebException) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ResourceHelper.GetString("UnlockProfileFailed")); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }
public async Task SendForgotPasswordLinkAsync() { try { // Get the email address var email = await DialogHelper.GetValueAsync(null, ResourceHelper.GetString("ForgotPassword"), Email, ResourceHelper.GetString("ForgotPasswordPrompt")); if (email != null) { // Log in and get access token await KryptPadApi.SendForgotPasswordLinkAsync(email); await DialogHelper.ShowMessageDialogAsync("If your email address is associated to your account, you should recieve an email with password reset instructions."); } } catch (WebException ex) { await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }
private async void DeauthorizeDevicesCommandHandlerAsync(object obj) { IsBusy = true; try { // Log in and get access token await KryptPadApi.DeauthorizeDevices(); // 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; }
protected async void RenameFieldCommandHandler(object p) { // Get data context var field = p as FieldModel; await DialogHelper.GetValueAsync(async (d) => { try { // Update name field.Name = d.Value; // Call api to delete the field from the item await KryptPadApi.SaveFieldAsync(Category.Id, Item.Id, field.Field); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }); }
public LoginPageViewModel() { // Ensure that the access token is cleared upon arrival KryptPadApi.SignOutAsync(); (App.Current as App).SignInStatus = SignInStatus.SignedOut; // Register commands RegisterCommands(); }
public SelectProfilePageViewModel() { RegisterCommands(); // Set the profile selection visibility ProfileSelectionVisible = Visibility.Collapsed; WindowsHelloVisibility = Visibility.Collapsed; // Ensure the profile is closed and stored passphrase is cleared KryptPadApi.CloseProfile(); // Success, tell the app we are not signed in with a profile (App.Current as App).SignInStatus = SignInStatus.SignedIn; }
/// <summary> /// Fetch the system message if there is one /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void BroadcastMessageText_Loaded(object sender, RoutedEventArgs e) { try { // Get broadcast message var message = await KryptPadApi.GetBroadcastMessage(); if (!string.IsNullOrWhiteSpace(message)) { BroadcastMessage.Visibility = Visibility.Visible; BroadcastMessageText.Text = message; } } catch (Exception) { } }
/// <summary> /// Gets the profiles for the user /// </summary> /// <returns></returns> public async Task GetProfilesAsync() { IsBusy = true; // Call the api and get some data! try { var resp = await KryptPadApi.GetProfilesAsync(); // Create instance to credential locker var locker = new PasswordVault(); // Clear the profiles list Profiles.Clear(); // Add the profiles to the list foreach (var profile in resp.Profiles) { var profileModel = new ProfileModel(profile) { WindowsHelloEnabled = HasSavedPassphrase(locker, profile.Id.ToString()) }; // Add profile to list Profiles.Add(profileModel); } // Set the selected profile. // TODO: Make this restore last selected profile... somehow //SelectedProfile = Profiles.FirstOrDefault(); // If we don't have any profiles, hide the selection ProfileSelectionVisible = Profiles.Any() ? Visibility.Visible : Visibility.Collapsed; } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } IsBusy = false; }
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; }
/// <summary> /// Handles the move command /// </summary> /// <param name="obj"></param> private async void MoveItemsCommandHandler(object obj) { // Show a dialog to pick a new category var dialog = new ChangeCategoryDialog(); // Show the dialog var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { // Get the model var m = dialog.DataContext as ChangeCategoryDialogViewModel; try { // Save each item foreach (var item in SelectedItems) { // Store old category var oldCategoryId = item.CategoryId; // Set new category item.CategoryId = m.SelectedCategory.Id; // Save await KryptPadApi.SaveItemAsync(oldCategoryId, item); } // 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); } } }
private async void RestoreBackupCommandHandler(object obj) { try { var fop = new FileOpenPicker(); // Add supported file types fop.FileTypeFilter.Add(".kdf"); // Pick file to open and read var result = await fop.PickSingleFileAsync(); if (result != null) { var fs = await result.OpenReadAsync(); string profileData; // Create a stream reader using (var sr = new StreamReader(fs.AsStreamForRead())) { profileData = await sr.ReadToEndAsync(); } // Upload the profile data var resp = await KryptPadApi.UploadProfile(profileData); await DialogHelper.ShowMessageDialogAsync(ResourceHelper.GetString("ProfileRestored")); await GetProfilesAsync(); } } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }
private async Task SaveProfile() { try { // Create a new profile var request = new CreateProfileRequest() { Name = ProfileName, Passphrase = ProfilePassphrase, ConfirmPassphrase = ConfirmProfilePassphrase }; // Call api to create the profile. var profile = await KryptPadApi.CreateProfileAsync(request); // Go to profile await KryptPadApi.LoadProfileAsync(profile, ProfilePassphrase); // Success, tell the app we are signed in (App.Current as App).SignInStatus = SignInStatus.SignedInWithProfile; // Redirect to the main item list page NavigationHelper.Navigate(typeof(ItemsPage), null, NavigationHelper.NavigationType.Main); // Hide the dialog Hide(); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }
/// <summary> /// Get the list of categories from the database /// </summary> /// <returns></returns> public async Task RefreshItemsAsync() { // Set busy IsBusy = true; try { // Get the items if not already got var resp = await KryptPadApi.GetFavoritesAsync(); // Set the list to our list of categories foreach (var item in resp.Items) { Items.Add(item); } // Refresh OnPropertyChanged(nameof(Items)); // Show empty message if there are no categories EmptyMessageVisibility = Items.Count == 0 ? Visibility.Visible : Visibility.Collapsed; } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } // Not busy any more IsBusy = false; }
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> /// Get the list of categories from the database /// </summary> /// <returns></returns> public async Task RefreshCategoriesAsync() { // Set busy IsBusy = true; try { // Get the items if not already got var resp = await KryptPadApi.GetCategoriesWithItemsAsync(); // Set the list to our list of categories Categories = resp.Categories.ToList(); // Add view to the ItemsView object ItemsView.Source = Categories; // Refresh OnPropertyChanged(nameof(ItemsView)); // Show empty message if there are no categories EmptyMessageVisibility = Categories.Count == 0 ? Visibility.Visible : Visibility.Collapsed; } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } // Not busy any more IsBusy = false; }
/// <summary> /// Loads the categories /// </summary> /// <returns></returns> public async Task LoadCategoriesAsync() { try { // Get the categories from the api var result = await KryptPadApi.GetCategoriesAsync(); // Add the categories foreach (var category in result.Categories) { Categories.Add(category); } } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } }
private void SessionEndWarning_Tapped(object sender, TappedRoutedEventArgs e) { KryptPadApi.ExtendSessionTime(); // Hide the message ShowSessionWarningMessage(false); }
/// <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); }
/// <summary> /// Loads an item into the view model /// </summary> /// <param name="item"></param> public async Task LoadItemAsync(ApiItem selectedItem, ApiCategory category) { // Prevent change triggers _isLoading = true; IsBusy = true; try { // Get list of categories for the combobox control var categories = await KryptPadApi.GetCategoriesAsync(); // Set the category view source for the combobox CategoriesView.Source = categories.Categories; // Update view OnPropertyChanged(nameof(CategoriesView)); // Set the selected category in the list Category = (from c in categories.Categories where c.Id == category.Id select c).SingleOrDefault(); // Check to make sure our parameters are set if (Category == null) { // Show error throw new WarningException("The item you are trying to edit does not exist in this category."); } // Get the item var itemResp = await KryptPadApi.GetItemAsync(Category.Id, selectedItem.Id); // Get the item var item = itemResp.Items.FirstOrDefault(); // Set item Item = item; // Set properties ItemName = item.Name; Notes = item.Notes; SelectedColor = item.Background; // Set fields foreach (var field in item.Fields) { // Add field to the list AddFieldToCollection(new FieldModel(field)); } } catch (WarningException ex) { // Operation failed await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (WebException ex) { // Operation failed await DialogHelper.ShowMessageDialogAsync(ex.Message); // Navigate back to the items page NavigationHelper.Navigate(typeof(ItemsPage), null); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); // Navigate back to the items page NavigationHelper.Navigate(typeof(ItemsPage), null); } _isLoading = false; IsBusy = false; }
private async void AddItemCommandHandler(object p) { // Prompt to create the new item var dialog = new AddItemDialog(); // Show the dialog and wait for a response var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { try { // Get the category var category = p as ApiCategory; // Create an item var item = new ApiItem() { Name = dialog.ItemName }; // Save the item to the api var r = await KryptPadApi.SaveItemAsync(category.Id, item); // Set the item item.Id = r.Id; // If a template was selected, create a couple of fields to start with if (dialog.SelectedItemTemplate != null) { var templateFields = dialog.SelectedItemTemplate.Fields; // A template was selected, add all the fields from the template foreach (var templateField in templateFields) { // Create field var field = new ApiField() { Name = templateField.Name, FieldType = templateField.FieldType }; // Send to api await KryptPadApi.SaveFieldAsync(category.Id, item.Id, field); } } // Navigate to item edit page NavigationHelper.Navigate(typeof(NewItemPage), new EditItemPageParams() { Category = category, Item = item }); } catch (WebException ex) { // Something went wrong in the api await DialogHelper.ShowMessageDialogAsync(ex.Message); } catch (Exception ex) { // Failed await DialogHelper.ShowGenericErrorDialogAsync(ex); } } }
/// <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); }