本文整理汇总了C#中FileHelperAsyncEngine.BeginWriteFile方法的典型用法代码示例。如果您正苦于以下问题:C# FileHelperAsyncEngine.BeginWriteFile方法的具体用法?C# FileHelperAsyncEngine.BeginWriteFile怎么用?C# FileHelperAsyncEngine.BeginWriteFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelperAsyncEngine
的用法示例。
在下文中一共展示了FileHelperAsyncEngine.BeginWriteFile方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generateBtn_Click
private void generateBtn_Click(object sender, EventArgs e)
{
List<Record> recordList = new List<Record>();
var engine = new FileHelperAsyncEngine<Record>();
engine.HeaderText = engine.GetFileHeader();
recordList = RecordCreator.getRecords();
try
{
using (engine.BeginWriteFile(savePathTB.Text))
{
foreach (Record rec in recordList)
{
engine.WriteNext(rec);
}
}
DialogResult result;
result = MessageBox.Show("Done! Open file?", "File generated.", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
System.Diagnostics.Process.Start(savePathTB.Text);
}
}
catch(Exception error)
{
DialogResult result;
result = MessageBox.Show(error.Message, "Error!", MessageBoxButtons.RetryCancel);
if (result == DialogResult.Retry)
{
generateButton.PerformClick();
}
}
}
示例2: Run
//-> /File
//-> Instantiate a FileHelperAsyncEngine and read or write files:
public override void Run()
{
//-> File:Example.cs
var engine = new FileHelperAsyncEngine<Customer>();
// Read
using(engine.BeginReadFile("Input.txt"))
{
// The engine is IEnumerable
foreach(Customer cust in engine)
{
// your code here
Console.WriteLine(cust.Name);
}
}
// Write
var arrayCustomers = new Customer[] {
new Customer { CustId = 1732, Name = "Juan Perez", Balance = 435.00m,
AddedDate = new DateTime (2020, 5, 11) },
new Customer { CustId = 554, Name = "Pedro Gomez", Balance = 12342.30m,
AddedDate = new DateTime (2004, 2, 6) },
};
using(engine.BeginWriteFile("TestOut.txt"))
{
foreach(Customer cust in arrayCustomers)
{
engine.WriteNext(cust);
}
}
//-> /File
}
示例3: WriteNullAsync
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");
}
示例4: WriteEvents
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);
}
示例5: ExportApprovalList
public void ExportApprovalList(string fileName, CancellationToken token)
{
using (DatabaseContext context = GetContext())
{
// init engine
FileHelperAsyncEngine<CsvApprovalItem> engine = new FileHelperAsyncEngine<CsvApprovalItem>() { HeaderText = CsvApprovalItem.HeaderLine };
engine.BeginWriteFile(fileName);
// look for approval items
var query = context.ViewApprovalLists.Where("[email protected]", new ObjectParameter("st", APPROVAL_STATUS_NEW));
foreach (ViewApprovalList item in query)
{
if (token.IsCancellationRequested) break;
engine.WriteNext(new CsvApprovalItem()
{
ItemID = item.Id,
EngineName = item.EngineName,
ProductName = item.SearchName,
FoundName = item.Name,
URL = item.Url,
Price = item.Price,
Command = APPROVAL_COMMAND_UNDEFINED
});
}
engine.Close();
}
}
示例6: BeginWriteWhileReading
public void BeginWriteWhileReading()
{
FileHelperAsyncEngine eng = new FileHelperAsyncEngine(typeof(SampleType));
eng.BeginReadString("jejjeje");
var filename = TestCommon.GetTempFile("TempWrite.txt");
Assert.Throws<BadUsageException>(()
=> eng.BeginWriteFile(filename));
}
示例7: BeginReadWhileWriting
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);
}
});
}
示例8: DiscardWriteRead2
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");
}
示例9: DiscardWriteRead2
public void DiscardWriteRead2()
{
engine = new FileHelperEngine(typeof(DiscardType1));
DiscardType1[] res = (DiscardType1[])Common.ReadTest(engine, @"Good\DiscardFirst1.txt");
asyncEngine = new FileHelperAsyncEngine(typeof(DiscardType1));
asyncEngine.HeaderText = "This is a new header....";
asyncEngine.BeginWriteFile("tempo.txt");
asyncEngine.WriteNexts(res);
asyncEngine.Close();
asyncEngine.HeaderText = "none none\r\n";
asyncEngine.BeginReadFile(@"tempo.txt");
while (asyncEngine.ReadNext() != null)
{}
Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
Assert.AreEqual("This is a new header....\r\n", asyncEngine.HeaderText);
asyncEngine.Close();
Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
Assert.AreEqual("This is a new header....\r\n", asyncEngine.HeaderText);
if (File.Exists("tempo.txt")) File.Delete("tempo.txt");
}
示例10: DiscardWriteRead2
public void DiscardWriteRead2()
{
var engine = new FileHelperEngine<DiscardType1>();
DiscardType1[] res = engine.ReadFile(FileTest.Good.DiscardFirst1.Path);
var asyncEngine = new FileHelperAsyncEngine<DiscardType1>();
asyncEngine.HeaderText = "This is a new header....";
asyncEngine.BeginWriteFile("tempo.txt");
asyncEngine.WriteNexts(res);
asyncEngine.Close();
asyncEngine.HeaderText = "none none\r\n";
asyncEngine.BeginReadFile(@"tempo.txt");
while (asyncEngine.ReadNext() != null) {}
Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
Assert.AreEqual(mExpectedShortHeaderText, asyncEngine.HeaderText);
asyncEngine.Close();
Assert.AreEqual(res.Length, asyncEngine.TotalRecords);
Assert.AreEqual(mExpectedShortHeaderText, asyncEngine.HeaderText);
if (File.Exists("tempo.txt"))
File.Delete("tempo.txt");
}