Beispiel #1
0
        static void save(StockSplitInfo[] infos, splitType filename)
        {
            var data = tryGet(a => true, filename);
            var ex   = infos.Except(data);

            if (!ex.Any())
            {
                StockPriceManager.SetMessage(DataSource.KabuDotCom, "新規データが存在しなかったため書き込み処理をスキップしました。");
                return;
            }

            if (!Directory.Exists(localPath))
            {
                Directory.CreateDirectory(localPath);
            }
            string tgtPath = localPath + filename.toFileName();

            try {
                using (FileStream f = new FileStream(tgtPath, FileMode.Create)) {
                    var seri = new XmlSerializer(typeof(StockSplitInfo[]));
                    seri.Serialize(f, data.Union(infos).ToArray());
                    StockPriceManager.SetMessage(DataSource.KabuDotCom, filename.toDisplayName() + "データを保存しました。");
                }
            } catch (Exception e) {
                StockPriceManager.SetMessage(new ManagementMessage()
                {
                    Sender  = DataSource.KabuDotCom,
                    Signal  = MessageSignal.Error,
                    Message = "書き込み処理に失敗しました。",
                    Detail  = e.Message,
                });
            }
        }
Beispiel #2
0
        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]);
            }
        }