Esempio n. 1
0
 /// <summary>
 /// User ViewModelを取得します。<para />
 /// 内部キャッシュを更新します。
 /// </summary>
 /// <param name="user">ユーザー情報(nullは指定できません)</param>
 public static UserViewModel Get(TwitterUser user)
 {
     if (user == null)
         throw new ArgumentNullException("user");
     var newvm = new UserViewModel(user);
     dictionary.AddOrUpdate(user.ScreenName, newvm);
     return newvm;
 }
Esempio n. 2
0
 public EventDescription(EventKind kind, UserViewModel source, UserViewModel target, TweetViewModel tweet = null)
 {
     this.CreatedAt = DateTime.Now;
     this.Kind = kind;
     this.SourceUser = source;
     this.TargetUser = target;
     this.TargetTweet = tweet;
 }
Esempio n. 3
0
 public NotificationViewModel(MainWindowViewModel parent, UserViewModel source, UserViewModel target, string text, EventKind eventKind = EventKind.Undefined)
 {
     this.Parent = parent;
     this.SourceUser = source;
     this.TargetUser = target;
     this.Text = text;
     this.NotifyEventKind = eventKind;
     this.RaisePropertyChanged(() => SourceUser);
     this.RaisePropertyChanged(() => TargetUser);
     this.RaisePropertyChanged(() => Text);
     this.RaisePropertyChanged(() => NotifyEventKind);
 }
Esempio n. 4
0
 /// <summary>
 /// User ViewModelを取得します。<para />
 /// 内部キャッシュを更新します。
 /// </summary>
 /// <param name="user">ユーザー情報(nullは指定できません)</param>
 public static UserViewModel Get(TwitterUser user)
 {
     if (user == null)
         throw new ArgumentNullException("user");
     var newvm = new UserViewModel(user);
     using (lockWrap.GetWriterLock())
     {
         if (dictionary.ContainsKey(user.ScreenName))
             dictionary[user.ScreenName] = newvm;
         else
             dictionary.Add(user.ScreenName, newvm);
     }
     return newvm;
 }
Esempio n. 5
0
 /// <summary>
 /// User ViewModelを取得します。<para />
 /// nullを返すことがあります。
 /// </summary>
 /// <param name="userScreenName">ユーザースクリーン名</param>
 /// <param name="useCache">内部キャッシュが可能であれば使用する</param>
 /// <returns></returns>
 public static UserViewModel Get(string userScreenName, bool useCache = true)
 {
     if (String.IsNullOrEmpty(userScreenName))
         throw new ArgumentNullException("userScreenName", "userScreenNameがNullであるか、または空白です。");
     UserViewModel ret = null;
     if (useCache && dictionary.TryGetValue(userScreenName, out ret))
     {
         return ret;
     }
     else
     {
         var acc = AccountStorage.GetRandom(ai => true, true);
         if (acc != null)
         {
             try
             {
                 var ud = acc.GetUserByScreenName(userScreenName);
                 if (ud != null)
                 {
                     var uvm = new UserViewModel(ud);
                     dictionary.AddOrUpdate(userScreenName, uvm);
                     return uvm;
                 }
             }
             catch (Exception e)
             {
                 ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "ユーザー情報の受信に失敗しました。(ユーザー @" + userScreenName + " を アカウント @" + acc.ScreenName + " で受信しようとしました。)");
             }
             return null;
         }
         else
         {
             return null;
         }
     }
 }
Esempio n. 6
0
 public static void OnRetweeted(TweetViewModel tweet, UserViewModel retweeter)
 {
     if (AccountStorage.Contains(retweeter.TwitterUser.ScreenName) || tweet.CreatedAt < wakeupTime)
         return;
     Register(new EventDescription(EventKind.Retweet, retweeter,
             UserStorage.Get(tweet.Status.User), tweet));
 }
Esempio n. 7
0
 public static void OnRemoved(UserViewModel fromUser, UserViewModel toUser)
 {
     Register(new EventDescription(EventKind.Unfollow,
         fromUser, toUser));
 }
Esempio n. 8
0
 public static void OnUnfavored(TweetViewModel tweet, UserViewModel favorer)
 {
     if (AccountStorage.Contains(favorer.TwitterUser.ScreenName))
         return;
     Register(new EventDescription(EventKind.Unfavorite,
         favorer, UserStorage.Get(tweet.Status.User), tweet));
 }
Esempio n. 9
0
 public static bool IsFollowingCurrent(UserViewModel user, TabProperty property)
 {
     if (user == null) return false;
     return property.LinkAccountInfos.All(i => i.IsFollowing(user.TwitterUser.NumericId));
 }
Esempio n. 10
0
 public static bool IsFollowingAny(UserViewModel user)
 {
     if (user == null) return false;
     return AccountStorage.Accounts.Any(d => d.Followings.Contains(user.TwitterUser.NumericId));
 }
