Esempio n. 1
0
        private async Task <IEnumerable <BulkEntity> > DownloadEntitiesAsyncImpl(DownloadParameters parameters, IProgress <BulkOperationProgressInfo> progress, CancellationToken cancellationToken)
        {
            var resultFile = await DownloadFileAsyncImpl(parameters, progress, cancellationToken).ConfigureAwait(false);

            var resultFileType = parameters.LastSyncTimeInUTC == null ? ResultFileType.FullDownload : ResultFileType.PartialDownload;

            return(new BulkEntityReaderEnumerable(BulkEntityReaderFactory.CreateBulkFileReader(resultFile, resultFileType, parameters.FileType)));
        }
Esempio n. 2
0
        private async Task <IEnumerable <BulkEntity> > UploadEntityRecordsImpl(EntityUploadParameters parameters, IProgress <BulkOperationProgressInfo> progress, CancellationToken cancellationToken)
        {
            var request = new UploadEntityRecordsRequest()
            {
                EntityRecords = WriteUploadEntitiesAsPayload(parameters.Entities),
                ResponseMode  = ResponseMode.ErrorsAndResults
            };

            try
            {
                using (var bulkService = new ServiceClient <IBulkService>(_authorizationData, _apiEnvironment))
                {
                    var uploadEntityRecordsResponse = await bulkService.CallAsync((s, r) => s.UploadEntityRecordsAsync(r), request).ConfigureAwait(false);

                    if (FallBacktoAsync(uploadEntityRecordsResponse))
                    {
                        using (var operation = new BulkUploadOperation(uploadEntityRecordsResponse.RequestId, _authorizationData, uploadEntityRecordsResponse.TrackingId, _apiEnvironment)
                        {
                            StatusPollIntervalInMilliseconds = StatusPollIntervalInMilliseconds,
                            DownloadHttpTimeout = DownloadHttpTimeout
                        })
                        {
                            await operation.TrackAsync(progress, cancellationToken).ConfigureAwait(false);

                            var resultFile = await DownloadBulkFile(parameters.ResultFileDirectory,
                                                                    parameters.ResultFileName,
                                                                    parameters.OverwriteResultFile,
                                                                    operation).ConfigureAwait(false);


                            return(new BulkEntityReaderEnumerable(BulkEntityReaderFactory.CreateBulkFileReader(resultFile, ResultFileType.Upload, DownloadFileType.Csv)));
                        }
                    }
                    return(new BulkEntityReaderEnumerable(BulkEntityReaderFactory.CreateBulkRowsReader(uploadEntityRecordsResponse.EntityRecords)));
                }
            }
            catch (FaultException ex)
            {
                if (NeedToRetryWithBulkUpload(ex))
                {
                    var fileUploadParameters = CreateFileUploadParameters(parameters);

                    return(await UploadEntitiesAsyncImpl(progress, cancellationToken, fileUploadParameters));
                }
                throw;
            }
        }
Esempio n. 3
0
        private async Task <IEnumerable <BulkEntity> > UploadEntitiesAsyncImpl(IProgress <BulkOperationProgressInfo> progress, CancellationToken cancellationToken, FileUploadParameters fileUploadParameters)
        {
            var resultFile = await UploadFileAsyncImpl(fileUploadParameters, progress, cancellationToken).ConfigureAwait(false);

            return(new BulkEntityReaderEnumerable(BulkEntityReaderFactory.CreateBulkFileReader(resultFile, ResultFileType.Upload, DownloadFileType.Csv)));
        }