static void Main(string[] args) { ActiveGridConnection connection = new ActiveGridConnection("http://localhost:5432/"); bool cont = true; Task lookupPrices = Task.Factory.StartNew(() => { while (true) { foreach (var t in _tickers) { Task.Factory.StartNew((ticker) => { string url = string.Format("http://www.google.com/ig/api?stock={0}", ticker); WebClient webclient = new WebClient(); string response = webclient.DownloadString(url); XDocument xdoc = XDocument.Parse(response); XElement last = xdoc.Element("xml_api_reply").Element("finance").Element("last"); decimal price = decimal.Parse(last.Attribute("data").Value); var updates = new GridUpdates(); updates.action = GridActionType.update; updates.match = new { Ticker = ticker }; updates.item = new { Price = price }; connection.UpdateGrid(updates); }, t); } Thread.Sleep(15000); } }); while (cont) { Console.WriteLine("Enter a new ticker:"); string input = Console.ReadLine(); if (input.ToLower() == "exit") { cont = false; } else if (input.ToLower() == "list") { foreach (var ticker in _tickers) { Console.WriteLine(string.Format("Maintaining price for: {0}", ticker)); } } else { if (_tickers.Where(t => t == input).Count() != 0) { continue; } _tickers.Add(input.Trim()); } } }
// POST /api/<controller> public void Post(Holding holding) { holding.HoldingId = Holdings.Data.Max(h => h.HoldingId); Holdings.Data.Add(holding); GridUpdates updates = new GridUpdates(); updates.action = GridActionType.create; updates.match = ""; updates.item = holding; string url = string.Format("{0}://{1}:{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Host, this.Request.RequestUri.Port); ActiveGridConnection connection = new ActiveGridConnection(url); connection.UpdateGrid(updates); }