void onDeletedTweetUIUpdate(Tweet tweet)
        {
            Interlocked.Decrement(ref nbOutstandingOperations);

            // scroll only after X seconds
            if (DateTime.Now.Ticks - lastDataGridScroll > (TimeSpan.TicksPerSecond * MIN_SCROLL_INTERVAL))
            {
                lock (_lockerLastDataGridScroll)
                {
                    if (DateTime.Now.Ticks - lastDataGridScroll > (TimeSpan.TicksPerSecond * MIN_SCROLL_INTERVAL))
                    {
                        //update datagrid
                        RunOnUIThread(delegate()
                        {
                            gridTweets.SelectedItem = tweet;
                            gridTweets.BringItemIntoView(tweet);
                        });

                        lastDataGridScroll = DateTime.Now.Ticks;
                    }
                }
            }

            //update progressbar
            RunOnUIThread(delegate()
            {
                progressBar.Value = 100 - (nbOutstandingOperations * 100 / nbTweetsToErase);
                txtPrcnt.Text = 100 - (nbOutstandingOperations * 100 / nbTweetsToErase) + "%";
            });
        }
예제 #2
0
        //We start multiple actions in parallel to delete tweets
        void EraseTweetsAction(TwitterContext ctx, CancellationToken cancelToken)
        {
            int nextTweetID = getNextTweetIDSync();

#if DEBUG
            Random rnd = new Random();
#endif

            //Are we done?
            while (nextTweetID != Int32.MinValue)
            {
                //We can't cancel here, we have already fetched a new ID and if we cancel here it will never be deteled

                Tweet tweet = tweets[nextTweetID];

                //Clear Tweets logic here
                try
                {
#if DEBUG
                    Thread.Sleep(sleepFakeWaitMilliseconds);
                    if (rnd.Next() % 3 == 0)    // Simulate error
                    {
                        throw new ArgumentNullException();
                    }
                    else
                    {
                        throw new Exception("Sorry, that page does not exist");
                    }
#else
                    Status ret = ctx.DestroyStatus(tweet.ID);
#endif
                    tweet.Status = STATUS_DELETED;
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Sorry, that page does not exist"))
                    {
                        tweet.Status = STATUS_NOT_FOUND;
                    }
                    else if (ex.Message.Contains("You may not delete another user's status"))
                    {
                        tweet.Status = STATUS_NOT_ALLOWED;
                    }
                    else
                    {
                        tweet.Status = STATUS_ERROR;
                        var tmp = new tweetTJson()
                        {
                            created_at = tweet.Date.ToString("yyyy-MM-dd H:m:s zzz"), id_str = tweet.ID, text = tweet.Text
                        };

                        lock (_lockerNotDeletedTweetsLst)
                        {
                            notDeletedTweets.Add(tmp);
                        }
                    }
                }

                onDeletingTweetUIUpdate(tweet);

                //We cancel once a tweet is completely handeled, we make sure not to request for a new one
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }

                nextTweetID = getNextTweetIDSync();
            }
        }
예제 #3
0
        void ApplyFilterToCollectionView()
        {
            filters.Add(txtFilterTweets.Text);

            if (isRegularExpressionMatch)
            {
                try
                {
                    // validate that regex pattern is valid
                    Regex.IsMatch("dummy", txtFilterTweets.Text, RegexOptions.IgnoreCase);
                }
                catch (Exception)
                {
                    MessageBox.Show(string.Format("Invalid RegEx pattern {0}", txtFilterTweets.Text), "Twitter Archive Eraser");
                    return;
                }
            }

            // reset previous filter
            tweetsCollectionView.Filter = t => { return(true); };
            tweetsCollectionView.Refresh();

            if (isRegularExpressionMatch)
            {
                tweetsCollectionView.Filter = t =>
                {
                    Tweet tweet = t as Tweet;
                    if (tweet == null)
                    {
                        return(false);
                    }

                    if (filterTargetUsername)
                    {
                        return(Regex.IsMatch(tweet.Username, txtFilterTweets.Text, RegexOptions.IgnoreCase) &&
                               (filterShowRetweetsOnly == true ? tweet.Type == TweetType.Retweet : true));
                    }
                    else
                    {
                        return(Regex.IsMatch(tweet.Text, txtFilterTweets.Text, RegexOptions.IgnoreCase) &&
                               (filterShowRetweetsOnly == true ? tweet.Type == TweetType.Retweet : true));
                    }
                };
            }
            else
            {
                tweetsCollectionView.Filter = t =>
                {
                    Tweet tweet = t as Tweet;
                    if (tweet == null)
                    {
                        return(false);
                    }

                    if (filterTargetUsername)
                    {
                        return(tweet.Username.ToLowerInvariant().Contains(txtFilterTweets.Text.ToLowerInvariant()) &&
                               (filterShowRetweetsOnly == true ? tweet.Type == TweetType.Retweet : true));
                    }
                    else
                    {
                        return(tweet.Text.ToLowerInvariant().Contains(txtFilterTweets.Text.ToLowerInvariant()) &&
                               (filterShowRetweetsOnly == true ? tweet.Type == TweetType.Retweet : true));
                    }
                };
            }

            tweetsCollectionView.Refresh();
        }
