Ejemplo n.º 1
0
        private static void UnfavTweetSink(IEnumerable <AccountInfo> infos, TweetViewModel status)
        {
            var ts = status.Status as TwitterStatus;

            if (ts == null)
            {
                NotifyStorage.Notify("DirectMessageはFavできません。");
                return;
            }
            if (ts.RetweetedOriginal != null)
            {
                status = TweetStorage.Get(ts.RetweetedOriginal.Id, true);
            }
            if (status == null)
            {
                NotifyStorage.Notify("Unfav 対象ステータスが見つかりません。");
                return;
            }
            bool success = true;

            Parallel.ForEach(infos,
                             (d) =>
            {
                var ud = d.UserViewModel;
                // ふぁぼり状態更新
                if (ud != null)
                {
                    status.RemoveFavored(ud);
                }
                try
                {
                    unfavoriteInjection.Execute(new Tuple <AccountInfo, TweetViewModel>(d, status));
                }
                catch (Exception ex)
                {
                    success = false;
                    if (ud != null)
                    {
                        status.RegisterFavored(ud);
                    }
                    NotifyStorage.Notify("Unfavに失敗しました: @" + d.ScreenName);
                    if (!(ex is ApplicationException))
                    {
                        ExceptionStorage.Register(ex, ExceptionCategory.TwitterError,
                                                  "Unfav操作時にエラーが発生しました");
                    }
                }
            });
            if (success)
            {
                NotifyStorage.Notify("Unfavしました: @" + status.Status.User.ScreenName + ": " + status.Status.Text);
            }
        }
Ejemplo n.º 2
0
        public static void FavTweetSink(IEnumerable <AccountInfo> infos, TweetViewModel status)
        {
            var ts = status.Status as TwitterStatus;

            if (ts == null)
            {
                NotifyStorage.Notify("DirectMessageはFavできません。");
                return;
            }
            if (ts.RetweetedOriginal != null)
            {
                status = TweetStorage.Get(ts.RetweetedOriginal.Id, true);
            }
            if (status == null)
            {
                NotifyStorage.Notify("Fav 対象ステータスが見つかりません。");
                return;
            }
            bool success = true;

            Parallel.ForEach(infos,
                             (d) =>
            {
                var ud = d.UserViewModel;
                // ふぁぼり状態更新
                if (ud != null)
                {
                    status.RegisterFavored(ud);
                }
                try
                {
                    favoriteInjection.Execute(new Tuple <AccountInfo, TweetViewModel>(d, status));
                }
                catch (Exception ex)
                {
                    success = false;
                    if (ud != null)
                    {
                        status.RemoveFavored(ud);
                    }
                    if (ex is FavoriteSuspendedException && Setting.Instance.InputExperienceProperty.EnableFavoriteFallback)
                    {
                        // ふぁぼ規制 -> フォールバック
                        AccountInfo fallback = null;
                        if (!String.IsNullOrEmpty(d.AccountProperty.FallbackAccount) &&
                            (fallback = AccountStorage.Get(d.AccountProperty.FallbackAccount)) != null &&
                            !status.FavoredUsers.Contains(fallback.UserViewModel))
                        {
                            NotifyStorage.Notify("Fav fallbackします: @" + d.ScreenName + " >> @");
                            FavTweetSink(new[] { fallback }, status);
                        }
                    }
                    else
                    {
                        NotifyStorage.Notify("Favに失敗しました: @" + d.ScreenName);
                        if (!(ex is ApplicationException))
                        {
                            ExceptionStorage.Register(ex, ExceptionCategory.TwitterError,
                                                      "Fav操作時にエラーが発生しました");
                        }
                    }
                }
            });
            if (success)
            {
                NotifyStorage.Notify("Favしました: @" + status.Status.User.ScreenName + ": " + status.Status.Text);
            }
        }