public async Task <object> GetContext(Catalog.Request.IncorporatedStocks stocks)
        {
            try
            {
                var response = await client.ExecuteAsync(new RestRequest(security.RequestCount(stocks), Method.GET), source.Token);

                if (response != null && response.RawBytes != null && response.RawBytes.Length > 0)
                {
                    Coin += security.GetSettleTheFare(response.RawBytes.Length);
                    SendMessage(Coin);
                }
                if (string.IsNullOrEmpty(stocks.Date))
                {
                    var page = JsonConvert.DeserializeObject <int>(response.Content);

                    if (response.StatusCode.Equals(HttpStatusCode.OK) && page < 0x16)
                    {
                        return(page);
                    }
                }
                else
                {
                    return(JsonConvert.DeserializeObject <List <Catalog.Request.IncorporatedStocks> >(response.Content));
                }
            }
            catch (Exception ex)
            {
                SendMessage(ex.StackTrace);
            }
            return(null);
        }
Example #2
0
        public Stack <Catalog.Request.IncorporatedStocks> OnReceiveSequentially(int page)
        {
            try
            {
                driver.Navigate().GoToUrl(security.RequestParameter(page));
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(7);
                var stack = new Stack <Catalog.Request.IncorporatedStocks>();
                var date  = DateTime.Now.ToString("yyMMdd");

                foreach (var tr in driver.FindElementByXPath("/html/body/div/table[1]").FindElement(By.TagName("tbody")).FindElements(By.TagName("tr")))
                {
                    var index = 0;
                    var stock = new Catalog.Request.IncorporatedStocks
                    {
                        Date   = date,
                        Market = 'P'
                    };
                    foreach (var a in tr.FindElements(By.TagName("a")))
                    {
                        var code = a.GetAttribute("href").Split('=')[1];

                        if (code.Length == 6)
                        {
                            stock.Code = code.Trim();
                            stock.Name = a.Text.Trim();
                        }
                    }
                    foreach (var td in tr.FindElements(By.TagName("td")))
                    {
                        if (index++ == 6 && int.TryParse(td.Text.Replace(",", string.Empty), out int total))
                        {
                            stock.Capitalization = total;
                            stack.Push(stock);
                        }
                    }
                }
                return(stack);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                driver.Close();
                driver.Dispose();
                service.Dispose();
                GC.Collect();
            }
            return(null);
        }