protected override SubmitCompletedResult EndSubmitCore(IAsyncResult asyncResult) { // Maybe assert expected type if (this.Error != null) { throw this.Error; } this.Submitted = true; AdcSubmitAsyncResult result = asyncResult as AdcSubmitAsyncResult; result.SubmitOperations.First().Entity = result.User; result.Submit(this.SubmitConflictMembers, this.SubmitErrors, this.SubmitValidationErrors); SubmitCompletedResult results = new SubmitCompletedResult(result.ChangeSet, result.SubmitOperations); return(results); }
protected override Task <SubmitCompletedResult> SubmitAsyncCore(EntityChangeSet changeSet, CancellationToken cancellationToken) { Assert.AreEqual(0, changeSet.AddedEntities.Count, "Change set should not contained added entities."); Assert.IsFalse(changeSet.IsEmpty, "Change set should not be empty."); Assert.AreEqual(1, changeSet.ModifiedEntities.Count, "Change set should contain a single modified entity."); Assert.AreEqual(0, changeSet.RemovedEntities.Count, "Change set should not contained removed entities."); ChangeSetEntry[] submitOperations = changeSet.GetChangeSetEntries().ToArray(); Assert.AreEqual(1, submitOperations.Length, "A single submit operation is expected."); MockUser userToSubmit = (MockUser)submitOperations[0].Entity; MockUser userToReturn = new MockUser() { Name = userToSubmit.Name, Type = UserType.Saved }; List <ChangeSetEntry> submitOperationsToReturn = new List <ChangeSetEntry>(); submitOperationsToReturn.Add(new ChangeSetEntry(userToReturn, submitOperations[0].Id, submitOperations[0].Operation)); AsyncCallback completeCallback = (asyncResult) => { var tcs = (TaskCompletionSource <SubmitCompletedResult>)asyncResult.AsyncState; // Maybe assert expected type if (this.Error != null) { tcs.SetException(this.Error); } else if (this.CancellationRequested) { tcs.SetCanceled(); } else { this.Submitted = true; AdcSubmitAsyncResult result = asyncResult as AdcSubmitAsyncResult; result.SubmitOperations.First().Entity = result.User; result.Submit(this.SubmitConflictMembers, this.SubmitErrors, this.SubmitValidationErrors); SubmitCompletedResult results = new SubmitCompletedResult(result.ChangeSet, result.SubmitOperations); tcs.SetResult(results); } }; var taskCompletionSource = new TaskCompletionSource <SubmitCompletedResult>(); this.Result = new AdcSubmitAsyncResult(changeSet, submitOperationsToReturn, userToReturn, completeCallback, taskCompletionSource); cancellationToken.Register(res => { this.CancellationRequested = true; }, this.Result); return(taskCompletionSource.Task); }