public void Run() { // Example of each tools Console.WriteLine("Today(): " + MTools.Today()); Console.WriteLine("Today(): " + MTools.Today(0, "dddd, dd MMMM yyyy HH:mm:ss")); Console.WriteLine("Today(-7): " + MTools.Today(-7)); Console.WriteLine("Today(7): " + MTools.Today(7)); Console.WriteLine("MTools.FrDateAdd(\"21/06/2004\", 15): " + MTools.FrDateAdd("21/06/2004", 15)); Console.WriteLine("MTools.IsPastFrDate(\"21/06/2004\"): " + MTools.IsPastFrDate("21/06/2004")); Console.WriteLine("MTools.DateNumToFrDate(\"20191115\"): " + MTools.DateNumToFrDate("20191115")); Console.WriteLine("MTools.CompareFrDate(\"21/06/2004\", \"21/07/2004\"): " + MTools.CompareFrDate("21/06/2004","21/07/2004")); Console.WriteLine("MTools.FrDateToYMDDate(\"21/06/2004\"): " + MTools.FrDateToYMDDate("21/06/2004")); Console.WriteLine("MTools.FrDateToDateNum(\"21/06/2004\"): " + MTools.FrDateToDateNum("21/06/2004")); Console.WriteLine("RandDate(2020): " + MTools.RandDate(2020)); Console.WriteLine("RandNum(3): " + MTools.RandNum(3)); Console.WriteLine("RandAlphaNum(10): " + MTools.RandAlphaNum(10)); Console.WriteLine("RandStr(10): " + MTools.RandStr(10)); Console.WriteLine("FirstCharToUpper(\"john\"): " + MTools.FirstCharToUpper("john")); Console.WriteLine("Siren(): " + MTools.Siren()); Console.WriteLine("RandCountry(): " + MTools.RandCountry()); Console.WriteLine("RandCountry(\"FRANCE\"): " + MTools.RandCountry("FRANCE")); Console.WriteLine(System.Environment.NewLine); // Demo on csv string string s = "{};COM;{} etc... string s = DatasetTools.ProcessData("{today};{today(5)};CHATEAUROUX;Jean-{randu1str(12)};{randstr(12)};{randnum(5)}; {randcountry}") Console.WriteLine("ProcessData: " + s); Dictionary<string, string> replacementDico = new Dictionary<string, string>(); replacementDico.Add("author", "Antoine De Saint-Exupéry") s = DatasetTools.ProcessData("{today};{today(5)};CHATEAUROUX;Jean-{randu1str(12)};{randstr(12)};{randnum(5)}; {randcountry};{#author}"); Console.WriteLine(System.Environment.NewLine); // Demo on csv file CsvInfo csvInfo = new CsvInfo(); csvInfo.fullFilename = "demo.csv"; var resList = CSVLoader.LoadAndProcessData(csvInfo); foreach(var line in resList) { Console.WriteLine(line); } }
public static List <string> LoadAndProcessData(CsvInfo csvInfo, Dictionary <string, string> replacementDico = null) { Func <string, string> func = (line) => { return(DatasetTools.ProcessData(line, replacementDico)); }; List <string> retList = _Preproc(csvInfo, func); return(retList); }
public static int LoadProcessDataAndSave(CsvInfo csvInfo, string ouputFullFilename, Dictionary <string, string> replacementDico = null) { Func <string, string> func = (line) => { return(DatasetTools.ProcessData(line, replacementDico)); }; List <string> retList = _Preproc(csvInfo, func); // Then Save System.IO.File.WriteAllLines(ouputFullFilename, retList); return(retList.Count); }
public static List <string> Load(CsvInfo csvInfo) { List <string> retList = _Preproc(csvInfo, null); return(retList); }
private static List <string> _Preproc(CsvInfo csvInfo, Func <string, string> stringAction) { string fullFillname = csvInfo.fullFilename; List <string> retList = new List <string>(); int nHeaderLines = csvInfo.headerCount; // Load CSV File try { //var reader = new StreamReader(fullFillname); var stream = new FileStream(fullFillname, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var reader = new StreamReader(stream); // Skip header while (!reader.EndOfStream && nHeaderLines > 0) { var line = reader.ReadLine(); if (stringAction != null) { retList.Add(line); } nHeaderLines--; } // Reads data lines while (!reader.EndOfStream) { var line = reader.ReadLine(); try { line = line.Trim(); // Skip special lines if (line.StartsWith("#") || String.IsNullOrEmpty(line)) { // It is a comment => skip // Empty line => skip continue; } if (stringAction != null) { line = stringAction(line); // Entire line. Not each field by each field //line = DatasetTools.PerformData(line); // Entire line. Not each field by each field } retList.Add(line); } catch (Exception e) { Console.WriteLine(e); } } } catch (Exception e) { Console.WriteLine(e); } return(retList); }