public void Process() { IEnumerable <QtyCSVItemModel> qtyBasedRecords = CSVFileParser.Parse <QtyCSVItemModel, QtyCSVItemModelMapping>(this.csvFilePath); //Convert qty-based records to code-based records, utilising beginCode and codePrefixStr List <CodesCSVItemModel> codeBasedRecords = new List <CodesCSVItemModel>(); int currentCode = this.beginCode; int qty; foreach (var record in qtyBasedRecords) { if (!int.TryParse(record.Qty, out qty)) { throw new FormatException(string.Format("Quantity {0} (for price {1}) is not an integer!", record.Qty, record.Price)); } for (int i = 0; i < qty; i++) { codeBasedRecords.Add(new CodesCSVItemModel { Code = this.codePrefixStr + currentCode.ToString(), Price = record.Price }); currentCode++; } } csvRecords = codeBasedRecords; }
public void CSVFileToArray_FileIsEmpty_ReturnsEmptyArray() { string csvFilename = fileNameEmpty; double[,] data; data = CSVFileParser.ToArray(csvFilename); }
public void loadFrameOverlayHeader() { try { CSVFileParser l_Parser = new CSVFileParser(); l_Parser.startParsingCSVData(mVideoInfoFilepath, 0, 0); string[] row; row = l_Parser.getNextRow(0); mVideoFilepath = ProjectConstants.PROJECT_MEDIA_PATH + @"\" + row[1]; row = l_Parser.getNextRow(0); mSlowMoVideoFilepath = ProjectConstants.PROJECT_MEDIA_PATH + @"\" + row[1]; row = l_Parser.getNextRow(0); FPS = Convert.ToInt32(row[1]); row = l_Parser.getNextRow(0); Duration = Convert.ToInt32(row[1]); row = l_Parser.getNextRow(0); SlowMoRatio = Convert.ToDouble(row[1]); } catch (CSVFileException e) { throw e; } }
public void CSVFileToArray_FileIsEmpty_ReturnsEmptyArray() { string csvFilename = fileNameEmpty; double[,] data; var fp = new CSVFileParser(); data = fp.ParseToDoubleArr(csvFilename, 0); }
private void CheckAndCreateParsers() { if (EasyKillEnemiesParser != null) { return; } EasyKillEnemiesParser = new CSVFileParser(); EasyKillEnemiesParser.Parse("Assets/Text/KILLObjective.txt", "EASY"); }
public void CSVFileToArray_FileHasHeaderOnly_ReturnsEmptyArray() { string csvFilename = "fileWithOnlyHeader.csv"; double[,] data; data = CSVFileParser.ToArray(csvFilename, 1); Assert.IsNotNull(data, "array is null"); Assert.AreEqual(0, data.GetLength(0), "array dim0 should be 0"); Assert.AreEqual(0, data.GetLength(1), "array dim1 should be 0"); }
static void Main(string[] args) { //validate input parameters if (!ValidateParamsLength(args)) { return; } //read input parameters string path = args[0]; int filterColumnIndex = 0; string filterColumnValue = null; if (args.Length == 3) { if (!Int32.TryParse(args[1], out filterColumnIndex) || filterColumnIndex < 1) { ReportError($"Param {filterColumnIndexParamName} must be an integer, starting from 1."); return; } filterColumnValue = args[2]; } try { //read file CSVFileParser parser = new CSVFileParser(path); CommaSeparatedValues csvData = parser.Read(); //output to console depending on input parameters if (filterColumnValue == null) { Console.Write(csvData.ToString()); } else { //validate filterColumnIndex if (filterColumnIndex < 1 || filterColumnIndex > csvData.ColumnsCount) { throw new IndexOutOfRangeException(string.Format("{0} is out of range.", nameof(filterColumnIndex))); } int filterColumnIndex0Based = filterColumnIndex - 1; Console.Write(csvData.ToString(filterColumnIndex0Based, filterColumnValue)); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(string.Format("Error during processing. Exception message: {0} ", ex.Message)); } }
public void CSVFileToArray_FileHasContentAndHeader_ArrayIsRightSize() { string csvFilename = "FileWithHeader.csv"; double[,] data; data = CSVFileParser.ToArray(csvFilename, 1); Assert.IsNotNull(data); Assert.AreEqual(3, data.GetLength(0), "array dim0 should be 3"); Assert.AreEqual(3, data.GetLength(1), "array dim1 should be 3"); Assert.AreEqual(9, data.Length, "length"); }
public void loadShapeData(List <Shape> p_DynamicShapes) { m_Parser = new CSVFileParser(); m_Parser.startParsingCSVData(ProjectConstants.SHAPE_LIST_PATH, 0, 0); string[] row; while ((row = m_Parser.getNextRow(0)) != null) { Shape l_Shape = Shape.getShape(row); p_DynamicShapes.Add(l_Shape); } }
public static IFileParser GetParser(string fileToParse) { FileInfo file = new FileInfo(fileToParse); IFileParser parserToReturn = null; switch (file.Extension.ToLower()) { case "csv": parserToReturn = new CSVFileParser(fileToParse); break; case "txt": parserToReturn = new TextFileParser(fileToParse); break; } return(parserToReturn); }
public XSection(string XsectionCsvFile, int firstDataRow, int firstDataColumn) { double[,] pointArr = CSVFileParser.ToArray(XsectionCsvFile, firstDataRow); for (int i = firstDataRow; i < pointArr.GetLength(0); i++) { double x = pointArr[i, firstDataColumn]; double y = Math.Abs(pointArr[i, firstDataColumn + 1]); Add(new Vector2(x, y)); } SortByX(); Origin = this[0]; MeshSize = this[1].X - this[0].X; Width = this[Count - 1].X - Origin.X; }
public void TestRead(string inputFilePath, string[][] expectedCSVFields, Encoding encoding) { CSVFileParser parser = new CSVFileParser(Path.Combine(Helper.GetAssemblyPath(), inputFilePath), encoding); CommaSeparatedValues csv = parser.Read(); Assert.AreEqual(expectedCSVFields.Length > 0 ? expectedCSVFields[0].Length : 0, csv.ColumnsCount); Assert.AreEqual(expectedCSVFields.Length, csv.RowsCount); for (int i = 0; i < expectedCSVFields.Length; i++) { for (int j = 0; j < expectedCSVFields[i].Length; j++) { Assert.AreEqual(expectedCSVFields[i][j], csv.GetField(i, j)); } } }
public void CSVFileToArray_FileHasContentAndHeader_ReturnsAllContent() { string csvFilename = "FileWithHeader.csv"; double[,] data; data = CSVFileParser.ToArray(csvFilename, 1); Assert.IsNotNull(data); Assert.AreEqual(3, data.GetLength(0), "array dim0 should be 3"); Assert.AreEqual(3, data.GetLength(1), "array dim1 should be 3"); Assert.AreEqual(9, data.Length, "length"); Assert.AreEqual(1.0, (double)data[0, 0], "r0,c0"); Assert.AreEqual(4.0, (double)data[1, 0], " r1,c0"); Assert.AreEqual(5.0, (double)data[1, 1], " r1,c1"); Assert.AreEqual(7.0, (double)data[2, 0], " r2,c0"); Assert.AreEqual(9.0, (double)data[2, 2], " r2,c2"); }
private string getVideoFilename(string pVideoInfoFilepath) { try { CSVFileParser l_Parser = new CSVFileParser(); l_Parser.startParsingCSVData(pVideoInfoFilepath, 0, 0); string[] row = l_Parser.getNextRow(0); l_Parser.close(); return(row[VIDEO_FILEPATH_INDEX]); } catch (CSVFileException e) { throw e; } }
static void Main(string[] args) { // usage: // note this wont run as getting streams is not Implemented // but will get you started CSVFileParser fileParser = new CSVFileParser(); // TO Do: configure fileparser PersonParser personParser = new PersonParser(fileParser); List<Person> persons = new List<Person>(); // if the file is large and there is a good way to limit // without having to reparse the whole file you can use a // linq query if you desire foreach (Person person in personParser.GetPersons()) { persons.Add(person); } // now we have a list of Person objects }
public List <Vector2> ParseFile(string scanFilename, double minYValue, double maxYValue) { var stringArr = CSVFileParser.ParseFile(scanFilename); var vectorList = new List <Vector2>(); for (int i = 0; i < stringArr.GetLength(0); i++) { double x = 0; double y = maxYValue * 2; if (double.TryParse(stringArr[i, 0], out x) && double.TryParse(stringArr[i, 1], out y)) { if (y >= minYValue && y <= maxYValue) { var v = new Vector2(x, y); vectorList.Add(v); } } } return(vectorList); }
public void CSVFileToArray_FileHasContentOnly_ReturnsContent() { string csvFilename = "TextFile2.csv"; double[,] data; var fp = new CSVFileParser(); data = fp.ParseToDoubleArr(csvFilename, 0); Assert.IsNotNull(data); Assert.AreEqual(3, data.GetLength(0), "array dim0 should be 3"); Assert.AreEqual(3, data.GetLength(1), "array dim1 should be 3"); Assert.AreEqual(9, data.Length, "length"); Assert.AreEqual(1.0, (double)data[0, 0], "r0,c0"); Assert.AreEqual(4.0, (double)data[1, 0], " r1,c0"); Assert.AreEqual(5.0, (double)data[1, 1], " r1,c1"); Assert.AreEqual(7.0, (double)data[2, 0], " r2,c0"); Assert.AreEqual(9.0, (double)data[2, 2], " r2,c2"); }
//build jet from normalized csv scan of jet. x and r normalized to 1 private void BuildJet(string csvFilename) { var stringArr = CSVFileParser.ParseFile(csvFilename); //x,mrr csvfilename int headerRowCount = 1; int rowCount = stringArr.GetLength(0); int colCount = stringArr.GetLength(1); mrrList = new List <Tuple <double, double> >(); for (int i = headerRowCount; i < rowCount; i++) { double x = 0; double mrr = 0; if (double.TryParse(stringArr[i, 0], out x) && double.TryParse(stringArr[i, 1], out mrr)) { mrrList.Add(new Tuple <double, double>(x, mrr)); } } }
public void loadFrameOverlayData(int pVideoWidth, int pVideoHeight) { try { CSVFileParser l_Parser = new CSVFileParser(); l_Parser.startParsingCSVData(mVideoInfoFilepath, 0, 0); string[] row; //Skip 6 Row l_Parser.getNextRow(0); l_Parser.getNextRow(0); l_Parser.getNextRow(0); l_Parser.getNextRow(0); l_Parser.getNextRow(0); l_Parser.getNextRow(0); while ((row = l_Parser.getNextRow(0)) != null) { FrameOverlayItem lFrameOverlayItem = new FrameOverlayItem(this, row, pVideoWidth, pVideoHeight); mFrameOverlayItemList.Add(lFrameOverlayItem); if (lFrameOverlayItem.FrameEvent) { mFrameMilestoneEventList.Add(lFrameOverlayItem.FrameEventName); } } l_Parser.close(); setMaxFrameCountForOverlayItems(); createFrameOverlayStructure(); } catch (CSVFileException e) { throw e; } }
private void SpaceSensorRecordingThreadSimulation() { CSVFileParser l_Parser = new CSVFileParser(); l_Parser.startParsingCSVData(ProjectConstants.SPACE_SENSOR_SIMULATED_DATA_PATH, 0, 14); string[] row; while ((row = l_Parser.getNextRow(0)) != null) { SensorData sensor1DataObj = new SensorData(); ReadSimulationSensorData(sensor1DataObj, row, 2); SensorData sensor2DataObj = new SensorData(); ReadSimulationSensorData(sensor2DataObj, row, 12); mParent.ReceivedEventRecordingData(sensor2DataObj, sensor2DataObj); Thread.Sleep(1); } l_Parser.close(); }
public string[] getNextDataRow(int rowSkipStep) { try { if (m_CSVDataParsingInProgress == false) { m_CSVFileParser = new CSVFileParser(); m_CSVFileParser.startParsingCSVData(FilePath, NUMBER_OF_HEADER_ROWS, NUMBER_OF_UNUSEDDATA_ROWS_TO_SKIP); m_CSVDataParsingInProgress = true; } string[] rows = m_CSVFileParser.getNextRow(rowSkipStep); if (rows == null) { stopCSVParsing(); } return(rows); } catch (CSVFileException e) { throw e; } }
public void TestReadFail(string inputFilePath, Encoding encoding) { CSVFileParser parser = new CSVFileParser(Path.Combine(Helper.GetAssemblyPath(), inputFilePath), encoding); Assert.Throws(typeof(CSVFormatException), () => parser.Read()); }
/// <summary> /// Callback method that is called when a file is successfully downloaded. This /// method extracts the ZIP file and produces the final output file. /// </summary> /// <param name="result"></param> private void FileDownloaded(FileDownloadedResult result) { try { if (result.Filename.ToLower().Trim().EndsWith(".zip")) { Logger.Log("INFO", string.Format("Extracting {0}", result.Filename)); ZipFile.ExtractToDirectory(result.Filename, downloadFolder + result.OrganizationID + "-" + result.FileIdentifier.ToString()); System.IO.File.Delete(result.Filename); FileLocator locator = new FileLocator(downloadFolder + result.OrganizationID + "-" + result.FileIdentifier.ToString()); var filenames = locator.FindHIDFiles(); using (IUnitOfWorkDataProvider dp = AppStorage.GetUnitOfWorkDataProvider()) { int oldLineCount = 0; Organization org = dp.Organizations.FindSingle(x => x.RemoteID == result.OrganizationID); int currentFileCount = 1; foreach (var filename in filenames) { //instantiate parser which will read file CSVFileParser parser = new CSVFileParser(filename); //if no data in file then no reason to do anything if (!string.IsNullOrEmpty(parser.FirstLineText) && parser.LineCount > 1 && !string.IsNullOrWhiteSpace(parser.MachineID)) { //look to see if we have read another file with the same data appearing at the start of the file //new files may get uploaded that are really the same data with additional modules //appended. var files = dp.SourceFiles.FindMatching(x => x.FirstLineText == parser.FirstLineText && org.Id == x.OrganizationId); SourceFile file = null; //get source file that had the highest line count if (files != null && files.Count() > 0) { file = files.OrderByDescending(x => x.LineCount).ToList()[0]; } var shortName = filename.Replace(downloadFolder, ""); OutputFile outputFile = new OutputFile(); outputFile.Filename = downloadFolder.Replace("\\temp", "") + parser.MachineID.ToUpper().Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss_fff") + ".TXT"; outputFile.Created = DateTime.Now; oldLineCount = 0; if (file != null) { oldLineCount = file.LineCount; } //add a record for this file id - file will not be downloaded in //subsequent downloads SourceFile newFile = new SourceFile(); newFile.BatchNumber = batchNumber; newFile.FileIdentifer = result.FileIdentifier; newFile.SourceFilename = shortName; newFile.FirstDownload = DateTime.Now; newFile.LastDownload = DateTime.Now; newFile.OrganizationId = org.Id; newFile.LineCount = parser.LineCount; newFile.FirstLineText = parser.FirstLineText.ToLower().Trim(); if (parser.LineCount > oldLineCount) { newFile.OutputFiles.Add(outputFile); parser.WriteFile(outputFile.Filename, oldLineCount); } dp.SourceFiles.Add(newFile); dp.SaveChanges(); currentFileCount++; } else { Logger.Log("WARNING", "Empty file downloaded ignoring."); } } } } } catch (Exception exc) { Logger.Log(exc); extractErrors++; } }
private void stopCSVParsing() { m_CSVDataParsingInProgress = false; m_CSVFileParser.close(); m_CSVFileParser = null; }
private void SpaceSensorRecordingThreadSimulation() { CSVFileParser l_Parser = new CSVFileParser(); l_Parser.startParsingCSVData(ProjectConstants.SPACE_SENSOR_SIMULATED_DATA_PATH, 0, 14); string[] row; while ((row = l_Parser.getNextRow(0)) != null) { SensorData sensor1DataObj = new SensorData(); ReadSimulationSensorData(sensor1DataObj,row,2); SensorData sensor2DataObj = new SensorData(); ReadSimulationSensorData(sensor2DataObj, row, 12); mParent.ReceivedEventRecordingData(sensor2DataObj, sensor2DataObj); Thread.Sleep(1); } l_Parser.close(); }
public void loadShapeData(List<WiimoteOrgeControlShape> p_DynamicShapes) { m_Parser = new CSVFileParser(); m_Parser.startParsingCSVData(ProjectConstants.SHAPE_LIST_PATH, 0, 0); string[] row; while ((row = m_Parser.getNextRow(0)) != null) { WiimoteOrgeControlShape l_Shape = WiimoteOrgeControlShape.getShape(row); p_DynamicShapes.Add(l_Shape); } }
private string getVideoFilename(string pVideoInfoFilepath) { try { CSVFileParser l_Parser = new CSVFileParser(); l_Parser.startParsingCSVData(pVideoInfoFilepath, 0, 0); string[] row = l_Parser.getNextRow(0); l_Parser.close(); return row[VIDEO_FILEPATH_INDEX]; } catch (CSVFileException e) { throw e; } }
public void loadFrameOverlayData(int pVideoWidth,int pVideoHeight) { try { CSVFileParser l_Parser = new CSVFileParser(); l_Parser.startParsingCSVData(mVideoInfoFilepath, 0, 0); string[] row; //Skip 6 Row l_Parser.getNextRow(0); l_Parser.getNextRow(0); l_Parser.getNextRow(0); l_Parser.getNextRow(0); l_Parser.getNextRow(0); l_Parser.getNextRow(0); while ((row = l_Parser.getNextRow(0)) != null) { FrameOverlayItem lFrameOverlayItem = new FrameOverlayItem(this, row, pVideoWidth, pVideoHeight); mFrameOverlayItemList.Add(lFrameOverlayItem); if (lFrameOverlayItem.FrameEvent) mFrameMilestoneEventList.Add(lFrameOverlayItem.FrameEventName); } l_Parser.close(); setMaxFrameCountForOverlayItems(); createFrameOverlayStructure(); } catch (CSVFileException e) { throw e; } }
public void Process() { csvRecords = CSVFileParser.Parse <CodesCSVItemModel, CodesCSVItemModelMapping>(this.csvFilePath).ToList(); }