private async Task <Boolean> ProcessEachLineAsync(ImportFileRecord importFileRecord) { Boolean retVal = false; try { if (importFileRecord != null) { int resourceGroupId = await WorkspaceQueryHelper.GetResourcePoolAsync(AgentHelper.GetServicesManager(), ExecutionIdentity.System, WorkspaceArtifactId); //get selected markup sub types in the import job List <int> selectedMarkupSubTypes = _markupUtilityImportJob .MarkupUtilityTypes .Select(x => MarkupTypeHelper.GetMarkupSubTypeValueAsync(x.Name).Result) .ToList(); //insert into import manager holding table only if the sub type is selected in the import job if (selectedMarkupSubTypes.Contains(importFileRecord.MarkupSubType)) { await QueryHelper.InsertRowIntoImportManagerHoldingTableAsync( AgentHelper.GetDBContext(-1), WorkspaceArtifactId, importFileRecord.DocumentIdentifier, importFileRecord.FileOrder, resourceGroupId, _markupUtilityImportJob.ArtifactId, _markupUtilityImportJob.MarkupSetArtifactId, _markupUtilityImportJob.JobType, importFileRecord, _markupUtilityImportJob.SkipDuplicateRedactions, ImportManagerHoldingTable); _expectedRedactionCount++; } retVal = true; } } catch (Exception ex) { throw new MarkupUtilityException("An error occured when inserting redaction record to the import manager holding table.", ex); } finally { _importFileRedactionCount++; if (_importFileRedactionCount % 100 == 0) { RaiseMessage($"Parsed {_importFileRedactionCount} records in import file."); } } return(retVal); }
private async Task <bool> ProcessEachLineAsync(ImportFileRecord importFileRecord) { return(await Task.Run(() => { if (importFileRecord == null) { return false; } _lineCount++; return true; })); }
public async Task ParseFileContentsAsync(StreamReader fileStreamReader, Func <ImportFileRecord, Task <bool> > processEachLineAsyncFunc, Func <Task <bool> > afterProcessingAllLinesAsyncFunc) { if (fileStreamReader == null) { throw new ArgumentNullException(nameof(fileStreamReader)); } if (processEachLineAsyncFunc == null) { throw new ArgumentNullException(nameof(processEachLineAsyncFunc)); } if (afterProcessingAllLinesAsyncFunc == null) { throw new ArgumentNullException(nameof(afterProcessingAllLinesAsyncFunc)); } try { using (fileStreamReader) { var count = 1; while (fileStreamReader.Peek() > 0) { var line = await fileStreamReader.ReadLineAsync(); if (line.Trim() == string.Empty) { continue; //skip empty lines } var columns = line.Split(Constant.ImportFile.COLUMN_SEPARATOR).Select(x => x.Trim()).ToList(); //validate column count if (columns.Count != Constant.ImportFile.COLUMN_COUNT) { throw new MarkupUtilityException(Constant.ErrorMessages.COLUMN_COUNT_MISMATCH); } if (count++ == 1) { //validate column names if (columns.Any(column => !Constant.ExportFile.ColumnsList.Contains(column.Trim()))) { throw new MarkupUtilityException(Constant.ErrorMessages.COLUMN_NAME_MISMATCH); } continue; //skip column headers column } ImportFileRecord newImportFileRecord = new ImportFileRecord( columns[0], columns[1], columns[2], columns[3], columns[4], columns[5], columns[6], columns[7], columns[8], columns[9], columns[10], columns[11], columns[12], columns[13], columns[14], columns[15], columns[16], columns[17], columns[18], columns[19], columns[20], columns[21], columns[22], columns[23], columns[24], columns[25], columns[26], columns[27], columns[28], columns[29], columns[30], columns[31] ); await processEachLineAsyncFunc(newImportFileRecord); } await afterProcessingAllLinesAsyncFunc(); } } catch (Exception ex) { throw new MarkupUtilityException(Constant.ErrorMessages.PARSE_FILE_CONTENTS_ERROR, ex); } }