/// <summary> /// Profiles and pre-processes a file. Pre-processing involves 1) removing headers and footers, 2) skipping lines, /// 3) un-quoting fields, and 4) splitting fields. /// </summary> /// <param name="PrepFileFqpn">The fully-qualified path name of the prepped file generated by the method. If the /// method does not perform prepping, then the output variable will be set to null</param> /// <param name="SplitCols">A Dictionary of column splitting specifiers. The key is a column name, and the /// value is the value within a field upon which to split. E.g. <"foo",":"> splits the foo column into foo, /// and foo_descr on the colon character</param> /// <returns>A List of ProfileColumn instances with data type info about the file.</returns> public static List <ProfileColumn> Process(out string PrepFileFqpn, Dictionary <string, string> SplitCols) { List <ProfileColumn> Cols = ProfileColumn.BuildColumnList(SplitCols); ProcessOneFile(Cols, out PrepFileFqpn, SplitCols != null); return(Cols); }
/// <summary> /// Reads a user-specified number of lines from the top of the file, displays them to the console, /// and then exits/ /// </summary> /// <param name="SplitCols">A Dictionary of column splitting specifiers. The key is a column name, and the /// value is the value within a field upon which to split. E.g. <"foo",":"> splits the foo column into foo, /// and foo_descr on the colon character</param> public static void Preview(Dictionary <string, string> SplitCols) { int InRows = 0; List <ProfileColumn> Cols = ProfileColumn.BuildColumnList(SplitCols); Dictionary <int, string> SplitOrdinals = SplitOrdinalsToDict(Cols); Log.InformationMessage("Previewing the file"); using (FileReader Rdr = FileReader.NewFileReader(Cfg.File, Cfg.Prep)) { List <string> InFields = null; while ((InFields = Rdr.ReadLine()) != null) { if (SplitCols != null) { InFields = ProfileColumn.SplitFields(InFields, SplitOrdinals); } Log.InformationMessage(string.Join(",", InFields.ToArray())); if (++InRows >= Cfg.Preview) { break; } } } }