public void WriteReadImage() { var ima = new ImageClass(); var bmp = new Bitmap(20, 10); bmp.SetPixel(10, 5, Color.Gainsboro); bmp.SetPixel(10, 7, Color.Navy); ima.MyImage = bmp; var engine = new FileHelperEngine <ImageClass>(); string data = engine.WriteString(new ImageClass[] { ima }); ImageClass[] res = engine.ReadString(data); Assert.AreEqual(1, res.Length); Assert.IsNotNull(res[0].MyImage); Assert.AreEqual(typeof(Bitmap), res[0].MyImage.GetType()); Assert.AreEqual(Color.Gainsboro.R, ((Bitmap)res[0].MyImage).GetPixel(10, 5).R); Assert.AreEqual(Color.Gainsboro.G, ((Bitmap)res[0].MyImage).GetPixel(10, 5).G); Assert.AreEqual(Color.Gainsboro.B, ((Bitmap)res[0].MyImage).GetPixel(10, 5).B); Assert.AreEqual(Color.Navy.R, ((Bitmap)res[0].MyImage).GetPixel(10, 7).R); Assert.AreEqual(Color.Navy.G, ((Bitmap)res[0].MyImage).GetPixel(10, 7).G); Assert.AreEqual(Color.Navy.B, ((Bitmap)res[0].MyImage).GetPixel(10, 7).B); }
public FileResult FileHelperCsv() { var engine = new FileHelperEngine<Product> {HeaderText = "Id,Name"}; var data = engine.WriteString(getProducts()); var bytes = Encoding.UTF8.GetBytes(data); return File(bytes, "text/csv", "Products.csv"); }
//-> /File //-> Instantiate a FileHelperEngine and write the file: public override void Run() { //-> File:Example.cs var engine = new FileHelperEngine <Orders>(); var orders = new List <Orders>(); orders.Add(new Orders() { OrderID = 1, CustomerID = "AIRG", Freight = 82.43M, OrderDate = new DateTime(2009, 05, 01) }); orders.Add(new Orders() { OrderID = 2, CustomerID = "JSYV", Freight = 12.22M, OrderDate = new DateTime(2009, 05, 02) }); engine.WriteFile("Output.Txt", orders); //-> /File Console.WriteLine(engine.WriteString(orders)); }
public void WriteEvents() { before = 0; after = 0; engine = new FileHelperEngine(typeof(SampleType)); engine.BeforeWriteRecord += new BeforeWriteRecordHandler(engine_BeforeWriteRecord); engine.AfterWriteRecord += new AfterWriteRecordHandler(engine_AfterWriteRecord); SampleType[] 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.WriteString(res); Assert.AreEqual(2, engine.TotalRecords); Assert.AreEqual(2, before); Assert.AreEqual(2, after); }
//-> /File //-> Finally you must to instantiate a FileHelperEngine and write the file public override void Run() { //-> File:Example.cs var engine = new FileHelperEngine<Orders>(); var orders = new List<Orders>(); orders.Add(new Orders() { OrderID = 1, CustomerID = "AIRG", Freight = 82.43M, OrderDate = new DateTime(2009, 05, 01) }); orders.Add(new Orders() { OrderID = 2, CustomerID = "JSYV", Freight = 12.22M, OrderDate = new DateTime(2009, 05, 02) }); engine.WriteFile("Output.Txt", orders); //-> /File Console.WriteLine(engine.WriteString(orders)); }
public void WriteReadImage() { ImageClass ima = new ImageClass(); Bitmap bmp = new Bitmap(20, 10); bmp.SetPixel(10, 5, Color.Gainsboro); bmp.SetPixel(10, 7, Color.Navy); ima.MyImage = bmp; FileHelperEngine engine = new FileHelperEngine(typeof(ImageClass)); string data = engine.WriteString((IList) new object[] {ima}); ImageClass[] res = (ImageClass[]) engine.ReadString(data); Assert.AreEqual(1, res.Length); Assert.IsNotNull(res[0].MyImage); Assert.AreEqual(typeof(Bitmap), res[0].MyImage.GetType()); Assert.AreEqual(Color.Gainsboro.R, ((Bitmap)res[0].MyImage).GetPixel(10, 5).R); Assert.AreEqual(Color.Gainsboro.G, ((Bitmap)res[0].MyImage).GetPixel(10, 5).G); Assert.AreEqual(Color.Gainsboro.B, ((Bitmap)res[0].MyImage).GetPixel(10, 5).B); Assert.AreEqual(Color.Navy.R, ((Bitmap)res[0].MyImage).GetPixel(10, 7).R); Assert.AreEqual(Color.Navy.G, ((Bitmap)res[0].MyImage).GetPixel(10, 7).G); Assert.AreEqual(Color.Navy.B, ((Bitmap)res[0].MyImage).GetPixel(10, 7).B); }
//-> /File //-> Now just create some records and write them with the Engine: public override void Run() { //-> File:Example.cs var engine = new FileHelperEngine <Customer>(); var customers = new List <Customer>(); var order1 = new Customer() { CustId = 1, Name = "Antonio Moreno Taquería", AddedDate = new DateTime(2009, 05, 01) }; var order2 = new Customer() { CustId = 2, Name = "Berglunds snabbköp", AddedDate = new DateTime(2009, 05, 02) }; customers.Add(order1); customers.Add(order2); engine.WriteFile("Output.Txt", customers); //-> /File Console.WriteLine(engine.WriteString(customers)); }
public void BadRecordType() { var engine = new FileHelperEngine(typeof(BadRecordTypeClass)); Assert.Throws <BadUsageException>(() => engine.WriteString(new[] { "hola" })); }
public void WriteNullableTypes2() { var orders = new List <TestOrder>(); var or1 = new TestOrder(); or1.OrderID = 1; or1.OrderDate = null; or1.RequiredDate = new DateTime(2007, 1, 2); or1.ShipVia = null; orders.Add(or1); var or2 = new TestOrder(); or2.OrderID = 2; or2.OrderDate = new DateTime(2007, 2, 1); or2.RequiredDate = null; or2.ShipVia = 1; orders.Add(or2); var fileHelperEngine = new FileHelperEngine <TestOrder>(); TestOrder[] res = fileHelperEngine.ReadString(fileHelperEngine.WriteString(orders)); Assert.IsNull(res[0].OrderDate); Assert.IsNull(res[1].RequiredDate); Assert.IsNull(res[0].ShipVia); }
public void WriteBadUsage2() { var engine = new FileHelperEngine <SampleType>(); Assert.Throws <ArgumentNullException>(() => engine.WriteString(null)); }
public void WriteEvents() { before = 0; after = 0; engine = new FileHelperEngine<SampleType>(); engine.BeforeWriteRecord += engine_BeforeWriteRecord; engine.AfterWriteRecord += engine_AfterWriteRecord; SampleType[] 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.WriteString(res); Assert.AreEqual(2, engine.TotalRecords); Assert.AreEqual(2, before); Assert.AreEqual(2, after); }
public void BadRecordType() { FileHelperEngine engine = new FileHelperEngine(typeof(BadRecordTypeClass)); string res = engine.WriteString(new string[] { "hola" }); Console.Write(res); }
//-> /File //-> Now just create some records and write them with the Engine public override void Run() { //-> File:Example.cs var engine = new FileHelperEngine<Customer>(); var customers = new List<Customer>(); var order1 = new Customer() { CustId = 1, Name = "Antonio Moreno Taquería", AddedDate = new DateTime(2009, 05, 01) }; var order2 = new Customer() { CustId = 2, Name = "Berglunds snabbköp", AddedDate = new DateTime(2009, 05, 02) }; customers.Add(order1); customers.Add(order2); engine.WriteFile("Output.Txt", customers); //-> /File Console.WriteLine(engine.WriteString(customers)); }
public void WriteNullableTypes1() { var engine = new FileHelperEngine <NullableType>(); var toWrite = new List <NullableType>(); NullableType record; record = new NullableType(); record.Field1 = new DateTime(1314, 12, 11); record.Field2 = "901"; record.Field3 = 234; toWrite.Add(record); record = new NullableType(); record.Field1 = null; record.Field2 = "012"; record.Field3 = null; toWrite.Add(record); record = new NullableType(); record.Field1 = new DateTime(1316, 5, 6); record.Field2 = "111"; record.Field3 = 4; toWrite.Add(record); NullableType[] res = engine.ReadString(engine.WriteString(toWrite)); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1); Assert.AreEqual("901", res[0].Field2); Assert.AreEqual(234, res[0].Field3); Assert.IsNull(res[1].Field1); Assert.AreEqual("012", res[1].Field2); Assert.IsNull(res[1].Field3); Assert.AreEqual(new DateTime(1316, 5, 6), res[2].Field1); Assert.AreEqual("", engine.WriteString(toWrite).Split(new string[] { Environment.NewLine }, StringSplitOptions.None)[1]. Substring(0, 8).Trim()); }
public void WriteStringNullableGuid() { var engine = new FileHelperEngine <SampleTypeNullableGuid>(); string resStr = engine.WriteString(new[] { new SampleTypeNullableGuid() }); Assert.AreEqual(Environment.NewLine, resStr); }
public void WriteNullableTypes1() { engine = new FileHelperEngine(typeof(NullableType)); System.Collections.Generic.List <NullableType> toWrite = new System.Collections.Generic.List <NullableType>(); NullableType record; record = new NullableType(); record.Field1 = new DateTime(1314, 12, 11); record.Field2 = "901"; record.Field3 = 234; toWrite.Add(record); record = new NullableType(); record.Field1 = null; record.Field2 = "012"; record.Field3 = null; toWrite.Add(record); record = new NullableType(); record.Field1 = new DateTime(1316, 5, 6); record.Field2 = "111"; record.Field3 = 4; toWrite.Add(record); NullableType[] res = (NullableType[])engine.ReadString(engine.WriteString(toWrite)); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1); Assert.AreEqual("901", res[0].Field2); Assert.AreEqual(234, res[0].Field3); Assert.IsNull(res[1].Field1); Assert.AreEqual("012", res[1].Field2); Assert.IsNull(res[1].Field3); Assert.AreEqual(new DateTime(1316, 5, 6), res[2].Field1); Assert.AreEqual("", engine.WriteString(toWrite).Split(new string[] { "\r\n" }, StringSplitOptions.None)[1]. Substring(0, 8).Trim()); }
private void RunAlignTest() { engine = new FileHelperEngine(typeof (AlignClass)); AlignClass[] resTemp = (AlignClass[]) TestCommon.ReadTest(engine, "Good", "Trim1.txt"); string tmp = engine.WriteString(resTemp); engine = new FileHelperEngine(typeof (AlignClass2)); res = (AlignClass2[]) engine.ReadString(tmp); }
private void RunAlignTest() { engine = new FileHelperEngine(typeof(AlignClass)); AlignClass[] resTemp = (AlignClass[])TestCommon.ReadTest(engine, @"Good\Trim1.txt"); string tmp = engine.WriteString(resTemp); engine = new FileHelperEngine(typeof(AlignClass2)); res = (AlignClass2[])engine.ReadString(tmp); }
public void ArrayFieldsRW() { engine = new FileHelperEngine(typeof(ArrayType1)); ArrayType1[] res = engine.ReadFile(Common.TestPath(@"good\ArrayFields.txt")) as ArrayType1[]; SimpleComparer(res); res = engine.ReadString(engine.WriteString(res)) as ArrayType1[]; SimpleComparer(res); }
public void GenerateStockMutations(Int32 vendorId, List <WehkampStockMutation> mutations) { var mappedList = _mapper.MapToDatCol(vendorId, mutations); var flatFile = _stockEngine.WriteString(mappedList); var path = CommunicatorService.GetMessagePath(vendorId, MessageTypes.StockMutation); File.WriteAllText(Path.Combine(path.MessagePath, _fileName), flatFile); }
private void RunAlignTest() { var engine = new FileHelperEngine<AlignClass>(); var resTemp = TestCommon.ReadTest<AlignClass>(engine, "Good", "Trim1.txt"); string tmp = engine.WriteString(resTemp); var engine2 = new FileHelperEngine<AlignClass2>(); res = engine2.ReadString(tmp); }
private static void Main(string[] args) { var engine = new FileHelperEngine <MyClass>(); var myClass1 = new MyClass(); myClass1.Field1 = "Dear Sir,\n Blah blah blah"; myClass1.Field2 = "Yours sincerely,\n George"; var output = engine.WriteString(new MyClass[] { myClass1 }); Assert.AreEqual(@"""Dear Sir, Blah blah blah"",""Yours sincerely, George""" + Environment.NewLine, output); }
private void RunAlignTest() { var engine = new FileHelperEngine <AlignClass>(); var resTemp = TestCommon.ReadTest <AlignClass>(engine, "Good", "Trim1.txt"); string tmp = engine.WriteString(resTemp); var engine2 = new FileHelperEngine <AlignClass2>(); res = engine2.ReadString(tmp); }
public void ArrayFieldsRW() { var engine = new FileHelperEngine <ArrayType1>(); var res = engine.ReadFile(FileTest.Good.ArrayFields.Path); SimpleComparer(res); res = engine.ReadString(engine.WriteString(res)); SimpleComparer(res); }
public void CheckItWritesToFileWithCaption() { var engine = new FileHelperEngine <CustomersVerticalBarWithFieldCaption>(); var records = engine.ReadFile(FileTest.Good.CustomersVerticalBarDemo.Path); engine.HeaderText = engine.GetFileHeader(); var result = engine.WriteString(records); Check.That(result).StartsWith("Customer ID|Company Name|Contact Name|Contact Title|Address|City|Country"); Check.That(result.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length) .IsEqualTo(records.Length + 1); }
private void cmdRun_Click(object sender, EventArgs e) { cmdRun.Enabled = false; FileHelperEngine engine = new FileHelperEngine(typeof (CustomersVerticalBar)); object[] records = engine.ReadFile(MainClass.GlobalTestFile); Application.DoEvents(); engine.Progress += ProgressChange; engine.WriteString(records); cmdRun.Enabled = true; }
public void CheckItWritesToFile() { var engine = new FileHelperEngine<CustomersVerticalBar>(); var records = engine.ReadFile(FileTest.Good.CustomersVerticalBarDemo.Path); engine.HeaderText = engine.GetFileHeader(); var result = engine.WriteString(records); Check.That(result).StartsWith("CustomerID|CompanyName|ContactName|ContactTitle|Address|City|Country"); Check.That(result.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length) .IsEqualTo(records.Length + 1); }
private void WriteFileOnPath(string path, string filename, Agora file) { var eng = new FileHelperEngine <Campos>(); StringBuilder sb = new StringBuilder(); sb.AppendLine(file.Header.ToString()); sb.AppendLine(string.Join(" ", eng.Options.FieldsNames)); sb.AppendLine(eng.WriteString(file.Campos)); var bytes = Encoding.ASCII.GetBytes(sb.ToString()); filename = $"/MinhaCDN_{DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss")}_{filename}"; File.WriteAllBytes(string.Concat(path, filename), bytes); }
/// <summary> /// Generate csv as string from target data set /// </summary> /// <returns></returns> public String Export() { // Filehelpers doesn't support creating a header row for writing // the csv file, so use the class mapping order. var header = string.Join(",", _readDao.ClassMap.AllDataColsInOrder.ToArray()); var rows = _readDao.Get(); var engine = new FileHelperEngine <T> { HeaderText = header }; engine.AfterWriteRecord += EngineOnAfterWriteRecord; return(engine.WriteString(rows)); }
public void ReadFileMaxRecords08() { var engine = new FileHelperEngine <SampleType>(); var res = FileTest.Good.Test1.ReadWithEngine(engine); string temp = engine.WriteString(res); res = engine.ReadString(temp, int.MaxValue); Assert.AreEqual(4, res.Length); Assert.AreEqual(4, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); }
public void ReadFileMaxRecords07() { var engine = new FileHelperEngine<SampleType>(); SampleType[] res = FileTest.Good.Test1.ReadWithEngine(engine); string temp = engine.WriteString(res); res = engine.ReadString(temp, 2); Assert.AreEqual(2, res.Length); Assert.AreEqual(2, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); }
private void cmdRun_Click(object sender, EventArgs e) { cmdRun.Enabled = false; FileHelperEngine engine = new FileHelperEngine(typeof(CustomersVerticalBar)); object[] records = engine.ReadFile("Customers.txt"); Application.DoEvents(); engine.SetProgressHandler(new ProgressChangeHandler(ProgressChange)); engine.WriteString(records); cmdRun.Enabled = true; }
public void WriteBadUsage() { FileHelperEngine engine = new FileHelperEngine(typeof(SampleType)); SampleType[] res = new SampleType[2]; res[0] = new SampleType(); res[0].Field1 = DateTime.Now.AddDays(1); res[0].Field2 = "je"; res[0].Field3 = 0; engine.WriteString(res); }
public void ReadFileMaxRecords08() { engine = new FileHelperEngine(typeof(SampleType)); SampleType[] res; res = (SampleType[])Common.ReadTest(engine, @"Good\test1.txt"); string temp = engine.WriteString(res); res = (SampleType[])engine.ReadString(temp, int.MaxValue); Assert.AreEqual(4, res.Length); Assert.AreEqual(4, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); }
private static void Main(string[] args) { var engine = new FileHelperEngine <Person>(); engine.AfterWriteRecord += engine_AfterWriteRecord; var export = engine.WriteString( new Person[] { new Person() { FirstName = "Joe", LastName = "Bloggs" } }); Assert.AreEqual("Joe,Bloggs" + Environment.NewLine, export); }
public void WriteBadUsage() { var engine = new FileHelperEngine <SampleType>(); var res = new SampleType[2]; res[0] = new SampleType(); res[0].Field1 = DateTime.Now.AddDays(1); res[0].Field2 = "je"; res[0].Field3 = 0; Assert.Throws <BadUsageException>(() => engine.WriteString(res)); }
private void CheckDates <T>(string dates) where T : class { var engine = new FileHelperEngine <T>(); var res = engine.ReadString(dates); dynamic record = res[0]; Check.That((DateTime)record.Fecha).IsEqualTo(new DateTime(1996, 7, 16)); record = res[5]; Check.That((DateTime)record.Fecha).IsEqualTo(new DateTime(1996, 8, 16)); var toString = engine.WriteString(res); Check.That(toString.ToLower()).IsEqualTo(dates.ToLower()); }
/// <summary> /// Run the engine with a progress bar /// hooked into it to give the user a visual /// cue on how things are progressing. /// </summary> private void cmdRun_Click(object sender, EventArgs e) { // Disable the button, don't want it clicked twice cmdRun.Enabled = false; FileHelperEngine engine = new FileHelperEngine(typeof (CustomersVerticalBar)); object[] records = engine.ReadString(Resources.Customers); Application.DoEvents(); engine.Progress += ProgressChange; engine.WriteString(records); // enable the button again we have finished. cmdRun.Enabled = true; }
public void InNewLine1rw() { var engine = new FileHelperEngine<InNewLineType1>(); InNewLineType1[] res = engine.ReadFile(TestCommon.GetPath("Good", "InNewLine1.txt")); string tmp = engine.WriteString(res); res = (InNewLineType1[]) engine.ReadString(tmp); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual("166.90.252.2", res[0].IpAddress); Assert.AreEqual("67.105.166.35", res[1].IpAddress); Assert.AreEqual("67.105.166.35", res[2].IpAddress); }
public void NullDateFormat() { String data = "23/11/2010,24/11/2010\r\n,\r\n,\r\n"; var engine = new FileHelperEngine<NullDateFormatMulti>(); NullDateFormatMulti[] result = engine.ReadString( data ); Assert.AreEqual( new DateTime( 2010, 11, 23 ), result[0].OrderDate, "Order date should be 23/11/2010 from first line" ); Assert.AreEqual( new DateTime( 2010, 11, 24 ), result[0].ShipDate, "Ship date should be 24/11/2010 from first line" ); Assert.AreEqual( null, result[1].OrderDate, "Order date should be null on second line" ); Assert.AreEqual( null, result[1].ShipDate, "Ship date should be null on second line" ); Assert.AreEqual( null, result[2].OrderDate, "Order date should be null on third line with blanks" ); Assert.AreEqual( null, result[2].ShipDate, "Ship date should be null on third line with blanks" ); string newData = engine.WriteString( result ); Assert.AreEqual( data, newData, "Round trip should match" ); }
public void InNewLine0rw() { engine = new FileHelperEngine(typeof(InNewLineType0)); InNewLineType0[] res = (InNewLineType0[]) engine.ReadFile(Common.TestPath(@"Good\InNewLine0.txt")); string tmp = engine.WriteString(res); res = (InNewLineType0[]) engine.ReadString(tmp); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual("166.90.252.2", res[0].IpAddress); Assert.AreEqual("67.105.166.35", res[1].IpAddress); Assert.AreEqual("67.105.166.35", res[2].IpAddress); }
public void InNewLine2rw() { engine = new FileHelperEngine(typeof(InNewLineType2)); InNewLineType2[] res = (InNewLineType2[])engine.ReadString(engine.WriteString(engine.ReadFile(TestCommon.TestPath(@"Good\InNewLine2.txt")))); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual("166.90.252.2", res[0].IpAddress); Assert.AreEqual("67.105.166.35", res[1].IpAddress); Assert.AreEqual("67.105.166.35", res[2].IpAddress); Assert.AreEqual(111, res[0].FieldLast); Assert.AreEqual(222, res[1].FieldLast); Assert.AreEqual(333, res[2].FieldLast); }
public void InNewLineFixed1rw() { engine = new FileHelperEngine(typeof(InNewLineFixedType1)); InNewLineFixedType1[] res = (InNewLineFixedType1[])engine.ReadFile(TestCommon.TestPath(@"Good\InNewLineFixed1.txt")); string tmp = engine.WriteString(res); res = (InNewLineFixedType1[])engine.ReadString(tmp); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual("166.090.252.002", res[0].IpAddress); Assert.AreEqual("067.105.166.035", res[1].IpAddress); Assert.AreEqual("067.105.166.035", res[2].IpAddress); }
public void WriteNullableTypes1() { var engine = new FileHelperEngine<NullableType>(); var toWrite = new System.Collections.Generic.List<NullableType>(); NullableType record; record = new NullableType(); record.Field1 = new DateTime(1314, 12, 11); record.Field2 = "901"; record.Field3 = 234; toWrite.Add(record); record = new NullableType(); record.Field1 = null; record.Field2 = "012"; record.Field3 = null; toWrite.Add(record); record = new NullableType(); record.Field1 = new DateTime(1316, 5, 6); record.Field2 = "111"; record.Field3 = 4; toWrite.Add(record); NullableType[] res = engine.ReadString(engine.WriteString(toWrite)); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); Assert.AreEqual(new DateTime(1314, 12, 11), res[0].Field1); Assert.AreEqual("901", res[0].Field2); Assert.AreEqual(234, res[0].Field3); Assert.IsNull(res[1].Field1); Assert.AreEqual("012", res[1].Field2); Assert.IsNull(res[1].Field3); Assert.AreEqual(new DateTime(1316, 5, 6), res[2].Field1); Assert.AreEqual("", engine.WriteString(toWrite).Split(new string[] {Environment.NewLine}, StringSplitOptions.None)[1]. Substring(0, 8).Trim()); }
/// <summary> /// Run the engine with a progress bar /// hooked into it to give the user a visual /// cue on how things are progressing. /// </summary> private void cmdRun_Click(object sender, EventArgs e) { // Disable the button, don't want it clicked twice cmdRun.Enabled = false; FileHelperEngine engine = new FileHelperEngine(typeof(CustomersVerticalBar)); object[] records = engine.ReadString(Resources.Customers); Application.DoEvents(); engine.Progress += ProgressChange; engine.WriteString(records); // enable the button again we have finished. cmdRun.Enabled = true; }
public void WriteExcelCsv1() { ArrayList arr = new ArrayList(); ExcelCsv1Type record; record = new ExcelCsv1Type(); record.OrganizationName = "AllwaysOnTop"; record.TestField = "Test 1,"; arr.Add(record); record = new ExcelCsv1Type(); record.OrganizationName = "COMPUTERS, HARDWARE"; record.TestField = "Test, 2"; arr.Add(record); record = new ExcelCsv1Type(); record.OrganizationName = "4S Consulting, Inc."; record.TestField = " Test 3"; arr.Add(record); record = new ExcelCsv1Type(); record.OrganizationName = "SmartSolutions"; record.TestField = "Test 4"; arr.Add(record); engine = new FileHelperEngine(typeof (ExcelCsv1Type)); string tmp = engine.WriteString(arr.ToArray()); ExcelCsv1Type[] res = (ExcelCsv1Type[]) engine.ReadString(tmp); Assert.AreEqual(4, res.Length); Assert.AreEqual("AllwaysOnTop", res[0].OrganizationName); Assert.AreEqual("COMPUTERS, HARDWARE", res[1].OrganizationName); Assert.AreEqual("4S Consulting, Inc.", res[2].OrganizationName); Assert.AreEqual("SmartSolutions", res[3].OrganizationName); Assert.AreEqual("Test 1,", res[0].TestField); Assert.AreEqual("Test, 2", res[1].TestField); Assert.AreEqual(" Test 3", res[2].TestField); Assert.AreEqual("Test 4", res[3].TestField); }
public void WriteNull() { var engine = new FileHelperEngine<SampleType>(); SampleType[] res = new SampleType[3]; res[0] = new SampleType(); res[1] = new SampleType(); res[2] = new SampleType(); string tempo = engine.WriteString(res); res = engine.ReadString(tempo); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); Assert.AreEqual(DateTime.MinValue, res[0].Field1); Assert.AreEqual("", res[0].Field2); Assert.AreEqual(0, res[0].Field3); }
/// <summary> /// /// </summary> /// <returns></returns> public string Format() { Mapper.CreateMap<QuantityLocation, ItemFlattenedForCsv>(); Mapper.CreateMap<Item, ItemFlattenedForCsv>(); Mapper.CreateMap<Item, List<ItemFlattenedForCsv>>() .ConvertUsing(i => i.QuantityAtLocation.Select( itemFlat => { var flattenedList = Mapper.Map<ItemFlattenedForCsv>(i); Mapper.Map(itemFlat, flattenedList); return flattenedList; }).ToList()); var records = Mapper.Map<List<ItemFlattenedForCsv>>(_item); var engine = new FileHelperEngine<ItemFlattenedForCsv>(); string output = engine.WriteString(records); return output; }
public void WriteEvents() { var engine = new FileHelperEngine<SampleType>(); 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.WriteString(res); Assert.AreEqual(2, engine.TotalRecords); Assert.AreEqual(true, res[0].BeforeWriteNotif); Assert.AreEqual(true, res[1].BeforeWriteNotif); }
protected void ExportarButton_Click(object sender, EventArgs e) { System.Collections.Generic.List<CedForecastWebEntidades.Proyectado> lista; CedForecastWebEntidades.Proyectado Proyectado = new CedForecastWebEntidades.Proyectado(); Proyectado.IdTipoPlanilla = "Proyectado"; Proyectado.IdCuenta = CuentaDropDownList.SelectedValue.Trim(); CedForecastWebEntidades.Cliente cliente = new CedForecastWebEntidades.Cliente(); cliente.Id = ClienteDropDownList.SelectedValue.ToString().Trim(); Proyectado.Cliente = cliente; CedForecastWebRN.Periodo.ValidarPeriodoYYYYMM(PeriodoTextBox.Text); Proyectado.IdPeriodo = PeriodoTextBox.Text; lista = CedForecastWebRN.Proyectado.Lista(Proyectado, (CedForecastWebEntidades.Sesion)Session["Sesion"]); string archivo = "Id.Vendedor; Id.Cliente; Nombre Cliente; Id.Artículo; Nombre Artículo; "; int colFijas = 4; for (int i = 1; i <= 12; i++) { archivo += TextoCantidadHeader(i, PeriodoTextBox.Text) + "; "; } archivo += "Total " + PeriodoTextBox.Text + "; "; archivo += "Total " + Convert.ToDateTime("01" + PeriodoTextBox.Text.Substring(4,2) + "/" + PeriodoTextBox.Text.Substring(0,4)).AddYears(1).Year.ToString() + "; "; archivo += "Total " + Convert.ToDateTime("01" + PeriodoTextBox.Text.Substring(4,2) + "/" + PeriodoTextBox.Text.Substring(0,4)).AddYears(2).Year.ToString() + "; "; archivo += "\r\n"; FileHelperEngine fhe = new FileHelperEngine(typeof(CedForecastWebEntidades.Proyectado)); archivo += fhe.WriteString(lista); byte[] a = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(archivo); System.IO.MemoryStream m = new System.IO.MemoryStream(a); Byte[] byteArray = m.ToArray(); m.Flush(); m.Close(); Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=Proyectado.csv"); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(byteArray); Response.End(); }
public void WriteBadUsage2() { FileHelperEngine engine = new FileHelperEngine(typeof (SampleType)); engine.WriteString(null); }
public void InNewLineFixed2rw() { engine = new FileHelperEngine(typeof(InNewLineFixedType2)); InNewLineFixedType2[] res = (InNewLineFixedType2[]) engine.ReadFile(Common.TestPath(@"Good\InNewLineFixed2.txt")); string tmp = engine.WriteString(res); res = (InNewLineFixedType2[]) engine.ReadString(tmp); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual("166.090.252.002", res[0].IpAddress); Assert.AreEqual("067.105.166.035", res[1].IpAddress); Assert.AreEqual("067.105.166.035", res[2].IpAddress); Assert.AreEqual(111, res[0].FieldLast); Assert.AreEqual(222, res[1].FieldLast); Assert.AreEqual(333, res[2].FieldLast); }
public void WriteStringNullableGuid() { var engine = new FileHelperEngine<SampleTypeNullableGuid>(); string resStr = engine.WriteString(new []{new SampleTypeNullableGuid()}); Assert.AreEqual(Environment.NewLine, resStr); }
public void BadRecordType() { var engine = new FileHelperEngine(typeof (BadRecordTypeClass)); Assert.Throws<BadUsageException>(() => engine.WriteString(new[] {"hola"})); }
public void WriteBadUsage2() { var engine = new FileHelperEngine<SampleType>(); Assert.Throws<ArgumentNullException>(() => engine.WriteString(null)); }
public void WriteBadUsage() { var engine = new FileHelperEngine<SampleType>(); var res = new SampleType[2]; res[0] = new SampleType(); res[0].Field1 = DateTime.Now.AddDays(1); res[0].Field2 = "je"; res[0].Field3 = 0; Assert.Throws<BadUsageException>(() => engine.WriteString(res)); }
public void ArrayFieldsRW() { var engine = new FileHelperEngine<ArrayType1>(); var res = engine.ReadFile(FileTest.Good.ArrayFields.Path); SimpleComparer(res); res = engine.ReadString(engine.WriteString(res)); SimpleComparer(res); }
public void WriteNullableTypes2() { var orders = new System.Collections.Generic.List<TestOrder>(); TestOrder or1 = new TestOrder(); or1.OrderID = 1; or1.OrderDate = null; or1.RequiredDate = new DateTime(2007, 1, 2); or1.ShipVia = null; orders.Add(or1); TestOrder or2 = new TestOrder(); or2.OrderID = 2; or2.OrderDate = new DateTime(2007, 2, 1); or2.RequiredDate = null; or2.ShipVia = 1; orders.Add(or2); FileHelperEngine<TestOrder> fileHelperEngine = new FileHelperEngine<TestOrder>(); TestOrder[] res = fileHelperEngine.ReadString(fileHelperEngine.WriteString(orders)); Assert.IsNull(res[0].OrderDate); Assert.IsNull(res[1].RequiredDate); Assert.IsNull(res[0].ShipVia); }
public void InNewLine2rw() { var engine = new FileHelperEngine<InNewLineType2>(); InNewLineType2[] res = engine.ReadString(engine.WriteString(engine.ReadFile(TestCommon.GetPath("Good", "InNewLine2.txt")))); Assert.AreEqual(3, res.Length); Assert.AreEqual(3, engine.TotalRecords); Assert.AreEqual("166.90.252.2", res[0].IpAddress); Assert.AreEqual("67.105.166.35", res[1].IpAddress); Assert.AreEqual("67.105.166.35", res[2].IpAddress); Assert.AreEqual(111, res[0].FieldLast); Assert.AreEqual(222, res[1].FieldLast); Assert.AreEqual(333, res[2].FieldLast); }
public void WriteString() { var engine = new FileHelperEngine<SampleType>(); 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; string resStr = engine.WriteString(res); Assert.AreEqual(14 + newLineLen + 14 + newLineLen, resStr.Length); Assert.AreEqual(resStr.Substring(0, 8), DateTime.Now.AddDays(1).ToString("ddMMyyyy")); }