本文整理汇总了C#中FileHelperEngine.ReadString方法的典型用法代码示例。如果您正苦于以下问题:C# FileHelperEngine.ReadString方法的具体用法?C# FileHelperEngine.ReadString怎么用?C# FileHelperEngine.ReadString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelperEngine
的用法示例。
在下文中一共展示了FileHelperEngine.ReadString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: frmSort_Load
/// <summary>
/// Open file and read into array, display unsorted
/// </summary>
private void frmSort_Load(object sender, System.EventArgs e)
{
FileHelperEngine engine = new FileHelperEngine(typeof (CustomersVerticalBar));
mRecords = (CustomersVerticalBar[]) engine.ReadString(SampleData);
grid1.SelectedObject = mRecords;
}
示例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: ExceptionsTestsPriceConverterTest
public void ExceptionsTestsPriceConverterTest()
{
var engine = new FileHelperEngine<CustomConvType>();
Assert.Throws<ConvertException>(
() => engine.ReadString(testTo));
}
示例5: RunTimeEmptyGuidProperties
public void RunTimeEmptyGuidProperties()
{
var builder = new DelimitedClassBuilder("EntityWithGuid", "\t");
builder.AddField("Name", typeof(string));
builder.AddField("Id", typeof(Guid));
builder.LastField.FieldNullValue = Guid.Empty;
var engine = new FileHelperEngine(builder.CreateRecordClass())
{
Options = { IgnoreFirstLines = 1 }
};
const string inputValue = @"Name Id
first
second ";
var records = engine.ReadString(inputValue);
records.Length.AssertEqualTo(2);
dynamic record = records[0];
((Guid)record.Id).AssertEqualTo(Guid.Empty);
((string)record.Name).AssertEqualTo("first");
record = records[1];
((Guid)record.Id).AssertEqualTo(Guid.Empty);
((string)record.Name).AssertEqualTo("second");
}
示例6: cmdRun_Click
/// <summary>
/// Run the engine into an array and show data on a grid
/// </summary>
private void cmdRun_Click(object sender, EventArgs e)
{
var engine = new FileHelperEngine<CustomersVerticalBar>();
CustomersVerticalBar[] res = (CustomersVerticalBar[]) engine.ReadString(txtData.Text);
grid1.SelectedObject = res;
}
示例7: cmdRun_Click
/// <summary>
/// Run the engine over a grid and display
/// the result in a grid
/// </summary>
private void cmdRun_Click(object sender, EventArgs e)
{
var engine = new FileHelperEngine<CustomersFixed>();
grid1.SelectedObject = engine.ReadString(txtData.Text);
;
}
示例8: EncodingAdvanced3
public void EncodingAdvanced3()
{
var engine = new FileHelperEngine(typeof(EncodingRecord));
byte[] data = File.ReadAllBytes(FileTest.Good.EncodingAdv3.Path);
var encoding = new System.Text.ASCIIEncoding();
string dataString = encoding.GetString(data);
var res = (EncodingRecord[])engine.ReadString(dataString);
Assert.AreEqual(res.Length, 18);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: NullDateFormat
public void NullDateFormat()
{
String data = "23/11/2010,24/11/2010\n,\n , \n";
var engine = new FileHelperEngine<NullDateFormat>();
NullDateFormat[] 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");
}
示例13: OptionalForReadOnEmptyFields
public void OptionalForReadOnEmptyFields()
{
var eng = new FileHelperEngine<OptionalForReadOnEmptyFieldsClass>();
var records = eng.ReadString(@"id,text,number
121,""""""not good"""" line"", 4456
120,""good line this one"",789
122,,5446");
Check.That(records.Length).IsEqualTo(3);
Check.That(records[0].Text).IsEqualTo("\"not good\" line");
Check.That(records[2].Text).IsEqualTo("");
}
示例14: LoadCrimeData
private void LoadCrimeData()
{
if (_crimeList == null)
{
_crimeList = new List<CrimeDetail>();
}
var engine = new FileHelperEngine(typeof(CrimeDetail));
var crimesArray = engine.ReadString(CrimeData.Data) as CrimeDetail[];
if (crimesArray != null && crimesArray.Length > 0)
{
_crimeList.AddRange(crimesArray.Reverse());
}
}
示例15: ExceptionsTestsPriceConverterTest2
public void ExceptionsTestsPriceConverterTest2()
{
try {
var engine = new FileHelperEngine<CustomConvType>();
object[] res = engine.ReadString(testTo);
}
catch (ConvertException ex) {
Assert.IsTrue(ex.Message.IndexOf("VeryBadConverter") >= 0);
Assert.IsTrue(ex.Message.IndexOf("custom converter") >= 0);
Assert.IsTrue(ex.Message.IndexOf("Line: 1") >= 0);
Assert.IsTrue(ex.Message.IndexOf("Column: 1") >= 0);
}
}