本文整理汇总了C#中FileHelperEngine.WriteStream方法的典型用法代码示例。如果您正苦于以下问题:C# FileHelperEngine.WriteStream方法的具体用法?C# FileHelperEngine.WriteStream怎么用?C# FileHelperEngine.WriteStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelperEngine
的用法示例。
在下文中一共展示了FileHelperEngine.WriteStream方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportStatus
public void ExportStatus(TextWriter file, IList<StatusReport> reports)
{
var engine = new FileHelperEngine<StatusCsvItem>();
var items = new List<StatusCsvItem>();
// convert reports to items
engine.WriteStream(file, items);
}
示例2: WriteStream
public void WriteStream()
{
engine = new FileHelperEngine(typeof (SampleType));
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;
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
engine.WriteStream(writer, res, 1);
Assert.AreEqual(14 + 2, sb.ToString().Length);
Assert.AreEqual(sb.ToString(0, 8), DateTime.Now.AddDays(1).ToString("ddMMyyyy"));
}
示例3: WriteOperationShouldBeQuick
public void WriteOperationShouldBeQuick()
{
var sampleRecords = GetRecords();
Benchmark.This("FileHelperEngine.WriteStream", () =>
{
var engine = new FileHelperEngine<FixedSampleRecord>();
using (var stream = new MemoryStream())
using (var streamWriter = new StreamWriter(stream))
{
engine.WriteStream(streamWriter, sampleRecords);
}
})
.Against.This("FlatFileEngine.Write", () =>
{
var layout = new FixedSampleRecordLayout();
using (var stream = new MemoryStream())
{
var factory = new FixedLengthFileEngineFactory();
var flatFile = factory.GetEngine(layout);
flatFile.Write(stream, sampleRecords);
}
})
.WithWarmup(1000)
.For(10000)
.Iterations()
.PrintComparison();
}
示例4: ExportAllocations
public void ExportAllocations(TextWriter file, IList<ResourceAllocation> reports)
{
var engine = new FileHelperEngine<ResourceAllocationCsvItem>();
var items = new List<ResourceAllocationCsvItem>();
// convert reports to items
engine.WriteStream(file, items);
}
示例5: BigDataWriteOperationShouldBeQuick
public void BigDataWriteOperationShouldBeQuick()
{
var genarator = new FakeGenarator();
var sampleRecords = Enumerable.Range(0, 100000).Select(genarator.Generate).ToArray();
Benchmark.This("FileHelperEngine.WriteStream", () =>
{
var engine = new FileHelperEngine<FixedSampleRecord>();
using (var stream = new MemoryStream())
using (var streamWriter = new StreamWriter(stream))
{
engine.WriteStream(streamWriter, sampleRecords);
}
})
.Against.This("FlatFileEngine.Write", () =>
{
var layout = new FixedSampleRecordLayout();
using (var stream = new MemoryStream())
{
var factory = new FixedLengthFileEngineFactory();
var flatFile = factory.GetEngine(layout);
flatFile.Write(stream, sampleRecords);
}
})
.WithWarmup(10)
.For(100)
.Iterations()
.PrintComparison();
}
示例6: OnbtnExportClick
protected void OnbtnExportClick(object sender, EventArgs e)
{
var students = retrieveStudents();
if (students.Count < 1)
return;
List<StudentCSVImportItem> studentRows = students.Select(s => new StudentCSVImportItem()
{
Classroom = s.ClassRoom,
FirstName = s.FirstName,
LastName = s.LastName
}).ToList();
studentRows.Insert(0, new StudentCSVImportItem() { FirstName = "First Name", LastName = "Last Name", Classroom = "Classroom" });
FileHelperEngine<StudentCSVImportItem> engine = new FileHelperEngine<StudentCSVImportItem>();
MemoryStream stream = new MemoryStream();
TextWriter writer = new StreamWriter(stream);
engine.WriteStream(writer, studentRows);
writer.Close();
HttpResponse response = Response;
//Get data to output here...
//Turn off Caching and enforce a content type that will prompt to download/save.
response.AddHeader("Connection", "close");
response.AddHeader("Cache-Control", "private");
response.ContentType = "application/octect-stream";
//Give the browser a hint at the name of the file.
response.AddHeader("content-disposition", "attachment; filename=export.csv");
response.BinaryWrite(stream.GetBuffer());
response.Flush();
response.Close();
}
示例7: WriteStream
public void WriteStream()
{
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;
var sb = new StringBuilder();
var writer = new StringWriter(sb);
engine.WriteStream(writer, res);
Assert.AreEqual(14 + newLineLen + 14 + newLineLen, sb.ToString().Length);
Assert.AreEqual(sb.ToString(0, 8), DateTime.Now.AddDays(1).ToString("ddMMyyyy"));
}
示例8: NullRecords
public void NullRecords()
{
engine = new FileHelperEngine(typeof (SampleType));
engine.WriteStream(new StringWriter(new StringBuilder()), null);
}
示例9: NullWriter
public void NullWriter()
{
engine = new FileHelperEngine(typeof (SampleType));
engine.WriteStream(null, null);
}
示例10: NullWriter
public void NullWriter()
{
engine = new FileHelperEngine(typeof (SampleType));
Assert.Throws<ArgumentNullException>(()
=> engine.WriteStream(null, null));
}
示例11: NullRecords
public void NullRecords()
{
engine = new FileHelperEngine(typeof (SampleType));
Assert.Throws<ArgumentNullException>(()
=> engine.WriteStream(new StringWriter(new StringBuilder()), null));
}
示例12: WriteFile
public bool WriteFile(string fileName, string devarOrgCode, FeederSystemFixedLengthRecord[] transactionsArray)
{
var success = false;
using (var docStream = new MemoryStream())
{
using (var flatFileWriter = new StreamWriter(docStream, Encoding.ASCII))
{
var fileWriterEngine = new FileHelperEngine(typeof(FeederSystemFixedLengthRecord));
fileWriterEngine.WriteStream(flatFileWriter, transactionsArray);
// Flush contents of fileWriterStream to underlying docStream:
flatFileWriter.Flush();
// Upload to SFTP server:
_sftpService.UploadStream(docStream, fileName, devarOrgCode); // Upload file to A&FS server.
// Save file to cloud:
_blobStorageService.PutBlob(docStream, fileName);
success = _blobStorageService.Exists(fileName);
}
return success;
}
}
示例13: ReadDiscounts
/// <summary>
/// Helper method to read discounts
/// </summary>
private static void ReadDiscounts(AuthInfo authInfo, string csvFile)
{
List<Discount> discounts = new List<Discount>();
DiscountsWrapper.ReadDiscounts(authInfo, discounts);
Console.WriteLine("Writing Discounts to file...");
using (TextWriter writer = new StreamWriter(csvFile))
{
// Write file header
writer.WriteLine(Discount.CsvFileHeader);
// Write discounts
FileHelperEngine fileHelper = new FileHelperEngine(typeof(Discount));
fileHelper.WriteStream(writer, discounts);
}
}