public Guid ReadRetailPoolingFiles(RetailInputFileParam retailInputFileParam) { var inputFiles = new List <ABSARetailPoolingInput>(); var cleanTable = _iDbContextAccess.TruncateRetailPoolingInputTable(retailInputFileParam.DbContextType); var rowId = CreateRetailPoolingProgress(retailInputFileParam.DbContextType, retailInputFileParam.ProductName); var updateProgressStart = _iDbContextAccess.CreateRetailProcessingProgressDetails(retailInputFileParam.DbContextType, rowId, "Reading Input File", ProgressStatus.Started); using (StreamReader reader = new StreamReader(retailInputFileParam.FilePath)) { string line = reader.ReadLine(); while ((line = reader.ReadLine()) != null) { retailInputFileParam.ContentLine = line; var retailInput = FormatABSARetailInputLine(retailInputFileParam, rowId); inputFiles.Add(retailInput); if (inputFiles.Count == 100000) { var bulkInsert = BulkInsert(inputFiles, retailInputFileParam.DbContextType); inputFiles.Clear(); } } if (inputFiles.Count > 0) { var bulkInsert = BulkInsert(inputFiles, retailInputFileParam.DbContextType); inputFiles.Clear(); } } var updateProgressEnd = _iDbContextAccess.CreateRetailProcessingProgressDetails(retailInputFileParam.DbContextType, rowId, "Reading Input File", ProgressStatus.Completed); return(rowId); }
private ABSARetailPoolingInput FormatABSARetailInputLine(RetailInputFileParam retailInputFileParam, Guid rowId) { string[] content = retailInputFileParam.ContentLine.ConvertDelimetedStringToArray(retailInputFileParam.ContentDelimeter); var retailInput = new ABSARetailPoolingInput() { ObligorId = content[0].Trim(), FacilityId = content[1].Trim(), RSq = double.Parse(content[2].Trim()), QSq = double.Parse(content[3].Trim()), AssetReturnWeights = content[4].Trim(), RecoveryWeights = content[5].Trim(), Tenors = int.Parse(content[6].Trim()), TimeToMaturity = int.Parse(content[7].Trim()), CumulativePDs = !string.IsNullOrEmpty(content[8].Trim()) ? double.Parse(content[8].Trim()) : 0, LGD = !string.IsNullOrEmpty(content[9].Trim()) ? double.Parse(content[9].Trim()) : 0, EAD = !string.IsNullOrEmpty(content[10].Trim()) ? double.Parse(content[10].Trim()) : 0, SUBMISSION_UNIT_CD = content[11].Trim(), EC_SEG = content[12].Trim(), PROD = content[13].Trim(), EC_CLUSTER = content[14].Trim(), UNIQUE_KEY = content[15].Trim(), FinalPDRank = 0, FinalLGDRank = 0, FinalTMRank = 0, CreatedDate = DateTime.Now, InputType = retailInputFileParam.ProductName.ToString(), RowId = rowId, PoolingLGD = !string.IsNullOrEmpty(content[16].Trim()) ? double.Parse(content[16].Trim()) : 0, OrginalPoolingLGD = !string.IsNullOrEmpty(content[16].Trim()) ? double.Parse(content[16].Trim()) : 0 }; retailInput.PoolingLGD = Math.Round(retailInput.PoolingLGD, 2); return(retailInput); }
public bool ProcessSingleProductRetailPoolingRank(RetailPoolingFileType productType, DbContextType dbContextType) { var retailPoolingConfigs = _iDbContextAccess.GetRetailPoolingConfigs(dbContextType); var result = false; var inputFilesbaseDirectory = retailPoolingConfigs.FirstOrDefault(x => string.Compare(x.Type, ABSARetailPoolingEnumConfigType.SharedBaseDirectory.ToString(), true) == 0).Value; var fileContentDelimeter = retailPoolingConfigs.FirstOrDefault(x => string.Compare(x.Type, ABSARetailPoolingEnumConfigType.InputFileContentDelimeter.ToString(), true) == 0).Value; //var expectedTotalFile = retailPoolingConfigs.FirstOrDefault(x => string.Compare(x.Type, ABSARetailPoolingEnumConfigType.TotalRequiredFiles.ToString(), true) == 0).Value; var outputFilesBaseDirectory = retailPoolingConfigs.FirstOrDefault(x => string.Compare(x.Type, ABSARetailPoolingEnumConfigType.OutputBaseDirectory.ToString(), true) == 0).Value; var outputFolderName = string.Format("Output_{0}_{1}", DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss"), DateTime.Now.Ticks.ToString("x")); var fileName = string.Format("_{0}_", productType.ToString()); var baseDirectoryLastFolder = fileManager.GetLastFolder(inputFilesbaseDirectory); var filePath = fileManager.SearchFiles(baseDirectoryLastFolder).FirstOrDefault(x => x.ToLower().Contains(fileName.ToLower())); if (!string.IsNullOrEmpty(filePath)) { var inputParam = new RetailInputFileParam() { ContentDelimeter = fileContentDelimeter, ProductName = productType, DbContextType = dbContextType, ContentLine = fileContentDelimeter, FilePath = filePath }; var rowId = ReadRetailPoolingFiles(inputParam); var pd = PDRank(productType, dbContextType, rowId); var lgd = LGDRank(productType, dbContextType, rowId); var tm = TMRank(productType, dbContextType, rowId); var fileContent = _iDbContextAccess.GetFileContents(productType, dbContextType, rowId); var outputFileName = string.Format("{0}_RANKING_PROCESSING_{1}_{2}", productType.ToString().ToUpper(), DateTime.Now.ToString("yyyyMMddmmss"), DateTime.Now.Ticks.ToString("x")); result = fileManager.CreatePoolingOutputFiles($"{outputFileName}_Input", outputFilesBaseDirectory, fileContent, outputFolderName); var pdContents = _iDbContextAccess.GetFileContentsPD(dbContextType, rowId); result = fileManager.CreatePoolingOutputFilePD($"{outputFileName}_PDLOGIC", outputFilesBaseDirectory, pdContents, outputFolderName); var lgdContents = _iDbContextAccess.GetFileContentsLGD(dbContextType, rowId); result = fileManager.CreatePoolingOutputFileLGD($"{outputFileName}_LGDLOGIC", outputFilesBaseDirectory, lgdContents, outputFolderName); var tmContents = _iDbContextAccess.GetFileContentsTM(dbContextType, rowId); result = fileManager.CreatePoolingOutputFileTM($"{outputFileName}_TMLOGIC", outputFilesBaseDirectory, tmContents, outputFolderName); var processingDone = _iDbContextAccess.UpdateRetailProcessingProgress(dbContextType, rowId); var updateProgressStart = _iDbContextAccess.CreateRetailProcessingProgressDetails(dbContextType, rowId, "Clearing Temp Data", ProgressStatus.Started); var cleanTable = _iDbContextAccess.TruncateRetailPoolingInputTable(dbContextType); var updateProgressEnd = _iDbContextAccess.CreateRetailProcessingProgressDetails(dbContextType, rowId, "Clearing Temp Data", ProgressStatus.Completed); fileContent.Clear(); } return(result); }