public GoogleMarket(GoogleMarketServer svr)
            {
                _Svr = svr;
                try
                {
                    // Use StringBuilder instead of StringBuffer. We do not concern
                    // on thread safety.
                    StringBuilder builder = new StringBuilder("http://www.google.com/finance/info?client=ig&q=");
                    // Exception will be thrown from apache httpclient, if we do not
                    // perform URL encoding.
                    builder.Append(_Svr.codes[0].toString());
                    int size = _Svr.codes.Count;

                    for (int i = 1; i < size; i++)
                    {
                        builder.Append(",");
                        builder.Append(_Svr.codes[i].toString());
                    }
                    String location = builder.ToString();
                    String respond  = Gui.Utils.getResponseBodyAsStringBasedOnProxyAuthOption(location);
                    // Google returns "// [ { "id": ... } ]".
                    // We need to turn them into "[ { "id": ... } ]".
                    List <Dictionary <string, string> > jsonArray = mapper.readValue(Utils.GoogleRespondToJSON(respond), typeof(List <Dictionary <string, string> >));
                    List <Stock> stocks = new List <Stock>();
                    size = jsonArray.Count;
                    for (int i = 0; i < size; i++)
                    {
                        Dictionary <String, String> jsonObject = jsonArray[i];
                        double l_curr = Double.Parse(jsonObject["l_cur"].Replace(",", ""));
                        double c      = Double.Parse(jsonObject["c"].Replace(",", ""));
                        // We ignore changePricePercentage. GoogleMarket doesn't
                        // need to return this value.
                        Stock stock = new Stock.Builder(_Svr.codes[i], Symbol.newInstance(_Svr.codes[i].toString())).lastPrice(l_curr).changePrice(c).build();
                        stocks.Add(stock);
                    }
                    // Store the result for later query purpose.
                    foreach (Stock stock in stocks)
                    {
                        map.Add(_Svr.codeToIndexMap[stock.getCode()], stock);
                    }
                }
                catch (Exception ex)
                {
                    // Jackson library may cause runtime exception if there is error
                    // in the JSON string.
                    throw new StockNotFoundException(null, ex);
                }
            }
            public GoogleMarket(GoogleMarketServer svr)
            {
                _Svr = svr;
                try
                {
                    // Use StringBuilder instead of StringBuffer. We do not concern
                    // on thread safety.
                    StringBuilder builder = new StringBuilder("http://www.google.com/finance/info?client=ig&q=");
                    // Exception will be thrown from apache httpclient, if we do not
                    // perform URL encoding.
                    builder.Append(_Svr.codes[0].toString());
                    int size = _Svr.codes.Count;

                    for (int i = 1; i < size; i++)
                    {
                        builder.Append(",");
                        builder.Append(_Svr.codes[i].toString());
                    }
                    String location = builder.ToString();
                    String respond = Gui.Utils.getResponseBodyAsStringBasedOnProxyAuthOption(location);
                    // Google returns "// [ { "id": ... } ]".
                    // We need to turn them into "[ { "id": ... } ]".
                    List<Dictionary<string, string>> jsonArray = mapper.readValue(Utils.GoogleRespondToJSON(respond), typeof(List<Dictionary<string, string>>));
                    List<Stock> stocks = new List<Stock>();
                    size = jsonArray.Count;
                    for (int i = 0; i < size; i++)
                    {
                        Dictionary<String, String> jsonObject = jsonArray[i];
                        double l_curr = Double.Parse(jsonObject["l_cur"].Replace(",", ""));
                        double c = Double.Parse(jsonObject["c"].Replace(",", ""));
                        // We ignore changePricePercentage. GoogleMarket doesn't
                        // need to return this value.
                        Stock stock = new Stock.Builder(_Svr.codes[i], Symbol.newInstance(_Svr.codes[i].toString())).lastPrice(l_curr).changePrice(c).build();
                        stocks.Add(stock);
                    }
                    // Store the result for later query purpose.
                    foreach (Stock stock in stocks)
                    {
                        map.Add(_Svr.codeToIndexMap[stock.getCode()], stock);
                    }
                }
                catch (Exception ex)
                {
                    // Jackson library may cause runtime exception if there is error
                    // in the JSON string.
                    throw new StockNotFoundException(null, ex);
                }
            }
Exemple #3
0
 private GoogleStockServerFactory(Country country)
 {
     marketServer = new GoogleMarketServer(country);
 }