예제 #4
0
        //We start multiple actions in parallel to delete tweets
        void EraseTweetsAction(TwitterContext ctx, CancellationToken cancelToken)
        {
            int nextTweetID = getNextTweetIDSync();

#if DEBUG_TEST
            Random rnd = new Random();
#endif

            //Are we done?
            while (nextTweetID != Int32.MinValue)
            {
                //We can't cancel here, we have already fetched a new ID and if we cancel here it will never be deteled

                Tweet tweet = tweets[nextTweetID];

                //Clear Tweets logic here
                try
                {
#if DEBUG_TEST1
                    Thread.Sleep(sleepFakeWaitMilliseconds);
                    if (rnd.Next() % 3 == 0)    // Simulate error
                    {
                        throw new ArgumentNullException();
                    }
                    else
                    {
                        Exception e = new Exception("Sorry, that page does not exist");
                        throw new Exception("", e);
                    }
#else
                    ulong         tid  = ulong.Parse(tweet.ID);
                    Status        ret  = null;
                    DirectMessage ret2 = null;

                    switch (TweetsEraseType)
                    {
                    case ApplicationSettings.EraseTypes.TweetsAndRetweets:
                        ret = ctx.DeleteTweetAsync(tid).Result;
                        break;

                    case ApplicationSettings.EraseTypes.Favorites:
                        ret = ctx.DestroyFavoriteAsync(tid).Result;
                        break;

                    case ApplicationSettings.EraseTypes.DirectMessages:
                        ret2 = ctx.DestroyDirectMessageAsync(tid, true).Result;
                        break;

                    default:
                        break;
                    }
#endif
                    tweet.Status = STATUS_DELETED;
                }
                catch (Exception ex)
                {
                    TwitterQueryException exception = ex.InnerException as TwitterQueryException;
                    if (exception != null && exception.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        tweet.Status = STATUS_NOT_FOUND;
                    }
                    else if (exception != null &&
                             (exception.StatusCode == System.Net.HttpStatusCode.Unauthorized || exception.StatusCode == System.Net.HttpStatusCode.Forbidden))
                    {
                        tweet.Status = STATUS_NOT_ALLOWED;
                    }
                    else
                    {
                        tweet.Status = STATUS_ERROR;
                        var tmp = new tweetTJson()
                        {
                            created_at = tweet.Date.ToString("yyyy-MM-dd H:m:s zzz"), id_str = tweet.ID, text = tweet.Text
                        };

                        lock (_lockerNotDeletedTweetsLst)
                        {
                            notDeletedTweets.Add(tmp);
                        }
                    }
                }

                onDeletingTweetUIUpdate(tweet);

                //We cancel once a tweet is completely handeled, we make sure not to request for a new one
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }

                nextTweetID = getNextTweetIDSync();
            }
        }
        void onDeletingTweetUIUpdate(Tweet tweet)
        {
            lock (_lockerNbTweetsDeleted)
            {
                nbTweetsDeleted++;
            }

            // scroll only after X seconds
            if (DateTime.Now.Ticks - lastDataGridScroll > (TimeSpan.TicksPerSecond * MIN_SCROLL_INTERVAL))
            {
                lock (_lockerLastDataGridScroll)
                {
                    if (DateTime.Now.Ticks - lastDataGridScroll > (TimeSpan.TicksPerSecond * MIN_SCROLL_INTERVAL))
                    {
                        //update datagrid
                        gridTweets.Dispatcher.BeginInvoke(new Action(delegate()
                        {
                            gridTweets.SelectedItem = tweet;
                            gridTweets.BringItemIntoView(tweet);
                            //gridTweets.ScrollIntoView(tweet);
                        }));

                        lastDataGridScroll = DateTime.Now.Ticks;
                    }
                }
            }

            //update progressbar
            progressBar.Dispatcher.BeginInvoke(new Action(delegate()
            {
                progressBar.Value = nbTweetsDeleted * 100 / nbTweetsToErase;
                txtPrcnt.Text = nbTweetsDeleted * 100 / nbTweetsToErase + "%";
            }));
        }
        void onDeletingTweetUIUpdate(Tweet tweet)
        {
            lock (_lockerNbTweetsDeleted)
            {
                nbTweetsDeleted++;
            }

            //update datagrid
            gridTweets.Dispatcher.BeginInvoke(new Action(delegate()
            {
                gridTweets.SelectedItem = tweet;
                gridTweets.ScrollIntoView(tweet);
            }));

            //update progressbar
            progressBar.Dispatcher.BeginInvoke(new Action(delegate()
            {
                progressBar.Value = nbTweetsDeleted * 100 / nbTweetsToErase;
                txtPrcnt.Text = nbTweetsDeleted * 100 / nbTweetsToErase + "%";
            }));
        }