private void worker_DoWork(object sender, DoWorkEventArgs e) { int err_count = 5; EXDocument doc = new EXDocument(); int count = 0; while (count < tweet_count) { if (worker.CancellationPending == true) { break; } // 直近の200件を取得 string xml = GetTweets(username, max_id); if (xml == "") { err_count--; if (err_count < 0) { MessageBox.Show("取得エラー発生", APPTITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); worker.CancelAsync(); return; } // 1秒待つ System.Threading.Thread.Sleep(1000); continue; } doc.LoadXML(xml); EXElements items = doc * "status"; foreach (EXElement status in items) { string id = status / "id"; if (max_id == id) { continue; } count++; Tweet twi = new Tweet() { Num = count, ID = status / "id", text = status / "text", created_at = status / "created_at" }; _tweets.Add(twi); max_id = twi.ID; } worker.ReportProgress(count * 100 / tweet_count); if (items.Count < 200) { break; } } }
/// <summary> /// 子要素を探索する /// </summary> /// <param name="doc"></param> /// <param name="s"></param> /// <returns></returns> public static EXElements operator /(EXDocument doc, string tag) { EXElements items = new EXElements(); if (doc.DocumentElement != null) { if (doc.DocumentElement.Name == tag) { items.Add(doc.DocumentElement); } } return items; }
/// <summary> /// 子孫要素を探索する /// </summary> /// <param name="doc"></param> /// <param name="tag"></param> /// <returns></returns> public static EXElements operator *(EXDocument doc, string tag) { EXElements items = new EXElements(); if (doc.DocumentElement != null) { if (doc.DocumentElement.Name == tag) { items.Add(doc.DocumentElement); } items.AddRange( doc.DocumentElement.selectNodes(tag, true)); } return items ; }