XmlElement GetItemXml(ItemInfo item) { return QueryItem(item.List, item.ListRelativePath); }
protected abstract ItemInfo RenameItemDirectly(ItemInfo item, string newName);
protected override void RemoveItemDirectly(ItemInfo item) { // Item removal modifies the parent element and stores the deletion time to the parent // list; the parent list last modification time will be touched too but because it is // computed from the most recent modification time of any child item we don't set it. var source = GetItemXml(item); var date = DateForNow; var parent = (XmlElement) source.ParentNode; parent.SetAttribute("Modified", date); var list = source.SelectElement("ancestor::List"); list.SetAttribute("Deleted", date); source.Remove(); SaveSite(parent); }
protected abstract void RemoveItemDirectly(ItemInfo item);
void AddCachedItem(ItemInfo item, ItemContainerInfo container = null) { if (container == null) { var path = PathUtility.GetParentPath(item.Path); Info parent; if (!path.IsEmpty() && Cache.TryGetObject(path, out parent)) container = (ItemContainerInfo) parent; } if (container != null) { var list = container as ListInfo; var folder = container as FolderInfo; var items = list != null ? list.ChildItems : folder.ChildItems; if (items != null) { items = items.Concat(new[] { item }).ToList(); if (list != null) list.ChildItems = items; else folder.ChildItems = items; } } }
public void RemoveItem(ItemInfo item) { if (item == null) throw new ArgumentNullException("item"); RemoveCachedItem(item); RemoveItemDirectly(item); }
protected abstract ItemInfo CopyItemDirectly(ItemInfo item, ItemContainerInfo target, bool recurse, string newName);
// Abstract methods modifying the actual SharePoint objects. Their implementation must // return the same raw XML information as the querying methods above. protected abstract XmlElement RawRenameItem(ItemInfo item, string newName);
// Implementation of the ModifyingConnector interface. The methods perform the operation // and use its raw XML result to create a new item similarly to the item getting and // listing methods. protected override ItemInfo RenameItemDirectly(ItemInfo item, string newName) { return CreateItemInfo(item.List, RawRenameItem(item, newName)); }
protected abstract XmlElement RawCopyItem(ItemInfo item, ItemContainerInfo target, bool recurse, string newName);
protected abstract XmlElement RawMoveItem(ItemInfo item, ItemContainerInfo target);
protected override ItemInfo MoveItemDirectly(ItemInfo item, ItemContainerInfo target) { return CreateItemInfo(item.List, RawMoveItem(item, target)); }
protected abstract ItemInfo MoveItemDirectly(ItemInfo item, ItemContainerInfo target);
public ItemInfo CopyItem(ItemInfo item, ItemContainerInfo target, bool recurse, string newName) { if (target == null) throw new ArgumentNullException("target"); var copy = CopyItemDirectly(item, target, recurse, newName); AddCachedItem(copy, target); return copy; }
ItemInfo CreateItemInfo(ListInfo list, string path, XmlElement source) { ItemInfo item; switch (GetItemType(source)) { case ItemType.Common: item = new ItemInfo(list, path); break; case ItemType.File: item = new FileInfo(list, path); ((FileInfo) item).Size = GetFileSize(source); break; default: // case ItemType.Folder: item = new FolderInfo(list, path); ((FolderInfo) item).ChildCount = GetFolderChildCount(source); break; } item.ID = GetItemID(source); item.UniqueID = GetItemUniqueID(source); item.Title = GetItemTitle(source); item.Created = GetItemCreated(source); item.LastModified = GetItemLastModified(source); FinalizeInfo(item, source); return item; }
public ItemInfo MoveItem(ItemInfo item, ItemContainerInfo target) { if (target == null) throw new ArgumentNullException("target"); var moved = MoveItemDirectly(item, target); RemoveCachedItem(item); AddCachedItem(moved, target); return moved; }
protected override ItemInfo CopyItemDirectly(ItemInfo item, ItemContainerInfo target, bool recurse, string newName) { return CreateItemInfo(item.List, RawCopyItem(item, target, recurse, newName)); }
public ItemInfo RenameItem(ItemInfo item, string newName) { if (newName == null) throw new ArgumentNullException("newName"); if (string.IsNullOrEmpty(newName)) throw new ArgumentException("The new item name must not be empty."); Cache.RemoveObject(item); var renamed = RenameItemDirectly(item, newName); AddCachedItem(renamed); return renamed; }
protected override XmlElement RawCopyItem(ItemInfo item, ItemContainerInfo target, bool recurse, string newName) { // Common items have no children and files can have versions as children; we should // always enable deep cloning for those terminal objects not to corrupt them. var deeply = recurse | !(item is FolderInfo); var source = (XmlElement) GetItemXml(item).CloneNode(deeply); var lastID = GetLastItemID(item.List); InitializeItemClones(source, ref lastID); PlaceItemXml(source, target, newName); SaveSite(source); return source; }
protected override XmlElement RawMoveItem(ItemInfo item, ItemContainerInfo container) { // Item move modifies both old and new parent elements but not the moved item itself. // the parent is touched after the item is placed to the new container because that // operation can fail if an item of the same name has been already there. If the item // is moved to other list it needs a new ID unique in the new list. var source = GetItemXml(item); var parent = (XmlElement) source.ParentNode; source.Remove(); var target = GetItemContainerXml(container); PlaceItemXml(source, target); if (!item.List.Path.EqualsCI(container.List.Path)) { var lastID = GetLastItemID(container.List); source.SetAttribute("ID", (++lastID).ToStringI()); } TouchItemXml(parent); TouchItemXml(target); SaveSite(target); return source; }
protected override XmlElement RawRenameItem(ItemInfo item, string newName) { var source = GetItemXml(item); RenameItemXml(source, newName); TouchItemXml(source); SaveSite(source); return source; }
void RemoveCachedItem(ItemInfo item) { Cache.RemoveObject(item); var path = PathUtility.GetParentPath(item.Path); Info container; if (!path.IsEmpty() && Cache.TryGetObject(path, out container)) { var list = container as ListInfo; var folder = container as FolderInfo; var items = list != null ? list.ChildItems : folder.ChildItems; if (items != null) { items = items.Where(current => current.ID != item.ID).ToList(); if (list != null) list.ChildItems = items; else folder.ChildItems = items; } } }