Пример #1
0
        private async Task <IReadOnlyList <ListElement> > FetchListsAsync()
        {
            using var dialog = new WaitingDialog(Properties.Resources.ListsGetting);
            var cancellationToken = dialog.EnableCancellation();

            var task = this.tw.GetListsApi();
            await dialog.WaitForAsync(this, task);

            cancellationToken.ThrowIfCancellationRequested();

            return(TabInformations.GetInstance().SubscribableLists);
        }
Пример #2
0
        private async Task <IReadOnlyList <ListElement> > FetchListsAsync()
        {
            using var dialog = new WaitingDialog("Getting Lists...");
            var cancellationToken = dialog.EnableCancellation();

            var tw   = ((TweenMain)this.Owner).TwitterInstance;
            var task = tw.GetListsApi();
            await dialog.WaitForAsync(this, task);

            cancellationToken.ThrowIfCancellationRequested();

            return(TabInformations.GetInstance().SubscribableLists);
        }
Пример #3
0
        private async Task RefreshListBox()
        {
            using (var dialog = new WaitingDialog(Properties.Resources.ListsGetting))
            {
                var cancellationToken = dialog.EnableCancellation();

                var task = Task.Run(() => this.FetchMembershipListIds());
                await dialog.WaitForAsync(this, task);

                cancellationToken.ThrowIfCancellationRequested();
            }

            using (ControlTransaction.Update(this.ListsCheckedListBox))
            {
                this.ListsCheckedListBox.Items.Clear();

                foreach (var list in this.ownedLists)
                {
                    var added = this.addedListIds.Contains(list.Id);
                    this.ListsCheckedListBox.Items.Add(list, isChecked: added);
                }
            }
        }
Пример #4
0
        private async Task RefreshListBox()
        {
            using (var dialog = new WaitingDialog(Properties.Resources.ListsGetting))
            {
                var cancellationToken = dialog.EnableCancellation();

                var task = Task.Run(() => this.FetchMembershipListIds());
                await dialog.WaitForAsync(this, task);

                cancellationToken.ThrowIfCancellationRequested();
            }

            using (ControlTransaction.Update(this.ListsCheckedListBox))
            {
                this.ListsCheckedListBox.Items.Clear();

                foreach (var list in this.ownedLists)
                {
                    var added = this.addedListIds.Contains(list.Id);
                    this.ListsCheckedListBox.Items.Add(list, isChecked: added);
                }
            }
        }
Пример #5
0
        private async Task RemoveCommand(string id, bool skipInput)
        {
            if (!skipInput)
            {
                using (var inputName = new InputTabName())
                {
                    inputName.FormTitle = "Unfollow";
                    inputName.FormDescription = Properties.Resources.FRMessage1;
                    inputName.TabName = id;

                    if (inputName.ShowDialog(this) != DialogResult.OK)
                        return;
                    if (string.IsNullOrWhiteSpace(inputName.TabName))
                        return;

                    id = inputName.TabName.Trim();
                }
            }

            using (var dialog = new WaitingDialog(Properties.Resources.RemoveCommandText1))
            {
                var task = Task.Run(() => this.tw.PostRemoveCommand(id));
                var err = await dialog.WaitForAsync(this, task);
                if (!string.IsNullOrEmpty(err))
                {
                    MessageBox.Show(Properties.Resources.FRMessage2 + err);
                    return;
                }
            }

            MessageBox.Show(Properties.Resources.FRMessage3);
        }
Пример #6
0
        private async Task<IReadOnlyList<ListElement>> FetchListsAsync()
        {
            using (var dialog = new WaitingDialog("Getting Lists..."))
            {
                var cancellationToken = dialog.EnableCancellation();

                var tw = ((TweenMain)this.Owner).TwitterInstance;
                var task = Task.Run(() => tw.GetListsApi());
                await dialog.WaitForAsync(this, task);

                cancellationToken.ThrowIfCancellationRequested();
            }

            return TabInformations.GetInstance().SubscribableLists;
        }
