private void ReceiveTimeline()
 {
     if (User == null || User.TwitterUser == null)
     {
         return;
     }
     IsStandby = false;
     Task.Factory.StartNew(() =>
     {
         try
         {
             var acc    = AccountStorage.GetRandom(a => a.Followings.Contains(this.User.TwitterUser.NumericId), true);
             var tweets = InjectionPoint.UnfoldTimeline(i => acc.GetUserTimeline(userId: this.User.TwitterUser.NumericId, count: 100, includeRts: true, page: i), 100, 5);
             if (tweets != null)
             {
                 tweets.ForEach(t => TweetStorage.Register(t));
             }
         }
         catch (Exception e)
         {
             ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "ユーザータイムラインを受信できませんでした: @" + this.User.TwitterUser.ScreenName, ReceiveTimeline);
         }
         finally
         {
             IsStandby = true;
         }
     });
 }
Exemple #2
0
 private void CheckFollower(UserViewModel userViewModel, string receiver)
 {
     try
     {
         // 自分からのフォローなら無視
         if (AccountStorage.Contains(userViewModel.TwitterUser.NumericId) ||
             AccountStorage.Contains(userViewModel.TwitterUser.ScreenName))
         {
             return;
         }
         // 自分がフォローしている相手なら無視
         if (TwitterHelper.IsFollowingAny(userViewModel))
         {
             return;
         }
         // 直近ツイートを取得
         var ai = AccountStorage.GetRandom(i => i.IsFollowedBy(userViewModel.TwitterUser.NumericId), true);
         if (ai == null)
         {
             return;
         }
         var tl = ai.GetUserTimeline(userId: userViewModel.TwitterUser.NumericId, count: 50);
         if (tl == null)
         {
             return;
         }
         var checkresult = GetRules()
                           .Where(r => r.Check(userViewModel, tl)).ToArray();
         if (checkresult.Length > 0)
         {
             ShowR4SCandidateDialog(userViewModel, receiver, String.Join(", ", checkresult.Select(r => r.Description)));
         }
     }
     catch (Exception ex)
     {
         ExceptionStorage.Register(ex, ExceptionCategory.TwitterError, "MapleMagicでの照合に失敗しました。", () => CheckFollower(userViewModel, receiver));
     }
 }
