Beispiel #1
0
        /// <summary>
        /// Parses the items.
        /// </summary>
        /// <param name="rawListItems">The raw list items.</param>
        /// <returns>A parsed list of tasks</returns>
        internal static Collection <SharePointListItem> ParseItems(XContainer rawListItems)
        {
            if (rawListItems == null)
            {
                throw new ArgumentNullException("rawListItems");
            }

            XNamespace nameSpace = "#RowsetSchema";
            Collection <SharePointListItem> listItems = new Collection <SharePointListItem>();

            foreach (XElement row in rawListItems.Descendants(nameSpace + "row"))
            {
                SharePointListItem task = new SharePointListItem()
                {
                    DisplayName = row.GetRowAttributeValue("ows_Title"),
                    AuthorId    = row.GetRowAttributeValue("ows_Author"),
                };

                if ((row.Attribute("ows_ID") != null && (string.IsNullOrEmpty(row.Attribute("ows_ID").Value) == false)))
                {
                    task.Id = row.Attribute("ows_ID").Value;
                    TraceManager.TraceInformation("\t{0}", task.Id);
                }

                TraceManager.TraceInformation("\tDebugging information:{0}", row.Attribute("ows_Created").Value);
                TraceManager.TraceInformation("\t{0}", row.Attribute("ows_Modified").Value);

                if (string.IsNullOrEmpty(row.Attribute("ows_Modified").Value) == false)
                {
                    DateTime value;
                    if (DateTime.TryParseExact(row.Attribute("ows_Modified").Value, "yyyy-MM-dd hh:mm:ss", CultureInfo.CurrentCulture, DateTimeStyles.None, out value))
                    {
                        task.ModifiedOn = value;
                    }
                }

                TraceManager.TraceInformation("\t{0}", task.ModifiedOn);

                foreach (XAttribute attribute in row.Attributes())
                {
                    if (attribute.Name.Equals("ows_ID") ||
                        attribute.Name.Equals("ows_Title") ||
                        attribute.Name.Equals("ows_Modified") ||
                        attribute.Name.Equals("ows_Author"))
                    {
                        // already parsed so we don't need to do it again
                        continue;
                    }

                    string name = attribute.Name.LocalName.Remove(0, 4); // remove ows_
                    name = name.Replace("_", string.Empty).Replace("x0020", string.Empty);
                    task.Columns.Add(name, attribute.Value);
                }

                listItems.Add(task);
            }

            return(listItems);
        }
Beispiel #2
0
        /// <summary>
        /// Creates the field revision description doc.
        /// </summary>
        /// <param name="task">The task.</param>
        /// <returns></returns>
        private static XmlDocument CreateFieldRevisionDescriptionDoc(SharePointListItem task)
        {
            XElement columns = new XElement("Columns",
                                            new XElement("Column",
                                                         new XAttribute("DisplayName", "Author"),
                                                         new XAttribute("ReferenceName", "Author"),
                                                         new XAttribute("Type", "String"),
                                                         new XElement("Value", task.AuthorId)),
                                            new XElement("Column",
                                                         new XAttribute("DisplayName", "DisplayName"),
                                                         new XAttribute("ReferenceName", "DisplayName"),
                                                         new XAttribute("Type", "String"),
                                                         new XElement("Value", task.DisplayName)),
                                            new XElement("Column",
                                                         new XAttribute("DisplayName", "Id"),
                                                         new XAttribute("ReferenceName", "Id"),
                                                         new XAttribute("Type", "String"),
                                                         new XElement("Value", task.Id.ToString())));

            foreach (KeyValuePair <string, object> column in task.Columns)
            {
                columns.Add(new XElement("Column",
                                         new XAttribute("DisplayName", column.Key),
                                         new XAttribute("ReferenceName", column.Key),
                                         new XAttribute("Type", "String"),
                                         new XElement("Value", column.Value)));
            }

            XElement descriptionDoc = new XElement("WorkItemChanges",
                                                   new XAttribute("Revision", "0"),
                                                   new XAttribute("WorkItemType", "SharePointItem"),
                                                   new XAttribute("Author", task.AuthorId),
                                                   new XAttribute("ChangeDate", task.ModifiedOn.ToString(CultureInfo.CurrentCulture)),
                                                   new XAttribute("WorkItemID", task.Id.ToString()),
                                                   columns);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(descriptionDoc.ToString());
            return(doc);
        }