public object Execute() { CreatedGroup = new CredentialGroup(GroupName); AllGroups.Add(CreatedGroup); return(AllGroups); }
public Credential AddCredential(CredentialGroup group, Credential credential) { if (group == null) { throw new InvalidOperationException("Es muss eine Gruppe zugeordnet werden."); } else if (String.IsNullOrWhiteSpace(credential.Name)) { throw new InvalidOperationException("Der Name darf nicht leer sein."); } else if (_currentData.First(g => g == group).Credentials.Any(c => c.Name == credential.Name)) { throw new InvalidOperationException("Ein Eintrag mit diesem Namen existiert bereits."); } int id = Convert.ToInt32(_currentData.SelectMany(g => g?.Credentials)?.Max(c => c?.ID)) + 1; credential.ID = id; ICommand command = new AddCredentialCommand() { Group = group, CredentialToCreate = credential }; credential = (Credential)ExecuteCommand(command); return(credential); }
private void RemoveSelectedGroup() { int listBoxIndexToRemove = Groups.SelectedIndex; string groupName = Groups.SelectedItem as string; CredentialGroup toDelete = _manager.FindGroup(groupName); if (toDelete != null) { var confirmation = MessageBox.Show( $"Gruppe \"{toDelete.Name}\" wirklich löschen?\r\nAlle Passwörter in dieser Gruppe werden ebenfalls entfernt.", "Bestätigen", MessageBoxButtons.YesNo ); if (confirmation == DialogResult.Yes) { _manager.RemoveGroup(toDelete); Groups.Items.RemoveAt(listBoxIndexToRemove); Groups.SelectedItem = null; } } else { MessageBox.Show("Gruppe konnte nicht gefunden werden."); } }
private void Redo() { _ribbon.Tabs.First().Panels.Find(p => p.Name == "Functions").Items.Where(i => new[] { "Redo" }.Contains(i.Name)).ToList().ForEach(i => i.Enabled = false); string[] groupsBefore = _manager.GetGroups().Select(g => g.Name).ToArray(); _manager.Redo(); string[] groupsAfter = _manager.GetGroups().Select(g => g.Name).ToArray(); if (string.Join(",", groupsBefore) != string.Join(",", groupsAfter)) { BindGroups(_manager.GetGroups()); string newGroup = groupsAfter.ToList().Except(groupsBefore.ToList()).FirstOrDefault(); if (newGroup != null) { int newIndex = Groups.FindStringExact(newGroup); Groups.SelectedIndex = newIndex; } } else { CredentialGroup group = GetSelectedGroup(); if (group != null) { BindDetails(group); } } }
public CredentialsEditor(IPasswordSafe passwordManager, CredentialGroup credentialGroup) { InitializeComponent(); DoMagic(); SetInstance(passwordManager); _credential = new Credential(); _credentialGroup = credentialGroup; }
public void RemoveGroup(CredentialGroup toBeRemoved) { ICommand command = new DeleteGroupCommand() { AllGroups = _currentData, DeletedGroup = toBeRemoved }; ExecuteCommand(command); }
private void MoveItem_Click(object sender, EventArgs e) { Credential credential = GetSelectedCredential(); CredentialGroup sourceGroup = credential.Group; string moveTo = ((MenuItem)sender).Text; CredentialGroup target = _manager.FindGroup(moveTo); _manager.MoveCredential(credential, target); BindDetails(sourceGroup); }
public EditGroupDialog(IPasswordSafe passwordManager, CredentialGroup group) { InitializeComponent(); DoMagic(); _passwordManager = passwordManager; EditedGroup = group; _group = (CredentialGroup)group.Clone(); tbGroupName.Text = _group.Name; }
private void AddGroup_Click(object sender, System.EventArgs e) { EditGroupDialog addGroupDialog = new EditGroupDialog(_manager); DialogResult result = addGroupDialog.ShowDialog(); if (result == DialogResult.OK) { CredentialGroup created = addGroupDialog.EditedGroup; int newItemIndex = Groups.Items.Add(created.Name); Groups.SelectedIndex = newItemIndex; } }
private CredentialGroup GetSelectedGroup() { string selectedGroupName = (string)Groups.SelectedItem; CredentialGroup group = null; try { group = _manager.FindGroup(selectedGroupName); } catch { ; } return(group); }
private void _details_ItemActivate(object sender, System.EventArgs e) { ObjectListView objectListView = sender as ObjectListView; CredentialGroup group = GetSelectedGroup(); Credential credential = (Credential)objectListView.SelectedObject; if (credential == null) { MessageBox.Show("Kein Eintrag selektiert."); } else { EditCredential(group, credential); } }
private void BindDetails(CredentialGroup group) { _details.SelectedItem = null; _details.Objects = null; _details.ItemSelectionChanged += _details_ItemSelectionChanged; if (group != null) { group.Credentials.ToList().ForEach(i => { _details.AddObject(i); }); _details.Sort(0); } _details.AutoResizeColumns(); }
public void MoveCredential(Credential credential, CredentialGroup targetGroup) { if (credential == null) { throw new InvalidOperationException("Keine Credentials ausgewählt."); } if (targetGroup == null) { throw new InvalidOperationException("Zielgruppe nicht angegeben."); } ICommand command = new MoveCredentialCommand() { Credential = credential, TargetGroup = targetGroup }; ExecuteCommand(command); }
private void EditCredential(CredentialGroup group, Credential credential) { CredentialsEditor editor; if (credential != null) { editor = new CredentialsEditor(_manager, credential); } else { editor = new CredentialsEditor(_manager, group); } DialogResult result = editor.ShowDialog(); if (result == DialogResult.OK) { BindDetails(editor.EditedCredential.Group); } }
private void EditGroup() { CredentialGroup toEdit = GetSelectedGroup(); if (toEdit != null) { EditGroupDialog editDialog = new EditGroupDialog(_manager, toEdit); DialogResult result = editDialog.ShowDialog(); if (result == DialogResult.OK) { CredentialGroup updated = editDialog.EditedGroup; Groups.Items[Groups.SelectedIndex] = updated.Name; } } else { MessageBox.Show("Gruppe konnte nicht gefunden werden."); } }
public CredentialGroup UpdateGroup(CredentialGroup toBeUpdated, CredentialGroup updated) { if (String.IsNullOrWhiteSpace(updated.Name)) { throw new InvalidOperationException("Der Name darf nicht leer sein."); } else if (_currentData.Any(g => g.Name == updated.Name)) { throw new InvalidOperationException("Eine Gruppe mit diesem Namen existiert bereits."); } ICommand command = new UpdateGroupCommand() { ToBeUpdated = toBeUpdated, UpdatedCredential = updated }; toBeUpdated = (CredentialGroup)ExecuteCommand(command); return(toBeUpdated); }
private void ButtonOk_Click(object sender, EventArgs e) { string groupName = tbGroupName.Text; try { if (_group != null) { _group.Name = groupName; EditedGroup = _passwordManager.UpdateGroup(EditedGroup, _group); } else { EditedGroup = _passwordManager.CreateGroup(groupName); } DialogResult = DialogResult.OK; Close(); } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); } }
private void AddCredentials_Click(object sender, System.EventArgs e) { CredentialGroup group = GetSelectedGroup(); EditCredential(group, null); }