/// <summary> /// Empties the trash can /// </summary> /// <param name="itemDeletedCallback">a function to call whenever an item is removed from the bin</param> public void CallTheGarbageMan(Action <int> itemDeletedCallback) { lock (m_Locker) { //first, move all nodes underneath the recycle bin directly under the recycle bin node (flatten heirarchy) //then delete them all. SqlHelper.ExecuteNonQuery("UPDATE umbracoNode SET parentID=@parentID, level=1 WHERE path LIKE '%," + ((int)m_BinType).ToString() + ",%'", SqlHelper.CreateParameter("@parentID", (int)m_BinType)); foreach (var c in Children.ToList()) { switch (m_BinType) { case RecycleBinType.Content: new Document(c.Id).delete(true); itemDeletedCallback(RecycleBin.Count(m_BinType)); break; case RecycleBinType.Media: new Media(c.Id).delete(true); itemDeletedCallback(RecycleBin.Count(m_BinType)); break; } } } }
private void emptyTrashCanDo(RecycleBin.RecycleBinType type) { var trashCan = new RecycleBin(type); var callback = new Action<int>(x => { Application.Lock(); Application["trashcanEmptyLeft"] = x.ToString(); Application.UnLock(); }); trashCan.CallTheGarbageMan(callback); }
public void EmptyTrashcan(RecycleBin.RecycleBinType type) { //validate against the app type! switch (type) { case RecycleBin.RecycleBinType.Content: if (!AuthorizeRequest(DefaultApps.content.ToString())) return; break; case RecycleBin.RecycleBinType.Media: if (!AuthorizeRequest(DefaultApps.media.ToString())) return; break; default: throw new ArgumentOutOfRangeException("type"); } //TODO: This will never work in LB scenarios Application["trashcanEmptyLeft"] = RecycleBin.Count(type).ToString(); emptyTrashCanDo(type); }
/// <summary> /// If I smell, I'm not empty /// </summary> public bool Smells() { return(RecycleBin.Count(m_BinType) > 0); }
public void Document_Empty_Recycle_Bin() { var docList = new List<Document>(); var total = 20; var dt = m_ExistingDocType; //allow the doc type to be created underneath itself dt.AllowedChildContentTypeIDs = new int[] { dt.Id }; dt.Save(); //create 20 content nodes underneath each other, this will test deleting with heirarchy as well var lastParentId = -1; for (var i = 0; i < total; i++) { var newDoc = Document.MakeNew("R-" + i.ToString() + Guid.NewGuid().ToString("N"), dt, m_User, lastParentId); docList.Add(newDoc); Assert.IsTrue(docList[docList.Count - 1].Id > 0); Assert.AreEqual(lastParentId, newDoc.ParentId); lastParentId = newDoc.Id; } //now delete all of them, since they are nested, we only need to delete one docList.First().delete(); //a callback action for each item removed from the recycle bin var totalDeleted = 0; var bin = new RecycleBin(RecycleBin.RecycleBinType.Content); var totalTrashedItems = bin.GetDescendants().Cast<object>().Count(); bin.CallTheGarbageMan(x => { Assert.AreEqual(totalTrashedItems - (++totalDeleted), x); }); Assert.AreEqual(0, RecycleBin.Count(RecycleBin.RecycleBinType.Content)); }
public void Media_Empty_Recycle_Bin() { //System.Diagnostics.Debugger.Break(); var mediaList = new List<Media>(); var total = 20; var mt = m_ExistingMediaType; //allow the doc type to be created underneath itself mt.AllowedChildContentTypeIDs = new int[] { mt.Id }; mt.Save(); //create 20 media nodes underneath each other, this will test deleting with heirarchy as well var lastParentId = -1; for (var i = 0; i < total; i++) { var newMedia = Media.MakeNew("R-" + i.ToString() + Guid.NewGuid().ToString("N"), mt, m_User, lastParentId); mediaList.Add(newMedia); Assert.IsTrue(mediaList[mediaList.Count - 1].Id > 0); Assert.AreEqual(lastParentId, newMedia.ParentId); lastParentId = newMedia.Id; } //now delete all of them, since they are nested, we only need to delete one mediaList.First().delete(); //a callback action for each item removed from the recycle bin var totalDeleted = 0; var bin = new RecycleBin(RecycleBin.RecycleBinType.Media); var totalTrashedItems = bin.GetDescendants().Cast<object>().Count(); bin.CallTheGarbageMan(x => { Assert.AreEqual(totalTrashedItems - (++totalDeleted), x); }); Assert.AreEqual(0, RecycleBin.Count(RecycleBin.RecycleBinType.Media)); }