Beispiel #1
0
 /// <summary>
 /// リストデータを取得します。キャッシュは考慮しませんが、更新されます。
 /// </summary>
 public static TwitterList Receive(string screenName, string listName)
 {
     try
     {
         if (!Setting.IsInitialized)
         {
             return(null);
         }
         var acInfo = GetSuitableAccount(screenName, listName);
         if (acInfo == null)
         {
             return(null);
         }
         var list = ApiHelper.ExecApi(() => acInfo.GetList(screenName, listName));
         if (list == null)
         {
             throw new Exception("リストの読み込みを行えませんでした。");
         }
         return(list);
     }
     catch (Exception e)
     {
         ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "リストデータの読み込みに失敗しました。", () => Receive(screenName, listName));
         return(null);
     }
 }
Beispiel #2
0
        public static IEnumerable <UserViewModel> GetListMembers(string screenName, string listName)
        {
            Tuple <string, string> key;

            using (memberLock.GetReaderLock())
            {
                key = listMemberDicts.Keys.FirstOrDefault(f =>
                                                          f.Item1.Equals(screenName, StringComparison.CurrentCultureIgnoreCase) &&
                                                          f.Item2.ToLower().Replace('_', '-').Equals(listName.ToLower().Replace('_', '-')));
            }
            if (key != null)
            {
                return(listMemberDicts[key]);
            }
            else
            {
                var acInfo = GetSuitableAccount(screenName, listName);
                if (acInfo == null)
                {
                    return(null);
                }
                IEnumerable <TwitterUser> members = null;
                try
                {
                    members = ApiHelper.ExecApi(() => acInfo.GetListMembersAll(screenName, listName).ToArray());
                    if (members == null)
                    {
                        throw new WebException("Twitter returns empty");
                    }
                }
                catch (Exception e)
                {
                    ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "リストメンバーを読み込めませんでした: @" + screenName + "/" + listName);
                }
                var users = members.Select(u => UserStorage.Get(u)).ToArray();
                // キャッシュ作成
                using (memberLock.GetWriterLock())
                {
                    var wkey = new Tuple <string, string>(screenName, listName);
                    if (!listMemberDicts.ContainsKey(wkey))
                    {
                        listMemberDicts.Add(wkey, users);
                    }
                }
                return(users);
            }
        }
Beispiel #3
0
        private static UserViewModel DownloadUser(string userScreenName)
        {
            ManualResetEvent mre;

            lock (semaphoreAccessLocker)
            {
                if (!strSemaphores.TryGetValue(userScreenName, out mre))
                {
                    strSemaphores.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(ud.NumericId))
                                {
                                    dictionary[ud.NumericId] = uvm;
                                }
                                else
                                {
                                    dictionary.Add(ud.NumericId, uvm);
                                }
                            }
                            return(uvm);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionStorage.Register(e, ExceptionCategory.TwitterError, "ユーザー情報の受信に失敗しました。(ユーザー @" + userScreenName + " を アカウント @" + acc.ScreenName + " で受信しようとしました。)");
                    }
                    return(null);
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                lock (semaphoreAccessLocker)
                {
                    if (strSemaphores.ContainsKey(userScreenName))
                    {
                        strSemaphores[userScreenName].Set();
                        strSemaphores.Remove(userScreenName);
                    }
                }
            }
        }