public void FromApiDeletedNodeSummary() { // ARRANGE NodeType expectedType = NodeType.File; string expectedTypeValue = "file"; RecycleBinItem expected = FactoryNode.RecycleBinItem; expected.Type = expectedType; ApiDeletedNodeSummary param = new ApiDeletedNodeSummary() { Type = expectedTypeValue, ParentId = expected.ParentId, ParentPath = expected.ParentPath, Name = expected.Name, FirstDeletedAt = expected.FirstDeletedAt, LastDeletedAt = expected.LastDeletedAt, LastDeletedNodeId = expected.LastDeletedNodeId, CntVersions = expected.VersionsCount }; Mock.Arrange(() => EnumConverter.ConvertValueToNodeTypeEnum(expectedTypeValue)).Returns(expectedType); // ACT RecycleBinItem actual = NodeMapper.FromApiDeletedNodeSummary(param); // ASSERT Assert.Equal(expected, actual, new RecycleBinItemComparer()); }
public void FromApiDeletedNodeSummary_Null() { // ARRANGE RecycleBinItem expected = null; ApiDeletedNodeSummary param = null; // ACT RecycleBinItem actual = NodeMapper.FromApiDeletedNodeSummary(param); // ASSERT Assert.Equal(expected, actual, new RecycleBinItemComparer()); }
internal RecycleBinItem GetRecycleBinItem(Microsoft.SharePoint.Client.Site site) { if (Item != null) { return(Item); } if (!_id.HasValue) { return(null); } _item = site.RecycleBin.GetById(_id.Value); site.Context.Load(_item); site.Context.ExecuteQueryRetry(); return(Item); }
internal static RecycleBinItem FromApiDeletedNodeSummary(ApiDeletedNodeSummary apiNode) { if (apiNode == null) { return(null); } RecycleBinItem node = new RecycleBinItem { Type = EnumConverter.ConvertValueToNodeTypeEnum(apiNode.Type), ParentId = apiNode.ParentId, ParentPath = apiNode.ParentPath, Name = apiNode.Name, FirstDeletedAt = apiNode.FirstDeletedAt, LastDeletedAt = apiNode.LastDeletedAt, LastDeletedNodeId = apiNode.LastDeletedNodeId, VersionsCount = apiNode.CntVersions }; return(node); }
private void RestoreList(String title, SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { // Check to see that a user hasn't manually deleted the list from the Recycle Bin RecycleBinItemCollection bin = clientContext.Web.RecycleBin; IEnumerable <RecycleBinItem> matchingItems = clientContext.LoadQuery(bin.Where(item => item.Title == title)); clientContext.ExecuteQuery(); RecycleBinItem recycledList = matchingItems.FirstOrDefault(); // If it is there, restore it. if (recycledList != null) { recycledList.Restore(); clientContext.ExecuteQuery(); } } } }
public void Restore() { RecycleBinItem.Restore(); this.Remove(); }
public RecycleBinItemPipeBind(RecycleBinItem item) { _item = item; }
public RecycleBinItemPipeBind() { _item = null; _id = null; }
private string TryRecycleList(String listTitle, SPRemoteEventProperties properties) { string errorMessage = String.Empty; using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { // Get references to all the objects you are going to need. ListCollection allLists = clientContext.Web.Lists; IEnumerable <List> matchingLists = clientContext.LoadQuery(allLists.Where(list => list.Title == listTitle)); RecycleBinItemCollection bin = clientContext.Web.RecycleBin; IEnumerable <RecycleBinItem> matchingRecycleBinItems = clientContext.LoadQuery(bin.Where(item => item.Title == listTitle)); clientContext.ExecuteQuery(); List foundList = matchingLists.FirstOrDefault(); RecycleBinItem recycledList = matchingRecycleBinItems.FirstOrDefault(); // Delegate the rollback logic to the SharePoint server. ExceptionHandlingScope scope = new ExceptionHandlingScope(clientContext); using (scope.StartScope()) { using (scope.StartTry()) { // Check to see that a user hasn't already recycled the list in the SharePoint UI. // If it is still there, recycle it. ConditionalScope condScope = new ConditionalScope(clientContext, () => foundList.ServerObjectIsNull.Value == false, true); using (condScope.StartScope()) { // Looks crazy to test for nullity inside a test for nullity, // but without this inner test, foundList.Recycle() throws a null reference // exception when the client side runtime is creating the XML to // send to the server. if (foundList != null) { foundList.Recycle(); } } // To test that your StartCatch block runs, uncomment the following two lines // and put them somewhere in the StartTry block. //List fakeList = clientContext.Web.Lists.GetByTitle("NoSuchList"); //clientContext.Load(fakeList); } using (scope.StartCatch()) { // Check to see that the list is in the Recycle Bin. // A user might have manually deleted the list from the Recycle Bin, // or StartTry block may have errored before it recycled the list. // If it is in the Recycle Bin, restore it. ConditionalScope condScope = new ConditionalScope(clientContext, () => recycledList.ServerObjectIsNull.Value == false, true); using (condScope.StartScope()) { // Another test within a test to avoid a null reference. if (recycledList != null) { recycledList.Restore(); } } } using (scope.StartFinally()) { } } clientContext.ExecuteQuery(); if (scope.HasException) { errorMessage = String.Format("{0}: {1}; {2}; {3}; {4}; {5}", scope.ServerErrorTypeName, scope.ErrorMessage, scope.ServerErrorDetails, scope.ServerErrorValue, scope.ServerStackTrace, scope.ServerErrorCode); } } } return(errorMessage); }