ListInfo CreateListInfo(WebInfo web, XmlElement source) { var path = PathUtility.JoinPath(web.Path, GetListName(source)); var list = new ListInfo(web, path); list.ID = GetListID(source); list.Title = GetListTitle(source); list.Created = GetListCreated(source); list.LastModified = GetListLastModified(source); list.LastDeleted = GetListLastDeleted(source); list.ItemCount = GetListItemCount(source); if (HasListFields(source)) { list.Fields = GetListFields(source).ToList(); } if (web.ID.IsEmpty()) { web.ID = GetListWebID(source); } FinalizeInfo(list, source); return(list); }
XmlNode AddCamlFields(XmlDocument input, ListInfo list) { if (list.Fields == null) { list.Fields = QueryFields(list).ToList(); } if (!list.Fields.Any()) { return(null); } var fields = new StringBuilder(); foreach (var field in list.Fields) { fields.AppendFormat(@"<FieldRef Name=""{0}"" />", XmlUtility.EscapeXmlValue(field.Name)); } var view = input.CreateElement("ViewFields"); view.InnerXml = fields.ToString(); return(view); }
protected override XmlElement QueryItem(ListInfo list, string path) { Log.Verbose("Querying item at /{0}/{1}.", list.Path, path); string name; string parent = PathUtility.GetParentPath(path, out name); var input = new XmlDocument(); var query = AddCamlName(input, name); var view = AddCamlFields(input, list); var folder = string.IsNullOrEmpty(parent) ? null : PathUtility.JoinPath(list.WebRelativePath, parent); var options = AddCamlOptions(input, folder); var output = (XmlElement)GetService <Lists>(list.Web.Path).GetListItems( list.StringID, null, query, view, null, options, null); // Pick /listitems/data/row[1]. Avoiding XPath with namespaces. var item = output.ChildNodes.OfType <XmlElement>().First(). ChildNodes.OfType <XmlElement>().FirstOrDefault(); if (item == null) { throw new ApplicationException("No item found."); } return(item); }
protected abstract bool HasItem(ListInfo list, string path);
public FolderInfo(ListInfo list, string path) : base(list, path) { }
protected abstract void RemoveListDirectly(ListInfo list);
protected abstract ItemInfo GetItemDirectly(ListInfo list, string path);
public void RemoveList(ListInfo list) { if (list == null) throw new ArgumentNullException("list"); Cache.RemoveObject(list); if (list.Web.Lists != null) list.Web.Lists = list.Web.Lists.Where(item => item.ID != list.ID).ToList(); RemoveListDirectly(list); }
protected override XmlElement QueryItem(ListInfo list, string path) { var source = GetListXml(list); foreach (var name in PathUtility.SplitPath(path)) { source = source.SelectElement(string.Format("Item[@Name={0}]", XmlUtility.FormatXPathLiteral(name))); if (source == null) throw new ApplicationException("Item not found."); } return source; }
ListInfo CreateListInfo(WebInfo web, XmlElement source) { var path = PathUtility.JoinPath(web.Path, GetListName(source)); var list = new ListInfo(web, path); list.ID = GetListID(source); list.Title = GetListTitle(source); list.Created = GetListCreated(source); list.LastModified = GetListLastModified(source); list.LastDeleted = GetListLastDeleted(source); list.ItemCount = GetListItemCount(source); if (HasListFields(source)) list.Fields = GetListFields(source).ToList(); if (web.ID.IsEmpty()) web.ID = GetListWebID(source); FinalizeInfo(list, source); return list; }
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; }
protected abstract XmlElement QueryItem(ListInfo list, string path);
protected override ItemInfo GetItemDirectly(ListInfo list, string path) { var fullPath = PathUtility.JoinPath(list.Path, path); return CreateItemInfo(list, fullPath, QueryItem(list, path)); }
protected override void RemoveListDirectly(ListInfo list) { Log.Verbose("Removing list at /{0}.", list.Path); GetService <Lists>(list.Web.Path).DeleteList(list.StringID); }
public FileInfo(ListInfo list, string path) : base(list, path) { }
protected override void RemoveListDirectly(ListInfo list) { var source = GetListXml(list); var parent = (XmlElement) source.ParentNode; source.Remove(); SaveSite(parent); }
protected override ItemInfo GetItem(ListInfo list, string path) { var fullPath = PathUtility.JoinPath(list.Path, path); return (ItemInfo) Cache.GetObjectOrDefault(fullPath) ?? GetItemDirectly(list, path); }
int GetLastItemID(ListInfo list) { var items = GetListXml(list).SelectNodes("//Item").OfType<XmlElement>(); return items.Any() ? items.Max(item => ValueUtility.GetInt(item.GetAttribute("ID"))) : 0; }
protected override bool HasItem(ListInfo list, string path) { if (path.EndsWith("/*")) { var parent = PathUtility.JoinPath(list.Path, PathUtility.GetParentPath(path)); if (parent.IsEmpty()) return list.HasChildren(); } var fullPath = PathUtility.JoinPath(list.Path, path); if (Cache.GetObjectOrDefault(fullPath) == null) try { var container = GetItemDirectly(list, path) as ContainerInfo; if (container == null) return false; return container.HasChildren(); } catch { return false; } return true; }
XmlElement GetListXml(ListInfo list) { var source = GetWebXml(list.Web); source = source.SelectElement(string.Format("List[@Name={0}]", XmlUtility.FormatXPathLiteral(list.WebRelativePath))); if (source == null) throw new ApplicationException("List not found."); return source; }
protected abstract ItemInfo GetItem(ListInfo list, string path);
protected override ItemInfo GetItemDirectly(ListInfo list, string path) { var fullPath = PathUtility.JoinPath(list.Path, path); return(CreateItemInfo(list, fullPath, QueryItem(list, path))); }
public ItemInfo(ListInfo list, string path) : base(list, path) { if (list == null) throw new ArgumentNullException("list"); List = list; }