Пример #7
0
        private async Task<IReadOnlyList<ListElement>> FetchListsAsync()
        {
            using (var dialog = new WaitingDialog("Getting Lists..."))
            {
                var cancellationToken = dialog.EnableCancellation();

                var tw = ((TweenMain)this.Owner).TwitterInstance;
                var task = Task.Run(() => tw.GetListsApi());
                var err = await dialog.WaitForAsync(this, task);

                cancellationToken.ThrowIfCancellationRequested();

                if (!string.IsNullOrEmpty(err))
                {
                    MessageBox.Show("Failed to get lists. (" + err + ")");
                    throw new WebApiException(err);
                }
            }

            return TabInformations.GetInstance().SubscribableLists;
        }
Пример #8
0
        internal async Task RemoveCommand(string id, bool skipInput)
        {
            if (!skipInput)
            {
                using (var inputName = new InputTabName())
                {
                    inputName.FormTitle = "Unfollow";
                    inputName.FormDescription = Properties.Resources.FRMessage1;
                    inputName.TabName = id;

                    if (inputName.ShowDialog(this) != DialogResult.OK)
                        return;
                    if (string.IsNullOrWhiteSpace(inputName.TabName))
                        return;

                    id = inputName.TabName.Trim();
                }
            }

            using (var dialog = new WaitingDialog(Properties.Resources.RemoveCommandText1))
            {
                try
                {
                    var task = this.twitterApi.FriendshipsDestroy(id);
                    await dialog.WaitForAsync(this, task);
                }
                catch (WebApiException ex)
                {
                    MessageBox.Show(Properties.Resources.FRMessage2 + ex.Message);
                    return;
                }
            }

            MessageBox.Show(Properties.Resources.FRMessage3);
        }
Пример #9
0
        private async void RtCountMenuItem_Click(object sender, EventArgs e)
        {
            if (!this.ExistCurrentPost)
                return;

            var statusId = this._curPost.RetweetedId ?? this._curPost.StatusId;
            int retweetCount = 0;

            using (var dialog = new WaitingDialog(Properties.Resources.RtCountMenuItem_ClickText1))
            {
                var cancellationToken = dialog.EnableCancellation();

                var task = Task.Run(() => this.tw.GetStatus_Retweeted_Count(statusId, ref retweetCount));
                var err = await dialog.WaitForAsync(this, task);

                if (cancellationToken.IsCancellationRequested)
                    return;

                if (!string.IsNullOrEmpty(err))
                {
                    MessageBox.Show(Properties.Resources.RtCountText2 + Environment.NewLine + err);
                    return;
                }
            }

            MessageBox.Show(retweetCount + Properties.Resources.RtCountText1);
        }
Пример #10
0
        private async Task doShowUserStatus(string id, bool ShowInputDialog)
        {
            TwitterUser user = null;

            if (ShowInputDialog)
            {
                using (var inputName = new InputTabName())
                {
                    inputName.FormTitle = "Show UserStatus";
                    inputName.FormDescription = Properties.Resources.FRMessage1;
                    inputName.TabName = id;

                    if (inputName.ShowDialog(this) != DialogResult.OK)
                        return;
                    if (string.IsNullOrWhiteSpace(inputName.TabName))
                        return;

                    id = inputName.TabName.Trim();
                }
            }

            using (var dialog = new WaitingDialog(Properties.Resources.doShowUserStatusText1))
            {
                var cancellationToken = dialog.EnableCancellation();

                var task = Task.Run(() => this.tw.GetUserInfo(id, ref user));
                var err = await dialog.WaitForAsync(this, task);

                if (cancellationToken.IsCancellationRequested)
                    return;

                if (!string.IsNullOrEmpty(err))
                {
                    MessageBox.Show(err);
                    return;
                }
            }

            await this.doShowUserStatus(user);
        }
Пример #11
0
        private async Task FollowCommand(string id)
        {
            using (var inputName = new InputTabName())
            {
                inputName.FormTitle = "Follow";
                inputName.FormDescription = Properties.Resources.FRMessage1;
                inputName.TabName = id;

                if (inputName.ShowDialog(this) != DialogResult.OK)
                    return;
                if (string.IsNullOrWhiteSpace(inputName.TabName))
                    return;

                id = inputName.TabName.Trim();
            }

            using (var dialog = new WaitingDialog(Properties.Resources.FollowCommandText1))
            {
                try
                {
                    var task = Task.Run(() => this.tw.PostFollowCommand(id));
                    await dialog.WaitForAsync(this, task);
                }
                catch (WebApiException ex)
                {
                    MessageBox.Show(Properties.Resources.FRMessage2 + ex.Message);
                    return;
                }
            }

            MessageBox.Show(Properties.Resources.FRMessage3);
        }
