本文整理汇总了C#中FileHelperEngine.WriteString方法的典型用法代码示例。如果您正苦于以下问题:C# FileHelperEngine.WriteString方法的具体用法?C# FileHelperEngine.WriteString怎么用?C# FileHelperEngine.WriteString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelperEngine
的用法示例。
在下文中一共展示了FileHelperEngine.WriteString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileHelperCsv
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");
}
示例2: Run
//-> /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));
}
示例3: WriteReadImage
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);
}
示例4: Run
//-> /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));
}
示例5: WriteEvents
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);
}
示例6: RunAlignTest
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);
}
示例7: RunAlignTest
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);
}
示例8: CheckItWritesToFile
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);
}
示例9: cmdRun_Click
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;
}
示例10: ReadFileMaxRecords07
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);
}
示例11: cmdRun_Click
/// <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;
}
示例12: NullDateFormat
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" );
}
示例13: InNewLine1rw
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);
}
示例14: InNewLine0rw
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);
}
示例15: WriteNullableTypes1
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());
}