}
[Fact]
+ public async Task ListsOwnerships_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.GetAsync<TwitterLists>(
+ new Uri("lists/ownerships.json", UriKind.Relative),
+ new Dictionary<string, string> {
+ { "screen_name", "twitterapi" },
+ { "cursor", "-1" },
+ },
+ "/lists/ownerships")
+ )
+ .ReturnsAsync(new TwitterLists());
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.ListsOwnerships("twitterapi", cursor: -1L)
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
+ public async Task ListsSubscriptions_Test()
+ {
+ using (var twitterApi = new TwitterApi())
+ {
+ var mock = new Mock<IApiConnection>();
+ mock.Setup(x =>
+ x.GetAsync<TwitterLists>(
+ new Uri("lists/subscriptions.json", UriKind.Relative),
+ new Dictionary<string, string> {
+ { "screen_name", "twitterapi" },
+ { "cursor", "-1" },
+ },
+ "/lists/subscriptions")
+ )
+ .ReturnsAsync(new TwitterLists());
+
+ twitterApi.apiConnection = mock.Object;
+
+ await twitterApi.ListsSubscriptions("twitterapi", cursor: -1L)
+ .ConfigureAwait(false);
+
+ mock.VerifyAll();
+ }
+ }
+
+ [Fact]
public async Task ListsStatuses_Test()
{
using (var twitterApi = new TwitterApi())
return this.apiConnection.PostLazyAsync<TwitterStatus>(endpoint, param);
}
+ public Task<TwitterLists> ListsOwnerships(string screenName, long? cursor = null)
+ {
+ var endpoint = new Uri("lists/ownerships.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["screen_name"] = screenName,
+ };
+
+ if (cursor != null)
+ param["cursor"] = cursor.ToString();
+
+ return this.apiConnection.GetAsync<TwitterLists>(endpoint, param, "/lists/ownerships");
+ }
+
+ public Task<TwitterLists> ListsSubscriptions(string screenName, long? cursor = null)
+ {
+ var endpoint = new Uri("lists/subscriptions.json", UriKind.Relative);
+ var param = new Dictionary<string, string>
+ {
+ ["screen_name"] = screenName,
+ };
+
+ if (cursor != null)
+ param["cursor"] = cursor.ToString();
+
+ return this.apiConnection.GetAsync<TwitterLists>(endpoint, param, "/lists/subscriptions");
+ }
+
public Task<TwitterStatus[]> ListsStatuses(long listId, int? count = null, long? maxId = null, long? sinceId = null, bool? includeRTs = null)
{
var endpoint = new Uri("lists/statuses.json", UriKind.Relative);
}
#region Lists
- public HttpStatusCode GetLists(string user, ref string content)
- {
- Dictionary<string, string> param = new Dictionary<string, string>();
- param.Add("screen_name", user);
-
- return httpCon.GetContent(GetMethod,
- this.CreateTwitterUri("/1.1/lists/list.json"),
- param,
- ref content,
- this.CreateRatelimitHeadersDict(),
- this.CreateApiCalllback("/lists/list"));
- }
-
public HttpStatusCode UpdateListID(string user, string list_id, string name, Boolean isPrivate, string description, ref string content)
{
string mode = "public";
null);
}
- public HttpStatusCode GetListsSubscriptions(string user, ref string content)
- {
- Dictionary<string, string> param = new Dictionary<string, string>();
- param.Add("screen_name", user);
-
- return httpCon.GetContent(GetMethod,
- this.CreateTwitterUri("/1.1/lists/subscriptions.json"),
- param,
- ref content,
- this.CreateRatelimitHeadersDict(),
- this.CreateApiCalllback("/lists/subscriptions"));
- }
-
public HttpStatusCode CreateLists(string listname, Boolean isPrivate, string description, ref string content)
{
string mode = "public";
ListFilters.Items.Clear();
}
- private void ButtonAddTab_Click(object sender, EventArgs e)
+ private async void ButtonAddTab_Click(object sender, EventArgs e)
{
string tabName = null;
MyCommon.TabUsageType tabType;
{
try
{
- ((TweenMain)this.Owner).TwitterInstance.GetListsApi();
+ using (var dialog = new WaitingDialog(Properties.Resources.ListsGetting))
+ {
+ var cancellationToken = dialog.EnableCancellation();
+
+ var task = ((TweenMain)this.Owner).TwitterInstance.GetListsApi();
+ await dialog.WaitForAsync(this, task);
+
+ cancellationToken.ThrowIfCancellationRequested();
+ }
}
+ catch (OperationCanceledException) { return; }
catch (WebApiException ex)
{
MessageBox.Show("Failed to get lists. (" + ex.Message + ")");
var cancellationToken = dialog.EnableCancellation();
var tw = ((TweenMain)this.Owner).TwitterInstance;
- var task = Task.Run(() => tw.GetListsApi());
+ var task = tw.GetListsApi();
await dialog.WaitForAsync(this, task);
cancellationToken.ThrowIfCancellationRequested();
}
}
- private void DeleteListButton_Click(object sender, EventArgs e)
+ private async void DeleteListButton_Click(object sender, EventArgs e)
{
if (this.ListsList.SelectedItem == null) return;
- ListElement list = (ListElement) this.ListsList.SelectedItem;
- if (MessageBox.Show(Properties.Resources.ListManageDeleteLists1, Application.ProductName, MessageBoxButtons.OKCancel) == DialogResult.OK)
+ using (ControlTransaction.Disabled(this))
{
- try
- {
- this.tw.DeleteList(list.Id.ToString());
- }
- catch (WebApiException ex)
- {
- MessageBox.Show(Properties.Resources.ListManageOKButton2, ex.Message);
- return;
- }
+ ListElement list = (ListElement)this.ListsList.SelectedItem;
- try
- {
- this.tw.GetListsApi();
- }
- catch (WebApiException ex)
+ if (MessageBox.Show(Properties.Resources.ListManageDeleteLists1, Application.ProductName, MessageBoxButtons.OKCancel) == DialogResult.OK)
{
- MessageBox.Show(Properties.Resources.ListsDeleteFailed, ex.Message);
- return;
+ try
+ {
+ this.tw.DeleteList(list.Id.ToString());
+ }
+ catch (WebApiException ex)
+ {
+ MessageBox.Show(Properties.Resources.ListManageOKButton2, ex.Message);
+ return;
+ }
+
+ try
+ {
+ await this.tw.GetListsApi();
+ }
+ catch (WebApiException ex)
+ {
+ MessageBox.Show(Properties.Resources.ListsDeleteFailed, ex.Message);
+ return;
+ }
+
+ this.ListsList.Items.Clear();
+ this.ListManage_Load(this, EventArgs.Empty);
}
-
- this.ListsList.Items.Clear();
- this.ListManage_Load(this, EventArgs.Empty);
}
}
{
var cancellationToken = dialog.EnableCancellation();
- var task = Task.Run(() => tw.GetListsApi());
+ var task = this.tw.GetListsApi();
await dialog.WaitForAsync(this, task);
cancellationToken.ThrowIfCancellationRequested();
this.ListsCheckedListBox.ItemCheck += this.ListsCheckedListBox_ItemCheck;
}
- private void ListRefreshButton_Click(object sender, EventArgs e)
+ private async void ListRefreshButton_Click(object sender, EventArgs e)
{
- try
+ using (ControlTransaction.Disabled(this))
{
- this._tw.GetListsApi();
- }
- catch (WebApiException ex)
- {
- MessageBox.Show(string.Format(Properties.Resources.ListsDeleteFailed, ex.Message));
- return;
- }
+ try
+ {
+ await this._tw.GetListsApi();
+ }
+ catch (WebApiException ex)
+ {
+ MessageBox.Show(string.Format(Properties.Resources.ListsDeleteFailed, ex.Message));
+ return;
+ }
- this.ListsCheckedListBox.Items.Clear();
- this.MyLists_Load(this, EventArgs.Empty);
+ this.ListsCheckedListBox.Items.Clear();
+ this.MyLists_Load(this, EventArgs.Empty);
+ }
}
private void ListsCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
}
}
- private void ListManageUserContextToolStripMenuItem_Click(object sender, EventArgs e)
+ private async void ListManageUserContextToolStripMenuItem_Click(object sender, EventArgs e)
{
string user;
{
try
{
- this.tw.GetListsApi();
+ using (var dialog = new WaitingDialog(Properties.Resources.ListsGetting))
+ {
+ var cancellationToken = dialog.EnableCancellation();
+
+ var task = this.tw.GetListsApi();
+ await dialog.WaitForAsync(this, task);
+
+ cancellationToken.ThrowIfCancellationRequested();
+ }
}
+ catch (OperationCanceledException) { return; }
catch (WebApiException ex)
{
MessageBox.Show("Failed to get lists. (" + ex.Message + ")");
.ConfigureAwait(false);
}
- public void GetListsApi()
+ public async Task GetListsApi()
{
this.CheckAccountState();
- HttpStatusCode res;
- IEnumerable<ListElement> lists;
- var content = "";
-
- try
- {
- res = twCon.GetLists(this.Username, ref content);
- }
- catch (Exception ex)
- {
- throw new WebApiException("Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", ex);
- }
-
- this.CheckStatusCode(res, content);
-
- try
- {
- lists = TwitterList.ParseJsonArray(content)
- .Select(x => new ListElement(x, this));
- }
- catch (SerializationException ex)
- {
- MyCommon.TraceOut(ex.Message + Environment.NewLine + content);
- throw new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, ex);
- }
- catch (Exception ex)
- {
- MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
- throw new WebApiException("Err:Invalid Json!", content, ex);
- }
-
- try
- {
- res = twCon.GetListsSubscriptions(this.Username, ref content);
- }
- catch (Exception ex)
- {
- throw new WebApiException("Err:" + ex.Message + "(" + MethodBase.GetCurrentMethod().Name + ")", ex);
- }
-
- this.CheckStatusCode(res, content);
+ var ownedLists = await TwitterLists.GetAllItemsAsync(x => this.Api.ListsOwnerships(this.Username, cursor: x))
+ .ConfigureAwait(false);
- try
- {
- lists = lists.Concat(TwitterList.ParseJsonArray(content)
- .Select(x => new ListElement(x, this)));
- }
- catch (SerializationException ex)
- {
- MyCommon.TraceOut(ex.Message + Environment.NewLine + content);
- throw new WebApiException("Err:Json Parse Error(DataContractJsonSerializer)", content, ex);
- }
- catch (Exception ex)
- {
- MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
- throw new WebApiException("Err:Invalid Json!", content, ex);
- }
+ var subscribedLists = await TwitterLists.GetAllItemsAsync(x => this.Api.ListsSubscriptions(this.Username, cursor: x))
+ .ConfigureAwait(false);
- TabInformations.GetInstance().SubscribableLists = lists.ToList();
+ TabInformations.GetInstance().SubscribableLists = Enumerable.Concat(ownedLists, subscribedLists)
+ .Select(x => new ListElement(x, this))
+ .ToList();
}
public void DeleteList(string list_id)