コード例 #1
0
        private async Task <BulkDownloadOperation> SubmitDownloadAsyncImpl(SubmitDownloadParameters parameters)
        {
            if (parameters.CampaignIds == null)
            {
                var request = new DownloadCampaignsByAccountIdsRequest
                {
                    AccountIds                = new[] { _authorizationData.AccountId },
                    DataScope                 = parameters.DataScope,
                    DownloadFileType          = parameters.FileType,
                    DownloadEntities          = parameters.DownloadEntities?.ToArray(),
                    FormatVersion             = FormatVersion,
                    LastSyncTimeInUTC         = parameters.LastSyncTimeInUTC,
                    PerformanceStatsDateRange = parameters.PerformanceStatsDateRange,
                };

                DownloadCampaignsByAccountIdsResponse response;

                using (var apiService = new ServiceClient <IBulkService>(_authorizationData, _apiEnvironment))
                {
                    try
                    {
                        response = await apiService.CallAsync((s, r) => s.DownloadCampaignsByAccountIdsAsync(r), request).ConfigureAwait(false);
                    }
                    catch (Exception e)
                    {
                        throw new CouldNotSubmitBulkDownloadException("Submit download operation failed.", e);
                    }
                }

                return(new BulkDownloadOperation(response.DownloadRequestId, _authorizationData, response.TrackingId, _apiEnvironment)
                {
                    StatusPollIntervalInMilliseconds = StatusPollIntervalInMilliseconds,
                    DownloadHttpTimeout = DownloadHttpTimeout
                });
            }
            else
            {
                var request = new DownloadCampaignsByCampaignIdsRequest
                {
                    Campaigns = parameters.CampaignIds.Select(c => new CampaignScope {
                        CampaignId = c, ParentAccountId = _authorizationData.AccountId
                    }).ToList(),
                    DataScope                 = parameters.DataScope,
                    DownloadFileType          = parameters.FileType,
                    DownloadEntities          = parameters.DownloadEntities?.ToArray(),
                    FormatVersion             = FormatVersion,
                    LastSyncTimeInUTC         = parameters.LastSyncTimeInUTC,
                    PerformanceStatsDateRange = parameters.PerformanceStatsDateRange
                };

                DownloadCampaignsByCampaignIdsResponse response;

                using (var apiService = new ServiceClient <IBulkService>(_authorizationData, _apiEnvironment))
                {
                    try
                    {
                        response = await apiService.CallAsync((s, r) => s.DownloadCampaignsByCampaignIdsAsync(r), request).ConfigureAwait(false);
                    }
                    catch (Exception e)
                    {
                        throw new CouldNotSubmitBulkDownloadException("Submit download operation failed.", e);
                    }
                }

                return(new BulkDownloadOperation(response.DownloadRequestId, _authorizationData, response.TrackingId, _apiEnvironment)
                {
                    StatusPollIntervalInMilliseconds = StatusPollIntervalInMilliseconds,
                    DownloadHttpTimeout = DownloadHttpTimeout
                });
            }
        }