private async void pgPage_Loaded(object sender, RoutedEventArgs e) { if (manager.CurrentScheme != null) { this.fieldsList.ItemsSource = manager.CurrentScheme.Fields; fieldValues = new List <string>(manager.CurrentScheme.Fields.Count); for (int i = 0; i < manager.CurrentScheme.Fields.Count; ++i) { fieldValues.Add(""); } switch (manager.CurrentScheme.TimeToHashType) { case SPMSchemeTimeToHashType.FIXED: this.iterationText.Text = string.Format("Fixed: {0} times.", manager.CurrentScheme.TimeToHashParam); break; case SPMSchemeTimeToHashType.FROM_FIELD: int index = manager.CurrentScheme.TimeToHashParam; if (index < this.fieldValues.Count) { this.iterationText.Text = string.Format("Length of {0}.", manager.CurrentScheme.Fields[index].Name); } else { this.iterationText.Text = string.Format("Length (Param invalid). Please override."); } break; } foreach (var field in manager.CurrentScheme.Fields) { this.iterFieldCombo.Items.Add(field.Name); } this.iterFieldCombo.SelectedIndex = 0; int procIndex = CSHelper.IndexOfEnum(this.procCombo.Items, manager.CurrentScheme.ProcessType); this.procCombo.SelectedIndex = procIndex >= 0 ? procIndex : 0; } else { await this.ShowMessage("Error", "Critical error: null scheme passed to the page."); // TODO: log if (Frame.CanGoBack) { Frame.GoBack(); } else { Frame.Navigate(typeof(MainPage)); } } }
private void sePage_Loaded(object sender, RoutedEventArgs e) { if (manager.CurrentScheme == null) { currScheme = new SPMScheme(); isNewScheme = true; } else { currScheme = new SPMScheme(manager.CurrentScheme); } if (currScheme.Fields.Count == 0) { currScheme.Fields.Add(new SPMSchemeField() { Name = "Default", Description = "Just fill in something.", SaltingType = SPMSchemeSaltingType.ALWAYS }); } fieldsForList = new ListExtraMemberHelper <SPMSchemeField>(); fieldsForList.members = currScheme.Fields; fieldsForList.membersAfter = new List <SPMSchemeField>() { new SPMSchemeField() { Name = "Add a new field", Description = "Tap here to add a new field", isActual = false } }; updateFieldsList(); foreach (var field in currScheme.Fields) { this.iterFieldCombo.Items.Add(field.Name); } int procIndex = CSHelper.IndexOfEnum(procCombo.Items, currScheme.ProcessType); this.procCombo.SelectedIndex = procIndex >= 0 ? procIndex : 0; if (currScheme.TimeToHashType == SPMSchemeTimeToHashType.FROM_FIELD) { this.iterChoiceLength.IsChecked = true; this.iterFieldCombo.SelectedIndex = currScheme.TimeToHashParam >= 0 && currScheme.TimeToHashParam < this.iterFieldCombo.Items.Count ? currScheme.TimeToHashParam : 0; } else { this.numIterBox.Text = currScheme.TimeToHashParam.ToString(); this.iterFieldCombo.SelectedIndex = 0; } this.nameBox.Text = currScheme.Name; this.descBox.Text = currScheme.Description; }
private async Task <bool> PromptFieldEdit(SPMSchemeField field) { int result = 0; var dialog = new ContentDialog(); dialog.Title = "Edit Field"; dialog.MaxWidth = ActualWidth; var panel = new StackPanel(); panel.Children.Add(new TextBlock { Text = "Name:", TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap }); var nameBox = new TextBox(); nameBox.Text = field.Name; panel.Children.Add(nameBox); panel.Children.Add(new TextBlock { Text = "Description:", TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap }); var descBox = new TextBox(); descBox.Text = field.Description; panel.Children.Add(descBox); panel.Children.Add(new TextBlock { Text = "Method:", TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap }); var methCombo = new ComboBox(); foreach (var v in Enum.GetValues(typeof(SPMSchemeSaltingType))) { methCombo.Items.Add(v); } int methIndex = CSHelper.IndexOfEnum(methCombo.Items, field.SaltingType); methCombo.SelectedIndex = methIndex >= 0 ? methIndex : 0; methCombo.HorizontalAlignment = HorizontalAlignment.Stretch; panel.Children.Add(methCombo); var delBtn = new Button(); delBtn.Click += (o, e) => { result = 2; dialog.Hide(); }; delBtn.Margin = new Thickness(0, 12, 0, 0); delBtn.Content = new TextBlock { Text = "Delete", Foreground = new SolidColorBrush(Windows.UI.Colors.Red), TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap }; delBtn.HorizontalAlignment = HorizontalAlignment.Stretch; delBtn.HorizontalContentAlignment = HorizontalAlignment.Center; panel.Children.Add(delBtn); dialog.Content = panel; dialog.PrimaryButtonText = "OK"; dialog.PrimaryButtonClick += (o, e) => { result = 1; }; dialog.SecondaryButtonText = "Cancel"; #if DEBUG dialog.Tapped += (o, e) => { System.Diagnostics.Debug.WriteLine(String.Format("Height {0}, ActualHeight {1}, panel.Height {2}, panel.ActualHeight {3}", dialog.Height, dialog.ActualHeight, panel.Height, panel.ActualHeight)); }; #endif await dialog.ShowAsync(); if (result == 2) // delete { return(false); } else if (result == 1) // save changes { field.Name = nameBox.Text; field.Description = descBox.Text; field.SaltingType = (SPMSchemeSaltingType)methCombo.SelectedItem; } return(true); }