Example #1
0
        private async Task RefreshSelectedStockList()
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            string url = "/services/stocks?quotes=urn:issue:" + string.Join(",urn:issue:", this.notificationWindow.StockList);
            string res = await WebController.GetStringAsync("https://api.lecho.be" + url);

            dynamic json = JObject.Parse(res);

            foreach (var updatedStock in json.results)
            {
                Stock currentStock = this.GetStockById(Stock.GetStockId(updatedStock.issueUrn.ToString()));

                if (currentStock != null)
                {
                    currentStock.Value      = updatedStock.lastPrice;
                    currentStock.Pct        = updatedStock.dayChangePercentage;
                    currentStock.LastUpdate = updatedStock.updatedOn;
                }
            }

            stopWatch.Stop();
            Debug.Print($"Update executed in {stopWatch.Elapsed.TotalMilliseconds:0} milliseconds.");
        }
Example #2
0
        private async Task LoadAllData()
        {
            var n       = this.JsonUrls.Count;
            var tasks   = new Task <List <Stock> > [n];
            var results = new List <Stock> [n];

            // Create and start the tasks
            int k = 0;

            foreach (var market in JsonUrls.Keys)
            {
                var url = JsonUrls[market];
                tasks[k] = WebController.GetStocksAsync(market, url);
                k++;
            }

            // Wait for each task to finish and populate stockList
            for (int i = 0; i < n; i++)
            {
                results[i] = await tasks[i];
                foreach (var s in results[i])
                {
                    this.stockList[s.Id] = s;
                }

                this.UpdateLoadingPercentage(i + 1, n);
            }
        }
Example #3
0
        private async Task LoadAllData()
        {
            var n       = this.JsonUrls.Count;
            var tasks   = new Task <List <Stock> > [n];
            var results = new List <Stock> [n];

            // Create and start the tasks
            for (int i = 0; i < n; i++)
            {
                tasks[i] = WebController.GetStocksAsync(this.JsonUrls[i]);
            }

            // Wait for each task to finish and populate stockList
            for (int i = 0; i < n; i++)
            {
                results[i] = await tasks[i];
                foreach (var s in results[i])
                {
                    this.stockList[s.Id] = s;
                }

                this.UpdateLoadingPercentage(i + 1, n);
            }

            // this.stockList = results.SelectMany(x => x).ToDictionary(s => s.Id, s => s);
        }