本文整理汇总了C#中FileHelperEngine类的典型用法代码示例。如果您正苦于以下问题:C# FileHelperEngine类的具体用法?C# FileHelperEngine怎么用?C# FileHelperEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileHelperEngine类属于命名空间,在下文中一共展示了FileHelperEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunTests
private static void RunTests(Encoding enc, params string[] pathElements)
{
var engine = new FileHelperEngine<CustomersVerticalBar>();
engine.Encoding = enc;
Assert.AreEqual(enc, engine.Encoding);
CoreRunTest(engine, pathElements);
}
示例2: ReadWrite
/// <summary>
/// Process the delimited file twice,
/// once with the simple engine, once with Async
/// </summary>
/// <remarks>
/// This is a simple sample of using the Normal engine and the Async engine
/// </remarks>
public void ReadWrite()
{
var engine = new FileHelperEngine<Orders>();
// to Read use:
Orders[] res = engine.ReadFile(@"C:\TestIn.txt");
// to Write use:
engine.WriteFile(@"C:\TestOut.txt", res);
foreach (Orders order in res) {
Console.WriteLine("Order Info:");
Console.WriteLine(order.CustomerID + " - " +
order.OrderDate.ToString("dd/MM/yy"));
}
var asyncEngine = new FileHelperAsyncEngine<Orders>();
asyncEngine.BeginReadFile(@"C:\TestIn.txt");
Orders ord;
while (asyncEngine.ReadNext() != null) {
ord = asyncEngine.LastRecord;
// your code here
Console.WriteLine(ord.CustomerID);
}
}
示例3: Delimited0
public void Delimited0()
{
var engine = new FileHelperEngine<OptionalDelimited1>();
var res = TestCommon.ReadTest<OptionalDelimited1>(engine, "Good", "OptionalDelimited0.txt");
Assert.AreEqual(ExpectedRecords, res.Length);
}
示例4: GetMSWSReportsFromURL_AsStream_20060709_28Records
public void GetMSWSReportsFromURL_AsStream_20060709_28Records()
{
DateTime date = new DateTime(2006, 7, 20);
string url = string.Format(MSWSDataUrl_Format, date.ToString(MSWSDataURL_DateFormat));
MSWSDailyReportRecord[] res = null;
FileHelperEngine engine = new FileHelperEngine(typeof(MSWSDailyReportRecord));
// make request
HttpWebRequest webReq = null;
HttpWebResponse webResp = null;
StreamReader reader = null;
try
{
webReq = (HttpWebRequest)HttpWebRequest.Create(url);
webResp = (HttpWebResponse)webReq.GetResponse();
Encoding encode = Encoding.GetEncoding("utf-8");
reader = new StreamReader(webResp.GetResponseStream(), encode);
res = (MSWSDailyReportRecord[]) engine.ReadStream(reader);
}
catch
{
throw;
}
finally
{
if (webReq != null) webReq = null;
if (webResp != null) webResp.Close();
if (reader != null) reader.Close();
}
Assert.AreEqual(res.Length, 32);
}
示例5: Import
static void Import(string simAreasPath, DbConnection connection)
{
var simarea = new SimAreasContext(connection, false, new DropCreateDatabaseAlways<SimAreasContext>());
var engine = new FileHelperEngine(typeof(SimAreas));
var entries = (SimAreas[])engine.ReadFile(simAreasPath);
foreach (var entry in entries)
{
var area = (from s in simarea.SimAreas
where s.SimAreaName == entry.SimAreaName
select s).FirstOrDefault();
if (area == null)
{
area = new SimArea
{
SimAreaName = entry.SimAreaName,
Latitude = entry.Latitude,
Longitude = entry.Longitude,
Height = entry.Height,
GeoidSeparation = entry.GeoidSeparation,
OpsLimitFile = entry.OpsLimitFile,
SimLimitFile = entry.SimLimitFile,
};
simarea.SimAreas.Add(area);
simarea.SaveChanges();
}
}
}
示例6: 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));
}
示例7: WriteFile2
public void WriteFile2()
{
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.WriteFile(@"miprueba.txt", res, -10);
res = (SampleType[]) engine.ReadFile(@"miprueba.txt");
if (File.Exists(@"miprueba.txt"))
File.Delete(@"miprueba.txt");
Assert.AreEqual(2, res.Length);
}
示例8: FullClassBuilding
public void FullClassBuilding()
{
var cb = new DelimitedClassBuilder("Customers", ",");
cb.IgnoreFirstLines = 1;
cb.IgnoreEmptyLines = true;
cb.AddField("Field1", typeof(DateTime));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.QuoteMode = QuoteMode.AlwaysQuoted;
cb.LastField.FieldNullValue = DateTime.Today;
cb.AddField("Field2", typeof(string));
cb.LastField.FieldQuoted = true;
cb.LastField.QuoteChar = '"';
cb.AddField("Field3", typeof(int));
mEngine = new FileHelperEngine(cb.CreateRecordClass());
DataTable dt = mEngine.ReadFileAsDT(TestCommon.GetPath("Good", "Test2.txt"));
Assert.AreEqual(4, dt.Rows.Count);
Assert.AreEqual(4, mEngine.TotalRecords);
Assert.AreEqual(0, mEngine.ErrorManager.ErrorCount);
Assert.AreEqual("Field1", dt.Columns[0].ColumnName);
Assert.AreEqual("Field2", dt.Columns[1].ColumnName);
Assert.AreEqual("Field3", dt.Columns[2].ColumnName);
Assert.AreEqual("Hola", dt.Rows[0][1]);
Assert.AreEqual(DateTime.Today, dt.Rows[2][0]);
}
示例9: TestingNameAndTypes
public void TestingNameAndTypes()
{
var cb = new DelimitedClassBuilder("Customers", ",");
cb.IgnoreFirstLines = 1;
cb.IgnoreEmptyLines = true;
cb.AddField("Field1", typeof (DateTime));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.QuoteMode = QuoteMode.AlwaysQuoted;
cb.LastField.FieldNullValue = DateTime.Today;
cb.AddField("Field2", typeof (string));
cb.LastField.FieldQuoted = true;
cb.LastField.QuoteChar = '"';
cb.AddField("Field3", typeof (int));
mEngine = new FileHelperEngine(cb.CreateRecordClass());
DataTable dt = mEngine.ReadFileAsDT(TestCommon.GetPath("Good", "Test2.txt"));
Assert.AreEqual("Field1", dt.Columns[0].ColumnName);
Assert.AreEqual(typeof (DateTime), dt.Columns[0].DataType);
Assert.AreEqual("Field2", dt.Columns[1].ColumnName);
Assert.AreEqual(typeof (string), dt.Columns[1].DataType);
Assert.AreEqual("Field3", dt.Columns[2].ColumnName);
Assert.AreEqual(typeof (int), dt.Columns[2].DataType);
}
示例10: Inherited1
public void Inherited1()
{
var engine = new FileHelperEngine<SampleInheritType>();
Assert.AreEqual(3, engine.Options.FieldCount);
Assert.AreEqual("Field1", engine.Options.FieldsNames[0]);
Assert.AreEqual("Field2", engine.Options.FieldsNames[1]);
Assert.AreEqual("Field3", engine.Options.FieldsNames[2]);
SampleInheritType[] res;
res = TestCommon.ReadTest<SampleInheritType>(engine, "Good", "Test1.txt");
Assert.AreEqual(4, res.Length);
Assert.AreEqual(4, 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.AreEqual(new DateTime(1314, 11, 10), res[1].Field1);
Assert.AreEqual("012", res[1].Field2);
Assert.AreEqual(345, res[1].Field3);
}
示例11: Delimited0
public void Delimited0()
{
engine = new FileHelperEngine(typeof (OptionalDelimited1));
OptionalDelimited1[] res = (OptionalDelimited1[]) Common.ReadTest(engine, @"Good\OptionalDelimited0.txt");
Assert.AreEqual(ExpectedRecords, res.Length);
}
示例12: PullSensorDataFromCsvFileAsList
public IHttpActionResult PullSensorDataFromCsvFileAsList(string fileName)
{
try
{
//filehelper object
FileHelperEngine engine = new FileHelperEngine(typeof(TemperatureSensor));
//set header text
engine.HeaderText = "DeviceId,IsActive,SensorId,Temperature,LogDate,LogHour,LogMinute,LogSecond";
var result = StorageHelper.ReadDataFromBlob(string.Format("{0}.csv", fileName)).Result;
//read the CSV file into your object Arrary
var sensorsDataArray = (TemperatureSensor[])engine.ReadString(result);
var sensorsDataList = sensorsDataArray.ToList();
if (sensorsDataList != null)
return Ok(sensorsDataList);
return BadRequest("Result was invalid");
}
catch(Exception ex)
{
return BadRequest(ex.Message);
}
}
示例13: 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"));
}
示例14: Load
public StartAndEndPair[] Load()
{
var fh = new FileHelperEngine<CommentedStartAndEndPair>();
var values = fh.ReadFile(_fileName);
var returnValues = new List<StartAndEndPair>();
foreach (var value in values)
{
if (_matchRequiredTag)
{
if (value.Comment.Contains(_requiredTag))
{
returnValues.Add(new StartAndEndPair(value.Start, value.End));
}
}
else
{
returnValues.Add(new StartAndEndPair(value.Start, value.End));
}
}
return returnValues.ToArray();
}
示例15: ExceptionsTestsPriceConverterTest
public void ExceptionsTestsPriceConverterTest()
{
var engine = new FileHelperEngine<CustomConvType>();
Assert.Throws<ConvertException>(
() => engine.ReadString(testTo));
}