/// <summary> /// Delete an entry. /// </summary> /// <param name="pe">The entry to be deleted. Must not be <c>null</c>.</param> /// <param name="permanent">Permanent delete or move to recycle bin</param> public void DeleteEntry(PwEntry pe, bool permanent = false) { if (pe == null) { throw new ArgumentNullException("pe"); } PwGroup pgRecycleBin = RootGroup.FindGroup(RecycleBinUuid, true); PwGroup pgParent = pe.ParentGroup; if (pgParent == null) { return; // Can't remove } pgParent.Entries.Remove(pe); bool bPermanent = false; if (RecycleBinEnabled == false) { bPermanent = true; } else if (permanent) { bPermanent = true; } else if (pgRecycleBin == null) { } // if we cannot find it, we will create it later else if (pgParent == pgRecycleBin) { bPermanent = true; } else if (pgParent.IsContainedIn(pgRecycleBin)) { bPermanent = true; } DateTime dtNow = DateTime.UtcNow; if (bPermanent) { PwDeletedObject pdo = new PwDeletedObject(pe.Uuid, dtNow); DeletedObjects.Add(pdo); } else // Recycle { EnsureRecycleBin(ref pgRecycleBin); pgRecycleBin.AddEntry(pe, true, true); pe.Touch(false); } }
/// <summary> /// Delete a group. /// </summary> /// <param name="pg">Group to be added. Must not be <c>null</c>.</param> /// <param name="permanent">Permanent delete or move to recycle bin</param> public void DeleteGroup(PwGroup pg, bool permanent = false) { if (pg == null) { throw new ArgumentNullException("pg"); } PwGroup pgParent = pg.ParentGroup; if (pgParent == null) { throw new ArgumentNullException("pgParent"); // Can't remove virtual or root group } PwGroup pgRecycleBin = RootGroup.FindGroup(RecycleBinUuid, true); bool bPermanent = false; if (RecycleBinEnabled == false) { bPermanent = true; } else if (permanent) { bPermanent = true; } else if (pgRecycleBin == null) { } // if we cannot find it, we will create it later else if (pg == pgRecycleBin) { bPermanent = true; } else if (pg.IsContainedIn(pgRecycleBin)) { bPermanent = true; } else if (pgRecycleBin.IsContainedIn(pg)) { bPermanent = true; } pgParent.Groups.Remove(pg); if (bPermanent) { pg.DeleteAllObjects(this); PwDeletedObject pdo = new PwDeletedObject(pg.Uuid, DateTime.UtcNow); DeletedObjects.Add(pdo); } else // Recycle { EnsureRecycleBin(ref pgRecycleBin); try { pgRecycleBin.AddGroup(pg, true, true); } catch (Exception) { if (pgRecycleBin.Groups.IndexOf(pg) < 0) { pgParent.AddGroup(pg, true, true); // Undo removal } } pg.Touch(false); } }