svnno****@sourc*****
svnno****@sourc*****
2011年 9月 9日 (金) 20:00:06 JST
Revision: 1578 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1578 Author: f_swallow Date: 2011-09-09 20:00:06 +0900 (Fri, 09 Sep 2011) Log Message: ----------- FavoriteQueueを簡易実装 Modified Paths: -------------- trunk/Tween/Tween.vbproj trunk/Tween/Twitter.vb Added Paths: ----------- trunk/Tween/FavoriteQueue.vb -------------- next part -------------- Added: trunk/Tween/FavoriteQueue.vb =================================================================== --- trunk/Tween/FavoriteQueue.vb (rev 0) +++ trunk/Tween/FavoriteQueue.vb 2011-09-09 11:00:06 UTC (rev 1578) @@ -0,0 +1,62 @@ +Imports System.Threading.Tasks +Imports System.Net + +Public Class FavoriteQueue + Private Shared _instance As New FavoriteQueue + Public Shared ReadOnly Property GetInstance As FavoriteQueue + Get + Return _instance + End Get + End Property + + Public FavoriteCache As New List(Of Long) + + Public Sub Add(ByVal stsId As Long) + If Not FavoriteCache.Contains(stsId) Then + FavoriteCache.Add(stsId) + End If + End Sub + + Public Sub AddRange(ByVal stsIds As IEnumerable(Of Long)) + FavoriteCache.AddRange(stsIds) + End Sub + + Public Sub Remove(ByVal stsId As Long) + FavoriteCache.Remove(stsId) + End Sub + + Public Sub FavoriteCacheAdd(ByVal statusId As Long, ByVal res As HttpStatusCode, Optional ByRef isMsg As Boolean = True) + 'If Not SettingInfo.Instance.IsUseFavoriteQueue Then Exit Sub + Select Case res + Case HttpStatusCode.BadGateway, HttpStatusCode.BadRequest, HttpStatusCode.ServiceUnavailable, HttpStatusCode.InternalServerError, HttpStatusCode.RequestTimeout + isMsg = False + FavoriteCache.Add(statusId) + End Select + End Sub + + Public Sub FavoriteCacheStart() + If Not FavoriteCache.Count = 0 Then + Dim _cacheList As New List(Of Long)(FavoriteCache) + AllClear() + Parallel.ForEach(Of Long)(_cacheList, New Action(Of Long)(Sub(stsId As Long) + TweenMain.GetInstance.TwitterInstance.PostFavAdd(stsId) + End Sub)) + End If + End Sub + + Public ReadOnly Property Count As Integer + Get + Return FavoriteCache.Count + End Get + End Property + + Public Sub AllClear() + FavoriteCache.Clear() + FavoriteCache.TrimExcess() + End Sub + + Public Function Contains(stsId As Long) As Boolean + Return FavoriteCache.Contains(stsId) + End Function + +End Class Modified: trunk/Tween/Tween.vbproj =================================================================== --- trunk/Tween/Tween.vbproj 2011-09-07 17:21:27 UTC (rev 1577) +++ trunk/Tween/Tween.vbproj 2011-09-09 11:00:06 UTC (rev 1578) @@ -293,6 +293,7 @@ <Compile Include="TweenAboutBox.vb"> <SubType>Form</SubType> </Compile> + <Compile Include="FavoriteQueue.vb" /> <Compile Include="Twitter.vb" /> <Compile Include="UserInfo.vb" /> <Compile Include="WebBrowserController.vb" /> Modified: trunk/Tween/Twitter.vb =================================================================== --- trunk/Tween/Twitter.vb 2011-09-07 17:21:27 UTC (rev 1577) +++ trunk/Tween/Twitter.vb 2011-09-09 11:00:06 UTC (rev 1578) @@ -1094,13 +1094,16 @@ If Twitter.AccountState <> ACCOUNT_STATE.Valid Then Return "" + If FavoriteQueue.GetInstance.Contains(id) Then FavoriteQueue.GetInstance.Remove(id) + Google.GASender.GetInstance().TrackEventWithCategory("post", "favorites", Me.UserId) Dim res As HttpStatusCode Dim content As String = "" Try res = twCon.CreateFavorites(id, content) Catch ex As Exception - Return "Err:" + ex.Message + "(" + GetCurrentMethod.Name + ")" + FavoriteQueue.GetInstance.Add(id) + Return "Err:->FavoriteQueue:" + ex.Message + "(" + GetCurrentMethod.Name + ")" End Try Select Case res @@ -1115,8 +1118,15 @@ If String.IsNullOrEmpty(errMsg) Then Return "Err:Forbidden(" + GetCurrentMethod.Name + ")" Else + If errMsg.Contains("It's great that you like so many updates") Then + FavoriteQueue.GetInstance.Add(id) + Return "Err:->FavoriteQueue:" + errMsg + End If Return "Err:" + errMsg End If + Case HttpStatusCode.BadGateway, HttpStatusCode.ServiceUnavailable, HttpStatusCode.InternalServerError, HttpStatusCode.RequestTimeout + FavoriteQueue.GetInstance.Add(id) + Return "Err:->FavoriteQueue:" + res.ToString + "(" + GetCurrentMethod.Name + ")" Case Else Return "Err:" + res.ToString + "(" + GetCurrentMethod.Name + ")" End Select @@ -1165,6 +1175,11 @@ If Twitter.AccountState <> ACCOUNT_STATE.Valid Then Return "" + If FavoriteQueue.GetInstance.Contains(id) Then + FavoriteQueue.GetInstance.Remove(id) + Return "" + End If + Google.GASender.GetInstance().TrackEventWithCategory("post", "destroy_favorites", Me.UserId) Dim res As HttpStatusCode Dim content As String = ""