public async Task <List <BatchInfoResult> > RunJobAsync <T>(string objectName, string externalIdFieldName,
                                                                    BulkConstants.OperationType operationType, IEnumerable <ISObjectList <T> > recordsLists)
        {
            if (recordsLists == null)
            {
                throw new ArgumentNullException("recordsLists");
            }

            if (operationType == BulkConstants.OperationType.Upsert && string.IsNullOrEmpty(externalIdFieldName))
            {
                throw new ArgumentNullException(nameof(externalIdFieldName));
            }

            var jobInfoResult = await CreateJobAsync(objectName, externalIdFieldName, operationType);

            var batchResults = new List <BatchInfoResult>();

            foreach (var recordList in recordsLists)
            {
                batchResults.Add(await CreateJobBatchAsync(jobInfoResult, recordList));
            }
            await CloseJobAsync(jobInfoResult);

            return(batchResults);
        }
        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);
        }
 public async Task <JobInfoResult> CreateJobAsync(string objectName, BulkConstants.OperationType operationType)
 {
     return(await CreateJobAsync(objectName, null, operationType));
 }
 public async Task <List <BatchResultList> > RunJobAndPollAsync <T>(string objectName, BulkConstants.OperationType operationType,
                                                                    IEnumerable <ISObjectList <T> > recordsLists)
 {
     return(await RunJobAndPollAsync(objectName, null, operationType, recordsLists));
 }
        // BULK METHODS

        public async Task <List <BatchInfoResult> > RunJobAsync <T>(string objectName, BulkConstants.OperationType operationType,
                                                                    IEnumerable <ISObjectList <T> > recordsLists, CancellationToken token)
        {
            if (recordsLists == null)
            {
                throw new ArgumentNullException("recordsLists");
            }

            var jobInfoResult = await CreateJobAsync(objectName, operationType, token).ConfigureAwait(false);

            var batchResults = new List <BatchInfoResult>();

            foreach (var recordList in recordsLists)
            {
                var batchInfoResult = await CreateJobBatchAsync(jobInfoResult, recordList, token).ConfigureAwait(false);

                batchResults.Add(batchInfoResult);
            }
            await CloseJobAsync(jobInfoResult, token).ConfigureAwait(false);

            return(batchResults);
        }