public async Task <JobInfoResult> CreateJobAsync(string objectName, BulkConstants.OperationType operationType) { if (string.IsNullOrEmpty(objectName)) { throw new ArgumentNullException("objectName"); } var jobInfo = new JobInfo { ContentType = "XML", Object = objectName, Operation = operationType.Value() }; return(await _xmlHttpClient.HttpPostAsync <JobInfoResult>(jobInfo, "/services/async/{0}/job")); }
public async Task <List <BatchResultList> > RunJobAndPollAsync <T>(string objectName, BulkConstants.OperationType operationType, IEnumerable <ISObjectList <T> > recordsLists) { const float pollingStart = 1000; const float pollingIncrease = 2.0f; var batchInfoResults = await RunJobAsync(objectName, operationType, recordsLists); var currentPoll = pollingStart; var finishedBatchInfoResults = new List <BatchInfoResult>(); while (batchInfoResults.Count > 0) { var removeList = new List <BatchInfoResult>(); foreach (var batchInfoResult in batchInfoResults) { var batchInfoResultNew = await PollBatchAsync(batchInfoResult); if (batchInfoResultNew.State.Equals(BulkConstants.BatchState.Completed.Value()) || batchInfoResultNew.State.Equals(BulkConstants.BatchState.Failed.Value()) || batchInfoResultNew.State.Equals(BulkConstants.BatchState.NotProcessed.Value())) { finishedBatchInfoResults.Add(batchInfoResultNew); removeList.Add(batchInfoResult); } } foreach (var removeItem in removeList) { batchInfoResults.Remove(removeItem); } await Task.Delay((int)currentPoll); currentPoll *= pollingIncrease; } var batchResults = new List <BatchResultList>(); foreach (var batchInfoResultComplete in finishedBatchInfoResults) { batchResults.Add(await GetBatchResultAsync(batchInfoResultComplete)); } return(batchResults); }
// BULK METHODS public async Task <List <BatchInfoResult> > RunJobAsync <T>(string objectName, BulkConstants.OperationType operationType, IEnumerable <ISObjectList <T> > recordsLists) { if (recordsLists == null) { throw new ArgumentNullException("recordsLists"); } var jobInfoResult = await CreateJobAsync(objectName, operationType); var batchResults = new List <BatchInfoResult>(); foreach (var recordList in recordsLists) { batchResults.Add(await CreateJobBatchAsync(jobInfoResult, recordList)); } await CloseJobAsync(jobInfoResult); return(batchResults); }