public PageOwner(EncryptionControl encryptionControl) { InitializeComponent(); DataContext = _viewModel; EncryptionTab.Content = encryptionControl ?? throw new ArgumentNullException(nameof(encryptionControl)); HashingTab.Content = new HashingUserControl(new HashingControlViewModel()); }
/// <summary> /// Populates form fields with a settings profile. /// </summary> /// <param name="settings">Settings profile that should be displayed on the form./</param> private void PopulateForm(Settings settings) { try { currentProfile = settings; edtBackendUrl.Text = settings.Url; edtBackendTimeout.Text = settings.Timeout.ToString(); edtDomain.Text = settings.Domain; edtUsername.Text = settings.Username; edtPassword.Text = EncryptionControl.DecryptWithDeviceID(settings.Password); edtFragmentSize.Text = settings.FragmentSize.ToString(); chkIsTestInstance.Checked = settings.IsTestInstance; edtProfileName.Text = settings.ProfileName; if (!customEnabled) { edtBackendUrl.Enabled = false; edtBackendTimeout.Enabled = false; edtDomain.Enabled = false; edtUsername.Enabled = false; edtPassword.Enabled = false; edtFragmentSize.Enabled = false; chkIsTestInstance.Enabled = false; txtProfileName.Visibility = ViewStates.Invisible; edtProfileName.Visibility = ViewStates.Invisible; linButtons.Visibility = ViewStates.Invisible; } else { edtBackendUrl.Enabled = true; edtBackendTimeout.Enabled = true; edtDomain.Enabled = true; edtUsername.Enabled = true; edtPassword.Enabled = true; edtFragmentSize.Enabled = true; chkIsTestInstance.Enabled = true; txtProfileName.Visibility = ViewStates.Visible; edtProfileName.Visibility = ViewStates.Visible; linButtons.Visibility = ViewStates.Visible; } } catch (Exception e) { Log.Info("MobuAndroid", "Error while populating settings form.", e.Message); } }
protected override void OnStartup(StartupEventArgs e) { var messageBox = new MessageBoxFacade(); try { (string key, string iv) = GetAesConfig(); var viewModel = new EncryptionControlViewModel { KeyString = key, IVString = iv }; var encryptionControl = new EncryptionControl(viewModel); var window = new PageOwner(encryptionControl); window.Show(); } catch (Exception ex) { messageBox.ShowError("Fatal Error..."); messageBox.ShowError(ex); Shutdown(-1); } }
/// <summary> /// Saves the details on screen to a new or existing profile to file after validating it. /// Default profiles cannot be edited. /// </summary> private void SaveProfile() { var newSettings = new Settings(); try { newSettings.ProfileName = spinProfiles.SelectedItem.ToString().Trim(); newSettings.Url = edtBackendUrl.Text.Trim(); newSettings.Timeout = Convert.ToInt32(edtBackendTimeout.Text); newSettings.Domain = edtDomain.Text; newSettings.Username = edtUsername.Text; newSettings.Password = EncryptionControl.EncryptWithDeviceID(edtPassword.Text); newSettings.FragmentSize = Convert.ToInt32(edtFragmentSize.Text); newSettings.IsTestInstance = chkIsTestInstance.Checked; } catch (Exception e) { Log.Info("MobuAndroid", "Error while saving invalid settings.", e.Message); } if (!String.IsNullOrEmpty(edtProfileName.Text) && edtProfileName.Text != spinProfiles.SelectedItem.ToString()) { newSettings.ProfileName = edtProfileName.Text; } if (profiles.Any((x => x.IsDefault && x.ProfileName == newSettings.ProfileName))) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Cannot Change Default Settings"); alert.SetMessage("You cannot change a default settings profile. Please enter a different name for this new settings profile."); alert.SetNeutralButton("OK", (senderAlert, args) => { }); Dialog dialog = alert.Create(); dialog.Show(); return; } if (!newSettings.IsValid()) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Invalid Settings"); alert.SetMessage("Please complete all fields before saving settings."); alert.SetNeutralButton("OK", (senderAlert, args) => { }); Dialog dialog = alert.Create(); dialog.Show(); } else { if (settingsControl.SaveSettingsProfile(newSettings)) { currentProfile = newSettings; profiles = settingsControl.GetSettingsProfiles(); spinProfiles.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, profiles.Select(x => x.ProfileName).ToList()); spinProfiles.SetSelection(profiles.FindIndex(x => x.ProfileName == currentProfile.ProfileName)); AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Profile saved"); alert.SetMessage("Settings profile " + currentProfile.ProfileName + " saved."); alert.SetNeutralButton("OK", (senderAlert, args) => { }); Dialog dialog = alert.Create(); dialog.Show(); } else { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Save Failed"); alert.SetMessage("Settings profile " + currentProfile.ProfileName + " could not be saved."); alert.SetNeutralButton("OK", (senderAlert, args) => { }); Dialog dialog = alert.Create(); dialog.Show(); } } }