public IActionResult ProcessFile(int id) { /* * This solution assumes that this web application is running on an intranet (not the public internet) and none of the users are malicious * There is basic protection insofar as this method does not accept any string inputs * However if this were to go on the public internet, a security review might first be needed */ var file = _csvLoader.GetFileById(id); if (file == null) { throw new System.Exception("File Not Found"); } var records = _csvLoader.LoadCsvFile(_inputFilesPath + "\\" + file.Name); IncrementalValue.DefaultNullsToZeroes(records); var defects = _fileValidator.Validate(file, records); if (defects != null && defects.Errors.Any()) { return(RedirectToAction("Index", "Failure", defects)); } if (records != null) { MinAndMaxYears minAndMaxYears = new MinAndMaxYears { Minimum = records.Min(p => p.OriginYear), Maximum = records.Max(p => p.OriginYear) }; var recordsPerProduct = _recordsPerProduct.SortRecordsByProduct(records); recordsPerProduct = new MissingYears().Add(recordsPerProduct, minAndMaxYears); string outputFileName = _csvOutput.GetOutputFileName(file.Name); _csvOutput.Write(recordsPerProduct, outputFileName); } return(RedirectToAction("Index", "Success", new { id = file.Id, fileName = file.Name })); }
public void Setup() { _target = new MissingYears(); }