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,
                    Entities                  = parameters.Entities,
                    FormatVersion             = FormatVersion,
                    LastSyncTimeInUTC         = parameters.LastSyncTimeInUTC,
                    LocationTargetVersion     = parameters.LocationTargetVersion,
                    PerformanceStatsDateRange = parameters.PerformanceStatsDateRange,
                };

                DownloadCampaignsByAccountIdsResponse response;

                using (var apiService = new ServiceClient <IBulkService>(_authorizationData))
                {
                    response = await apiService.CallAsync((s, r) => s.DownloadCampaignsByAccountIdsAsync(r), request).ConfigureAwait(false);
                }

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

                DownloadCampaignsByCampaignIdsResponse response;

                using (var apiService = new ServiceClient <IBulkService>(_authorizationData))
                {
                    response = await apiService.CallAsync((s, r) => s.DownloadCampaignsByCampaignIdsAsync(r), request).ConfigureAwait(false);
                }

                return(new BulkDownloadOperation(response.DownloadRequestId, _authorizationData, response.TrackingId)
                {
                    StatusPollIntervalInMilliseconds = StatusPollIntervalInMilliseconds
                });
            }
        }
        public async Task <DownloadCampaignsByCampaignIdsResponse> DownloadCampaignsByCampaignIdsAsync(
            ApiAuthentication auth,
            CampaignScope[] campaigns,
            long accountId,
            long?customerId,
            DataScope dataScope,
            BulkDownloadEntity entities,
            CompressionType compressionType   = CompressionType.Zip,
            DownloadFileType downloadFileType = DownloadFileType.Tsv,
            string formatVersion       = "4.0",
            DateTime?lastSyncTimeInUTC = null,
            DateTime?start             = null,
            DateTime?end = null)
        {
            var request = new DownloadCampaignsByCampaignIdsRequest
            {
                CustomerId                = string.Format("{0}", customerId),
                CustomerAccountId         = string.Format("{0}", accountId),
                Campaigns                 = campaigns,
                CompressionType           = compressionType,
                DataScope                 = dataScope,
                DownloadFileType          = downloadFileType,
                Entities                  = entities,
                FormatVersion             = formatVersion,
                LastSyncTimeInUTC         = lastSyncTimeInUTC,
                PerformanceStatsDateRange = BuildDateRange(start, end)
            };

            try
            {
                SetAuthHelper.SetAuth(auth, request);

                return(await Check().DownloadCampaignsByCampaignIdsAsync(request));
            }
            catch (Exception ex)
            {
                Log(new LogEventArgs(ServiceType.Bulk, "DownloadCampaignsByCampaignIdsAsync", ex.Message, new { Request = request }, ex));
            }

            return(null);
        }
        public async Task <DownloadCampaignsByCampaignIdsResponse> DownloadCampaignsByCampaignIdsAsync(
            IList <CampaignScope> campaigns,
            CompressionType?compressionType,
            DataScope dataScope,
            IList <DownloadEntity> downloadEntities,
            DownloadFileType?downloadFileType,
            String formatVersion,
            DateTime?lastSyncTimeInUTC)
        {
            var request = new DownloadCampaignsByCampaignIdsRequest
            {
                Campaigns         = campaigns,
                CompressionType   = compressionType,
                DataScope         = dataScope,
                DownloadEntities  = downloadEntities,
                DownloadFileType  = downloadFileType,
                FormatVersion     = formatVersion,
                LastSyncTimeInUTC = lastSyncTimeInUTC
            };

            return(await BulkService.CallAsync((s, r) => s.DownloadCampaignsByCampaignIdsAsync(r), request));
        }
Exemple #4
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
                });
            }
        }