Пример #12
0
        private async Task<IReadOnlyList<ListElement>> FetchListsAsync()
        {
            using (var dialog = new WaitingDialog(Properties.Resources.ListsGetting))
            {
                var cancellationToken = dialog.EnableCancellation();

                var task = Task.Run(() => tw.GetListsApi());
                await dialog.WaitForAsync(this, task);

                cancellationToken.ThrowIfCancellationRequested();
            }

            return TabInformations.GetInstance().SubscribableLists;
        }
Пример #13
0
        private async void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
        {
            TwitterApiStatus apiStatus;

            using (var dialog = new WaitingDialog(Properties.Resources.ApiInfo6))
            {
                var cancellationToken = dialog.EnableCancellation();

                var task = Task.Run(() => this.tw.GetInfoApi());
                apiStatus = await dialog.WaitForAsync(this, task);

                if (cancellationToken.IsCancellationRequested)
                    return;

                if (apiStatus == null)
                {
                    MessageBox.Show(Properties.Resources.ApiInfo5, Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }

            using (var apiDlg = new ApiInfoDialog())
            {
                apiDlg.ShowDialog(this);
            }
        }
Пример #14
0
        private async void RtCountMenuItem_Click(object sender, EventArgs e)
        {
            if (!this.ExistCurrentPost)
                return;

            var statusId = this._curPost.RetweetedId ?? this._curPost.StatusId;
            TwitterStatus status;

            using (var dialog = new WaitingDialog(Properties.Resources.RtCountMenuItem_ClickText1))
            {
                var cancellationToken = dialog.EnableCancellation();

                try
                {
                    var task = this.twitterApi.StatusesShow(statusId);
                    status = await dialog.WaitForAsync(this, task);
                }
                catch (WebApiException ex)
                {
                    if (!cancellationToken.IsCancellationRequested)
                        MessageBox.Show(Properties.Resources.RtCountText2 + Environment.NewLine + "Err:" + ex.Message);
                    return;
                }

                if (cancellationToken.IsCancellationRequested)
                    return;
            }

            MessageBox.Show(status.RetweetCount + Properties.Resources.RtCountText1);
        }
Пример #15
0
        private async Task doShowUserStatus(string id, bool ShowInputDialog)
        {
            TwitterUser user = null;

            if (ShowInputDialog)
            {
                using (var inputName = new InputTabName())
                {
                    inputName.FormTitle = "Show UserStatus";
                    inputName.FormDescription = Properties.Resources.FRMessage1;
                    inputName.TabName = id;

                    if (inputName.ShowDialog(this) != DialogResult.OK)
                        return;
                    if (string.IsNullOrWhiteSpace(inputName.TabName))
                        return;

                    id = inputName.TabName.Trim();
                }
            }

            using (var dialog = new WaitingDialog(Properties.Resources.doShowUserStatusText1))
            {
                var cancellationToken = dialog.EnableCancellation();

                try
                {
                    var task = this.twitterApi.UsersShow(id);
                    user = await dialog.WaitForAsync(this, task);
                }
                catch (WebApiException ex)
                {
                    if (!cancellationToken.IsCancellationRequested)
                        MessageBox.Show($"Err:{ex.Message}(UsersShow)");
                    return;
                }

                if (cancellationToken.IsCancellationRequested)
                    return;
            }

            await this.doShowUserStatus(user);
        }
Пример #16
0
        internal async Task ShowFriendship(string[] ids)
        {
            foreach (string id in ids)
            {
                bool isFollowing, isFollowed;

                using (var dialog = new WaitingDialog(Properties.Resources.ShowFriendshipText1))
                {
                    var cancellationToken = dialog.EnableCancellation();

                    try
                    {
                        var task = this.twitterApi.FriendshipsShow(this.twitterApi.CurrentScreenName, id);
                        var friendship = await dialog.WaitForAsync(this, task);

                        isFollowing = friendship.Relationship.Source.Following;
                        isFollowed = friendship.Relationship.Source.FollowedBy;
                    }
                    catch (WebApiException ex)
                    {
                        if (!cancellationToken.IsCancellationRequested)
                            MessageBox.Show($"Err:{ex.Message}(FriendshipsShow)");
                        return;
                    }

                    if (cancellationToken.IsCancellationRequested)
                        return;
                }

                string result = "";
                string ff = "";

                ff = "  ";
                if (isFollowing)
                {
                    ff += Properties.Resources.GetFriendshipInfo1;
                }
                else
                {
                    ff += Properties.Resources.GetFriendshipInfo2;
                }

                ff += System.Environment.NewLine + "  ";
                if (isFollowed)
                {
                    ff += Properties.Resources.GetFriendshipInfo3;
                }
                else
                {
                    ff += Properties.Resources.GetFriendshipInfo4;
                }
                result += id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
                if (isFollowing)
                {
                    if (MessageBox.Show(
                        Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result, Properties.Resources.GetFriendshipInfo8,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        await this.RemoveCommand(id, true);
                    }
                }
                else
                {
                    MessageBox.Show(result);
                }
            }
        }
Пример #17
0
        internal async Task ShowFriendship(string id)
        {
            using (var inputName = new InputTabName())
            {
                inputName.FormTitle = "Show Friendships";
                inputName.FormDescription = Properties.Resources.FRMessage1;
                inputName.TabName = id;

                if (inputName.ShowDialog(this) != DialogResult.OK)
                    return;
                if (string.IsNullOrWhiteSpace(inputName.TabName))
                    return;

                id = inputName.TabName.Trim();
            }

            bool isFollowing, isFollowed;

            using (var dialog = new WaitingDialog(Properties.Resources.ShowFriendshipText1))
            {
                var cancellationToken = dialog.EnableCancellation();

                try
                {
                    var task = this.twitterApi.FriendshipsShow(this.twitterApi.CurrentScreenName, id);
                    var friendship = await dialog.WaitForAsync(this, task);

                    isFollowing = friendship.Relationship.Source.Following;
                    isFollowed = friendship.Relationship.Source.FollowedBy;
                }
                catch (WebApiException ex)
                {
                    if (!cancellationToken.IsCancellationRequested)
                        MessageBox.Show($"Err:{ex.Message}(FriendshipsShow)");
                    return;
                }

                if (cancellationToken.IsCancellationRequested)
                    return;
            }

            string result = "";
            if (isFollowing)
            {
                result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
            }
            else
            {
                result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
            }
            if (isFollowed)
            {
                result += Properties.Resources.GetFriendshipInfo3;
            }
            else
            {
                result += Properties.Resources.GetFriendshipInfo4;
            }
            result = id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
            MessageBox.Show(result);
        }
Пример #18
0
        private async void ButtonAddTab_Click(object sender, EventArgs e)
        {
            string tabName = null;
            MyCommon.TabUsageType tabType;
            using (InputTabName inputName = new InputTabName())
            {
                inputName.TabName = _sts.MakeTabName("MyTab");
                inputName.IsShowUsage = true;
                inputName.ShowDialog();
                if (inputName.DialogResult == DialogResult.Cancel) return;
                tabName = inputName.TabName;
                tabType = inputName.Usage;
            }
            if (!string.IsNullOrEmpty(tabName))
            {
                //List対応
                ListElement list = null;
                if (tabType == MyCommon.TabUsageType.Lists)
                {
                    try
                    {
                        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 + ")");
                    }
                    using (ListAvailable listAvail = new ListAvailable())
                    {
                        if (listAvail.ShowDialog(this) == DialogResult.Cancel) return;
                        if (listAvail.SelectedList == null) return;
                        list = listAvail.SelectedList;
                    }
                }

                TabModel tab;
                switch (tabType)
                {
                    case MyCommon.TabUsageType.UserDefined:
                        tab = new FilterTabModel(tabName);
                        break;
                    case MyCommon.TabUsageType.PublicSearch:
                        tab = new PublicSearchTabModel(tabName);
                        break;
                    case MyCommon.TabUsageType.Lists:
                        tab = new ListTimelineTabModel(tabName, list);
                        break;
                    default:
                        return;
                }

                if (!_sts.AddTab(tab) || !((TweenMain)this.Owner).AddNewTab(tab, startup: false))
                {
                    string tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
                    MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                else
                {
                    // タブ作成成功

                    // 末尾のタブを取得する
                    var lastIdx = this.ListTabs.Items.Count - 1;
                    var lastTab = lastIdx != -1
                        ? this._sts.Tabs[(string)this.ListTabs.Items[lastIdx]]
                        : null;

                    // 末尾がミュートタブであればその手前に追加する
                    if (lastTab != null && lastTab.TabType == MyCommon.TabUsageType.Mute)
                        this.ListTabs.Items.Insert(lastIdx, tabName);
                    else
                        this.ListTabs.Items.Add(tabName);
                }
            }
        }
Пример #19
0
        private async Task ShowFriendship(string id)
        {
            using (var inputName = new InputTabName())
            {
                inputName.FormTitle = "Show Friendships";
                inputName.FormDescription = Properties.Resources.FRMessage1;
                inputName.TabName = id;

                if (inputName.ShowDialog(this) != DialogResult.OK)
                    return;
                if (string.IsNullOrWhiteSpace(inputName.TabName))
                    return;

                id = inputName.TabName.Trim();
            }

            var isFollowing = false;
            var isFollowed = false;

            using (var dialog = new WaitingDialog(Properties.Resources.ShowFriendshipText1))
            {
                var cancellationToken = dialog.EnableCancellation();

                var task = Task.Run(() => this.tw.GetFriendshipInfo(id, ref isFollowing, ref isFollowed));
                var err = await dialog.WaitForAsync(this, task);

                if (cancellationToken.IsCancellationRequested)
                    return;

                if (!string.IsNullOrEmpty(err))
                {
                    MessageBox.Show(err);
                    return;
                }
            }

            string result = "";
            if (isFollowing)
            {
                result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
            }
            else
            {
                result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
            }
            if (isFollowed)
            {
                result += Properties.Resources.GetFriendshipInfo3;
            }
            else
            {
                result += Properties.Resources.GetFriendshipInfo4;
            }
            result = id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
            MessageBox.Show(result);
        }
Пример #20
0
        private async Task ShowFriendship(string[] ids)
        {
            foreach (string id in ids)
            {
                var isFollowing = false;
                var isFollowed = false;

                using (var dialog = new WaitingDialog(Properties.Resources.ShowFriendshipText1))
                {
                    var cancellationToken = dialog.EnableCancellation();

                    var task = Task.Run(() => this.tw.GetFriendshipInfo(id, ref isFollowing, ref isFollowed));
                    var err = await dialog.WaitForAsync(this, task);

                    if (cancellationToken.IsCancellationRequested)
                        return;

                    if (!string.IsNullOrEmpty(err))
                    {
                        MessageBox.Show(err);
                        continue;
                    }
                }

                string result = "";
                string ff = "";

                ff = "  ";
                if (isFollowing)
                {
                    ff += Properties.Resources.GetFriendshipInfo1;
                }
                else
                {
                    ff += Properties.Resources.GetFriendshipInfo2;
                }

                ff += System.Environment.NewLine + "  ";
                if (isFollowed)
                {
                    ff += Properties.Resources.GetFriendshipInfo3;
                }
                else
                {
                    ff += Properties.Resources.GetFriendshipInfo4;
                }
                result += id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
                if (isFollowing)
                {
                    if (MessageBox.Show(
                        Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result, Properties.Resources.GetFriendshipInfo8,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        await this.RemoveCommand(id, true);
                    }
                }
                else
                {
                    MessageBox.Show(result);
                }
            }
        }
Пример #21
0
        private async Task<IReadOnlyList<ListElement>> FetchListsAsync()
        {
            using (var dialog = new WaitingDialog(Properties.Resources.ListsGetting))
            {
                var cancellationToken = dialog.EnableCancellation();

                var task = Task.Run(() => tw.GetListsApi());
                var err = await dialog.WaitForAsync(this, task);

                cancellationToken.ThrowIfCancellationRequested();

                if (!string.IsNullOrEmpty(err))
                {
                    MessageBox.Show(string.Format(Properties.Resources.ListsDeleteFailed, err));
                    throw new WebApiException(err);
                }
            }

            return TabInformations.GetInstance().SubscribableLists;
        }