コード例 #1
0
        public ActionResult <FileDetail> UploadQuantityOnHand()
        {
            FileExtractionResult fileExtractionResult = null;

            try
            {
                fileExtractionResult = httpRequestFileExtractor.ExtractDataFromRequest(Request);
            }
            catch (InvalidRequestException e)
            {
                return(BadRequest(e.Message));
            }
            logger.LogTrace("Created detail file record.");
            runningTask = Task.Run(() => quantityOnHandFileParser.processQuantityOnHandFileAsynchronously(fileExtractionResult));
            return(CreatedAtAction(nameof(RetrieveStatus), new { fileExtractionResult.FileDetail.Id }, fileExtractionResult.FileDetail));
        }
コード例 #2
0
        public async Task <Guid> processQuantityOnHandFileAsynchronously(FileExtractionResult fileExtractionResult)
        {
            logger.LogInformation("Starting processing of file.");
            using (var scope = serviceScopeFactory.CreateScope())
            {
                entityContext = scope.ServiceProvider.GetRequiredService <EntityContext>();

                uint     validLines   = 0;
                uint     invalidLines = 0;
                Boolean  headerLine   = true;
                string   qoh          = Encoding.UTF8.GetString(fileExtractionResult.FileContent, 0, fileExtractionResult.FileContent.Length);
                string[] lines        = qoh.Split("\n");
                foreach (string line in lines)
                {
                    if (headerLine)
                    {
                        headerLine = false;
                        logger.LogInformation("Skipping header.");
                    }
                    else if (line.Length == 0)
                    {
                        logger.LogInformation("Skipping blank line.");
                        continue;
                    }
                    else
                    {
                        if (ProcessDetailLine(line))
                        {
                            validLines++;
                        }
                        else
                        {
                            invalidLines++;
                        }
                    }
                }
                logger.LogInformation("Completed processing file.");
                UpdateFileDetailToCompleted(fileExtractionResult.FileDetail, validLines, invalidLines);
                logger.LogInformation("Quantity On Hand File Details updated.");
                logger.LogInformation("Number of Inventory Summaries: {0}", entityContext.InventorySummaries.Count);
                int x = await entityContext.SaveChangesAsync();

                return(fileExtractionResult.FileDetail.Id);
            }
        }