private async void MenuFlyoutDuplicate_Click(object sender, RoutedEventArgs e) { SPMScheme scheme = (SPMScheme)((MenuFlyoutItem)sender).Tag; manager.CurrentScheme = scheme; // get a name string n = null; bool prompting = true; while (prompting) { n = await this.PromptForInput("Duplicate Scheme", "Give the new scheme a name:", scheme.Name); if (!SPMScheme.IsNameValid(n)) { await this.ShowMessage("Invalid Name", "The name of scheme should have at most 32 characters of letters, numbers, and these characters: []().,_ But it shall not end with a dot or a space."); continue; } if (manager.Schemes.Find(sc => String.Compare(n, sc.Name) == 0) == null) { prompting = false; } else { bool cont = await this.ShowYesNoMessage("Name Collision", "There is already a scheme with the same name (not case-sensative). Please change the name of the scheme. Tap Yes to try again, No to give up."); if (!cont) { return; } } } SPMScheme s = new SPMScheme(manager.CurrentScheme); s.Name = n; manager.Schemes.Insert(manager.Schemes.IndexOf(manager.CurrentScheme) + 1, s); manager.CurrentScheme = s; bool result = await manager.SaveCurrentSchemeAsync(); if (!result) { await this.ShowMessage("Error", "An error occurred while writing the new scheme. Sorry."); manager.CurrentScheme = null; manager.Schemes.Remove(s); return; } updateSchemesList(); }
private async Task <bool> UpdateCurrSchemeExceptFields() { if (!SPMScheme.IsNameValid(nameBox.Text)) { await this.ShowMessage("Invalid Name", "The name of scheme should have at most 32 characters of letters, numbers, and these characters: []().,_ But it shall not end with a dot or a space."); return(false); } bool iterIsFixed = iterChoiceFixed.IsChecked ?? false; int param = 0; if (iterIsFixed) { if (!int.TryParse(numIterBox.Text, out param)) { await this.ShowMessage("Invalid Number", "The number of iteration is not valid."); return(false); } else { if (param < 1 || param > 1000) { await this.ShowMessage("Iteration Out of Range", "The number of iteration should be in [1, 1000]"); return(false); } } } else { param = iterFieldCombo.SelectedIndex; } currScheme.Name = nameBox.Text; currScheme.Description = descBox.Text; currScheme.ProcessType = (SPMSchemeProcessType)procCombo.SelectedItem; currScheme.TimeToHashType = iterIsFixed ? SPMSchemeTimeToHashType.FIXED : SPMSchemeTimeToHashType.FROM_FIELD; currScheme.TimeToHashParam = param; return(true); }