コード例 #1
0
        private async void BT_Confirm_Click(object sender, RoutedEventArgs e)
        {
            BT_Confirm.IsEnabled = false;
            if (MainWindow.IsLoggedIn && !MainWindow.IsOffline)
            {
                int deleted = 0;
                int counted = 0;
                var feed    = await KakaoRequestClass.GetProfileFeed(MainWindow.UserProfile.id, null);

                if (feed.activities.Count == 0)
                {
                    MessageBox.Show("삭제할 게시글이 존재하지 않습니다.");
                    BT_Confirm.IsEnabled = true;
                    return;
                }
                else
                {
                    if (MessageBox.Show("조건에 맞는 게시글을 전부 삭제하시겠습니까?\n이 작업은 되돌릴 수 없습니다!", "경고", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                    {
                        CB_Category.IsEnabled  = false;
                        CB_Exclude.IsEnabled   = false;
                        CB_Include.IsEnabled   = false;
                        CB_Favorite.IsEnabled  = false;
                        TB_Filter.IsEnabled    = false;
                        SP_Progress.Visibility = Visibility.Visible;
                        TB_Progress.Text       = "삭제 준비중...";
                        try
                        {
                            MainWindow.IsLoggedIn = false;
                            async void Delete()
                            {
                                foreach (var activity in feed.activities)
                                {
                                    bool     willDelete = true;
                                    string[] shareIndex = { null, "A", "F", "P", "M" };
                                    if (CB_Category.SelectedIndex == 5)
                                    {
                                        if (!activity.blinded)
                                        {
                                            willDelete = false;
                                        }
                                    }
                                    else if (CB_Category.SelectedIndex > 0 && !activity.permission.Equals(shareIndex[CB_Category.SelectedIndex]))
                                    {
                                        willDelete = false;
                                    }
                                    if (CB_Include.IsChecked == true && !activity.content.Contains(TB_Filter.Text))
                                    {
                                        willDelete = false;
                                    }
                                    if (CB_Exclude.IsChecked == true && activity.content.Contains(TB_Filter.Text))
                                    {
                                        willDelete = false;
                                    }
                                    if (CB_Favorite.IsChecked == true && activity.pinned)
                                    {
                                        willDelete = false;
                                    }

                                    if (willDelete)
                                    {
                                        await Task.Delay(100);

                                        await KakaoRequestClass.DeletePost(activity.id);

                                        deleted++;
                                    }
                                    counted++;
                                    TB_Progress.Text = $"삭제된 게시글/전체 게시글 : {deleted}/{counted}";
                                    if (!activate)
                                    {
                                        break;
                                    }
                                }
                                if (!activate)
                                {
                                    MessageBox.Show("게시글 삭제가 취소됐습니다.", "안내");
                                    MainWindow.IsLoggedIn = true;
                                    await MainWindow.UpdateProfile();

                                    return;
                                }
                                feed = await KakaoRequestClass.GetProfileFeed(MainWindow.UserProfile.id, feed.activities[feed.activities.Count - 1].id);

                                if (feed != null && (feed.activities?.Count ?? 0) > 0)
                                {
                                    Delete();
                                }
                                else
                                {
                                    MessageBox.Show("삭제가 모두 완료됐습니다.", "안내");
                                    MainWindow.IsLoggedIn = true;
                                    await MainWindow.UpdateProfile();

                                    Close();
                                }
                            }
                            Delete();
                        } catch (Exception e2) { MessageBox.Show("작업 도중 알 수 없는 오류가 발생했습니다.\n" + e2.Message); }
                    }
                }
            }
        }