public async Task SaveCSVDataToDatabase(Stream csvBLOB, string name)
        {
            await repo.SetUpDB();

            await using var conn = new NpgsqlConnection(GetConnStr());
            await conn.OpenAsync();

            await ProcessCSVDataAsync(csvBLOB, conn);

            await _blobService.DeleteFile(name);
        }
Ejemplo n.º 2
0
        public async Task Run([BlobTrigger("import-person/{name}")] Stream myBlob, [DurableClient] IDurableOrchestrationClient starter, Binder binder, string name, ILogger log)
        {
            if (name.Contains(".report.txt") == false)
            {
                log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");

                string report;
                try
                {
                    var importJobs = await _importPersonHandler.Handle(myBlob);

                    importJobs.Id        = Guid.NewGuid().ToString();
                    importJobs.Name      = name;
                    importJobs.Container = _container;

                    report = _reportService.CreateImportReport(importJobs);

                    if (importJobs.ImportFileIsValid)
                    {
                        string instanceId = await starter.StartNewAsync("MonitorBulkImport", importJobs.Id, importJobs);
                    }

                    myBlob.Close();

                    await _blobService.DeleteFile(name, _container);
                }
                catch (Exception ex)
                {
                    report = $"Unable to import person CSV: {ex}";
                    log.LogError(report);
                    throw;
                }


                var attributes = new Attribute[]
                {
                    new BlobAttribute($"{_container}/Report/{name}.report.txt", FileAccess.Write),
                    new StorageAccountAttribute("Storage")
                };
                using (var writer = await binder.BindAsync <TextWriter>(attributes))
                {
                    await writer.WriteAsync(report);
                }
            }
        }