コード例 #1
0
ファイル: KabuDotComClient.cs プロジェクト: Houzkin/Caramelia
        static IEnumerable <StockSplitInfo> _download(splitType type)
        {
            string str = "";

            try {
                str = getSource(type.getUrl()).Result;
                StockPriceManager.SetMessage(DataSource.KabuDotCom, type.toDisplayName() + "データのダウンロード完了");
            } catch (Exception e) {
                StockPriceManager.SetMessage(new ManagementMessage()
                {
                    Sender  = DataSource.KabuDotCom,
                    Signal  = MessageSignal.Error,
                    Message = "接続エラー",
                    Detail  = e.Message,
                });
                return(new StockSplitInfo[0]);
            }
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(str);
            try {
                var dd = doc.DocumentNode
                         //.SelectNodes(@"table[@class=""tbl01""]");
                         .SelectNodes(@"//table[@class='tbl01']")
                         .Descendants("tr")
                         .Select(a => new { Prm = a.Elements("td").Select(e => e.InnerText) })
                         //.Select(a => ResultWithValue.Of<IEnumerable<string>, StockSplitInfo>(tryParse, a.Prm))
                         //.Where(a => a.Result)
                         //.Select(a => a.Value);
                         .Where(a => a.Prm.Any())
                         .Select(a => parse(a.Prm));
                StockPriceManager.SetMessage(DataSource.KabuDotCom, type.toDisplayName() + "データの解析完了");
                return(dd);
            }catch (Exception e) {
                StockPriceManager.SetMessage(new ManagementMessage()
                {
                    Sender  = DataSource.KabuDotCom,
                    Signal  = MessageSignal.Error,
                    Message = "解析エラー",
                    Detail  = e.Message,
                });
                return(new StockSplitInfo[0]);
            }
        }