/// <summary> /// /// </summary> /// <param name="allLines"></param> /// <param name="ares"></param> /// <returns></returns> private List <RawDataRow> ParseDataLines(List <string> allLines, IOResults ares, char delimeter) { List <RawDataRow> dt = new List <RawDataRow>(); char[] splitArray = new char[3]; // set up the delimiting characters splitArray[0] = delimeter; int fileLineNumber = 1; foreach (string ln in allLines) { try { string[] items = splitQuoted(ln, delimeter); // string[] items = ln.Split(splitArray, StringSplitOptions.None); RawDataRow rdr = new RawDataRow(); rdr.dataItems = new List <string>(items); dt.Add(rdr); } catch (Exception ex) { // error parsing the line, or casting the objects ares.errorMessage += ex.ToString(); } fileLineNumber++; } return(dt); }
/// <summary> /// /// </summary> /// <param name="isPreviewOnly"></param> /// <returns></returns> public List<RawDataRow> LoadRawDataForPreview(string inputDataFile, IOResults ares) { // first read the raw lines List<string> dataLines = ReadDataLines(true, inputDataFile, ares); List<RawDataRow> data = ParseDataLines(dataLines, ares, splitArray[0]); int maxCols = 0; foreach (RawDataRow r in data) { int ct = r.dataItems.Count; maxCols = Math.Max(ct, maxCols); } this.MaxCols = maxCols; previewLines = dataLines; return data; }
/// <summary> /// /// </summary> /// <param name="isPreviewOnly"></param> /// <returns></returns> public List <RawDataRow> LoadRawDataForPreview(string inputDataFile, IOResults ares) { // first read the raw lines List <string> dataLines = ReadDataLines(true, inputDataFile, ares); List <RawDataRow> data = ParseDataLines(dataLines, ares, splitArray[0]); int maxCols = 0; foreach (RawDataRow r in data) { int ct = r.dataItems.Count; maxCols = Math.Max(ct, maxCols); } this.MaxCols = maxCols; previewLines = dataLines; return(data); }
private void LoadLASTextDataForPreview(string inputFilename) { IOResults ares = new IOResults(); List<ColumnMetaInfo> mandatoryColumns = new List<ColumnMetaInfo>(); List<ColumnMetaInfo> optionalColumns = new List<ColumnMetaInfo>(); List<ColumnMetaInfo> dbFields = GetGeophysicsFieldsFromNKD(); foreach (ColumnMetaInfo s in dbFields) { mandatoryColumns.Add(s); } // talk to the database to get the column names ImportDataPreview.SetMandatoryMappingColumns(mandatoryColumns); ImportDataPreview.SetOptionalMappingColumns(optionalColumns); ImportDataPreview.SetPreviewType("MODEL"); bool firstLineIsHeader = true; var rawFileReader = new RawFileReader((inputFilename.ToLower().IndexOf(".csv") > -1) ? ',' : '\t'); List<RawDataRow> dt = rawFileReader.LoadRawDataForPreview(inputFilename, ares); ImportDataPreview.ResetTable(dt, firstLineIsHeader); }
private void LoadFileForPreview(string fileToLoad) { IOResults ares = new IOResults(); bool firstLineIsHeader = true;// (bool)dataEntryForm.checkBoxModelFirstRowHeader.IsChecked; var rawFileReader = new RawFileReader((fileToLoad.ToLower().IndexOf(".csv") > -1) ? ',' : '\t'); List<RawDataRow> dt = rawFileReader.LoadRawDataForPreview(fileToLoad, ares); rawFileReader.PerformColumnLoad(fileToLoad, ares, rawFileReader.MaxCols, firstLineIsHeader, workerLoadData); string ss = rawFileReader.GetColumnStats(); List<string> res = rawFileReader.DetermineColumnDataTypes(); columnDefs = new ModelColumnDefinitions(); // collect column assignments here rawFileReader.SetColumnDefinitions(columnDefs); }
private void LoadGeophysiscsTextDataForPreview(string inputFilename) { IOResults ares = new IOResults(); List<ColumnMetaInfo> dbFields = GetGeophysicsFieldsFromNKD(); // talk to the database to get the column names ImportDataPreview.SetMandatoryMappingColumns(dbFields); ImportDataPreview.SetPreviewType("GEOPHYISCS"); bool firstLineIsHeader = true; if (inputFilename.ToLower().EndsWith("las")) { LASFileReader lfr = new LASFileReader(); int errCode = 0; LASFile fl = lfr.ReadLASFile(inputFilename, 0, out errCode); List<RawDataRow> dt = new List<RawDataRow>(); RawDataRow rdh = new RawDataRow(); rdh.dataItems = new List<string>(); rdh.dataItems.Add("Depth"); foreach (string ss in fl.columnHeaders) { rdh.dataItems.Add(ss); } dt.Add(rdh); foreach (LASDataRow ldr in fl.dataRows) { RawDataRow rd = new RawDataRow(); rd.dataItems.Add("" + ldr.depth); foreach (double d in ldr.rowData) { rd.dataItems.Add("" + d); } dt.Add(rd); } ImportDataPreview.ResetTable(dt, true); } else { var rawFileReader = new RawFileReader(','); List<RawDataRow> dt = rawFileReader.LoadRawDataForPreview(inputFilename, ares); ImportDataPreview.ResetTable(dt, firstLineIsHeader); } }
private void LoadTextDataForPreview(string inputFilename) { IOResults ares = new IOResults(); // talk to the database to get the column names List<ColumnMetaInfo> dbFields = null; if (SelectedImportType == GeneralParameters.BLOCKMODEL) { dbFields = bmDBFields; } else if (SelectedImportType == GeneralParameters.COLLAR) { dbFields = collarDBFields; } else if (SelectedImportType == GeneralParameters.ASSAY) { dbFields = assayDBFields; } else if (SelectedImportType == GeneralParameters.COAL_QUALITY) { dbFields = coalQualityDBFields; } else if (SelectedImportType == GeneralParameters.SURVEY) { dbFields = surveyDBFields; } else if (SelectedImportType == GeneralParameters.LITHO) { dbFields = lithoDBFields; } else { } ImportDataPreview.SetMandatoryMappingColumns(dbFields); ImportDataPreview.SetPreviewType("MODEL"); bool firstLineIsHeader = true; var rawFileReader = new RawFileReader((SelectedFile.ToLower().IndexOf(".csv") > -1) ? ',' : '\t'); List<RawDataRow> dt = rawFileReader.LoadRawDataForPreview(inputFilename, ares); if (inputFilename.ToLower().EndsWith("las")) { ImportDataPreview.ResetTable(dt, false); } else { ImportDataPreview.ResetTable(dt, firstLineIsHeader); } }
private List <string> ReadDataLines(bool readPreview, string inputFile, IOResults ares) { //Pass the file path and file name to the StreamReader constructor readPreview = true; List <string> allLines = null; StreamReader sr = null; FileStream fs = null; try { fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); sr = new StreamReader(fs); } catch (FileNotFoundException fex) { ares.errorCondition = 1; ares.errorMessage = "Can't find the input file that was entered. Please make sure the file exists and that you have permission to read the file."; ares.extendedErrorMessage = fex.ToString(); } catch (Exception ex) { ares.errorCondition = 1; ares.errorMessage = "There has been a problem accessing the input data file. Pleas emake sure the file is not being open in other applications and that you have permission to read the file."; ares.extendedErrorMessage = ex.ToString(); } allLines = new List <string>(); if (sr != null) { string line = null; //Continue to read until you reach end of file if (readPreview) { int ct = 0; while ((line = sr.ReadLine()) != null) { // bypass specified number of lines if (ct >= SkipLines) { allLines.Add(line); if (ct > this.previewCount) { break; } } ct++; } } else { while ((line = sr.ReadLine()) != null) { allLines.Add(line); } } sr.Dispose(); sr.Close(); if (fs != null) { fs.Close(); } } if (ares.errorCondition == 0) { dataLoaded = true; } return(allLines); }
public void PerformColumnLoad(string fileName, IOResults ares, int numColumns, bool firstLineIsHeader, BackgroundWorker bw) { columnManager = new ColumnManager(numColumns); int maxLoadCount = 5000; int ct = 0; StreamReader sr = null; FileStream fs = null; try { fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); sr = new StreamReader(fs); } catch (FileNotFoundException fex) { ares.errorCondition = 1; ares.extendedErrorMessage = fex.ToString(); } catch (Exception ex) { ares.errorCondition = 1; ares.extendedErrorMessage = ex.ToString(); } if (sr != null) { string line = null; //Continue to read until you reach end of file int recordNumber = 0; if (firstLineIsHeader) { string headers = sr.ReadLine(); this.SetColumnHeaders(headers, columnManager); } int progressIndicator = 0; int reportProgressOn = 10000; while ((line = sr.ReadLine()) != null) { ct++; if (ct == maxLoadCount) { break; } ParseLineIntoColumns(recordNumber, line, numColumns); recordNumber++; progressIndicator++; if (progressIndicator == reportProgressOn) { progressIndicator = 0; bw.ReportProgress(recordNumber, fileName); } } sr.Dispose(); sr.Close(); if (fs != null) { fs.Close(); } } }
internal List <RawDataRow> LoadRawData(bool firstLineIsHeader, string fileName, IOResults ares) { List <string> rawStringData = ReadDataLines(false, fileName, ares); return(null); }
private List<string> ReadDataLines(bool readPreview, string inputFile, IOResults ares) { //Pass the file path and file name to the StreamReader constructor readPreview = true; List<string> allLines = null; StreamReader sr = null; FileStream fs = null; try { fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); sr = new StreamReader(fs); } catch (FileNotFoundException fex) { ares.errorCondition = 1; ares.errorMessage = "Can't find the input file that was entered. Please make sure the file exists and that you have permission to read the file."; ares.extendedErrorMessage = fex.ToString(); } catch (Exception ex) { ares.errorCondition = 1; ares.errorMessage = "There has been a problem accessing the input data file. Pleas emake sure the file is not being open in other applications and that you have permission to read the file."; ares.extendedErrorMessage = ex.ToString(); } allLines = new List<string>(); if (sr != null) { string line = null; //Continue to read until you reach end of file if (readPreview) { int ct = 0; while ((line = sr.ReadLine()) != null) { // bypass specified number of lines if (ct >= SkipLines) { allLines.Add(line); if (ct > this.previewCount) { break; } } ct++; } } else { while ((line = sr.ReadLine()) != null) { allLines.Add(line); } } sr.Dispose(); sr.Close(); if (fs != null) { fs.Close(); } } if(ares.errorCondition == 0){ dataLoaded = true; } return allLines; }
internal List<RawDataRow> LoadRawData(bool firstLineIsHeader, string fileName, IOResults ares) { List<string> rawStringData = ReadDataLines(false, fileName, ares); return null; }
/// <summary> /// /// </summary> /// <param name="allLines"></param> /// <param name="ares"></param> /// <returns></returns> private List<RawDataRow> ParseDataLines(List<string> allLines, IOResults ares, char delimeter) { List<RawDataRow> dt = new List<RawDataRow>(); char[] splitArray = new char[3]; // set up the delimiting characters splitArray[0] = delimeter; int fileLineNumber = 1; foreach (string ln in allLines) { try { string[] items = splitQuoted(ln, delimeter); // string[] items = ln.Split(splitArray, StringSplitOptions.None); RawDataRow rdr = new RawDataRow(); rdr.dataItems = new List<string>(items); dt.Add(rdr); } catch (Exception ex) { // error parsing the line, or casting the objects ares.errorMessage += ex.ToString(); } fileLineNumber++; } return dt; }