public async Task <ICsvCustomerImportReporter> CreateAsync(string reportFilePath, string delimiter)
        {
            var reportBlob = await _blobStorageProvider.GetBlobInfoAsync(reportFilePath);

            if (reportBlob != null)
            {
                await _blobStorageProvider.RemoveAsync(new[] { reportFilePath });
            }

            return(new CsvCustomerImportReporter(reportFilePath, _blobStorageProvider, delimiter));
        }
        public async ValueTask DisposeAsync()
        {
            using (await AsyncLock.GetLockByKey(_reportFilePath).GetReleaserAsync())
            {
                await _streamWriter.DisposeAsync();

                if (!ReportIsNotEmpty)
                {
                    await _blobStorageProvider.RemoveAsync(new[] { _reportFilePath });
                }
            }
        }
Beispiel #3
0
        public async ValueTask DisposeAsync()
        {
            using (await AsyncLock.GetLockByKey(_filePath).LockAsync())
            {
                await _streamWriter.FlushAsync();

                _streamWriter.Close();

                if (!ReportIsNotEmpty)
                {
                    await _blobStorageProvider.RemoveAsync(new[] { _filePath });
                }
            }
        }
 public async Task<IActionResult> DeleteBlobsAsync([FromQuery] string[] urls)
 {
     await _blobProvider.RemoveAsync(urls);
     return Ok();
 }
        public async Task ExportAsync(ExportDataRequest request, Action <ExportProgressInfo> progressCallback, ICancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var exportProgress = new ExportProgressInfo {
                ProcessedCount = 0, Description = "Export has started"
            };

            var dataSource = _customerExportPagedDataSourceFactory.Create(ModuleConstants.Settings.PageSize, request);

            exportProgress.TotalCount = await dataSource.GetTotalCountAsync();

            progressCallback(exportProgress);

            const string exportDescription = "{0} out of {1} have been exported.";

            exportProgress.Description = "Fetching...";
            progressCallback(exportProgress);

            var dynamicProperties = await _dynamicPropertySearchService.SearchDynamicPropertiesAsync(new DynamicPropertySearchCriteria()
            {
                ObjectTypes = new List <string> {
                    typeof(Contact).FullName, typeof(Organization).FullName
                },
                Skip = 0,
                Take = int.MaxValue
            });

            var contactsDynamicProperties =
                dynamicProperties.Results.Where(x => x.ObjectType == typeof(Contact).FullName).ToArray();

            var organizationsDynamicProperties =
                dynamicProperties.Results.Where(x => x.ObjectType == typeof(Organization).FullName).ToArray();

            var contactsFilePath    = GetExportFilePath("Contacts");
            var contactExportWriter = _exportWriterFactory.Create <ExportableContact>(contactsFilePath, new ExportConfiguration(), contactsDynamicProperties);

            var organizationFilePath     = GetExportFilePath("Organizations");
            var organizationExportWriter = _exportWriterFactory.Create <ExportableOrganization>(organizationFilePath, new ExportConfiguration(), organizationsDynamicProperties);

            try
            {
                while (await dataSource.FetchAsync())
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var contacts = dataSource.Items.OfType <ExportableContact>().ToArray();

                    if (!contacts.IsNullOrEmpty())
                    {
                        contactExportWriter.WriteRecords(contacts);
                    }

                    var organizations = dataSource.Items.OfType <ExportableOrganization>().ToArray();

                    if (!organizations.IsNullOrEmpty())
                    {
                        organizationExportWriter.WriteRecords(organizations);
                    }

                    exportProgress.ProcessedCount += dataSource.Items.Length;
                    exportProgress.Description     = string.Format(exportDescription, exportProgress.ProcessedCount,
                                                                   exportProgress.TotalCount);
                    progressCallback(exportProgress);
                }

                exportProgress.Description = "Export completed";
            }
            finally
            {
                contactExportWriter.Dispose();
                organizationExportWriter.Dispose();
            }

            try
            {
                var contactsFileInfo = await _blobStorageProvider.GetBlobInfoAsync(contactsFilePath);

                var organizationsFileInfo = await _blobStorageProvider.GetBlobInfoAsync(organizationFilePath);

                if (contactsFileInfo.Size > 0)
                {
                    exportProgress.ContactsFileUrl = _blobUrlResolver.GetAbsoluteUrl(contactsFilePath);
                }
                else
                {
                    await _blobStorageProvider.RemoveAsync(new string[] { contactsFilePath });
                }

                if (organizationsFileInfo.Size > 0)
                {
                    exportProgress.OrganizationsFileUrl = _blobUrlResolver.GetAbsoluteUrl(organizationFilePath);
                }
                else
                {
                    await _blobStorageProvider.RemoveAsync(new string[] { organizationFilePath });
                }
            }
            finally
            {
                progressCallback(exportProgress);
            }
        }