Beispiel #1
0
        public object Execute()
        {
            CreatedGroup = new CredentialGroup(GroupName);
            AllGroups.Add(CreatedGroup);

            return(AllGroups);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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.");
            }
        }
Beispiel #4
0
        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);
                }
            }
        }
Beispiel #5
0
        public CredentialsEditor(IPasswordSafe passwordManager, CredentialGroup credentialGroup)
        {
            InitializeComponent();
            DoMagic();
            SetInstance(passwordManager);

            _credential      = new Credential();
            _credentialGroup = credentialGroup;
        }
Beispiel #6
0
        public void RemoveGroup(CredentialGroup toBeRemoved)
        {
            ICommand command = new DeleteGroupCommand()
            {
                AllGroups    = _currentData,
                DeletedGroup = toBeRemoved
            };

            ExecuteCommand(command);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        public EditGroupDialog(IPasswordSafe passwordManager, CredentialGroup group)
        {
            InitializeComponent();
            DoMagic();
            _passwordManager = passwordManager;

            EditedGroup = group;
            _group      = (CredentialGroup)group.Clone();

            tbGroupName.Text = _group.Name;
        }
Beispiel #9
0
        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;
            }
        }
Beispiel #10
0
        private CredentialGroup GetSelectedGroup()
        {
            string          selectedGroupName = (string)Groups.SelectedItem;
            CredentialGroup group             = null;

            try {
                group = _manager.FindGroup(selectedGroupName);
            }
            catch {
                ;
            }

            return(group);
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
        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();
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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);
            }
        }
Beispiel #15
0
        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.");
            }
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
            }
        }
Beispiel #18
0
        private void AddCredentials_Click(object sender, System.EventArgs e)
        {
            CredentialGroup group = GetSelectedGroup();

            EditCredential(group, null);
        }