Esempio n. 11
0
 public static bool IsFollowerAny(UserViewModel user)
 {
     return AccountStorage.Accounts.Any(d => d.Followers.Contains(user.TwitterUser.NumericId));
 }
Esempio n. 12
0
 public Relation(AccountInfo info, UserViewModel user)
 {
     this.Info = info;
     this.TargetUser = user;
     IsStandby = true;
     RefreshUserData();
 }
Esempio n. 13
0
 /// <summary>
 /// 通知を発行する
 /// </summary>
 private static void IssueNotification(UserViewModel source, UserViewModel target, string text, EventKind eventKind, string soundPath = null)
 {
     if (Setting.Instance.StateProperty.IsInSilentMode) return;
     if (Setting.Instance.NotificationProperty.WindowNotificationStrategy != Configuration.Settings.NotificationStrategy.Disabled)
     {
         DispatcherHelper.BeginInvoke(() =>
         {
             if (Setting.Instance.NotificationProperty.WindowNotificationStrategy == Configuration.Settings.NotificationStrategy.OnlyInactive &&
                 Application.Current.MainWindow.IsActive)
                 return;
             var nvm = new NotificationViewModel(
                 Core.KernelService.MainWindowViewModel,
                 source,
                 target,
                 text,
                 eventKind);
             Core.KernelService.MainWindowViewModel.Messenger.Raise(
                 new TransitionMessage(nvm, TransitionMode.Normal, "Notification"));
         });
     }
     if (Setting.Instance.NotificationProperty.SoundNotificationStrategy != Configuration.Settings.NotificationStrategy.Disabled)
     {
         DispatcherHelper.BeginInvoke(() =>
         {
             if (Setting.Instance.NotificationProperty.SoundNotificationStrategy == Configuration.Settings.NotificationStrategy.OnlyInactive &&
                 Application.Current.MainWindow.IsActive)
                 return;
             PlaySound(eventKind, soundPath);
         }, System.Windows.Threading.DispatcherPriority.Background);
     }
 }
Esempio n. 14
0
 public R4SDialogViewModel(UserViewModel user, string receiver, string reason)
 {
     this.User = user;
     this.Receiver = receiver;
     this.Reason = reason;
 }
Esempio n. 15
0
 private void SetUserTimeline(UserViewModel user)
 {
     if (user == null) return;
     this.TimelineListCoreViewModel.Sources = new[] { new FilterUserId(user.TwitterUser.NumericId) };
     Task.Factory.StartNew(() => this.TimelineListCoreViewModel.InvalidateCache());
 }
Esempio n. 16
0
 public static void OnUnfavored(TweetViewModel tweet, UserViewModel favorer)
 {
     if (AccountStorage.Contains(favorer.TwitterUser.ScreenName) ||
         !Setting.Instance.NotificationProperty.IsNotifyOthersFavoriteEnabled && !AccountStorage.Contains(tweet.Status.User.ScreenName))
         return;
     Register(new EventDescription(EventKind.Unfavorite,
         favorer, UserStorage.Get(tweet.Status.User), tweet));
 }
Esempio n. 17
0
 public FollowManagerViewModel(UserViewModel target)
 {
     this.Target = target;
 }
Esempio n. 18
0
 /// <summary>
 /// ユーザー情報をダウンロードし、キャッシュを更新します。
 /// </summary>
 private static UserViewModel DownloadUser(string userScreenName)
 {
     ManualResetEvent mre;
     lock (semaphoreAccessLocker)
     {
         if (!semaphores.TryGetValue(userScreenName, out mre))
         {
             semaphores.Add(userScreenName, new ManualResetEvent(false));
         }
     }
     if (mre != null)
     {
         mre.WaitOne();
         return Get(userScreenName);
     }
     try
     {
         var acc = AccountStorage.GetRandom(ai => true, true);
         if (acc != null)
         {
             try
             {
                 var ud = acc.GetUserByScreenName(userScreenName);
                 if (ud != null)
                 {
                     var uvm = new UserViewModel(ud);
                     using (lockWrap.GetWriterLock())
                     {
                         if (dictionary.ContainsKey(userScreenName))
                             dictionary[userScreenName] = uvm;
                         else
                             dictionary.Add(userScreenName, uvm);
                     }
                     return uvm;
                 }
             }
             catch (Exception e)
             {
                 ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "ユーザー情報の受信に失敗しました。(ユーザー @" + userScreenName + " を アカウント @" + acc.ScreenName + " で受信しようとしました。)");
             }
             return null;
         }
         else
         {
             return null;
         }
     }
     finally
     {
         lock (semaphoreAccessLocker)
         {
             if (semaphores.ContainsKey(userScreenName))
             {
                 semaphores[userScreenName].Set();
                 semaphores.Remove(userScreenName);
             }
         }
     }
 }