リビジョン | 5022f8c707175d9d8cd0c38915e52b1fffd92271 (tree) |
---|---|
日時 | 2011-01-29 13:39:42 |
作者 | azyobuzin <azyobuzin@user...> |
コミッター | azyobuzin |
・エラー処理するようにした
・LINQ To Twitterを更新 -> To r84159
@@ -29,19 +29,25 @@ namespace Azyobuzi.Twirunrun | ||
29 | 29 | public override void RefreshTimeline(int page, int count, bool first) |
30 | 30 | { |
31 | 31 | NotifyStarted(); |
32 | - var newDMs = new[] { DirectMessageType.SentTo, DirectMessageType.SentBy }.SelectMany(type => | |
33 | - this.GetMainForm().TwitterContext.DirectMessage.Where(dm => | |
34 | - dm.Type == type && | |
35 | - dm.Page == page && | |
36 | - dm.Count == count | |
37 | - ) | |
38 | - ).Select(dm => new StatusInfo(dm)) | |
39 | - .Where(dm => !RecentStatusesCollection.Instance.AsParallel().Contains(dm)) | |
40 | - .ToArray(); | |
41 | - if (newDMs.Any()) | |
42 | - this.first = first; | |
43 | - RecentStatusesCollection.Instance.AddRange(newDMs); | |
44 | - NotifyCompleted(); | |
32 | + try | |
33 | + { | |
34 | + var newDMs = new[] { DirectMessageType.SentTo, DirectMessageType.SentBy }.SelectMany(type => | |
35 | + this.GetMainForm().TwitterContext.DirectMessage.Where(dm => | |
36 | + dm.Type == type && | |
37 | + dm.Page == page && | |
38 | + dm.Count == count | |
39 | + ) | |
40 | + ).Select(dm => new StatusInfo(dm)) | |
41 | + .Where(dm => !RecentStatusesCollection.Instance.AsParallel().Contains(dm)) | |
42 | + .ToArray(); | |
43 | + if (newDMs.Any()) | |
44 | + this.first = first; | |
45 | + RecentStatusesCollection.Instance.AddRange(newDMs); | |
46 | + } | |
47 | + finally | |
48 | + { | |
49 | + NotifyCompleted(); | |
50 | + } | |
45 | 51 | } |
46 | 52 | } |
47 | 53 | } |
@@ -30,18 +30,24 @@ namespace Azyobuzi.Twirunrun | ||
30 | 30 | public override void RefreshTimeline(int page, int count, bool first) |
31 | 31 | { |
32 | 32 | NotifyStarted(); |
33 | - var newTweets = this.GetMainForm().TwitterContext.Status.Where(tweet => | |
34 | - tweet.Type == StatusType.Home && | |
35 | - tweet.Page == page && | |
36 | - tweet.Count == count | |
37 | - ) | |
38 | - .Select(tweet => new StatusInfo(tweet)) | |
39 | - .Where(tweet => !RecentStatusesCollection.Instance.AsParallel().Contains(tweet)) | |
40 | - .ToArray(); | |
41 | - if (newTweets.Any()) | |
42 | - this.first = first; | |
43 | - RecentStatusesCollection.Instance.AddRange(newTweets); | |
44 | - NotifyCompleted(); | |
33 | + try | |
34 | + { | |
35 | + var newTweets = this.GetMainForm().TwitterContext.Status.Where(tweet => | |
36 | + tweet.Type == StatusType.Home && | |
37 | + tweet.Page == page && | |
38 | + tweet.Count == count | |
39 | + ) | |
40 | + .Select(tweet => new StatusInfo(tweet)) | |
41 | + .Where(tweet => !RecentStatusesCollection.Instance.AsParallel().Contains(tweet)) | |
42 | + .ToArray(); | |
43 | + if (newTweets.Any()) | |
44 | + this.first = first; | |
45 | + RecentStatusesCollection.Instance.AddRange(newTweets); | |
46 | + } | |
47 | + finally | |
48 | + { | |
49 | + NotifyCompleted(); | |
50 | + } | |
45 | 51 | } |
46 | 52 | } |
47 | 53 | } |
@@ -38,18 +38,24 @@ namespace Azyobuzi.Twirunrun | ||
38 | 38 | public override void RefreshTimeline(int page, int count, bool first) |
39 | 39 | { |
40 | 40 | NotifyStarted(); |
41 | - var newTweets = this.GetMainForm().TwitterContext.Status.Where(tweet => | |
42 | - tweet.Type == StatusType.Mentions && | |
43 | - tweet.Page == page && | |
44 | - tweet.Count == count | |
45 | - ) | |
46 | - .Select(tweet => new StatusInfo(tweet)) | |
47 | - .Where(tweet => !RecentStatusesCollection.Instance.AsParallel().Contains(tweet)) | |
48 | - .ToArray(); | |
49 | - if (newTweets.Any()) | |
50 | - this.first = first; | |
51 | - RecentStatusesCollection.Instance.AddRange(newTweets); | |
52 | - NotifyCompleted(); | |
41 | + try | |
42 | + { | |
43 | + var newTweets = this.GetMainForm().TwitterContext.Status.Where(tweet => | |
44 | + tweet.Type == StatusType.Mentions && | |
45 | + tweet.Page == page && | |
46 | + tweet.Count == count | |
47 | + ) | |
48 | + .Select(tweet => new StatusInfo(tweet)) | |
49 | + .Where(tweet => !RecentStatusesCollection.Instance.AsParallel().Contains(tweet)) | |
50 | + .ToArray(); | |
51 | + if (newTweets.Any()) | |
52 | + this.first = first; | |
53 | + RecentStatusesCollection.Instance.AddRange(newTweets); | |
54 | + } | |
55 | + finally | |
56 | + { | |
57 | + NotifyCompleted(); | |
58 | + } | |
53 | 59 | } |
54 | 60 | } |
55 | 61 | } |
@@ -9,6 +9,7 @@ using LinqToTwitter; | ||
9 | 9 | using System.Diagnostics; |
10 | 10 | using System.Threading; |
11 | 11 | using System.Threading.Tasks; |
12 | +using System.Net; | |
12 | 13 | |
13 | 14 | namespace Azyobuzi.Twirunrun |
14 | 15 | { |
@@ -151,7 +152,11 @@ namespace Azyobuzi.Twirunrun | ||
151 | 152 | |
152 | 153 | public void RefreshTimelines(IEnumerable<TimelineTabPage> tabs, bool first) |
153 | 154 | { |
154 | - var t = new Thread(() => tabs.AsParallel().ForAll(tab => tab.RefreshTimeline(first))); | |
155 | + var t = new Thread(() => | |
156 | + tabs.AsParallel().ForAll(tab => | |
157 | + ((Action)(() => tab.RefreshTimeline(first))) | |
158 | + .TryCatch(ex => ShowError(tab, ex)) | |
159 | + )); | |
155 | 160 | t.IsBackground = true; |
156 | 161 | t.Start(); |
157 | 162 | } |
@@ -230,5 +235,41 @@ namespace Azyobuzi.Twirunrun | ||
230 | 235 | { |
231 | 236 | notifyIcon1.ShowBalloonTip(timeout, tipTitle, tipText, tipIcon); |
232 | 237 | } |
238 | + | |
239 | + | |
240 | + public void ShowError(TimelineTabPage tabPage, Exception exception) | |
241 | + { | |
242 | + string message; | |
243 | + Exception ex = | |
244 | + exception.InnerException == null && exception.InnerException is TwitterQueryException | |
245 | + ? exception : exception.InnerException; | |
246 | + var twitterex = ex as TwitterQueryException; | |
247 | + if (twitterex != null) | |
248 | + { | |
249 | + if (twitterex.Response.Error == "See Inner Exception Details for more information." || | |
250 | + twitterex.Response.Error == "error message not received from Twitter") | |
251 | + { | |
252 | + var webex = twitterex.InnerException as WebException; | |
253 | + if (webex == null) | |
254 | + { | |
255 | + message = "不明なエラー"; | |
256 | + } | |
257 | + else | |
258 | + { | |
259 | + var statuscode = ((HttpWebResponse)webex.Response).StatusCode; | |
260 | + message = string.Format("{0} {1}", (int)statuscode, statuscode.ToString()); | |
261 | + } | |
262 | + } | |
263 | + else | |
264 | + { | |
265 | + message = twitterex.Response.Error; | |
266 | + } | |
267 | + } | |
268 | + else | |
269 | + { | |
270 | + message = ex.Message; | |
271 | + } | |
272 | + StatusChange(string.Format("{0}:{1}", tabPage.TabSettings.Name, message)); | |
273 | + } | |
233 | 274 | } |
234 | 275 | } |
@@ -1,4 +1,5 @@ | ||
1 | -using System.Collections.Generic; | |
1 | +using System; | |
2 | +using System.Collections.Generic; | |
2 | 3 | using System.Windows.Forms; |
3 | 4 | using LinqToTwitter; |
4 | 5 |
@@ -13,5 +14,6 @@ namespace Azyobuzi.Twirunrun | ||
13 | 14 | IEnumerable<TimelineTabPage> GetTabPages(); |
14 | 15 | void RefreshTimelines(IEnumerable<TimelineTabPage> tabs, bool first); |
15 | 16 | void ShowBalloon(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon); |
17 | + void ShowError(TimelineTabPage tabPage, Exception exception); | |
16 | 18 | } |
17 | 19 | } |
@@ -534,7 +534,7 @@ namespace Azyobuzi.Twirunrun | ||
534 | 534 | // |
535 | 535 | //投稿欄の位置 |
536 | 536 | // |
537 | - private DockStyle postPanelPosition = DockStyle.Bottom; | |
537 | + private DockStyle postPanelPosition = DockStyle.Top; | |
538 | 538 | public DockStyle PostPanelPosition |
539 | 539 | { |
540 | 540 | set |