/// #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); }
/// <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); }