Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 protected abstract bool HasItem(ListInfo list, string path);
Exemplo n.º 5
0
 public FolderInfo(ListInfo list, string path)
     : base(list, path)
 {
 }
Exemplo n.º 6
0
 protected abstract bool HasItem(ListInfo list, string path);
Exemplo n.º 7
0
 protected abstract void RemoveListDirectly(ListInfo list);
Exemplo n.º 8
0
 protected abstract ItemInfo GetItemDirectly(ListInfo list, string path);
Exemplo n.º 9
0
 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);
 }
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 13
0
 protected abstract XmlElement QueryItem(ListInfo list, string path);
Exemplo n.º 14
0
 protected override ItemInfo GetItemDirectly(ListInfo list, string path)
 {
     var fullPath = PathUtility.JoinPath(list.Path, path);
     return CreateItemInfo(list, fullPath, QueryItem(list, path));
 }
Exemplo n.º 15
0
 protected override void RemoveListDirectly(ListInfo list)
 {
     Log.Verbose("Removing list at /{0}.", list.Path);
     GetService <Lists>(list.Web.Path).DeleteList(list.StringID);
 }
Exemplo n.º 16
0
 public FileInfo(ListInfo list, string path) : base(list, path)
 {
 }
Exemplo n.º 17
0
 public FolderInfo(ListInfo list, string path) : base(list, path)
 {
 }
Exemplo n.º 18
0
 protected override void RemoveListDirectly(ListInfo list)
 {
     var source = GetListXml(list);
     var parent = (XmlElement) source.ParentNode;
     source.Remove();
     SaveSite(parent);
 }
Exemplo n.º 19
0
 protected override ItemInfo GetItem(ListInfo list, string path)
 {
     var fullPath = PathUtility.JoinPath(list.Path, path);
     return (ItemInfo) Cache.GetObjectOrDefault(fullPath) ??
                         GetItemDirectly(list, path);
 }
Exemplo n.º 20
0
 int GetLastItemID(ListInfo list)
 {
     var items = GetListXml(list).SelectNodes("//Item").OfType<XmlElement>();
     return items.Any() ? items.Max(item =>
                                     ValueUtility.GetInt(item.GetAttribute("ID"))) : 0;
 }
Exemplo n.º 21
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;
 }
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
 protected abstract ItemInfo GetItem(ListInfo list, string path);
Exemplo n.º 24
0
        protected override ItemInfo GetItemDirectly(ListInfo list, string path)
        {
            var fullPath = PathUtility.JoinPath(list.Path, path);

            return(CreateItemInfo(list, fullPath, QueryItem(list, path)));
        }
Exemplo n.º 25
0
 public FileInfo(ListInfo list, string path)
     : base(list, path)
 {
 }
Exemplo n.º 26
0
 protected abstract XmlElement QueryItem(ListInfo list, string path);
Exemplo n.º 27
0
 public ItemInfo(ListInfo list, string path)
     : base(list, path)
 {
     if (list == null)
         throw new ArgumentNullException("list");
     List = list;
 }
Exemplo n.º 28
0
 protected abstract void RemoveListDirectly(ListInfo list);