static private CreateSyncRequest ( string syncKey, string collectionId, List | ||
syncKey | string | Specify the sync key obtained from the last sync response. |
collectionId | string | Specify the server ID of the folder to be synchronized. |
data | List | Contains the data used to specify the Change element for Sync command. |
return | SyncRequest |
/// <summary> /// Call Sync command to add a task. /// </summary> /// <param name="addElements">The elements of a task item to be added.</param> /// <returns>Return the sync response.</returns> protected SyncStore SyncAddTask(Dictionary <Request.ItemsChoiceType8, object> addElements) { SyncStore initializeSyncResponse = this.TASKAdapter.Sync(Common.CreateInitialSyncRequest(this.UserInformation.TasksCollectionId)); // Verify sync result Site.Assert.AreEqual <byte>( 1, initializeSyncResponse.CollectionStatus, "The server should return a status code 1 in the Sync command response to indicate the Sync command executes successfully."); Dictionary <Request.ItemsChoiceType8, object> task = TestSuiteHelper.CreateTaskElements(); // Add elements if (addElements != null) { foreach (KeyValuePair <Request.ItemsChoiceType8, object> item in addElements) { if (task.ContainsKey(item.Key)) { task[item.Key] = item.Value; } else { task.Add(item.Key, item.Value); } } } List <object> addData = new List <object>(); Request.SyncCollectionAdd add = new Request.SyncCollectionAdd { ClientId = System.Guid.NewGuid().ToString(), ApplicationData = new Request.SyncCollectionAddApplicationData { Items = task.Values.ToArray <object>(), ItemsElementName = task.Keys.ToArray <Request.ItemsChoiceType8>() } }; addData.Add(add); SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(initializeSyncResponse.SyncKey, this.UserInformation.TasksCollectionId, addData); SyncStore syncResponse = this.TASKAdapter.Sync(syncRequest); Site.Assert.AreEqual <byte>( 1, syncResponse.CollectionStatus, "The server should return a Status 1 in the Sync command response indicate sync command succeed."); Site.Assert.IsNotNull( syncResponse.AddResponses, @"The Add elements in Responses element of the Sync response should not be null."); return(syncResponse); }
/// <summary> /// Call Sync command to delete a task. /// </summary> /// <param name="syncKey">The sync key.</param> /// <param name="serverId">The server id of the task, which is returned by server.</param> /// <returns>Return the sync delete result.</returns> protected SyncStore SyncDeleteTask(string syncKey, string serverId) { List <object> deleteData = new List <object>(); Request.SyncCollectionDelete delete = new Request.SyncCollectionDelete { ServerId = serverId }; deleteData.Add(delete); SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(syncKey, this.UserInformation.TasksCollectionId, deleteData); SyncStore syncResponse = this.TASKAdapter.Sync(syncRequest); return(syncResponse); }
/// <summary> /// Synchronize changes between client and server. /// </summary> /// <param name="collectionId">Specify the folder collection Id which needs to be synchronized.</param> /// <returns>Return the sync response.</returns> public SyncStore SyncChanges(string collectionId) { SyncStore syncResponse; int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); int counter = 0; // Synchronize to get the SyncKey. SyncStore initializeSyncResponse = this.TASKAdapter.Sync(Common.CreateInitialSyncRequest(collectionId)); SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(initializeSyncResponse.SyncKey, collectionId, null); do { Thread.Sleep(waitTime); // Get the server changes through sync command. syncResponse = this.TASKAdapter.Sync(syncRequest); if (syncResponse != null) { if (syncResponse.CollectionStatus == 1) { break; } } counter++; }while (counter < retryCount); // Verify sync response Site.Assert.AreEqual <byte>( 1, syncResponse.CollectionStatus, "If the Sync command executes successfully, the Status in response should be 1."); return(syncResponse); }