public ListItemCollection GetListItems(string listName, string viewName, string query, IEnumerable<string> viewFields, bool splitMetaInfo, int rowLimit, QueryOptions queryOptions) { if (String.IsNullOrEmpty(listName)) throw new ArgumentNullException("listName"); XmlDocument viewDoc = new XmlDocument(); XmlElement viewFieldsNode = viewDoc.CreateElement("ViewFields"); if (splitMetaInfo) viewFieldsNode.SetAttribute("Properties", "TRUE"); foreach (string field in viewFields) { XmlElement fieldRef = viewDoc.CreateElement("FieldRef"); fieldRef.SetAttribute("Name", field); viewFieldsNode.AppendChild(fieldRef); } XmlDocument queryDoc = null; if (!String.IsNullOrEmpty(query)) { queryDoc = new XmlDocument(); queryDoc.LoadXml(query); } XmlNode response = listService.GetListItems( listName, viewName, queryDoc, viewFieldsNode, rowLimit.ToString(), queryOptions.GetCamlQueryOptions(), null); return response.GetXElement().GetCamlListItems(); }
public ChangeBatch GetListItemChangesSinceToken( string listName, string viewName, string query, IEnumerable<string> viewFields, bool splitMetaInfo, int rowLimit, QueryOptions queryOptions, string changeToken) { if (String.IsNullOrEmpty(listName)) throw new ArgumentNullException("listName"); XmlDocument viewDoc = new XmlDocument(); XmlElement viewFieldsNode = viewDoc.CreateElement("ViewFields"); if (splitMetaInfo) viewFieldsNode.SetAttribute("Properties", "TRUE"); foreach (string field in viewFields) { XmlElement fieldRef = viewDoc.CreateElement("FieldRef"); fieldRef.SetAttribute("Name", field); viewFieldsNode.AppendChild(fieldRef); } XmlDocument queryDoc = null; if (!String.IsNullOrEmpty(query)) { queryDoc = new XmlDocument(); queryDoc.LoadXml(query); } XmlNode response = listService.GetListItemChangesSinceToken( listName, viewName, queryDoc, viewFieldsNode, rowLimit.ToString(), queryOptions.GetCamlQueryOptions(), changeToken, null); ChangeBatch batch = response.GetXElement().GetCamlChangeBatch(); // catch the case where no changes in list returns the same token if (batch.ChangeLog.Count == 0 && batch.NextChangeBatch == changeToken) { // re-query with empty token in order to get the very latest change token // and avoid token expiration XmlNode dummyResponse = listService.GetListItemChangesSinceToken( listName, viewName, queryDoc, viewFieldsNode, "10", queryOptions.GetCamlQueryOptions(), null, null); ChangeBatch batch2 = response.GetXElement().GetCamlChangeBatch(); batch.ChangeLog.NextLastChangeToken = batch2.ChangeLog.NextLastChangeToken; } return batch; }
/// <summary> /// Fills the tables insertTbl, updateTbl, deleteTbl with the changes fetch by the sharepoint server /// since a change token /// </summary> /// <param name="anchor">the anchor to specify the change token</param> /// <param name="rowLimit">the maximum number of rows to fetch </param> /// <param name="connection">the connection to the sharepoint server</param> /// <param name="insertTbl">the DataTable to append the rows that have been inserted</param> /// <param name="updateTbl">the DataTable to append the rows that have been updated</param> /// <param name="deleteTbl">the DataTable to append the rows that have been deleted</param> /// <remarks> /// Because of the response of the sharepoint changelog we cannot identify the updates from the inserts. /// So, no record will be added to the updateTbl. /// </remarks> /// <returns>the new SpSyncAnchor object to be used in subsequent calls</returns> /// #DOWNLOAD public SpSyncAnchor SelectIncremental(SpSyncAnchor anchor, int rowLimit, SpConnection connection, DataTable insertTbl, DataTable updateTbl, DataTable deleteTbl) { if (anchor == null) throw new ArgumentNullException("anchor"); if (connection == null) throw new ArgumentNullException("connection"); QueryOptions queryOptions = new QueryOptions() { PagingToken = anchor.PagingToken, DateInUtc = false }; IEnumerable<string> viewFields = GetViewFields(); ChangeBatch changes = connection.GetListItemChangesSinceToken( this.ListName, this.ViewName, FilterClause, viewFields, IncludeProperties, rowLimit, queryOptions, anchor.NextChangesToken); if (insertTbl != null) { foreach (ListItem item in changes.ChangedItems) { DataRow row = insertTbl.NewRow(); Exception e; MapListItemToDataRow(item, row, out e); if (e != null) { if (SyncTracer.IsErrorEnabled()) SyncTracer.Error(e.ToString()); } insertTbl.Rows.Add(row); } } // FIX: Cannot identify the updates from the inserts. if (deleteTbl != null) { foreach (ChangeItem item in changes.ChangeLog) { if (ChangeCommands.IsDelete(item.Command)) { DataRow row = deleteTbl.NewRow(); // FIX: Probably the ID is not mapped at all to the client table row[deleteTbl.PrimaryKey[0]] = item.ListItemID; deleteTbl.Rows.Add(row); } } } insertTbl.AcceptChanges(); // COMMITCHANGES updateTbl.AcceptChanges(); deleteTbl.AcceptChanges(); return CalculateNextAnchor(anchor, changes); }
/// #DOWNLOAD public SpSyncAnchor SelectIncremental(SpSyncAnchor anchor, int rowLimit, SpConnection connection, DataTable changeTable) { //#DOWNLOAD in batches - step 3 if (anchor == null) throw new ArgumentNullException("anchor"); if (connection == null) throw new ArgumentNullException("connection"); QueryOptions queryOptions = new QueryOptions() { PagingToken = anchor.PagingToken, DateInUtc = false }; IEnumerable<string> viewFields = GetViewFields(); ChangeBatch changes = connection.GetListItemChangesSinceToken( this.ListName, this.ViewName, FilterClause, viewFields, IncludeProperties, rowLimit, queryOptions, anchor.NextChangesToken); foreach (ListItem item in changes.ChangedItems) { DataRow row = changeTable.NewRow(); Exception e; MapListItemToDataRow(item, row, out e); if (e != null) { if (SyncTracer.IsErrorEnabled()) SyncTracer.Error(e.ToString()); } changeTable.Rows.Add(row); row.AcceptChanges(); row.SetModified(); } foreach (ChangeItem item in changes.ChangeLog) { string clientColumnName = GetClientColumnFromServerColumn("ID"); if (ChangeCommands.IsDelete(item.Command)) { DataRow row = changeTable.NewRow(); // FIX: Probably the ID is not mapped at all to the client table row[clientColumnName] = item.ListItemID; changeTable.Rows.Add(row); row.AcceptChanges(); row.Delete(); } } return CalculateNextAnchor(anchor, changes); }
/// #DOWNLOAD (not in batches) public SpSyncAnchor SelectAll(SpSyncAnchor anchor, int rowLimit, DataTable dataTable, SpConnection connection) { if (anchor == null) throw new ArgumentNullException("anchor"); if (connection == null) throw new ArgumentNullException("connection"); if (dataTable == null) throw new ArgumentNullException("dataTable"); QueryOptions queryOptions = new QueryOptions() { PagingToken = anchor.PagingToken, DateInUtc = false }; IEnumerable<string> viewFields = GetViewFields(); ListItemCollection listItems = connection.GetListItems( this.ListName, this.ViewName, this.FilterClause, viewFields, IncludeProperties, rowLimit, queryOptions); if (dataTable != null) { foreach (ListItem item in listItems) { DataRow row = dataTable.NewRow(); Exception e; MapListItemToDataRow(item, row, out e); if (e != null) { if (SyncTracer.IsErrorEnabled()) SyncTracer.Error(e.ToString()); } dataTable.Rows.Add(row); } } dataTable.AcceptChanges(); return CalculateNextAnchor(anchor, listItems.NextPage); }