public void WriteNullAsync() { asyncEngine = new FileHelperAsyncEngine(typeof (SampleType)); asyncEngine.BeginWriteFile("tempNull.txt"); asyncEngine.WriteNext(new SampleType()); asyncEngine.WriteNext(new SampleType()); asyncEngine.WriteNext(new SampleType()); asyncEngine.Close(); asyncEngine.BeginReadFile("tempNull.txt"); SampleType[] res = (SampleType[]) asyncEngine.ReadNexts(5000); asyncEngine.Close(); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); Assert.AreEqual(DateTime.MinValue, res[0].Field1); Assert.AreEqual("", res[0].Field2); Assert.AreEqual(0, res[0].Field3); if (File.Exists("tempNull.txt")) File.Delete("tempNull.txt"); }
public void ImportGeonamesFrom(string fileName) { var geoNames = new FileHelperAsyncEngine(typeof(Geoname)); geoNames.BeginReadFile(fileName); _geoDataStore.DeleteAll(); long cnt = 0; foreach (Geoname geoName in geoNames) { //Store the name in a format suitable for case-insensitive searching: geoName.Name = geoName.Name.ToUpper(); if (geoName.FeatureClass == "P") { SaveCity(geoName, cnt); } // Parks: http://127.0.0.1:28017/local/geonames/?filter_FeatureClass=L&filter_FeatureCode=PRK if(geoName.FeatureClass.Equals("L") && geoName.FeatureCode.Equals("PRK")) { SavePark(geoName); } cnt++; } _geoDataStore.DoIndexing(); geoNames.Close(); }
public void AsyncRead() { asyncEngine = new FileHelperAsyncEngine(typeof (SampleType)); SampleType rec1, rec2; TestCommon.BeginReadTest(asyncEngine, "Good", "Test1.txt"); rec1 = (SampleType) asyncEngine.ReadNext(); Assert.IsNotNull(rec1); rec2 = (SampleType) asyncEngine.ReadNext(); Assert.IsNotNull(rec1); Assert.IsTrue(rec1 != rec2); rec1 = (SampleType) asyncEngine.ReadNext(); Assert.IsNotNull(rec2); rec1 = (SampleType) asyncEngine.ReadNext(); Assert.IsNotNull(rec2); Assert.IsTrue(rec1 != rec2); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncRead() { FileHelperAsyncEngine<SampleType> asyncEngine = new FileHelperAsyncEngine<SampleType>(); SampleType rec1, rec2; asyncEngine.BeginReadFile(Common.TestPath(@"Good\test1.txt")); rec1 = asyncEngine.ReadNext(); Assert.IsNotNull(rec1); rec2 = asyncEngine.ReadNext(); Assert.IsNotNull(rec1); Assert.IsTrue(rec1 != rec2); rec1 = asyncEngine.ReadNext(); Assert.IsNotNull(rec2); rec1 = asyncEngine.ReadNext(); Assert.IsNotNull(rec2); Assert.IsTrue(rec1 != rec2); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncRead() { var asyncEngine = new FileHelperAsyncEngine<SampleType>(); SampleType rec1, rec2; asyncEngine.BeginReadFile(FileTest.Good.Test1.Path); rec1 = asyncEngine.ReadNext(); Assert.IsNotNull(rec1); rec2 = asyncEngine.ReadNext(); Assert.IsNotNull(rec1); Assert.IsTrue(rec1 != rec2); rec1 = asyncEngine.ReadNext(); Assert.IsNotNull(rec2); rec1 = asyncEngine.ReadNext(); Assert.IsNotNull(rec2); Assert.IsTrue(rec1 != rec2); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void WriteEvents() { before = 0; after = 0; engine = new FileHelperAsyncEngine<SampleType>(); engine.BeforeWriteRecord += new BeforeWriteHandler<SampleType>(engine_BeforeWriteRecord); engine.AfterWriteRecord += new AfterWriteHandler<SampleType>(engine_AfterWriteRecord); var res = new SampleType[2]; res[0] = new SampleType(); res[1] = new SampleType(); res[0].Field1 = DateTime.Now.AddDays(1); res[0].Field2 = "je"; res[0].Field3 = 0; res[1].Field1 = DateTime.Now; res[1].Field2 = "ho"; res[1].Field3 = 2; engine.BeginWriteFile("tempEvent.txt"); engine.WriteNexts(res); engine.Close(); File.Delete("tempEvent.txt"); Assert.AreEqual(2, engine.TotalRecords); Assert.AreEqual(2, before); Assert.AreEqual(2, after); }
public void AsyncFieldIndex1() { var engine = new FileHelperAsyncEngine(typeof (SampleType)); var sw = new StringWriter(); engine.BeginWriteStream(sw); engine[0] = new DateTime(2003, 2, 1); engine[1] = "B"; engine[2] = 18; engine.WriteNextValues(); engine.Close(); engine.BeginReadString(sw.GetStringBuilder().ToString()); engine.ReadNext(); Assert.AreEqual(new DateTime(2003, 2, 1), engine[0]); Assert.AreEqual("B", engine[1]); Assert.AreEqual(18, engine[2]); Assert.AreEqual(new DateTime(2003, 2, 1), engine.LastRecordValues[0]); Assert.AreEqual("B", engine.LastRecordValues[1]); Assert.AreEqual(18, engine.LastRecordValues[2]); engine.ReadNext(); Assert.IsNull(engine.LastRecord); Assert.IsNull(engine.LastRecordValues); }
public static object[] ReadAllAsync(FileHelperAsyncEngine engine, string fileName) { ArrayList arr = new ArrayList(); engine.BeginReadFile(@"..\..\data\" + fileName); while(engine.ReadNext() != null) arr.Add(engine.LastRecord); engine.Close(); return arr.ToArray(); }
public static object[] ReadAllAsync(FileHelperAsyncEngine engine, string fileName) { ArrayList arr = new ArrayList(); engine.BeginReadFile(TestPath(fileName)); while (engine.ReadNext() != null) { arr.Add(engine.LastRecord); } engine.Close(); return(arr.ToArray()); }
public void AsyncReadEnumerableBad() { var asyncEngine = new FileHelperAsyncEngine <SampleType>(); Assert.Throws <FileHelpersException>(() => { foreach (var rec1 in asyncEngine) { rec1.ToString(); } }); asyncEngine.Close(); }
public void AsyncFieldIndex3() { var engine = new FileHelperAsyncEngine(typeof (SampleType)); engine.BeginReadString(data); while (engine.ReadNext() != null) { Assert.AreEqual(engine["Field1"], engine.LastRecordValues[0]); Assert.AreEqual(engine["Field2"], engine.LastRecordValues[1]); Assert.AreEqual(engine["Field3"], engine.LastRecordValues[2]); } engine.Close(); }
static void Main(string[] args) { FileHelperAsyncEngine engine = new FileHelperAsyncEngine (typeof(TestRecord)); engine.BeginReadFile(@"E:\_SVN\FileHelpers\test2.csv"); //string s; while(engine.ReadNext() != null) { } engine.Close(); }
public void AsyncFieldIndexBad1() { var engine = new FileHelperAsyncEngine(typeof(SampleType)); engine.BeginReadString(data); while (engine.ReadNext() != null) { Assert.Throws <IndexOutOfRangeException>(() => { object val = engine[10]; }); } engine.Close(); }
public void AsyncFieldIndex4() { var engine = new FileHelperAsyncEngine(typeof (SampleType)); engine.BeginReadString(data); Assert.AreEqual(3, engine.Options.FieldCount); while (engine.ReadNext() != null) { for (int i = 0; i < engine.Options.FieldCount; i++) Assert.IsNotNull(engine[i]); } engine.Close(); }
public void DiscardWriteRead2() { engine = new FileHelperEngine(typeof(DiscardLastType1)); DiscardLastType1[] res = (DiscardLastType1[])Common.ReadTest(engine, @"Good\DiscardLast1.txt"); asyncEngine = new FileHelperAsyncEngine(typeof(DiscardLastType1)); asyncEngine.FooterText = "This is a new Footer...."; asyncEngine.BeginWriteFile("temp.txt"); asyncEngine.WriteNexts(res); asyncEngine.Close(); asyncEngine.FooterText = "none none"; asyncEngine.BeginReadFile("temp.txt"); while (asyncEngine.ReadNext() != null) { } Assert.AreEqual(res.Length, asyncEngine.TotalRecords); Assert.AreEqual("This is a new Footer....\r\n", asyncEngine.FooterText); asyncEngine.Close(); Assert.AreEqual(res.Length, asyncEngine.TotalRecords); Assert.AreEqual("This is a new Footer....\r\n", asyncEngine.FooterText); if (File.Exists("tempo.txt")) { File.Delete("tempo.txt"); } }
public void AsyncFieldIndex3() { var engine = new FileHelperAsyncEngine(typeof(SampleType)); engine.BeginReadString(data); while (engine.ReadNext() != null) { Assert.AreEqual(engine["Field1"], engine.LastRecordValues[0]); Assert.AreEqual(engine["Field2"], engine.LastRecordValues[1]); Assert.AreEqual(engine["Field3"], engine.LastRecordValues[2]); } engine.Close(); }
public void DiscardWriteRead2() { var engine = new FileHelperEngine <DiscardLastType1>(); DiscardLastType1[] res = TestCommon.ReadTest <DiscardLastType1>(engine, "Good", "DiscardLast1.txt"); var asyncEngine = new FileHelperAsyncEngine <DiscardLastType1>(); asyncEngine.FooterText = "This is a new Footer...."; asyncEngine.BeginWriteFile("temp.txt"); asyncEngine.WriteNexts(res); asyncEngine.Close(); asyncEngine.FooterText = "none none"; asyncEngine.BeginReadFile("temp.txt"); while (asyncEngine.ReadNext() != null) { } Assert.AreEqual(res.Length, asyncEngine.TotalRecords); Assert.AreEqual(expectedShortFooterText, asyncEngine.FooterText); asyncEngine.Close(); Assert.AreEqual(res.Length, asyncEngine.TotalRecords); Assert.AreEqual(expectedShortFooterText, asyncEngine.FooterText); if (File.Exists("tempo.txt")) { File.Delete("tempo.txt"); } }
public void AsyncFieldIndexBad2() { var engine = new FileHelperAsyncEngine(typeof(SampleType)); engine.BeginReadString(data); Assert.Throws <BadUsageException>(() => { while (engine.ReadNext() != null) { object val = engine["FieldNoThere"]; } }); engine.Close(); }
public static void WriteCSVEntryPoint(object parameter) { Customer cust = new Customer(); custStorage.TryDequeue(out cust); var newcustomers = new FileHelperAsyncEngine <Customer>(); if (cust != null) { newcustomers.BeginAppendToFile("TestOut.txt"); //newcustomers.BeginWriteFile("TestOut.txt"); Console.WriteLine("policyID: {0} -- county: {1}", cust.policyID, cust.county); newcustomers.WriteNext(cust); } newcustomers.Close(); }
static void WriteFile <T>(List <T> data, string header, string path) where T : class { Console.WriteLine("Writing: {0}", path); UTF8Encoding utf8 = new UTF8Encoding(); var writer = new FileHelperAsyncEngine <T>(utf8); writer.HeaderText = header; using (writer.BeginWriteFile(path)) { foreach (T item in data) { writer.WriteNext(item); } } writer.Close(); }
public void AsyncFieldIndex1() { var engine = new FileHelperAsyncEngine(typeof (SampleType)); engine.BeginReadString(data); foreach (SampleType rec in engine) { Assert.AreEqual(rec.Field1, engine[0]); Assert.AreEqual(rec.Field2, engine[1]); Assert.AreEqual(rec.Field3, engine[2]); Assert.AreEqual(rec.Field1, engine["Field1"]); Assert.AreEqual(rec.Field2, engine["Field2"]); Assert.AreEqual(rec.Field3, engine["Field3"]); } engine.Close(); }
/// <summary> /// Run the Async engine with a vertical bar file /// </summary> private void cmdRun_Click(object sender, EventArgs e) { txtOut.Text = string.Empty; var engine = new FileHelperAsyncEngine<CustomersVerticalBar>(); engine.BeginReadString(TestData.mCustomersTest); // The Async engines are IEnumerable foreach(CustomersVerticalBar cust in engine) { // your code here txtOut.Text += cust.CustomerID + " - " + cust.ContactTitle + Environment.NewLine; } engine.Close(); }
/// <summary> /// Run the Async engine with a vertical bar file /// </summary> private void cmdRun_Click(object sender, EventArgs e) { txtOut.Text = string.Empty; var engine = new FileHelperAsyncEngine <CustomersVerticalBar>(); engine.BeginReadString(TestData.mCustomersTest); // The Async engines are IEnumerable foreach (CustomersVerticalBar cust in engine) { // your code here txtOut.Text += cust.CustomerID + " - " + cust.ContactTitle + Environment.NewLine; } engine.Close(); }
public CsvDataSource(byte[] data) { if (data == null || data.Length == 0) { return; } var ms = new MemoryStream(data); var sr = new StreamReader(ms); var engine = new FileHelperAsyncEngine <T>(); engine.Options.IgnoreEmptyLines = true; //engine.Options.IgnoreFirstLines = 1; engine.Options.IgnoreCommentedLines.CommentMarker = "#"; engine.Options.IgnoreCommentedLines.InAnyPlace = true; //for (int i = 0; i < engine.Options.FieldsNames.Length; i++) //{ // UnityEngine.Logger.Log(engine.Options.FieldsNames[i] + " : " + engine.Options.Fields[i]); //} //var time = DateTime.Now; using (engine.BeginReadStream(sr)) { foreach (var item in engine) { if (ContainsKey(item.Id)) { Debug.LogError(typeof(T).Name + " 有重複項目 Id = " + item.Id); } else { Add(item.Id, item); } } } //Logger.Log(typeof(T).Name + " " + (DateTime.Now - time).TotalMilliseconds); ms.Dispose(); sr.Close(); sr.Dispose(); engine.Close(); }
public void AsyncReadEnumerable2() { using (asyncEngine = new FileHelperAsyncEngine(typeof(SampleType))) { TestCommon.BeginReadTest(asyncEngine, "Good", "Test1.txt"); int lineAnt = asyncEngine.LineNumber; foreach (SampleType rec1 in asyncEngine) { Assert.IsNotNull(rec1); Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber); lineAnt = asyncEngine.LineNumber; } } Assert.AreEqual(4, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncFieldIndex4() { var engine = new FileHelperAsyncEngine(typeof(SampleType)); engine.BeginReadString(data); Assert.AreEqual(3, engine.Options.FieldCount); while (engine.ReadNext() != null) { for (int i = 0; i < engine.Options.FieldCount; i++) { Assert.IsNotNull(engine[i]); } } engine.Close(); }
static LinkedList <T> ReadFile <T>(string path) where T : class { Console.WriteLine("Reading: {0}", path); UTF8Encoding utf8 = new UTF8Encoding(); var reader = new FileHelperAsyncEngine <T>(utf8); var result = new LinkedList <T>(); using (reader.BeginReadFile(path)) { foreach (T item in reader) { result.AddLast(item); } } reader.Close(); return(result); }
public void AsyncFieldIndex1() { var engine = new FileHelperAsyncEngine(typeof(SampleType)); engine.BeginReadString(data); foreach (SampleType rec in engine) { Assert.AreEqual(rec.Field1, engine[0]); Assert.AreEqual(rec.Field2, engine[1]); Assert.AreEqual(rec.Field3, engine[2]); Assert.AreEqual(rec.Field1, engine["Field1"]); Assert.AreEqual(rec.Field2, engine["Field2"]); Assert.AreEqual(rec.Field3, engine["Field3"]); } engine.Close(); }
public void AsyncReadEnumerable() { var asyncEngine = new FileHelperAsyncEngine<SampleType>(); asyncEngine.BeginReadFile(FileTest.Good.Test1.Path); int lineAnt = asyncEngine.LineNumber; foreach (var rec1 in asyncEngine) { Assert.IsNotNull(rec1); Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber); lineAnt = asyncEngine.LineNumber; } Assert.AreEqual(4, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
static void Main(string[] args) { long start = DateTime.Now.Ticks; FileHelperAsyncEngine engine = new FileHelperAsyncEngine(typeof(TestRecord)); engine.BeginReadFile(@"E:\_SVN\FileHelpers\test2.csv"); //string s; while (engine.ReadNext() != null) { } engine.Close(); TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start); Console.WriteLine("Total Time: " + Math.Round(ts.TotalSeconds, 2)); Console.ReadLine(); }
public void AsyncReadMoreAndMore() { FileHelperAsyncEngine <SampleType> asyncEngine = new FileHelperAsyncEngine <SampleType>(); SampleType rec1; asyncEngine.BeginReadFile(FileTest.Good.Test1.Path); rec1 = asyncEngine.ReadNext(); rec1 = asyncEngine.ReadNext(); rec1 = asyncEngine.ReadNext(); rec1 = asyncEngine.ReadNext(); rec1 = asyncEngine.ReadNext(); Assert.IsTrue(rec1 == null); rec1 = (SampleType)asyncEngine.ReadNext(); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncRead2() { SampleType rec1; var asyncEngine = new FileHelperAsyncEngine<SampleType>(); asyncEngine.BeginReadFile(FileTest.Good.Test1.Path); int lineAnt = asyncEngine.LineNumber; while (asyncEngine.ReadNext() != null) { rec1 = asyncEngine.LastRecord; Assert.IsNotNull(rec1); Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber); lineAnt = asyncEngine.LineNumber; } Assert.AreEqual(4, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncReadEnumerable() { FileHelperAsyncEngine <SampleType> asyncEngine = new FileHelperAsyncEngine <SampleType>(); asyncEngine.BeginReadFile(FileTest.Good.Test1.Path); int lineAnt = asyncEngine.LineNumber; foreach (SampleType rec1 in asyncEngine) { Assert.IsNotNull(rec1); Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber); lineAnt = asyncEngine.LineNumber; } Assert.AreEqual(4, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncRead2() { SampleType rec1; asyncEngine = new FileHelperAsyncEngine(typeof(SampleType)); Common.BeginReadTest(asyncEngine, @"Good\test1.txt"); int lineAnt = asyncEngine.LineNumber; while (asyncEngine.ReadNext() != null) { rec1 = (SampleType)asyncEngine.LastRecord; Assert.IsNotNull(rec1); Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber); lineAnt = asyncEngine.LineNumber; } Assert.AreEqual(4, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
static void Main(string[] args) { long start = DateTime.Now.Ticks; FileHelperAsyncEngine engine = new FileHelperAsyncEngine (typeof(TestRecord)); engine.BeginReadFile(@"E:\_SVN\FileHelpers\test2.csv"); //string s; while(engine.ReadNext() != null) { } engine.Close(); TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start); Console.WriteLine("Total Time: " + Math.Round(ts.TotalSeconds, 2)); Console.ReadLine(); }
public void BeginReadWhileWriting() { var eng = new FileHelperAsyncEngine(typeof(SampleType)); var filename = TestCommon.GetTempFile("TempWrite.txt"); Assert.Throws <BadUsageException>(() => { try { eng.BeginWriteFile(filename); eng.BeginReadString("jejjeje"); } finally { eng.Close(); if (File.Exists(filename)) { File.Delete(filename); } } }); }
public void AsyncReadMoreAndMore() { asyncEngine = new FileHelperAsyncEngine(typeof(SampleType)); SampleType rec1; TestCommon.BeginReadTest(asyncEngine, "Good", "Test1.txt"); rec1 = (SampleType)asyncEngine.ReadNext(); rec1 = (SampleType)asyncEngine.ReadNext(); rec1 = (SampleType)asyncEngine.ReadNext(); rec1 = (SampleType)asyncEngine.ReadNext(); rec1 = (SampleType)asyncEngine.ReadNext(); Assert.IsTrue(rec1 == null); rec1 = (SampleType)asyncEngine.ReadNext(); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncRead2() { SampleType rec1; FileHelperAsyncEngine <SampleType> asyncEngine = new FileHelperAsyncEngine <SampleType>(); asyncEngine.BeginReadFile(FileTest.Good.Test1.Path); int lineAnt = asyncEngine.LineNumber; while (asyncEngine.ReadNext() != null) { rec1 = asyncEngine.LastRecord; Assert.IsNotNull(rec1); Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber); lineAnt = asyncEngine.LineNumber; } Assert.AreEqual(4, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void BeginReadWhileWriting() { FileHelperAsyncEngine eng = new FileHelperAsyncEngine(typeof(SampleType)); var filename = TestCommon.GetTempFile("TempWrite.txt"); Assert.Throws<BadUsageException>(() => { try { eng.BeginWriteFile(filename); eng.BeginReadString("jejjeje"); } finally { eng.Close(); if (File.Exists(filename)) File.Delete(filename); } }); }
public void BeginReadWhileWriting() { FileHelperAsyncEngine eng = new FileHelperAsyncEngine(typeof(SampleType)); Assert.Throws <BadUsageException>(() => { try { eng.BeginWriteFile(@"c:\tempfile.tmp"); eng.BeginReadString("jejjeje"); } finally { eng.Close(); if (File.Exists(@"c:\tempfile.tmp")) { File.Delete(@"c:\tempfile.tmp"); } } }); }
public void AsyncRead2() { SampleType rec1; asyncEngine = new FileHelperAsyncEngine(typeof(SampleType)); TestCommon.BeginReadTest(asyncEngine, "Good", "Test1.txt"); int lineAnt = asyncEngine.LineNumber; while (asyncEngine.ReadNext() != null) { rec1 = (SampleType)asyncEngine.LastRecord; Assert.IsNotNull(rec1); Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber); lineAnt = asyncEngine.LineNumber; } Assert.AreEqual(4, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void ReadAsyncFieldIndex() { string data = "11121314901234\n" + "10111314012345\n" + "11101314123456\n" + "10101314234567\n"; asyncEngine = new FileHelperAsyncEngine(typeof(SampleType)); asyncEngine.BeginReadString(data); foreach (SampleType rec in asyncEngine) { Assert.AreEqual(rec.Field1, asyncEngine[0]); Assert.AreEqual(rec.Field2, asyncEngine[1]); Assert.AreEqual(rec.Field3, asyncEngine[2]); Assert.AreEqual(rec.Field1, asyncEngine["Field1"]); Assert.AreEqual(rec.Field2, asyncEngine["Field2"]); Assert.AreEqual(rec.Field3, asyncEngine["Field3"]); } asyncEngine.Close(); }
public void ReadAsyncFieldIndex() { string data = "11121314901234" + Environment.NewLine + "10111314012345" + Environment.NewLine + "11101314123456" + Environment.NewLine + "10101314234567" + Environment.NewLine; var asyncEngine = new FileHelperAsyncEngine <SampleType>(); asyncEngine.BeginReadString(data); foreach (var rec in asyncEngine) { Assert.AreEqual(rec.Field1, asyncEngine[0]); Assert.AreEqual(rec.Field2, asyncEngine[1]); Assert.AreEqual(rec.Field3, asyncEngine[2]); Assert.AreEqual(rec.Field1, asyncEngine["Field1"]); Assert.AreEqual(rec.Field2, asyncEngine["Field2"]); Assert.AreEqual(rec.Field3, asyncEngine["Field3"]); } asyncEngine.Close(); }
static GrimoireHandler() { //first, check for compiled grimoire file if (File.Exists("grimoire.cgm")) { FileInfo grimoireLoad = new FileInfo("grimoire.cgm"); BinaryFormatter b = new BinaryFormatter(); Stream s = grimoireLoad.OpenRead(); grimoire = (List <GrimoireAbility>)b.Deserialize(s); s.Close(); } else if (File.Exists("grimoire.csv")) { //compiled grimoire does not exist, recompile! FileHelperAsyncEngine <GrimoireLine> reader = new FileHelperAsyncEngine <GrimoireLine>(); reader.BeginReadFile("grimoire.csv"); foreach (GrimoireLine line in reader) { if (line.AllowInMCS) { grimoire.Add(new GrimoireAbility(line)); } } reader.Close(); //compile the grimoire to grimoire.cgm FileInfo compileTarget = new FileInfo("grimoire.cgm"); BinaryFormatter b = new BinaryFormatter(); Stream s = compileTarget.Open(FileMode.Create, FileAccess.Write); b.Serialize(s, grimoire); s.Close(); } else { MessageBox.Show("No grimoire.csv or grimoire.cgm detected. Unable to load in predefined character abilities. Please check the MCS Helper page for the most recent version of the grimoire.", "Can't find grimoire!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
public void AsyncReadMoreAndMore() { var asyncEngine = new FileHelperAsyncEngine<SampleType>(); SampleType rec1; asyncEngine.BeginReadFile(FileTest.Good.Test1.Path); rec1 = asyncEngine.ReadNext(); rec1 = asyncEngine.ReadNext(); rec1 = asyncEngine.ReadNext(); rec1 = asyncEngine.ReadNext(); rec1 = asyncEngine.ReadNext(); Assert.IsTrue(rec1 == null); rec1 = (SampleType) asyncEngine.ReadNext(); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncReadEnumerableBad() { var asyncEngine = new FileHelperAsyncEngine<SampleType>(); Assert.Throws<FileHelpersException>(() => { foreach (var rec1 in asyncEngine) { rec1.ToString(); } }); asyncEngine.Close(); }
public void AppendToEmptyAsync() { FileHelperEngine engineOld = new FileHelperEngine(typeof (SampleType)); FileHelperAsyncEngine engine = new FileHelperAsyncEngine(typeof (SampleType)); SampleType rec = new SampleType(); rec.Field1 = DateTime.Now.AddDays(1).Date; rec.Field2 = "je"; rec.Field3 = 0; File.Copy(TestCommon.GetPath("Good", "TestEmpty.txt"), "tempEmpty.txt", true); engine.BeginAppendToFile(@"tempEmpty.txt"); engine.WriteNext(rec); engine.Close(); SampleType[] res2 = (SampleType[]) engineOld.ReadFile(@"tempEmpty.txt"); Assert.AreEqual(1, res2.Length); Assert.AreEqual(rec.Field1, res2[0].Field1); if (File.Exists("tempEmpty.txt")) File.Delete("tempEmpty.txt"); }
public void ReadAsyncFieldIndex() { string data = "11121314901234" + Environment.NewLine + "10111314012345" + Environment.NewLine + "11101314123456" + Environment.NewLine + "10101314234567" + Environment.NewLine; var asyncEngine = new FileHelperAsyncEngine<SampleType>(); asyncEngine.BeginReadString(data); foreach (var rec in asyncEngine) { Assert.AreEqual(rec.Field1, asyncEngine[0]); Assert.AreEqual(rec.Field2, asyncEngine[1]); Assert.AreEqual(rec.Field3, asyncEngine[2]); Assert.AreEqual(rec.Field1, asyncEngine["Field1"]); Assert.AreEqual(rec.Field2, asyncEngine["Field2"]); Assert.AreEqual(rec.Field3, asyncEngine["Field3"]); } asyncEngine.Close(); }
public void AsyncReadEnumerableAutoDispose() { asyncEngine = new FileHelperAsyncEngine(typeof (SampleType)); TestCommon.BeginReadTest(asyncEngine, "Good", "Test1.txt"); asyncEngine.ReadNext(); asyncEngine.ReadNext(); asyncEngine.Close(); }
public void AsyncReadEnumerable2() { using (asyncEngine = new FileHelperAsyncEngine(typeof (SampleType))) { TestCommon.BeginReadTest(asyncEngine, "Good", "Test1.txt"); int lineAnt = asyncEngine.LineNumber; foreach (SampleType rec1 in asyncEngine) { Assert.IsNotNull(rec1); Assert.AreEqual(lineAnt + 1, asyncEngine.LineNumber); lineAnt = asyncEngine.LineNumber; } } Assert.AreEqual(4, asyncEngine.TotalRecords); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }
public void AsyncReadEnumerableBad() { asyncEngine = new FileHelperAsyncEngine(typeof (SampleType)); Assert.Throws<FileHelpersException>(() => { foreach (SampleType rec1 in asyncEngine) rec1.ToString(); }); asyncEngine.Close(); }
public void DiscardWriteRead2() { var engine = new FileHelperEngine<DiscardLastType1>(); DiscardLastType1[] res = TestCommon.ReadTest<DiscardLastType1>(engine, "Good", "DiscardLast1.txt"); var asyncEngine = new FileHelperAsyncEngine<DiscardLastType1>(); asyncEngine.FooterText = "This is a new Footer...."; asyncEngine.BeginWriteFile("temp.txt"); asyncEngine.WriteNexts(res); asyncEngine.Close(); asyncEngine.FooterText = "none none"; asyncEngine.BeginReadFile("temp.txt"); while (asyncEngine.ReadNext() != null) {} Assert.AreEqual(res.Length, asyncEngine.TotalRecords); Assert.AreEqual(expectedShortFooterText, asyncEngine.FooterText); asyncEngine.Close(); Assert.AreEqual(res.Length, asyncEngine.TotalRecords); Assert.AreEqual(expectedShortFooterText, asyncEngine.FooterText); if (File.Exists("tempo.txt")) File.Delete("tempo.txt"); }
public void ReadAsyncFieldIndex() { string data = "11121314901234\n" + "10111314012345\n" + "11101314123456\n" + "10101314234567\n" ; asyncEngine = new FileHelperAsyncEngine(typeof(SampleType)); asyncEngine.BeginReadString(data); foreach (SampleType rec in asyncEngine) { Assert.AreEqual(rec.Field1, asyncEngine[0]); Assert.AreEqual(rec.Field2, asyncEngine[1]); Assert.AreEqual(rec.Field3, asyncEngine[2]); Assert.AreEqual(rec.Field1, asyncEngine["Field1"]); Assert.AreEqual(rec.Field2, asyncEngine["Field2"]); Assert.AreEqual(rec.Field3, asyncEngine["Field3"]); } asyncEngine.Close(); }
public void AsyncReadEnumerableBad() { asyncEngine = new FileHelperAsyncEngine(typeof (SampleType)); foreach (SampleType rec1 in asyncEngine) { rec1.ToString(); } asyncEngine.Close(); }
static void ProcessFileAsync(string fileName) { _log.Info(string.Format("ProcessFileAsync {0}", fileName)); var csvFile = GetFullFileName(FTP_REQUESTS, fileName, BookingRequestFileExtension.Csv); var engine = new FileHelperAsyncEngine(typeof(BookingRequest)); engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue; engine.BeginReadFile(csvFile); var bookingRequests = new List<BookingRequest>(); while (engine.ReadNext() != null) { var record = (BookingRequest)engine.LastRecord; bookingRequests.Add(record); } if (engine.ErrorManager.Errors.Length > 0) { ProcessErrorRecords(engine, bookingRequests.Count, fileName); } engine.Close(); ProcessCorrectRecords(bookingRequests); var requestFileName = Path.GetFileName(fileName); File.Move(csvFile, GetFullFileName(FTP_READ, fileName, BookingRequestFileExtension.Csv)); File.Move(GetFullFileName(FTP_REQUESTS, fileName, BookingRequestFileExtension.Md5), GetFullFileName(FTP_READ, fileName, BookingRequestFileExtension.Md5)); }
public void AsyncReadMoreAndMore() { asyncEngine = new FileHelperAsyncEngine(typeof (SampleType)); SampleType rec1; Common.BeginReadTest(asyncEngine, @"Good\test1.txt"); rec1 = (SampleType) asyncEngine.ReadNext(); rec1 = (SampleType) asyncEngine.ReadNext(); rec1 = (SampleType) asyncEngine.ReadNext(); rec1 = (SampleType) asyncEngine.ReadNext(); rec1 = (SampleType) asyncEngine.ReadNext(); Assert.IsTrue(rec1 == null); rec1 = (SampleType) asyncEngine.ReadNext(); Assert.AreEqual(0, asyncEngine.ErrorManager.ErrorCount); asyncEngine.Close(); }