Exemple #3
0
        public FilterStatusId(long pivot, bool getStatus)
        {
            this.Range = LongRange.FromPivotValue(pivot);

            if (getStatus)
            {
                if (TweetStorage.Contains(pivot) != TweetExistState.Exists)
                {
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            var status = ApiHelper.ExecApi(() => AccountStorage.GetRandom().GetStatus(pivot));
                            if (status != null)
                            {
                                TweetStorage.Register(status);
                                RaisePartialRequireReaccept(status);
                            }
                        }
                        catch { }
                    });
                }
            }
        }
        public static void RegisterReceive(string listUser, string listName)
        {
            System.Diagnostics.Debug.WriteLine("** LIST LISTEN START:@" + listUser + "/" + listName);
            listName = NormalizeListName(listName);
            var fullname = BuildListName(listUser, listName);

            lock (rcLocker)
            {
                if (referenceCount.ContainsKey(fullname))
                {
                    referenceCount[fullname]++;
                }
                else
                {
                    var target = AccountStorage.Get(listUser);
                    if (target == null)
                    {
                        target = AccountStorage.GetRandom(ai => ai.IsFollowingList(listUser, listName), true);
                    }
                    var tscheduler = target != null?AutoCruiseSchedulerManager.GetScheduler(target) : null;

                    if (tscheduler == null)
                    {
                        // スケジューラがまだない
                        // スケジューラが更新されるまで待つ
                        waitings.Add(new Tuple <string, string>(listUser, listName));
                        return;
                    }
                    var task = new ListReceiveTask(target, listUser, listName);
                    receivers.Add(fullname, task);
                    tscheduler.AddSchedule(task);
                    Task.Factory.StartNew(() => ListStorage.Get(listUser, listName));
                    referenceCount.Add(fullname, 1);
                }
            }
        }
 /// <summary>
 /// ユーザーを設定します。<para />
 /// NullかString.Emptyが指定されると、ユーザー編集モードに入ります。
 /// </summary>
 internal void SetUser(string screenName)
 {
     if (String.IsNullOrEmpty(screenName))
     {
         User      = null;
         InputMode = true;
         this.Messenger.Raise(new Livet.Messaging.InteractionMessage("FocusToInput"));
     }
     else
     {
         InputMode      = false;
         screenName     = screenName.TrimStart('@', ' ', '\t');
         this.IsStandby = false;
         Task.Factory.StartNew(() =>
         {
             try
             {
                 var user = UserStorage.Lookup(screenName);
                 if (user == null)
                 {
                     var cred = AccountStorage.GetRandom();
                     if (cred != null)
                     {
                         var ud = ApiHelper.ExecApi(() => cred.GetUserByScreenName(screenName));
                         if (ud == null)
                         {
                             DispatcherHelper.BeginInvoke(() => this.Messenger.Raise(new Livet.Messaging.InformationMessage(
                                                                                         "ユーザー @" + screenName + " の情報を取得できません。" + Environment.NewLine +
                                                                                         "ユーザーが存在しない可能性があります。",
                                                                                         "ユーザー情報取得エラー", System.Windows.MessageBoxImage.Warning,
                                                                                         "InformationMessage")));
                             this.User = null;
                             return;
                         }
                         else
                         {
                             user = UserStorage.Get(ud);
                         }
                     }
                 }
                 if (user == null)
                 {
                     throw new Exception("ユーザー情報がありません。");
                 }
                 User = user;
             }
             catch (Exception e)
             {
                 ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "ユーザー @" + screenName + " の情報を取得できませんでした。");
                 DispatcherHelper.BeginInvoke(() => this.Messenger.Raise(new Livet.Messaging.InformationMessage(
                                                                             "ユーザー @" + screenName + "の情報を取得できません。",
                                                                             "ユーザー情報取得エラー", System.Windows.MessageBoxImage.Warning,
                                                                             "InformationMessage")));
                 this.User = null;
             }
             finally
             {
                 IsStandby = true;
             }
         });
     }
 }
Exemple #6
0
        private void RecursiveCheckId(long id)
        {
            if (id == 0)
            {
                RaiseRequireReaccept();
                return;
            }
            var cont = TweetStorage.Contains(id);

            if (cont == TweetExistState.Exists)
            {
                // データをチェックして、先があれば再帰
                var tweet = TweetStorage.Get(id);
                if (tweet == null)
                {
                    RaiseRequireReaccept();
                    return;
                }
                var ts = tweet.Status as TwitterStatus;
                if (ts != null && ts.InReplyToStatusId != 0)
                {
                    this.tracePoint = ts.InReplyToStatusId;
                    RaisePartialRequireReaccept(ts);
                    RecursiveCheckId(ts.InReplyToStatusId);
                    tweet.RefreshInReplyToInfo(); // 返信情報の更新を通知
                }
                else
                {
                    RaiseRequireReaccept();
                }
            }
            else if (cont == TweetExistState.ServerDeleted)
            {
                // 消されてるからダメ
                RaiseRequireReaccept();
                return;
            }
            else
            {
                // tweetを受信しようか
                Action receive = null;
                receive = () =>
                {
                    try
                    {
                        var status = ApiHelper.ExecApi(() => AccountStorage.GetRandom().GetStatus(id));
                        if (status != null)
                        {
                            var vm = TweetStorage.Register(status);
                            this.tracePoint = status.Id; // temporarily id
                            Task.Factory.StartNew(() => RecursiveCheckId(status.Id));
                            Task.Factory.StartNew(() =>
                                                  TweetStorage.GetAll(tvm => (tvm.Status is TwitterStatus) && ((TwitterStatus)tvm.Status).InReplyToStatusId == id)
                                                  .ForEach(tvm => tvm.RefreshInReplyToInfo()));
                        }
                        else
                        {
                            RaiseRequireReaccept();
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "ツイート " + id + " の受信に失敗しました。", receive);
                        RaiseRequireReaccept();
                    }
                };
                Task.Factory.StartNew(() => receive());
            }
        }