Я следую этому примеру .Насколько я могу судить, вызов GetRecords
не выполняется, когда я делаю запрос к конечной точке GetHist
, но я не понимаю, почему.
Я проверил, что:
- Мои данные соответствуют точным соглашениям об именах класса c # (я скопировал имена из csv для создания имен переменных в c #)
- Путь к файлу ввода правильный.
- Я использую последнюю версию CsvHelper (12.1.0)
Трассировка стека от вызова GetData:
"в CsvHelper.CsvReader.GetRecordsT + MoveNext () \ r \ n в System.Collections.Generic.LargeArrayBuilder 1.AddRange(IEnumerable
1 элементов) \ r \ n в System.Collections.Generic.EnumerableHelpers.ToArray [T] (10)1 источник) \ r \ n в System.Linq.SystemCore_EnumerableDebugView`1.get_Items () "
Мой код:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using CsvHelper;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
public class DataController : Controller
{
private readonly IHostingEnvironment _hostingEnvironment;
public DataController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
[HttpGet("[action]")]
public IEnumerable<OHLCData> GetHist()
{
var v=OHLCData.GetData(_hostingEnvironment);
return v;
}
public class OHLCData
{
string time;
double oask, hask, lask, cask, obid, hbid, lbid, cbid;
int volume;
//@TODO: shouldnt pass it to this class from controller, should set in startup and read in this method
public static IEnumerable<OHLCData> GetData(IHostingEnvironment _hostingEnvironment)
{
string filepath = Path.Combine(_hostingEnvironment.WebRootPath, "EUR_USD.csv");
using (var reader = new StreamReader(filepath))
using (var csv = new CsvReader(reader))
{
return csv.GetRecords<OHLCData>();
}
}
}
}