internal static IEnumerable <Base> Parse(string data) { if (string.IsNullOrEmpty(data)) { return(Enumerable.Empty <Base>()); } string[] u = data.Split(Environment.NewLine); List <string> y = new List <string>(); u.ToList().ForEach(a => y.Add(a.TrimEnd(';'))); var s = string.Join(Environment.NewLine, y); var types = typeof(Posting).GetNestedTypes().Where(f => f.BaseType == typeof(Base)).OrderBy(f => f.Name); List <Base> x1 = null; foreach (var t in types) { var e = new FileHelpers.FileHelperEngine(t); e.Options.IgnoreEmptyLines = true; e.Options.IgnoreFirstLines = 1; e.ErrorManager.ErrorMode = ErrorMode.IgnoreAndContinue; x1 = e.ReadString(s).Cast <Base>().ToList(); if (x1 != null && x1.Count > 0) { break; } } foreach (var x2 in x1) { x2.BilagsNummer = running++; } //var x = new CsvParser(data); //foreach (var y in x.ToList()) //{ // System.Diagnostics.Debug.WriteLine(((SparNord)y).Dato); //} return(x1); }
/// <summary> /// Used to write a file without instanciate the engine.<br /> /// <b>This is feature limited method try to use the non static methods.</b> /// </summary> /// <param name="recordClass">The record class.</param> /// <param name="fileName">The file name</param> /// <param name="records">The records to write</param> public static void WriteFile(Type recordClass, string fileName, object[] records) { FileHelperEngine engine = new FileHelperEngine(recordClass); engine.WriteFile(fileName, records); }
/// <summary> /// Used to read a string without instanciate the engine.<br /> /// <b>This is feature limited method try to use the non static methods.</b> /// </summary> /// <param name="recordClass">The record class.</param> /// <param name="input">The input string.</param> /// <returns>The read records.</returns> public static object[] ReadString(Type recordClass, string input) { FileHelperEngine engine = new FileHelperEngine(recordClass); return(engine.ReadString(input)); }
/// <summary> /// Used to read a file without instanciate the engine.<br /> /// <b>This is feature limited method try to use the non static methods.</b> /// </summary> /// <param name="recordClass">The record class.</param> /// <param name="fileName">The file name</param> /// <returns>The read records.</returns> public static object[] ReadFile(Type recordClass, string fileName) { FileHelperEngine engine = new FileHelperEngine(recordClass); return(engine.ReadFile(fileName)); }
/// <summary> /// Read an array of data from a supplied engine /// </summary> /// <typeparam name="T">Type of record to parse</typeparam> /// <param name="engine">Engine to read record from</param> /// <param name="maxRecords">Maximum number of records</param> /// <returns>array of data</returns> public T[] ReadWithEngine <T>(FileHelperEngine <T> engine, int maxRecords) where T : class { return(engine.ReadFile(Path, maxRecords)); }
/// <summary> /// Used to write a string without instanciate the engine.<br /> /// <b>This is feature limited method try to use the non static methods.</b> /// </summary> /// <param name="recordClass">The record class.</param> /// <param name="records">The records to write (Can be an array, ArrayList, etc)</param> /// <returns>The string with the writen records.</returns> public static string WriteString(Type recordClass, IEnumerable records) { FileHelperEngine engine = new FileHelperEngine(recordClass); return(engine.WriteString(records)); }
/// <summary> /// Used to read a file without instantiating the engine.<br /> /// <b>This method has limited features. We recommend using the non static methods.</b> /// </summary> /// <param name="recordClass">The record class.</param> /// <param name="fileName">The file name</param> /// <param name="maxRecords">The max number of records to read. Int32.MaxValue or -1 to read all records.</param> /// <returns>The read records.</returns> public static object[] ReadFile(Type recordClass, string fileName, int maxRecords) { var engine = new FileHelperEngine(recordClass); return(engine.ReadFile(fileName, maxRecords)); }
/// <summary> /// Perform a simple engine call restricting number of record /// </summary> /// <typeparam name="T">Type of data to parse</typeparam> /// <param name="maxRecords">Number of records to process</param> /// <returns>Array of type T</returns> public T[] ReadWithEngine <T>(int maxRecords) where T : class { var engine = new FileHelperEngine <T>(); return(ReadWithEngine(engine, maxRecords)); }
/// <summary> /// Used to write a file without instantiating the engine.<br /> /// <b>This method has limited features. We recommend using the non static methods.</b> /// </summary> /// <param name="fileName">The file name</param> /// <param name="records">The records to write (Can be an array, List, etc)</param> public static void WriteFile <T>(string fileName, IEnumerable <T> records) where T : class { var engine = new FileHelperEngine <T>(); engine.WriteFile(fileName, records); }
/// <summary> /// Used to write a string without instantiating the engine.<br /> /// <b>This method has limited features. We recommend using the non static methods.</b> /// </summary> /// <param name="records">The records to write (Can be an array, List, etc)</param> /// <returns>The string with the written records.</returns> public static string WriteString <T>(IEnumerable <T> records) where T : class { var engine = new FileHelperEngine <T>(); return(engine.WriteString(records)); }
/// <summary> /// Used to read a string without instantiating the engine.<br /> /// <b>This method has limited features. We recommend using the non static methods.</b> /// </summary> /// <param name="input">The input string.</param> /// <returns>The read records.</returns> public static T[] ReadString <T>(string input) where T : class { var engine = new FileHelperEngine <T>(); return(engine.ReadString(input)); }
/// <summary> /// Used to read a string without instantiating the engine.<br /> /// <b>This method has limited features. We recommend using the non static methods.</b> /// </summary> /// <param name="recordClass">The record class.</param> /// <param name="input">The input string.</param> /// <param name="maxRecords">The max number of records to read. Int32.MaxValue or -1 to read all records.</param> /// <returns>The read records.</returns> public static object[] ReadString(Type recordClass, string input, int maxRecords) { var engine = new FileHelperEngine(recordClass); return(engine.ReadString(input, maxRecords)); }
/// <summary> /// Used to read a file as a DataTable without instantiating the engine.<br /> /// <b>This method has limited features. We recommend using the non static methods.</b> /// </summary> /// <param name="recordClass">The record class.</param> /// <param name="fileName">The file name</param> /// <param name="maxRecords">The max number of records to read. Int32.MaxValue or -1 to read all records.</param> /// <returns>The DataTable representing all the read records.</returns> public static DataTable ReadFileAsDT(Type recordClass, string fileName, int maxRecords) { var engine = new FileHelperEngine(recordClass); return(engine.ReadFileAsDT(fileName, maxRecords)); }
/// <summary> /// Used to write a string without instanciate the engine.<br /> /// <b>This is feature limited method try to use the non static methods.</b> /// </summary> /// <param name="recordClass">The record class.</param> /// <param name="records">The records to write</param> /// <returns>The string with the writen records.</returns> public static string WriteString(Type recordClass, object[] records) { FileHelperEngine engine = new FileHelperEngine(recordClass); return(engine.WriteString(records)); }
/// <summary> /// Used to read a file without instantiating the engine.<br /> /// <b>This method has limited features. We recommend using the non static methods.</b> /// </summary> /// <param name="fileName">The file name</param> /// <param name="maxRecords">The max number of records to read. Int32.MaxValue or -1 to read all records.</param> /// <returns>The read records.</returns> public static T[] ReadFile <T>(string fileName, int maxRecords) where T : class { var engine = new FileHelperEngine <T>(); return(engine.ReadFile(fileName, maxRecords)); }
/// <summary> /// Perform a simple engine call on type T /// </summary> /// <typeparam name="T">Type of record to parse</typeparam> /// <returns>Parsed data</returns> public T[] ReadWithEngine <T>() where T : class { var engine = new FileHelperEngine <T>(); return(ReadWithEngine(engine)); }
private FileHelperEngine CreateEngineAndClearErrors() { FileHelperEngine engine = new FileHelperEngine(mRecordInfo);
/// <summary> /// array of data for a file /// </summary> /// <typeparam name="T">type or record</typeparam> /// <param name="engine">engine to process data</param> /// <returns>array of data</returns> public T[] ReadWithEngine <T>(FileHelperEngine <T> engine) where T : class { return(engine.ReadFile(Path)); }
/// <summary>Read the source file, the new file, get the new records and write them to a destination file.</summary> /// <param name="sourceFile">The file with the source records.</param> /// <param name="newFile">The file with the new records.</param> /// <param name="destFile">The destination file.</param> /// <returns>The new records on the new file.</returns> #if !GENERICS public object[] WriteNewRecords(string sourceFile, string newFile, string destFile) { FileHelperEngine engine = CreateEngineAndClearErrors(); object[] res = OnlyNewRecords(sourceFile, newFile);
/// <summary>Load errors from a file.</summary> /// <param name="fileName">The file that contains the errors.</param> public static ErrorInfo[] LoadErrors(string fileName) { FileHelperEngine engine = new FileHelperEngine(typeof(ErrorInfo)); return((ErrorInfo[])engine.ReadFile(fileName)); }
/// <summary> /// Used to read a string without instanciate the engine.<br /> /// <b>This is feature limited method try to use the non static methods.</b> /// </summary> /// <param name="input">The input string.</param> /// <returns>The read records.</returns> public static T[] ReadString <T>(string input) { FileHelperEngine <T> engine = new FileHelperEngine <T>(); return(engine.ReadString(input)); }