private readonly object LockObj = new object();
private List<long> followerId = new List<long>();
private bool _GetFollowerResult = false;
- private List<long> noRTId = new List<long>();
+ private long[] noRTId = new long[0];
private bool _GetNoRetweetResult = false;
private int _followersCount = 0;
return text;
}
- public string GetFollowersApi()
+ /// <summary>
+ /// フォロワーIDを更新します
+ /// </summary>
+ /// <exception cref="WebApiException"/>
+ public void RefreshFollowerIds()
{
- if (MyCommon._endingFlag) return "";
- long cursor = -1;
- var tmpFollower = new List<long>(followerId);
+ if (MyCommon._endingFlag) return;
- followerId.Clear();
+ var cursor = -1L;
+ var newFollowerIds = new List<long>();
do
{
- var ret = FollowerApi(ref cursor);
- if (!string.IsNullOrEmpty(ret))
- {
- followerId.Clear();
- followerId.AddRange(tmpFollower);
- _GetFollowerResult = false;
- return ret;
- }
- } while (cursor > 0);
+ var ret = this.GetFollowerIdsApi(ref cursor);
+ newFollowerIds.AddRange(ret.Id);
+ cursor = ret.NextCursor;
+ } while (cursor != 0);
- TabInformations.GetInstance().RefreshOwl(followerId);
+ this.followerId = newFollowerIds;
+ TabInformations.GetInstance().RefreshOwl(this.followerId);
- _GetFollowerResult = true;
- return "";
+ this._GetFollowerResult = true;
}
public bool GetFollowersSuccess
}
}
- private string FollowerApi(ref long cursor)
+ private TwitterDataModel.Ids GetFollowerIdsApi(ref long cursor)
{
- if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return "";
+ if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
+ throw new WebApiException("AccountState invalid");
HttpStatusCode res;
var content = "";
{
res = twCon.FollowerIds(cursor, ref content);
}
- catch(Exception ex)
+ catch(Exception e)
{
- return "Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")";
+ throw new WebApiException("Err:" + e.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", e);
}
var err = this.CheckStatusCode(res, content);
- if (err != null) return err;
+ if (err != null)
+ throw new WebApiException(err, content);
try
{
- var followers = MyCommon.CreateDataFromJson<TwitterDataModel.Ids>(content);
- followerId.AddRange(followers.Id);
- cursor = followers.NextCursor;
- return "";
+ return MyCommon.CreateDataFromJson<TwitterDataModel.Ids>(content);
}
- catch(SerializationException ex)
+ catch(SerializationException e)
{
- MyCommon.TraceOut(ex.Message + Environment.NewLine + content);
- return "Err:Json Parse Error(DataContractJsonSerializer)";
+ var ex = new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, e);
+ MyCommon.TraceOut(ex);
+ throw ex;
}
- catch(Exception ex)
+ catch(Exception e)
{
- MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
- return "Err:Invalid Json!";
+ var ex = new WebApiException("Err:Invalid Json!", content, e);
+ MyCommon.TraceOut(ex);
+ throw ex;
}
}
- public string GetNoRetweetIdsApi()
+ /// <summary>
+ /// RT 非表示ユーザーを更新します
+ /// </summary>
+ /// <exception cref="WebApiException"/>
+ public void RefreshNoRetweetIds()
{
- if (MyCommon._endingFlag) return "";
- long cursor = -1;
- var tmpIds = new List<long>(noRTId);
+ if (MyCommon._endingFlag) return;
- noRTId.Clear();
- do
- {
- var ret = NoRetweetApi(ref cursor);
- if (!string.IsNullOrEmpty(ret))
- {
- noRTId.Clear();
- noRTId.AddRange(tmpIds);
- return ret;
- }
- } while (cursor > 0);
+ this.noRTId = this.NoRetweetIdsApi();
- _GetNoRetweetResult = true;
- return "";
+ this._GetNoRetweetResult = true;
}
- private string NoRetweetApi(ref long cursor)
+ private long[] NoRetweetIdsApi()
{
- if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return "";
+ if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
+ throw new WebApiException("AccountState invalid");
HttpStatusCode res;
var content = "";
try
{
- res = twCon.NoRetweetIds(cursor, ref content);
+ res = twCon.NoRetweetIds(ref content);
}
- catch(Exception ex)
+ catch(Exception e)
{
- return "Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")";
+ throw new WebApiException("Err:" + e.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", e);
}
var err = this.CheckStatusCode(res, content);
- if (err != null) return err;
+ if (err != null)
+ throw new WebApiException(err, content);
try
{
- var ids = MyCommon.CreateDataFromJson<long[]>(content);
- noRTId.AddRange(ids);
- cursor = 0; //0より小さければ何でも良い。
- return "";
+ return MyCommon.CreateDataFromJson<long[]>(content);
}
- catch(SerializationException ex)
+ catch(SerializationException e)
{
- MyCommon.TraceOut(ex.Message + Environment.NewLine + content);
- return "Err:Json Parse Error(DataContractJsonSerializer)";
+ var ex = new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, e);
+ MyCommon.TraceOut(ex);
+ throw ex;
}
- catch(Exception ex)
+ catch(Exception e)
{
- MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
- return "Err:Invalid Json!";
+ var ex = new WebApiException("Err:Invalid Json!", content, e);
+ MyCommon.TraceOut(ex);
+ throw ex;
}
}
}
}
- public string ConfigurationApi()
+ /// <summary>
+ /// t.co の文字列長などの設定情報を取得します
+ /// </summary>
+ /// <exception cref="WebApiException"/>
+ public TwitterDataModel.Configuration ConfigurationApi()
{
HttpStatusCode res;
var content = "";
{
res = twCon.GetConfiguration(ref content);
}
- catch(Exception ex)
+ catch(Exception e)
{
- return "Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")";
+ throw new WebApiException("Err:" + e.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", e);
}
var err = this.CheckStatusCode(res, content);
- if (err != null) return err;
+ if (err != null)
+ throw new WebApiException(err, content);
try
{
- AppendSettingDialog.Instance.TwitterConfiguration = MyCommon.CreateDataFromJson<TwitterDataModel.Configuration>(content);
- return "";
+ return MyCommon.CreateDataFromJson<TwitterDataModel.Configuration>(content);
}
- catch(SerializationException ex)
+ catch(SerializationException e)
{
- MyCommon.TraceOut(ex.Message + Environment.NewLine + content);
- return "Err:Json Parse Error(DataContractJsonSerializer)";
+ var ex = new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, e);
+ MyCommon.TraceOut(ex);
+ throw ex;
}
- catch(Exception ex)
+ catch(Exception e)
{
- MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
- return "Err:Invalid Json!";
+ var ex = new WebApiException("Err:Invalid Json!", content, e);
+ MyCommon.TraceOut(ex);
+ throw ex;
}
}
}
}
- public string GetBlockUserIds()
+ /// <summary>
+ /// ブロック中のユーザーを更新します
+ /// </summary>
+ /// <exception cref="WebApiException"/>
+ public void RefreshBlockIds()
{
- if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return "";
+ if (MyCommon._endingFlag) return;
+
+ var cursor = -1L;
+ var newBlockIds = new List<long>();
+ do
+ {
+ var ret = this.GetBlockIdsApi(cursor);
+ newBlockIds.AddRange(ret.Id);
+ cursor = ret.NextCursor;
+ } while (cursor != 0);
+
+ newBlockIds.Remove(this.UserId); // 元のソースにあったので一応残しておく
+
+ TabInformations.GetInstance().BlockIds = newBlockIds;
+ }
+
+ public TwitterDataModel.Ids GetBlockIdsApi(long cursor)
+ {
+ if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
+ throw new WebApiException("AccountState invalid");
HttpStatusCode res;
var content = "";
-
try
{
- res = twCon.GetBlockUserIds(ref content);
+ res = twCon.GetBlockUserIds(ref content, cursor);
}
- catch(Exception ex)
+ catch(Exception e)
{
- return "Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")";
+ throw new WebApiException("Err:" + e.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", e);
}
var err = this.CheckStatusCode(res, content);
- if (err != null) return err;
+ if (err != null)
+ throw new WebApiException(err, content);
try
{
- var Ids = MyCommon.CreateDataFromJson<List<long>>(content);
- if (Ids.Contains(this.UserId)) Ids.Remove(this.UserId);
- TabInformations.GetInstance().BlockIds.AddRange(Ids);
- return ("");
+ return MyCommon.CreateDataFromJson<TwitterDataModel.Ids>(content);
}
- catch(SerializationException ex)
+ catch(SerializationException e)
{
- MyCommon.TraceOut(ex.Message + Environment.NewLine + content);
- return "Err:Json Parse Error(DataContractJsonSerializer)";
+ var ex = new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, e);
+ MyCommon.TraceOut(ex);
+ throw ex;
}
- catch(Exception ex)
+ catch(Exception e)
{
- MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
- return "Err:Invalid Json!";
+ var ex = new WebApiException("Err:Invalid Json!", content, e);
+ MyCommon.TraceOut(ex);
+ throw ex;
}
-
}
public string[] GetHashList()
--- /dev/null
+// OpenTween - Client of Twitter
+// Copyright (c) 2013 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace OpenTween
+{
+ /// <summary>
+ /// Twitter などの API 実行時に発生した例外を扱うクラス
+ /// </summary>
+ public class WebApiException : Exception
+ {
+ public readonly string ResponseText = null;
+
+ public WebApiException() : base() { }
+ public WebApiException(string message) : base(message) { }
+ public WebApiException(string message, Exception innerException) : base(message, innerException) { }
+
+ public WebApiException(string message, string responseText)
+ : this(message)
+ {
+ this.ResponseText = responseText;
+ }
+
+ public WebApiException(string message, string responseText, Exception innerException)
+ : this(message, innerException)
+ {
+ this.ResponseText = responseText;
+ }
+ }
+}