public async Task <TimeSeries> LoadData(ValidFileInfo fileInfo) { return(await Task.Run(() => { try { var oleDbConnectionString = new OleDbConnectionString(fileInfo); var progressItem = new ProgressManager { TimeStamp = DateTime.UtcNow, Progress = 1, Action = "OleDbLoader Load data: ", Message = "OleDbLoader Loader Load data started:" + fileInfo.Source }; oleDbConnectionString.ValidFileInfo.ProgressLogger?.Report(progressItem); var stopWatch = new Stopwatch(); stopWatch.Start(); var timeSeries = new TimeSeries { Source = oleDbConnectionString.ValidFileInfo.Source }; //;HDR=yes //;Format=xlsx;IMEX=1 var oledbConn = new System.Data.OleDb.OleDbConnection(oleDbConnectionString.Value); var command = new System.Data.OleDb.OleDbDataAdapter(oleDbConnectionString.Sql, oledbConn); command.TableMappings.Add("Table", "LoadTable"); var dtSet = new DataSet(); command.Fill(dtSet); var table = dtSet.Tables[0]; var dateCol = table.Columns["date"]; var closeCol = table.Columns["close"]; var nameCol = table.Columns["Name"]; foreach (DataRow tableRow in table.Rows) { var date = Utils.SafeCastToDate(tableRow[dateCol].ToString()); var close = Utils.SafeCastToDoubleParse(tableRow[closeCol].ToString()); var tsdp = new TimeSeriesDataPoint { Date = Utils.SafeCastToDate(date.ToString()), Close = Utils.SafeCastToDoubleParse(close.ToString()), Symbol = tableRow[nameCol].ToString(), Source = oleDbConnectionString.ValidFileInfo.Source, LastUpdated = ConfigDataHandler.SystemName, UpdateDate = DateTime.UtcNow }; timeSeries.Add(tsdp); } oledbConn.Close(); stopWatch.Stop(); timeSeries.LoadTime = stopWatch.Elapsed; progressItem = new ProgressManager { TimeStamp = DateTime.UtcNow, Progress = 1, Action = "OleDbLoader Load data", Message = "OleDbLoader Loader Load data stopped" + fileInfo.Source }; oleDbConnectionString.ValidFileInfo.ProgressLogger?.Report(progressItem); return timeSeries; } catch (Exception ex) { Console.WriteLine(ex.Message); } return new TimeSeries(); })); }
public static LoaderDataValidation <TimeSeriesDataPoint> IsTimeSeriesDataValid(TimeSeriesDataPoint timeSeriesDataPoint) { if (!timeSeriesDataPoint.Close.HasValue || double.IsNaN((double)timeSeriesDataPoint.Close)) { return(new LoaderDataValidation <TimeSeriesDataPoint>(timeSeriesDataPoint, false, "101: Closing value is NA")); } return(new LoaderDataValidation <TimeSeriesDataPoint>(timeSeriesDataPoint, true, string.Empty)); }
public async Task <TimeSeries> LoadData(ValidFileInfo fileInfo) { return(await Task.Run(() => { var timeSeries = new TimeSeries { Source = fileInfo.Source }; var stopWatch = new Stopwatch(); stopWatch.Start(); var progressItem = new ProgressManager { TimeStamp = DateTime.UtcNow, Progress = 1, Action = "XmlLoader Load data", Message = $"Xml Loader Load data started {fileInfo.Source}" }; fileInfo.ProgressLogger?.Report(progressItem); using (Stream s = File.OpenRead(fileInfo.Value.FullName)) { var xdoc = XElement.Load(s, LoadOptions.None); foreach (var element in xdoc.Elements()) { //.AsParallel() hold of parallising for the moment. //this can be improved to hold a column mappingname names. var tsdp = new TimeSeriesDataPoint { Date = Utils.ConvertValueToDate(element, "date"), Symbol = Utils.ConvertValueToString(element, "Name"), Close = Utils.ConvertValueToDouble(element, "close"), Source = fileInfo.Source, LastUpdated = "AutoLoad", UpdateDate = DateTime.UtcNow }; timeSeries.Add(tsdp); } stopWatch.Stop(); timeSeries.LoadTime = stopWatch.Elapsed; progressItem = new ProgressManager { TimeStamp = DateTime.UtcNow, Progress = 1, Action = "XmlLoader Load data", Message = $"Xml Loader Load data stopped {fileInfo.Source}" }; fileInfo.ProgressLogger?.Report(progressItem); return timeSeries; } })); //return await Task.Run(() => //{ // var deserializer = new XmlSerializer(typeof(TimeSeries)); // Stream s = File.OpenRead(fileInfo.Value.FullName); // var xdoc = XElement.Load(s, LoadOptions.None); // //s.Position = 0; // //var x = new StreamReader(s); // //var xy = deserializer.Deserialize(x); // using (StreamReader reader = new StreamReader(fileInfo.Value.FullName)) // { // var obj = deserializer.Deserialize(reader); // var xmlData = (List<TimeSeriesDataPoint>)obj; // return new TimeSeries(); // } //}); }