public async Task refreshCurrency() { while (true) { StockApi api = new WpfApplication1.StockApi(); Dictionary <string, dynamic> data = api.getData(this.urlParameters); if (data == null || !data.ContainsKey("Realtime Currency Exchange Rate")) { if (data == null) { MessageBox.Show("data == null"); } continue; } if (this.isClearingActive == true) { return; } int i = 0; await Dispatcher.BeginInvoke((Action)(() => { if (!this.Children.Contains(this.stackPanel)) { this.Children.Add(this.stackPanel); } foreach (JProperty timeInterval in data["Realtime Currency Exchange Rate"]) { if (this.isClearingActive == true) { return; } // do something with entry.Value or entry.Key JToken value = timeInterval; value = value.Next; value = value.Next; value = value.Next; value = value.Next; this.valueLabel.Content = value.First.ToString(); break; } })); if (this.isClearingActive == true) { this.isClearingActive = false; return; } await Task.Delay(refresh); if (this.isClearingActive == true) { this.isClearingActive = false; return; } } }
public async Task refreshGraph() { while (true) { StockApi api = new WpfApplication1.StockApi(); Dictionary <string, dynamic> data = api.getData(this.stockInfo.urlParameters); if (data == null || !data.ContainsKey(this.stockInfo.getTimeSeriesKey())) { MessageBox.Show("Service can not load required data at the moment! Please clear the window and try again!"); return; } List <KeyValuePair <string, double> > dataValues = new List <KeyValuePair <string, double> >(); int i = 0; await Dispatcher.BeginInvoke((Action)(() => { foreach (JProperty timeInterval in data[this.stockInfo.getTimeSeriesKey()]) { // do something with entry.Value or entry.Key JToken value = timeInterval.First.First; i++; while (true) { if (value.Path.Contains(EnumDescription(this.stockInfo.data)) && this.stockInfo is StockInfo) { dataValues.Add(new KeyValuePair <string, double>(timeInterval.Name, Convert.ToDouble(value.First.ToString()))); break; } else if (value.Path.Contains(EnumDescription(this.stockInfo.data)) && this.stockInfo is CryptoInfo) { if (this.stockInfo.data == DataType.MARKETCAP || this.stockInfo.data == DataType.VOLUME) { dataValues.Add(new KeyValuePair <string, double>(timeInterval.Name, Convert.ToDouble(value.First.ToString()))); break; } else if (value.Path.Contains(((CryptoInfo)this.stockInfo).marketCode)) { dataValues.Add(new KeyValuePair <string, double>(timeInterval.Name, Convert.ToDouble(value.First.ToString()))); break; } } value = value.Next; } // values.First = 1. open value if (i == stockInfo.numOfPoints) { break; } } LineSeries dataLineSeries = new LineSeries(); dataLineSeries.Title = EnumDescription(stockInfo.data); dataLineSeries.DependentValuePath = "Value"; dataLineSeries.IndependentValuePath = "Key"; dataLineSeries.ItemsSource = dataValues; Chart chart = new Chart(); chart.Series.Add(dataLineSeries); if (this.isClearingActive == true) { return; } if (this.Children.Contains(this.graphChart)) { this.Children.Remove(this.graphChart); } this.graphChart = chart; this.Children.Add(this.graphChart); })); if (this.isClearingActive == true) { this.isClearingActive = false; return; } await Task.Delay(refresh); } }
private async Task refreshCurrentValue() { while (true) { StockApi api = new WpfApplication1.StockApi(); Dictionary <string, dynamic> data = api.getData(this.stockInfo.urlParameters); if (data == null || !data.ContainsKey(this.stockInfo.getTimeSeriesKey())) { MessageBox.Show("Service can not load required data at the moment! Please clear the window and try again!"); return; } int i = 0; await Dispatcher.BeginInvoke((Action)(() => { foreach (JProperty timeInterval in data[this.stockInfo.getTimeSeriesKey()]) { if (this.isClearingActive == true) { return; } // do something with entry.Value or entry.Key JToken value = timeInterval.First.First; i++; //this.valueLabel.Content = stockInfo.fullName + "\n" + stockInfo.data.ToString() + "\n";\\ if (!this.Children.Contains(this.stackPanel)) { this.Children.Add(this.stackPanel); } //this.stackPanel.Height = this.ActualHeight - 20; //this.stackPanel.Width = this.ActualWidth - 70; //this.stackPanel.HorizontalAlignment = HorizontalAlignment.Center; //this.stackPanel.VerticalAlignment = VerticalAlign while (true) { if (value.Path.Contains(EnumDescription(this.stockInfo.data)) && this.stockInfo is StockInfo) { this.valueLabel.Content = value.First.ToString(); break; } else if (value.Path.Contains(EnumDescription(this.stockInfo.data)) && this.stockInfo is CryptoInfo) { if (this.stockInfo.data == DataType.MARKETCAP || this.stockInfo.data == DataType.VOLUME) { this.valueLabel.Content = value.First.ToString(); this.currency.Content = ((CryptoInfo)this.stockInfo).marketCode; break; } else if (value.Path.Contains(((CryptoInfo)this.stockInfo).marketCode)) { this.valueLabel.Content = value.First.ToString(); break; } } value = value.Next; } // values.First = 1. open value if (i == stockInfo.numOfPoints) { break; } if (!this.Children.Contains(this.valueLabel)) { this.Children.Add(this.valueLabel); } } })); if (this.isClearingActive == true) { this.isClearingActive = false; return; } await Task.Delay(refresh); } }
public async Task refreshGraph() { while (true) { StockApi api = new WpfApplication1.StockApi(); Dictionary <string, dynamic> data = api.getData(this.urlParameter); if (data == null) { continue; } //Dictionary<string, dynamic> data = api.getData("/"); List <KeyValuePair <string, double> > openData = new List <KeyValuePair <string, double> >(); List <KeyValuePair <string, double> > highData = new List <KeyValuePair <string, double> >(); List <KeyValuePair <string, double> > lowData = new List <KeyValuePair <string, double> >(); List <KeyValuePair <string, double> > closeData = new List <KeyValuePair <string, double> >(); List <KeyValuePair <string, double> > volumeData = new List <KeyValuePair <string, double> >(); int i = 0; await Dispatcher.BeginInvoke((Action)(() => { LineSeries closeLines = new LineSeries(); foreach (JProperty timeInterval in data["Time Series (1min)"]) { // do something with entry.Value or entry.Key JToken values = timeInterval.First.First; // values.First = 1. open value openData.Add(new KeyValuePair <string, double>(timeInterval.Name, Convert.ToDouble(values.First.ToString()))); values = values.Next; highData.Add(new KeyValuePair <string, double>(timeInterval.Name, Convert.ToDouble(values.First.ToString()))); values = values.Next; lowData.Add(new KeyValuePair <string, double>(timeInterval.Name, Convert.ToDouble(values.First.ToString()))); values = values.Next; closeData.Add(new KeyValuePair <string, double>(timeInterval.Name, Convert.ToDouble(values.First.ToString()))); values = values.Next; volumeData.Add(new KeyValuePair <string, double>(timeInterval.Name, Convert.ToDouble(values.First.ToString()))); if (++i == 10) { break; } } closeLines.Title = "Close"; closeLines.DependentValuePath = "Value"; closeLines.IndependentValuePath = "Key"; closeLines.ItemsSource = closeData; LineSeries openLines = new LineSeries(); openLines.Title = "Open"; openLines.DependentValuePath = "Value"; openLines.IndependentValuePath = "Key"; openLines.ItemsSource = openData; LineSeries highLines = new LineSeries(); highLines.Title = "High"; highLines.DependentValuePath = "Value"; highLines.IndependentValuePath = "Key"; highLines.ItemsSource = highData; LineSeries lowLines = new LineSeries(); lowLines.Title = "Low"; lowLines.DependentValuePath = "Value"; lowLines.IndependentValuePath = "Key"; lowLines.ItemsSource = lowData; LineSeries volumeLines = new LineSeries(); volumeLines.Title = "Volume"; volumeLines.DependentValuePath = "Value"; volumeLines.IndependentValuePath = "Key"; volumeLines.ItemsSource = volumeData; List <LineSeries> lines = new List <LineSeries>(); lines.Add(lowLines); lines.Add(highLines); lines.Add(openLines); lines.Add(closeLines); Chart chart = new Chart(); chart.Series.Add(lowLines); chart.Series.Add(highLines); chart.Series.Add(openLines); chart.Series.Add(closeLines); if (this.Children.Contains(this.graphChart)) { this.Children.Remove(this.graphChart); } this.graphChart = chart; this.Children.Add(this.graphChart); })); await Task.Delay(5000); } }