public void SpSyncAnchorConstructorTest3() { string changeToken = string.Empty; // TODO: Initialize to an appropriate value SpSyncAnchor target = new SpSyncAnchor(changeToken); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void NextChangesAnchorTest() { SpSyncAnchor target = new SpSyncAnchor(); // TODO: Initialize to an appropriate value SpSyncAnchor expected = null; // TODO: Initialize to an appropriate value SpSyncAnchor actual; target.NextChangesAnchor = expected; actual = target.NextChangesAnchor; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void PagingTokenTest() { SpSyncAnchor target = new SpSyncAnchor(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; target.PagingToken = expected; actual = target.PagingToken; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void NextChangesTokenTest() { SpSyncAnchor target = new SpSyncAnchor(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; target.NextChangesToken = expected; actual = target.NextChangesToken; Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
/// #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)); }
/// <summary> /// Calculates the next SpSyncAnchor from the current SpSyncAnchor object and the change batch just returned from the server /// </summary> /// <param name="currentAnchor">the current SpSyncAnchor object</param> /// <param name="nextPageToken">the next page token given from sharepoint</param> /// <returns>the new SpSyncAnchor for the next incremental select</returns> protected SpSyncAnchor CalculateNextAnchor(SpSyncAnchor currentAnchor, string nextPageToken) { SpSyncAnchor nextChanges = SpSyncAnchor.Empty; SpSyncAnchor nextAnchor = nextChanges; if (nextPageToken != null) { nextAnchor = new SpSyncAnchor(currentAnchor.NextChangesToken, nextPageToken); nextAnchor.NextChangesAnchor = nextChanges; } return(nextAnchor); }
/// <summary> /// Calculates the next SpSyncAnchor from the current SpSyncAnchor object and the change batch just returned from the server /// </summary> /// <param name="currentAnchor">the current SpSyncAnchor object</param> /// <param name="changes"> the ChangeBatch object</param> /// <returns>the new SpSyncAnchor for the next incremental select</returns> protected SpSyncAnchor CalculateNextAnchor(SpSyncAnchor currentAnchor, ChangeBatch changes) { SpSyncAnchor nextChanges = currentAnchor.NextChangesAnchor ?? new SpSyncAnchor(changes.NextChangeBatch, null); SpSyncAnchor nextAnchor = nextChanges; if (changes.HasMoreData()) { nextAnchor = new SpSyncAnchor(currentAnchor.NextChangesToken, changes.NextPage); nextAnchor.NextChangesAnchor = nextChanges; } nextAnchor.HasMoreData = changes.HasMoreChanges(); return(nextAnchor); }
/// #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); }
/// #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)); }
/// #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> /// Calculates the next SpSyncAnchor from the current SpSyncAnchor object and the change batch just returned from the server /// </summary> /// <param name="currentAnchor">the current SpSyncAnchor object</param> /// <param name="changes"> the ChangeBatch object</param> /// <returns>the new SpSyncAnchor for the next incremental select</returns> protected SpSyncAnchor CalculateNextAnchor(SpSyncAnchor currentAnchor, ChangeBatch changes) { SpSyncAnchor nextChanges = currentAnchor.NextChangesAnchor ?? new SpSyncAnchor(changes.NextChangeBatch, null); SpSyncAnchor nextAnchor = nextChanges; if (changes.HasMoreData()) { nextAnchor = new SpSyncAnchor(currentAnchor.NextChangesToken, changes.NextPage); nextAnchor.NextChangesAnchor = nextChanges; } nextAnchor.HasMoreData = changes.HasMoreChanges(); return nextAnchor; }
public void SpSyncAnchorConstructorTest() { string changeToken = string.Empty; // TODO: Initialize to an appropriate value string pageToken = string.Empty; // TODO: Initialize to an appropriate value SpSyncAnchor target = new SpSyncAnchor(changeToken, pageToken); Assert.Inconclusive("TODO: Implement code to verify target"); }
/// <summary> /// Calculates the next SpSyncAnchor from the current SpSyncAnchor object and the change batch just returned from the server /// </summary> /// <param name="currentAnchor">the current SpSyncAnchor object</param> /// <param name="nextPageToken">the next page token given from sharepoint</param> /// <returns>the new SpSyncAnchor for the next incremental select</returns> protected SpSyncAnchor CalculateNextAnchor(SpSyncAnchor currentAnchor, string nextPageToken) { SpSyncAnchor nextChanges = SpSyncAnchor.Empty; SpSyncAnchor nextAnchor = nextChanges; if (nextPageToken != null) { nextAnchor = new SpSyncAnchor(currentAnchor.NextChangesToken, nextPageToken); nextAnchor.NextChangesAnchor = nextChanges; } return nextAnchor; }
public void SpSyncAnchorConstructorTest2() { SpSyncAnchor target = new SpSyncAnchor(); Assert.Inconclusive("TODO: Implement code to verify target"); }
/// <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); }
/// <summary> /// Enumerates the changes from the server and puts them to the synccontext object /// </summary> /// <param name="groupMetadata">the metadata about the synchronization tables</param> /// <param name="syncSession">the object that contains synchronization variables</param> /// <param name="syncContext">the synchronization context to be changed</param> /// <param name="schema">the schema of the synchronization tables</param> private void EnumerateChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession, SyncContext syncContext, SyncSchema schema) {//#DOWNLOAD a batch 2 SyncStage syncStage = SyncStage.DownloadingChanges; SpSyncGroupAnchor newSyncAnchor = new SpSyncGroupAnchor(); bool hasMoreData = false; foreach (SyncTableMetadata tableMetadata in groupMetadata.TablesMetadata) { SpSyncAdapter adapter = null; if (this.SyncAdapters.Contains(tableMetadata.TableName)) { adapter = this.SyncAdapters[tableMetadata.TableName]; } if (adapter == null) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Messages.InvalidTableName, tableMetadata.TableName)); } if (!schema.SchemaDataSet.Tables.Contains(tableMetadata.TableName)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Messages.TableNotInSchema, tableMetadata.TableName)); } DataTable dataTable = schema.SchemaDataSet.Tables[tableMetadata.TableName].Clone(); SyncTableProgress tableProgress = syncContext.GroupProgress.FindTableProgress(tableMetadata.TableName); SpSyncAnchor tableAnchor = SpSyncAnchor.Empty; if (tableMetadata.LastReceivedAnchor != null && tableMetadata.LastReceivedAnchor.Anchor != null) { SpSyncGroupAnchor anchors = SpSyncGroupAnchor.Deserialize(tableMetadata.LastReceivedAnchor.Anchor); if (anchors != null) { if (anchors.Contains(connString, tableMetadata.TableName)) { tableAnchor = anchors[connString, tableMetadata.TableName]; } newSyncAnchor = anchors; } } SpSyncAnchor newAnchor = SpSyncAnchor.Empty; try { if (tableMetadata.SyncDirection == SyncDirection.Snapshot) { newAnchor = adapter.SelectAll(tableAnchor, BatchSize, dataTable, Connection); } else { newAnchor = adapter.SelectIncremental(tableAnchor, BatchSize, Connection, dataTable); } hasMoreData = hasMoreData || newAnchor.HasMoreData; if (syncContext.DataSet.Tables.Contains(tableMetadata.TableName)) { DataTable contextTable = syncContext.DataSet.Tables[tableMetadata.TableName]; foreach (DataRow row in dataTable.Rows) { contextTable.ImportRow(row); } } else { dataTable.TableName = tableMetadata.TableName; syncContext.DataSet.Tables.Add(dataTable); } } catch (Exception e) { var e2 = new Microsoft.Synchronization.SyncException(e.Message, e); throw e2; } finally { newSyncAnchor[connString, tableMetadata.TableName] = newAnchor; } tableProgress.DataTable = dataTable; SyncProgressEventArgs args = new SyncProgressEventArgs(tableMetadata, tableProgress, groupMetadata, syncContext.GroupProgress, syncStage);//SYNC TODO OnSyncProgress(args); tableProgress.DataTable = null; } syncContext.NewAnchor = new SyncAnchor(); syncContext.NewAnchor.Anchor = SpSyncGroupAnchor.Serialize(newSyncAnchor); int batchCount = groupMetadata.BatchCount == 0 ? 1 : groupMetadata.BatchCount; if (hasMoreData) { syncContext.BatchCount = batchCount + 1; } else { syncContext.BatchCount = batchCount; } }