OSDN Git Service

APIChangeEventブランチをマージ
authorsyo68k <syo68k@users.sourceforge.jp>
Mon, 23 Aug 2010 06:33:21 +0000 (06:33 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:14:55 +0000 (23:14 +0900)
git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@747 e39ad16e-3079-482e-bb30-4b4d378143b6

12 files changed:
Tween/ApiInformation.vb [new file with mode: 0644]
Tween/Connection/HttpConnectionBasic.vb
Tween/Connection/HttpConnectionOAuth.vb
Tween/Connection/HttpTwitter.vb
Tween/Connection/IHttpConnection.vb
Tween/Connection/TwitPic.vb
Tween/Connection/imgly.vb
Tween/MyCommon.vb
Tween/Setting.vb
Tween/Tween.vb
Tween/Tween.vbproj
Tween/Twitter.vb

diff --git a/Tween/ApiInformation.vb b/Tween/ApiInformation.vb
new file mode 100644 (file)
index 0000000..b8431f0
--- /dev/null
@@ -0,0 +1,192 @@
+Imports System.ComponentModel
+
+Public Class ApiInformationChangedEventArgs
+    Inherits EventArgs
+    Public ApiInfo As New ApiInfo
+End Class
+
+Public MustInherit Class ApiInfoBase
+    Protected Shared _MaxCount As Integer = -1
+    Protected Shared _RemainCount As Integer = -1
+    Protected Shared _ResetTime As New DateTime
+    Protected Shared _ResetTimeInSeconds As Integer = -1
+    Protected Shared _UsingCount As Integer = -1
+End Class
+
+Public Class ApiInfo
+    Inherits ApiInfoBase
+    Public MaxCount As Integer
+    Public RemainCount As Integer
+    Public ResetTime As DateTime
+    Public ResetTimeInSeconds As Integer
+    Public UsingCount As Integer
+
+    Public Sub New()
+        Me.MaxCount = _MaxCount
+        Me.RemainCount = _RemainCount
+        Me.ResetTime = _ResetTime
+        Me.ResetTimeInSeconds = _ResetTimeInSeconds
+        Me.UsingCount = _ResetTimeInSeconds
+    End Sub
+End Class
+
+Public Class ApiInformation
+    Inherits ApiInfoBase
+
+    'Private ReadOnly _lockobj As New Object 更新時にロックが必要かどうかは様子見
+
+    Public HttpHeaders As New Dictionary(Of String, String)(StringComparer.CurrentCultureIgnoreCase)
+
+    Public Sub Initialize()
+        If HttpHeaders.ContainsKey("X-RateLimit-Remaining") Then
+            HttpHeaders.Item("X-RateLimit-Remaining") = "-1"
+        Else
+            HttpHeaders.Add("X-RateLimit-Remaining", "-1")
+        End If
+
+        If HttpHeaders.ContainsKey("X-RateLimit-Limit") Then
+            HttpHeaders.Item("X-RateLimit-Limit") = "-1"
+        Else
+            HttpHeaders.Add("X-RateLimit-Limit", "-1")
+        End If
+
+        If HttpHeaders.ContainsKey("X-RateLimit-Reset") Then
+            HttpHeaders.Item("X-RateLimit-Reset") = "-1"
+        Else
+            HttpHeaders.Add("X-RateLimit-Reset", "-1")
+        End If
+        _MaxCount = -1
+        _RemainCount = -1
+        _ResetTime = New DateTime
+        _ResetTimeInSeconds = -1
+        'UsingCountは初期化対象外
+        RaiseEvent Changed(Me, New ApiInformationChangedEventArgs)
+    End Sub
+
+    Public Function ConvertResetTimeInSecondsToResetTime(ByVal seconds As Integer) As DateTime
+        If seconds >= 0 Then
+            Return System.TimeZone.CurrentTimeZone.ToLocalTime((New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(seconds))
+        Else
+            Return New DateTime
+        End If
+    End Function
+
+    Public Event Changed(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs)
+
+    Private Sub Raise_Changed()
+        Dim arg As New ApiInformationChangedEventArgs
+        RaiseEvent Changed(Me, arg)
+        _MaxCount = arg.ApiInfo.MaxCount
+        _RemainCount = arg.ApiInfo.RemainCount
+        _ResetTime = arg.ApiInfo.ResetTime
+        _ResetTimeInSeconds = arg.ApiInfo.ResetTimeInSeconds
+        _UsingCount = arg.ApiInfo.UsingCount
+    End Sub
+
+    Public Property MaxCount As Integer
+        Get
+            Return _MaxCount
+        End Get
+        Set(ByVal value As Integer)
+            If _MaxCount <> value Then
+                _MaxCount = value
+                Raise_Changed()
+            End If
+        End Set
+    End Property
+
+    Public Property RemainCount As Integer
+        Get
+            Return _RemainCount
+        End Get
+        Set(ByVal value As Integer)
+            If _RemainCount <> value Then
+                _RemainCount = value
+                Raise_Changed()
+            End If
+        End Set
+    End Property
+
+    Public Property ResetTime As DateTime
+        Get
+            Return _ResetTime
+        End Get
+        Set(ByVal value As DateTime)
+            If _ResetTime <> value Then
+                _ResetTime = value
+                Raise_Changed()
+            End If
+        End Set
+    End Property
+
+    Public Property ResetTimeInSeconds As Integer
+        Get
+            Return _ResetTimeInSeconds
+        End Get
+        Set(ByVal value As Integer)
+            If _ResetTimeInSeconds <> value Then
+                _ResetTimeInSeconds = value
+                Raise_Changed()
+            End If
+        End Set
+    End Property
+
+    Public Property UsingCount As Integer
+        Get
+            Return _UsingCount
+        End Get
+        Set(ByVal value As Integer)
+            If _UsingCount <> value Then
+                _UsingCount = value
+                Raise_Changed()
+            End If
+        End Set
+    End Property
+
+
+    Private ReadOnly Property RemainCountFromHttpHeader() As Integer
+        Get
+            Dim result As Integer = 0
+            If HttpHeaders("X-RateLimit-Remaining") = "" Then Return -1
+            If Integer.TryParse(HttpHeaders("X-RateLimit-Remaining"), result) Then
+                Return result
+            End If
+            Return -1
+        End Get
+    End Property
+
+    Private ReadOnly Property MaxCountFromHttpHeader() As Integer
+        Get
+            Dim result As Integer = 0
+            If HttpHeaders("X-RateLimit-Limit") = "" Then Return -1
+            If Integer.TryParse(HttpHeaders("X-RateLimit-Limit"), result) Then
+                Return result
+            End If
+            Return -1
+        End Get
+    End Property
+
+    Private ReadOnly Property ResetTimeFromHttpHeader() As DateTime
+        Get
+            Dim i As Integer
+            If Integer.TryParse(HttpHeaders("X-RateLimit-Reset"), i) Then
+                If i >= 0 Then
+                    Return System.TimeZone.CurrentTimeZone.ToLocalTime((New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(i))
+                Else
+                    Return New DateTime
+                End If
+            Else
+                Return New DateTime
+            End If
+        End Get
+    End Property
+
+    Public Sub ParseHttpHeaders(ByVal headers As Dictionary(Of String, String))
+        _MaxCount = MaxCountFromHttpHeader
+        _RemainCount = RemainCountFromHttpHeader
+        _ResetTime = ResetTimeFromHttpHeader
+        Raise_Changed()
+    End Sub
+End Class
+
+
index 303bd90..d7c88df 100644 (file)
@@ -33,12 +33,14 @@ Public Class HttpConnectionBasic
     '''<param name="param">GET時のクエリ、またはPOST時のエンティティボディ</param>
     '''<param name="content">[OUT]HTTP応答のボディデータ</param>
     '''<param name="headerInfo">[IN/OUT]HTTP応答のヘッダ情報。必要なヘッダ名を事前に設定しておくこと</param>
+    '''<param name="callback">処理終了直前に呼ばれるコールバック関数のデリゲート 不要な場合はNothingを渡すこと</param>
     '''<returns>HTTP応答のステータスコード</returns>
     Public Function GetContent(ByVal method As String, _
             ByVal requestUri As Uri, _
             ByVal param As Dictionary(Of String, String), _
             ByRef content As String, _
-            ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent
+            ByVal headerInfo As Dictionary(Of String, String), _
+            ByVal callback As IHttpConnection.CallbackDelegate) As HttpStatusCode Implements IHttpConnection.GetContent
 
         '認証済かチェック
         If String.IsNullOrEmpty(Me.credential) Then Return HttpStatusCode.Unauthorized
@@ -50,11 +52,16 @@ Public Class HttpConnectionBasic
         'BASIC認証用ヘッダを付加
         AppendApiInfo(webReq)
 
+        Dim code As HttpStatusCode
         If content Is Nothing Then
-            Return GetResponse(webReq, headerInfo, False)
+            code = GetResponse(webReq, headerInfo, False)
         Else
-            Return GetResponse(webReq, content, headerInfo, False)
+            code = GetResponse(webReq, content, headerInfo, False)
         End If
+        If callback IsNot Nothing Then
+            callback(Me)
+        End If
+        Return code
     End Function
 
     Public Function GetContent(ByVal method As String, _
@@ -62,7 +69,8 @@ Public Class HttpConnectionBasic
             ByVal param As Dictionary(Of String, String), _
             ByVal binary As List(Of KeyValuePair(Of String, FileInfo)), _
             ByRef content As String, _
-            ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent
+            ByVal headerInfo As Dictionary(Of String, String), _
+            ByVal callback As IHttpConnection.CallbackDelegate) As HttpStatusCode Implements IHttpConnection.GetContent
 
         '認証済かチェック
         If String.IsNullOrEmpty(Me.credential) Then Return HttpStatusCode.Unauthorized
@@ -75,13 +83,19 @@ Public Class HttpConnectionBasic
         'BASIC認証用ヘッダを付加
         AppendApiInfo(webReq)
 
+        Dim code As HttpStatusCode
         If content Is Nothing Then
-            Return GetResponse(webReq, headerInfo, False)
+            code = GetResponse(webReq, headerInfo, False)
         Else
-            Return GetResponse(webReq, content, headerInfo, False)
+            code = GetResponse(webReq, content, headerInfo, False)
+        End If
+        If callback IsNot Nothing Then
+            callback(Me)
         End If
+        Return code
     End Function
 
+
     '''<summary>
     '''BASIC認証とREST APIで必要なヘッダを付加
     '''</summary>
@@ -132,7 +146,7 @@ Public Class HttpConnectionBasic
         Dim orgCre As String = Me.credential
         Me.credential = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))
         Try
-            Dim httpCode As HttpStatusCode = Me.GetContent("GET", url, Nothing, Nothing, Nothing)
+            Dim httpCode As HttpStatusCode = Me.GetContent("GET", url, Nothing, Nothing, Nothing, Nothing)
             If httpCode = HttpStatusCode.OK Then
                 Me._userName = username
                 Me._password = password
index 9946d65..25fca64 100644 (file)
@@ -63,12 +63,14 @@ Public Class HttpConnectionOAuth
     '''<param name="param">GET時のクエリ、またはPOST時のエンティティボディ</param>
     '''<param name="content">[OUT]HTTP応答のボディデータ</param>
     '''<param name="headerInfo">[IN/OUT]HTTP応答のヘッダ情報。必要なヘッダ名を事前に設定しておくこと</param>
+    '''<param name="callback">処理終了直前に呼ばれるコールバック関数のデリゲート 不要な場合はNothingを渡すこと</param>
     '''<returns>HTTP応答のステータスコード</returns>
     Public Function GetContent(ByVal method As String, _
             ByVal requestUri As Uri, _
             ByVal param As Dictionary(Of String, String), _
             ByRef content As String, _
-            ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent
+            ByVal headerInfo As Dictionary(Of String, String), _
+            ByVal callback As IHttpConnection.CallbackDelegate) As HttpStatusCode Implements IHttpConnection.GetContent
         '認証済かチェック
         If String.IsNullOrEmpty(token) Then Return HttpStatusCode.Unauthorized
 
@@ -79,11 +81,16 @@ Public Class HttpConnectionOAuth
         'OAuth認証ヘッダを付加
         AppendOAuthInfo(webReq, param, token, tokenSecret)
 
+        Dim code As HttpStatusCode
         If content Is Nothing Then
-            Return GetResponse(webReq, headerInfo, False)
+            code = GetResponse(webReq, headerInfo, False)
         Else
-            Return GetResponse(webReq, content, headerInfo, False)
+            code = GetResponse(webReq, content, headerInfo, False)
         End If
+        If callback IsNot Nothing Then
+            callback(Me)
+        End If
+        Return code
     End Function
 
     '''<summary>
@@ -94,7 +101,8 @@ Public Class HttpConnectionOAuth
         ByVal param As Dictionary(Of String, String), _
         ByVal binary As List(Of KeyValuePair(Of String, FileInfo)), _
         ByRef content As String, _
-        ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode Implements IHttpConnection.GetContent
+        ByVal headerInfo As Dictionary(Of String, String), _
+        ByVal callback As IHttpConnection.CallbackDelegate) As HttpStatusCode Implements IHttpConnection.GetContent
         '認証済かチェック
         If String.IsNullOrEmpty(token) Then Return HttpStatusCode.Unauthorized
 
@@ -106,11 +114,16 @@ Public Class HttpConnectionOAuth
         'OAuth認証ヘッダを付加
         AppendOAuthInfo(webReq, Nothing, token, tokenSecret)
 
+        Dim code As HttpStatusCode
         If content Is Nothing Then
-            Return GetResponse(webReq, headerInfo, False)
+            code = GetResponse(webReq, headerInfo, False)
         Else
-            Return GetResponse(webReq, content, headerInfo, False)
+            code = GetResponse(webReq, content, headerInfo, False)
+        End If
+        If callback IsNot Nothing Then
+            callback(Me)
         End If
+        Return code
     End Function
 
 #Region "認証処理"
index a11ac71..348bb58 100644 (file)
@@ -20,7 +20,6 @@ Public Class HttpTwitter
     Private Const AccessTokenUrlXAuth As String = "https://api.twitter.com/oauth/access_token"
 
     Private Shared _protocol As String = "http://"
-    Private _remainCountApi As New Dictionary(Of String, String)(StringComparer.CurrentCultureIgnoreCase)
 
     Private Const PostMethod As String = "POST"
     Private Const GetMethod As String = "GET"
@@ -35,27 +34,7 @@ Public Class HttpTwitter
     Private connectionType As AuthMethod = AuthMethod.Basic
 
     Public Sub New()
-        InitializeCount()
-    End Sub
-
-    Private Sub InitializeCount()
-        If _remainCountApi.ContainsKey("X-RateLimit-Remaining") Then
-            _remainCountApi.Item("X-RateLimit-Remaining") = "-1"
-        Else
-            _remainCountApi.Add("X-RateLimit-Remaining", "-1")
-        End If
-
-        If _remainCountApi.ContainsKey("X-RateLimit-Limit") Then
-            _remainCountApi.Item("X-RateLimit-Limit") = "-1"
-        Else
-            _remainCountApi.Add("X-RateLimit-Limit", "-1")
-        End If
-
-        If _remainCountApi.ContainsKey("X-RateLimit-Reset") Then
-            _remainCountApi.Item("X-RateLimit-Reset") = "-1"
-        Else
-            _remainCountApi.Add("X-RateLimit-Reset", "-1")
-        End If
+        TwitterApiInfo.Initialize()
     End Sub
 
     Public Sub Initialize(ByVal accessToken As String, _
@@ -72,7 +51,7 @@ Public Class HttpTwitter
             tk = accessToken
             tks = accessTokenSecret
             un = username
-            InitializeCount()
+            TwitterApiInfo.Initialize()
         End If
         con.Initialize(ConsumerKey, ConsumerSecret, accessToken, accessTokenSecret, username, "screen_name")
         httpCon = con
@@ -89,7 +68,7 @@ Public Class HttpTwitter
             ' 以前の認証状態よりひとつでも変化があったらhttpヘッダより読み取ったカウントは初期化
             un = username
             pw = password
-            InitializeCount()
+            TwitterApiInfo.Initialize()
         End If
         con.Initialize(username, password)
         httpCon = con
@@ -166,43 +145,6 @@ Public Class HttpTwitter
         End Set
     End Property
 
-    Public ReadOnly Property RemainCountApi() As Integer
-        Get
-            Dim result As Integer = 0
-            If _remainCountApi("X-RateLimit-Remaining") = "" Then Return -1
-            If Integer.TryParse(_remainCountApi("X-RateLimit-Remaining"), result) Then
-                Return result
-            End If
-            Return -1
-        End Get
-    End Property
-
-    Public ReadOnly Property UpperCountApi() As Integer
-        Get
-            Dim result As Integer = 0
-            If _remainCountApi("X-RateLimit-Limit") = "" Then Return -1
-            If Integer.TryParse(_remainCountApi("X-RateLimit-Limit"), result) Then
-                Return result
-            End If
-            Return -1
-        End Get
-    End Property
-
-    Public ReadOnly Property ResetTimeApi() As DateTime
-        Get
-            Dim i As Integer
-            If Integer.TryParse(_remainCountApi("X-RateLimit-Reset"), i) Then
-                If i >= 0 Then
-                    Return System.TimeZone.CurrentTimeZone.ToLocalTime((New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(i))
-                Else
-                    Return New DateTime
-                End If
-            Else
-                Return New DateTime
-            End If
-        End Get
-    End Property
-
     Public Function UpdateStatus(ByVal status As String, ByVal replyToId As Long, ByRef content As String) As HttpStatusCode
         Dim param As New Dictionary(Of String, String)
         param.Add("status", status)
@@ -213,6 +155,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/statuses/update.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -221,6 +164,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/statuses/destroy/" + id.ToString + ".xml"), _
                             Nothing, _
                             Nothing, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -233,6 +177,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/direct_messages/new.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -241,6 +186,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/direct_messages/destroy/" + id.ToString + ".xml"), _
                             Nothing, _
                             Nothing, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -249,6 +195,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/statuses/retweet/" + id.ToString() + ".xml"), _
                             Nothing, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -259,7 +206,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/users/show.xml"), _
                             param, _
                             content, _
-                            Nothing)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
     Public Function CreateFriendships(ByVal screenName As String, ByRef content As String) As HttpStatusCode
         Dim param As New Dictionary(Of String, String)
@@ -269,6 +217,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/friendships/create.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -280,6 +229,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/friendships/destroy.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -291,6 +241,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/blocks/create.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -302,6 +253,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/blocks/destroy.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -313,6 +265,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/report_spam.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -325,7 +278,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/friendships/show.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function ShowStatuses(ByVal id As Long, ByRef content As String) As HttpStatusCode
@@ -333,7 +287,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/statuses/show/" + id.ToString() + ".xml"), _
                             Nothing, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function CreateFavorites(ByVal id As Long, ByRef content As String) As HttpStatusCode
@@ -341,6 +296,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/favorites/create/" + id.ToString() + ".xml"), _
                             Nothing, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -349,6 +305,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/favorites/destroy/" + id.ToString() + ".xml"), _
                             Nothing, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -368,7 +325,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/statuses/home_timeline.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function Mentions(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode
@@ -387,7 +345,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/statuses/mentions.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function DirectMessages(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode
@@ -406,7 +365,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/direct_messages.xml"), _
                             Nothing, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function DirectMessagesSent(ByVal count As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode
@@ -425,7 +385,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/direct_messages/sent.xml"), _
                             Nothing, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function Favorites(ByVal count As Integer, ByRef content As String) As HttpStatusCode
@@ -436,7 +397,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/favorites.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function Search(ByVal words As String, ByVal lang As String, ByVal rpp As Integer, ByVal page As Integer, ByVal sinceId As Long, ByRef content As String) As HttpStatusCode
@@ -465,7 +427,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/followers/ids.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function RateLimitStatus(ByRef content As String) As HttpStatusCode
@@ -473,6 +436,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/account/rate_limit_status.xml"), _
                             Nothing, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -483,7 +447,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/" + user + "/lists.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function PostListID(ByVal user As String, ByVal list_id As String, ByVal name As String, ByVal mode As String, ByVal description As String, ByRef content As String) As HttpStatusCode
@@ -496,6 +461,7 @@ Public Class HttpTwitter
                                   CreateTwitterUri("/1/" + user + "/lists/" + list_id + ".xml"), _
                                   param, _
                                   content, _
+                                  Nothing, _
                                   Nothing)
     End Function
 
@@ -507,6 +473,7 @@ Public Class HttpTwitter
                                   CreateTwitterUri("/1/" + user + "/lists/" + list_id + ".xml"), _
                                   param, _
                                   content, _
+                                  Nothing, _
                                   Nothing)
     End Function
 
@@ -517,7 +484,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/" + user + "/lists/subscriptions.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function GetListsStatuses(ByVal user As String, ByVal list_id As String, ByVal per_page As Integer, ByVal max_id As Long, ByVal since_id As Long, ByRef content As String) As HttpStatusCode
@@ -537,7 +505,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/" + user + "/lists/" + list_id + "/statuses.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function PostLists(ByVal user As String, ByVal listname As String, ByVal isPrivate As Boolean, ByVal description As String, ByRef content As String) As HttpStatusCode
@@ -556,6 +525,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/" + user + "/lists.xml"), _
                             param, _
                             content, _
+                            Nothing,
                             Nothing)
     End Function
 
@@ -566,7 +536,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/" + user + "/" + list_id + "/members.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function PostListMembers(ByVal user As String, ByVal list_id As String, ByVal id As String, ByRef content As String) As HttpStatusCode
@@ -576,6 +547,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/" + user + "/" + list_id + "/members.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -587,6 +559,7 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/" + user + "/" + list_id + "/members.xml"), _
                             param, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -595,7 +568,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/" + user + "/" + list_id + "/members/" + id + ".xml"), _
                             Nothing, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function Statusid_retweeted_by_ids(ByVal statusid As Long, ByVal count As Integer, ByVal page As Integer, ByRef content As String) As HttpStatusCode
@@ -611,7 +585,8 @@ Public Class HttpTwitter
                             CreateTwitterUri("/1/statuses/" + statusid.ToString + "/retweeted_by/ids.xml"), _
                             param, _
                             content, _
-                            _remainCountApi)
+                            TwitterApiInfo.HttpHeaders, _
+                            AddressOf GetApiCallback)
     End Function
 
     Public Function UpdateProfile(ByVal name As String, ByVal url As String, ByVal location As String, ByVal description As String, ByRef content As String) As HttpStatusCode
@@ -626,6 +601,7 @@ Public Class HttpTwitter
                     CreateTwitterUri("/1/account/update_profile.xml"), _
                     param, _
                     content, _
+                    Nothing, _
                     Nothing)
     End Function
 
@@ -638,6 +614,7 @@ Public Class HttpTwitter
                             Nothing, _
                             binary, _
                             content, _
+                            Nothing, _
                             Nothing)
     End Function
 
@@ -669,4 +646,7 @@ Public Class HttpTwitter
     End Property
 #End Region
 
+    Private Sub GetApiCallback(ByVal sender As Object)
+        TwitterApiInfo.ParseHttpHeaders(TwitterApiInfo.HttpHeaders)
+    End Sub
 End Class
index a5429d1..2efbed5 100644 (file)
@@ -7,16 +7,19 @@ Public Interface IHttpConnection
             ByVal requestUri As Uri, _
             ByVal param As Dictionary(Of String, String), _
             ByRef content As String, _
-            ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode
+            ByVal headerInfo As Dictionary(Of String, String), _
+            ByVal callback As CallbackDelegate) As HttpStatusCode
 
     Function GetContent(ByVal method As String, _
             ByVal requestUri As Uri, _
             ByVal param As Dictionary(Of String, String), _
             ByVal binary As List(Of KeyValuePair(Of String, FileInfo)), _
             ByRef content As String, _
-            ByVal headerInfo As Dictionary(Of String, String)) As HttpStatusCode
+            ByVal headerInfo As Dictionary(Of String, String), _
+            ByVal callback As CallbackDelegate) As HttpStatusCode
 
     Function Authenticate(ByVal url As Uri, ByVal username As String, ByVal password As String) As HttpStatusCode
 
     ReadOnly Property AuthUsername() As String
+    Delegate Sub CallbackDelegate(ByVal sender As Object)
 End Interface
index ad99282..c9d0447 100644 (file)
@@ -50,6 +50,7 @@ Public Class TwitPic
                           param, _
                           binary, _
                           content, _
+                          Nothing, _
                           Nothing)
     End Function
 
index e1ec2b7..a33f13a 100644 (file)
@@ -48,6 +48,7 @@ Public Class imgly
                           param, _
                           binary, _
                           content, _
+                          Nothing, _
                           Nothing)
     End Function
 
index b8929e2..22c0ef5 100644 (file)
@@ -536,4 +536,5 @@ retry:
 
     Public fileVersion As String
 
+    Public WithEvents TwitterApiInfo As New ApiInformation
 End Module
index 73f063e..a79fc1a 100644 (file)
@@ -1799,11 +1799,11 @@ Public Class Setting
         CalcApiUsing()
     End Sub
 
-    Private Sub DisplayApiMaxCount(ByVal apiCount As Twitter.ApiInfo)
-        If apiCount.MaxCount > -1 Then
-            LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, apiCount.UsingCount, apiCount.MaxCount)
+    Private Sub DisplayApiMaxCount(ByVal info As ApiInfo)
+        If TwitterApiInfo.MaxCount > -1 Then
+            LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, TwitterApiInfo.UsingCount, TwitterApiInfo.MaxCount)
         Else
-            LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, apiCount.UsingCount, "???")
+            LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, TwitterApiInfo.UsingCount, "???")
         End If
     End Sub
 
@@ -1848,20 +1848,20 @@ Public Class Setting
         End If
 
         If tw IsNot Nothing Then
-            If tw.UpperCountApi = -1 Then
+            If TwitterApiInfo.MaxCount = -1 Then
                 If Twitter.AccountState = ACCOUNT_STATE.Valid Then
-                    Dim info As New Twitter.ApiInfo
+                    Dim info As New ApiInfo
                     info.UsingCount = UsingApi
-                    Dim proc As New Action(Of Twitter.ApiInfo)(Sub(infoCount)
-                                                                   tw.GetInfoApi(infoCount) '取得エラー時はinfoCountは初期状態(値:-1)
-                                                                   Me.Invoke(New Action(Of Twitter.ApiInfo)(AddressOf DisplayApiMaxCount), infoCount)
-                                                               End Sub)
+                    Dim proc As New Action(Of ApiInfo)(Sub(infoCount)
+                                                           tw.GetInfoApi(infoCount) '取得エラー時はinfoCountは初期状態(値:-1)
+                                                           Me.Invoke(New Action(Of ApiInfo)(AddressOf DisplayApiMaxCount), infoCount)
+                                                       End Sub)
                     proc.BeginInvoke(info, Nothing, Nothing)
                 Else
                     LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, UsingApi, "???")
                 End If
             Else
-                LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, UsingApi, tw.UpperCountApi)
+                LabelApiUsing.Text = String.Format(My.Resources.SettingAPIUse1, UsingApi, TwitterApiInfo.MaxCount)
             End If
         End If
 
index 1666f1c..587f7ad 100644 (file)
@@ -530,6 +530,7 @@ Public Class TweenMain
         Me.Visible = False
         SecurityManager = New InternetSecurityManager(PostBrowser)
 
+        AddHandler TwitterApiInfo.Changed, AddressOf SetStatusLabelApiHandler
 
         VerUpMenuItem.Image = shield.Icon
         If Not My.Application.CommandLineArgs.Count = 0 AndAlso My.Application.CommandLineArgs.Contains("/d") Then TraceFlag = True
@@ -1614,7 +1615,7 @@ Public Class TweenMain
                                                            "Retweet",
                                                            MessageBoxButtons.YesNoCancel,
                                                            MessageBoxIcon.Question)
-            Select rtResult
+            Select Case rtResult
                 Case Windows.Forms.DialogResult.Yes
                     doReTweetOriginal(False)
                     StatusText.Text = ""
@@ -2811,8 +2812,6 @@ Public Class TweenMain
             result = SettingDialog.ShowDialog()
         Catch ex As Exception
             Exit Sub
-        Finally
-            SetStatusLabel()
         End Try
 
         If result = Windows.Forms.DialogResult.OK Then
@@ -6512,30 +6511,39 @@ RETRY:
         Else
             slbl.Append((SettingDialog.TimelinePeriodInt - _homeCounterAdjuster).ToString() + My.Resources.SetStatusLabelText3)
         End If
-        SetStatusLabelApi()
         Return slbl.ToString()
     End Function
 
+    Delegate Sub SetStatusLabelApiDelegate()
+
+    Private Sub SetStatusLabelApiHandler(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs)
+        If InvokeRequired Then
+            Invoke(New SetStatusLabelApiDelegate(AddressOf SetStatusLabelApi))
+        Else
+            SetStatusLabelApi()
+        End If
+    End Sub
+
     Private Sub SetStatusLabelApi()
         Dim slbl As New StringBuilder(256)
 
-        If tw.RemainCountApi > -1 AndAlso tw.UpperCountApi > -1 Then
+        If TwitterApiInfo.RemainCount > -1 AndAlso TwitterApiInfo.MaxCount > -1 Then
             ' 正常
-            slbl.Append("API " + tw.RemainCountApi.ToString + "/" + tw.UpperCountApi.ToString)
-        ElseIf tw.RemainCountApi > -1 Then
+            slbl.Append("API " + TwitterApiInfo.RemainCount.ToString + "/" + TwitterApiInfo.MaxCount.ToString)
+        ElseIf TwitterApiInfo.RemainCount > -1 Then
             ' uppercount不正
-            slbl.Append("API " + tw.RemainCountApi.ToString + "/???")
-        ElseIf tw.UpperCountApi > -1 Then
+            slbl.Append("API " + TwitterApiInfo.RemainCount.ToString + "/???")
+        ElseIf TwitterApiInfo.MaxCount > -1 Then
             ' remaincount不正
-            slbl.Append("API ???/" + tw.UpperCountApi.ToString)
+            slbl.Append("API ???/" + TwitterApiInfo.MaxCount.ToString)
         Else
             '両方とも不正
             slbl.Append("API ???/???")
         End If
 
         StatusLabelApi.Text = slbl.ToString()
-        If tw.ResetTimeApi >= DateTime.Now Then
-            StatusLabelApi.ToolTipText = "ResetTime " + tw.ResetTimeApi.ToString
+        If TwitterApiInfo.ResetTime >= DateTime.Now Then
+            StatusLabelApi.ToolTipText = "ResetTime " + TwitterApiInfo.ResetTime.ToString
         Else
             StatusLabelApi.ToolTipText = "ResetTime ???"
         End If
@@ -6834,11 +6842,11 @@ RETRY:
     Private Function UrlConvert(ByVal Converter_Type As UrlConverter) As Boolean
         'Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
         Dim result As String = ""
-         Const url As String = "(?<before>(?:[^\""':!=]|^|\:))" + _
-                                    "(?<url>(?<protocol>https?://)" + _
-                                    "(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" + _
-                                    "(?<path>/[a-z0-9!*'();:&=+$/%#\[\]\-_.,~@^]*[a-z0-9)=#/]?)?" + _
-                                    "(?<query>\?[a-z0-9!*'();:&=+$/%#\[\]\-_.,~]*[a-z0-9_&=#/])?)"
+        Const url As String = "(?<before>(?:[^\""':!=]|^|\:))" + _
+                                   "(?<url>(?<protocol>https?://)" + _
+                                   "(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" + _
+                                   "(?<path>/[a-z0-9!*'();:&=+$/%#\[\]\-_.,~@^]*[a-z0-9)=#/]?)?" + _
+                                   "(?<query>\?[a-z0-9!*'();:&=+$/%#\[\]\-_.,~]*[a-z0-9_&=#/])?)"
 
         Const nico As String = "^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$"
 
@@ -7663,7 +7671,7 @@ RETRY:
 
     Private Class GetApiInfoArgs
         Public tw As Twitter
-        Public info As Twitter.ApiInfo
+        Public info As ApiInfo
     End Class
 
     Private Sub GetApiInfo_Dowork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
@@ -7672,7 +7680,7 @@ RETRY:
     End Sub
 
     Private Sub ApiInfoMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApiInfoMenuItem.Click
-        Dim info As New Twitter.ApiInfo
+        Dim info As New ApiInfo
         Dim tmp As String
         Dim args As New GetApiInfoArgs With {.tw = tw, .info = info}
 
@@ -7703,33 +7711,29 @@ RETRY:
     End Sub
 
     Private Sub FollowCommand(ByVal id As String)
-        Try
-            Using inputName As New InputTabName()
-                inputName.FormTitle = "Follow"
-                inputName.FormDescription = My.Resources.FRMessage1
-                inputName.TabName = id
-                If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
-                   Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
-                    Dim arg As New FollowRemoveCommandArgs
-                    arg.tw = tw
-                    arg.id = inputName.TabName.Trim()
-                    Using _info As New FormInfo(My.Resources.FollowCommandText1, _
-                                                AddressOf FollowCommand_DoWork, _
-                                                Nothing, _
-                                                arg)
-                        _info.ShowDialog()
-                        Dim ret As String = DirectCast(_info.Result, String)
-                        If Not String.IsNullOrEmpty(ret) Then
-                            MessageBox.Show(My.Resources.FRMessage2 + ret)
-                        Else
-                            MessageBox.Show(My.Resources.FRMessage3)
-                        End If
-                    End Using
-                End If
-            End Using
-        Finally
-            SetStatusLabel()
-        End Try
+        Using inputName As New InputTabName()
+            inputName.FormTitle = "Follow"
+            inputName.FormDescription = My.Resources.FRMessage1
+            inputName.TabName = id
+            If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
+               Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
+                Dim arg As New FollowRemoveCommandArgs
+                arg.tw = tw
+                arg.id = inputName.TabName.Trim()
+                Using _info As New FormInfo(My.Resources.FollowCommandText1, _
+                                            AddressOf FollowCommand_DoWork, _
+                                            Nothing, _
+                                            arg)
+                    _info.ShowDialog()
+                    Dim ret As String = DirectCast(_info.Result, String)
+                    If Not String.IsNullOrEmpty(ret) Then
+                        MessageBox.Show(My.Resources.FRMessage2 + ret)
+                    Else
+                        MessageBox.Show(My.Resources.FRMessage3)
+                    End If
+                End Using
+            End If
+        End Using
     End Sub
 
     Private Sub RemoveCommandMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveCommandMenuItem.Click
@@ -7749,40 +7753,36 @@ RETRY:
     End Sub
 
     Private Sub RemoveCommand(ByVal id As String, ByVal skipInput As Boolean)
-        Try
-            Dim arg As New FollowRemoveCommandArgs
-            arg.tw = tw
-            arg.id = id
-            If Not skipInput Then
-                Using inputName As New InputTabName()
-                    inputName.FormTitle = "Unfollow"
-                    inputName.FormDescription = My.Resources.FRMessage1
-                    inputName.TabName = id
-                    If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
-                       Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
-                        arg.tw = tw
-                        arg.id = inputName.TabName.Trim()
-                    Else
-                        Exit Sub
-                    End If
-                End Using
-            End If
-
-            Using _info As New FormInfo(My.Resources.RemoveCommandText1, _
-                                        AddressOf RemoveCommand_DoWork, _
-                                        Nothing, _
-                                        arg)
-                _info.ShowDialog()
-                Dim ret As String = DirectCast(_info.Result, String)
-                If Not String.IsNullOrEmpty(ret) Then
-                    MessageBox.Show(My.Resources.FRMessage2 + ret)
+        Dim arg As New FollowRemoveCommandArgs
+        arg.tw = tw
+        arg.id = id
+        If Not skipInput Then
+            Using inputName As New InputTabName()
+                inputName.FormTitle = "Unfollow"
+                inputName.FormDescription = My.Resources.FRMessage1
+                inputName.TabName = id
+                If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
+                   Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
+                    arg.tw = tw
+                    arg.id = inputName.TabName.Trim()
                 Else
-                    MessageBox.Show(My.Resources.FRMessage3)
+                    Exit Sub
                 End If
             End Using
-        Finally
-            SetStatusLabel()
-        End Try
+        End If
+
+        Using _info As New FormInfo(My.Resources.RemoveCommandText1, _
+                                    AddressOf RemoveCommand_DoWork, _
+                                    Nothing, _
+                                    arg)
+            _info.ShowDialog()
+            Dim ret As String = DirectCast(_info.Result, String)
+            If Not String.IsNullOrEmpty(ret) Then
+                MessageBox.Show(My.Resources.FRMessage2 + ret)
+            Else
+                MessageBox.Show(My.Resources.FRMessage3)
+            End If
+        End Using
     End Sub
 
     Private Sub FriendshipMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FriendshipMenuItem.Click
@@ -7831,55 +7831,16 @@ RETRY:
     End Sub
 
     Private Sub ShowFriendship(ByVal id As String)
-        Try
-            Dim args As New ShowFriendshipArgs
-            args.tw = tw
-            Using inputName As New InputTabName()
-                inputName.FormTitle = "Show Friendships"
-                inputName.FormDescription = My.Resources.FRMessage1
-                inputName.TabName = id
-                If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
-                   Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
-                    Dim ret As String = ""
-                    args.ids.Add(New ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim))
-                    Using _info As New FormInfo(My.Resources.ShowFriendshipText1, _
-                                                AddressOf ShowFriendship_DoWork, _
-                                                Nothing, _
-                                                args)
-                        _info.ShowDialog()
-                        ret = DirectCast(_info.Result, String)
-                    End Using
-                    Dim result As String = ""
-                    If String.IsNullOrEmpty(ret) Then
-                        If args.ids(0).isFollowing Then
-                            result = My.Resources.GetFriendshipInfo1 + System.Environment.NewLine
-                        Else
-                            result = My.Resources.GetFriendshipInfo2 + System.Environment.NewLine
-                        End If
-                        If args.ids(0).isFollowed Then
-                            result += My.Resources.GetFriendshipInfo3
-                        Else
-                            result += My.Resources.GetFriendshipInfo4
-                        End If
-                        result = args.ids(0).id + My.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result
-                    Else
-                        result = ret
-                    End If
-                    MessageBox.Show(result)
-                End If
-            End Using
-        Finally
-            SetStatusLabel()
-        End Try
-    End Sub
-
-    Private Sub ShowFriendship(ByVal ids() As String)
-        Try
-            For Each id As String In ids
+        Dim args As New ShowFriendshipArgs
+        args.tw = tw
+        Using inputName As New InputTabName()
+            inputName.FormTitle = "Show Friendships"
+            inputName.FormDescription = My.Resources.FRMessage1
+            inputName.TabName = id
+            If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
+               Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
                 Dim ret As String = ""
-                Dim args As New ShowFriendshipArgs
-                args.tw = tw
-                args.ids.Add(New ShowFriendshipArgs.FriendshipInfo(id.Trim))
+                args.ids.Add(New ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim))
                 Using _info As New FormInfo(My.Resources.ShowFriendshipText1, _
                                             AddressOf ShowFriendship_DoWork, _
                                             Nothing, _
@@ -7888,40 +7849,71 @@ RETRY:
                     ret = DirectCast(_info.Result, String)
                 End Using
                 Dim result As String = ""
-                Dim fInfo As ShowFriendshipArgs.FriendshipInfo = args.ids(0)
-                Dim ff As String = ""
                 If String.IsNullOrEmpty(ret) Then
-                    ff = "  "
-                    If fInfo.isFollowing Then
-                        ff += My.Resources.GetFriendshipInfo1
+                    If args.ids(0).isFollowing Then
+                        result = My.Resources.GetFriendshipInfo1 + System.Environment.NewLine
                     Else
-                        ff += My.Resources.GetFriendshipInfo2
+                        result = My.Resources.GetFriendshipInfo2 + System.Environment.NewLine
                     End If
-                    ff += System.Environment.NewLine + "  "
-                    If fInfo.isFollowed Then
-                        ff += My.Resources.GetFriendshipInfo3
+                    If args.ids(0).isFollowed Then
+                        result += My.Resources.GetFriendshipInfo3
                     Else
-                        ff += My.Resources.GetFriendshipInfo4
+                        result += My.Resources.GetFriendshipInfo4
                     End If
-                    result += fInfo.id + My.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff
-                    If fInfo.isFollowing Then
-                        If MessageBox.Show( _
-                            "フォロー解除しますか?" + System.Environment.NewLine + result, "フォロー解除確認", _
-                            MessageBoxButtons.YesNo, _
-                            MessageBoxIcon.Question, _
-                            MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
-                            RemoveCommand(fInfo.id, True)
-                        End If
-                    Else
-                        MessageBox.Show(result)
+                    result = args.ids(0).id + My.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result
+                Else
+                    result = ret
+                End If
+                MessageBox.Show(result)
+            End If
+        End Using
+    End Sub
+
+    Private Sub ShowFriendship(ByVal ids() As String)
+        For Each id As String In ids
+            Dim ret As String = ""
+            Dim args As New ShowFriendshipArgs
+            args.tw = tw
+            args.ids.Add(New ShowFriendshipArgs.FriendshipInfo(id.Trim))
+            Using _info As New FormInfo(My.Resources.ShowFriendshipText1, _
+                                        AddressOf ShowFriendship_DoWork, _
+                                        Nothing, _
+                                        args)
+                _info.ShowDialog()
+                ret = DirectCast(_info.Result, String)
+            End Using
+            Dim result As String = ""
+            Dim fInfo As ShowFriendshipArgs.FriendshipInfo = args.ids(0)
+            Dim ff As String = ""
+            If String.IsNullOrEmpty(ret) Then
+                ff = "  "
+                If fInfo.isFollowing Then
+                    ff += My.Resources.GetFriendshipInfo1
+                Else
+                    ff += My.Resources.GetFriendshipInfo2
+                End If
+                ff += System.Environment.NewLine + "  "
+                If fInfo.isFollowed Then
+                    ff += My.Resources.GetFriendshipInfo3
+                Else
+                    ff += My.Resources.GetFriendshipInfo4
+                End If
+                result += fInfo.id + My.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff
+                If fInfo.isFollowing Then
+                    If MessageBox.Show( _
+                        "フォロー解除しますか?" + System.Environment.NewLine + result, "フォロー解除確認", _
+                        MessageBoxButtons.YesNo, _
+                        MessageBoxIcon.Question, _
+                        MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
+                        RemoveCommand(fInfo.id, True)
                     End If
                 Else
-                    MessageBox.Show(ret)
+                    MessageBox.Show(result)
                 End If
-            Next
-        Finally
-            SetStatusLabel()
-        End Try
+            Else
+                MessageBox.Show(ret)
+            End If
+        Next
     End Sub
 
     Private Sub OwnStatusMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OwnStatusMenuItem.Click
@@ -9162,63 +9154,55 @@ RETRY:
         Dim result As String = ""
         Dim xmlbuf As String = ""
         Dim args As New GetUserInfoArgs
-        Try
-            If ShowInputDialog Then
-                Using inputName As New InputTabName()
-                    inputName.FormTitle = "Show UserStatus"
-                    inputName.FormDescription = My.Resources.FRMessage1
-                    inputName.TabName = id
-                    If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
-                       Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
-                        id = inputName.TabName.Trim
-                        args.tw = tw
-                        args.id = id
-                        args.xmlbuf = xmlbuf
-                        Using _info As New FormInfo(My.Resources.doShowUserStatusText1, _
-                                                    AddressOf GetUserInfo_DoWork, _
-                                                    Nothing, _
-                                                    args)
-                            _info.ShowDialog()
-                            Dim ret As String = DirectCast(_info.Result, String)
-                            If String.IsNullOrEmpty(ret) Then
-                                doShowUserStatus(args.xmlbuf)
-                            Else
-                                MessageBox.Show(ret)
-                            End If
-                        End Using
-                    End If
-                End Using
-            Else
-                args.tw = tw
-                args.id = id
-                args.xmlbuf = xmlbuf
-                Using _info As New FormInfo(My.Resources.doShowUserStatusText1, _
-                                            AddressOf GetUserInfo_DoWork, _
-                                            Nothing, _
-                                            args)
-                    _info.ShowDialog()
-                    Dim ret As String = DirectCast(_info.Result, String)
-                    If String.IsNullOrEmpty(ret) Then
-                        doShowUserStatus(args.xmlbuf)
-                    Else
-                        MessageBox.Show(ret)
-                    End If
-                End Using
-            End If
-        Finally
-            SetStatusLabel()
-        End Try
+        If ShowInputDialog Then
+            Using inputName As New InputTabName()
+                inputName.FormTitle = "Show UserStatus"
+                inputName.FormDescription = My.Resources.FRMessage1
+                inputName.TabName = id
+                If inputName.ShowDialog() = Windows.Forms.DialogResult.OK AndAlso _
+                   Not String.IsNullOrEmpty(inputName.TabName.Trim()) Then
+                    id = inputName.TabName.Trim
+                    args.tw = tw
+                    args.id = id
+                    args.xmlbuf = xmlbuf
+                    Using _info As New FormInfo(My.Resources.doShowUserStatusText1, _
+                                                AddressOf GetUserInfo_DoWork, _
+                                                Nothing, _
+                                                args)
+                        _info.ShowDialog()
+                        Dim ret As String = DirectCast(_info.Result, String)
+                        If String.IsNullOrEmpty(ret) Then
+                            doShowUserStatus(args.xmlbuf)
+                        Else
+                            MessageBox.Show(ret)
+                        End If
+                    End Using
+                End If
+            End Using
+        Else
+            args.tw = tw
+            args.id = id
+            args.xmlbuf = xmlbuf
+            Using _info As New FormInfo(My.Resources.doShowUserStatusText1, _
+                                        AddressOf GetUserInfo_DoWork, _
+                                        Nothing, _
+                                        args)
+                _info.ShowDialog()
+                Dim ret As String = DirectCast(_info.Result, String)
+                If String.IsNullOrEmpty(ret) Then
+                    doShowUserStatus(args.xmlbuf)
+                Else
+                    MessageBox.Show(ret)
+                End If
+            End Using
+        End If
     End Sub
 
     Private Overloads Sub doShowUserStatus(ByVal xmldata As String)
-        Try
-            Using userinfo As New ShowUserInfo()
-                userinfo.XmlData = xmldata
-                userinfo.ShowDialog(Me)
-            End Using
-        Finally
-            SetStatusLabel()
-        End Try
+        Using userinfo As New ShowUserInfo()
+            userinfo.XmlData = xmldata
+            userinfo.ShowDialog(Me)
+        End Using
     End Sub
 
     Private Overloads Sub ShowUserStatus(ByVal id As String, ByVal ShowInputDialog As Boolean)
@@ -9292,23 +9276,19 @@ RETRY:
 
     Private Sub RtCountMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RtCountMenuItem.Click
         If _curPost IsNot Nothing Then
-            Try
-                Using _info As New FormInfo(My.Resources.RtCountMenuItem_ClickText1, _
+            Using _info As New FormInfo(My.Resources.RtCountMenuItem_ClickText1, _
                             AddressOf GetRetweet_DoWork)
-                    Dim retweet_count As Integer = 0
+                Dim retweet_count As Integer = 0
 
-                    ' ダイアログ表示
-                    _info.ShowDialog()
-                    retweet_count = CType(_info.Result, Integer)
-                    If retweet_count < 0 Then
-                        MessageBox.Show(My.Resources.RtCountText2)
-                    Else
-                        MessageBox.Show(retweet_count.ToString + My.Resources.RtCountText1)
-                    End If
-                End Using
-            Finally
-                SetStatusLabel()
-            End Try
+                ' ダイアログ表示
+                _info.ShowDialog()
+                retweet_count = CType(_info.Result, Integer)
+                If retweet_count < 0 Then
+                    MessageBox.Show(My.Resources.RtCountText2)
+                Else
+                    MessageBox.Show(retweet_count.ToString + My.Resources.RtCountText1)
+                End If
+            End Using
         End If
     End Sub
 
index 5b5ddf3..404401c 100644 (file)
     <Import Include="System.Windows.Forms" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="ApiInformation.vb" />
     <Compile Include="ApplicationEvents.vb" />
     <Compile Include="AtIdSupplement.Designer.vb">
       <DependentUpon>AtIdSupplement.vb</DependentUpon>
index f23ec9a..fc8d432 100644 (file)
@@ -79,7 +79,7 @@ Public Class Twitter
         Dim res As HttpStatusCode
         Dim content As String = ""
 
-        _infoapi.Initialize()
+        TwitterApiInfo.Initialize()
         Try
             res = twCon.AuthUserAndPass(username, password)
         Catch ex As Exception
@@ -121,7 +121,7 @@ Public Class Twitter
         If String.IsNullOrEmpty(token) OrElse String.IsNullOrEmpty(tokenSecret) OrElse String.IsNullOrEmpty(username) Then
             Twitter.AccountState = ACCOUNT_STATE.Invalid
         End If
-        _infoapi.Initialize()
+        TwitterApiInfo.Initialize()
         twCon.Initialize(token, tokenSecret, username)
         _uid = username.ToLower
         _UserIdNo = ""
@@ -132,7 +132,7 @@ Public Class Twitter
         If String.IsNullOrEmpty(username) OrElse String.IsNullOrEmpty(password) Then
             Twitter.AccountState = ACCOUNT_STATE.Invalid
         End If
-        _infoapi.Initialize()
+        TwitterApiInfo.Initialize()
         twCon.Initialize(username, password)
         _uid = username.ToLower
         _UserIdNo = ""
@@ -2416,77 +2416,6 @@ Public Class Twitter
         Return sb.ToString
     End Function
 
-    Public ReadOnly Property RemainCountApi() As Integer
-        Get
-            If twCon.RemainCountApi <> -1 Then
-                _infoapi.Initialize()
-                Return twCon.RemainCountApi
-            Else
-                If _infoapi.RemainCount <> -1 Then
-                    Return _infoapi.RemainCount
-                Else
-                    Return -1
-                End If
-            End If
-        End Get
-    End Property
-
-    Public ReadOnly Property UpperCountApi() As Integer
-        Get
-            If twCon.UpperCountApi <> -1 Then
-                _infoapi.Initialize()
-                Return twCon.UpperCountApi
-            Else
-                If _infoapi.MaxCount <> -1 Then
-                    Return _infoapi.MaxCount
-                Else
-                    Return -1
-                End If
-            End If
-        End Get
-    End Property
-
-    Public ReadOnly Property ResetTimeApi() As DateTime
-        Get
-            If twCon.ResetTimeApi.ToBinary <> 0 Then
-                _infoapi.Initialize()
-                Return twCon.ResetTimeApi
-            Else
-                If _infoapi.ResetTime.ToBinary <> 0 Then
-                    Return _infoapi.ResetTime
-                Else
-                    Return New DateTime
-                End If
-            End If
-        End Get
-    End Property
-
-    Public Class ApiInfo
-        Public MaxCount As Integer = -1
-        Public RemainCount As Integer = -1
-        Public ResetTime As New DateTime
-        Public ResetTimeInSeconds As Integer = -1
-        Public UsingCount As Integer = -1
-
-        Public Sub Initialize()
-            Me.MaxCount = -1
-            Me.RemainCount = -1
-            Me.ResetTime = New DateTime
-            Me.ResetTimeInSeconds = -1
-            'UsingCountは初期化対象外
-        End Sub
-
-        Public Function ConvertResetTimeInSecondsToResetTime(ByVal seconds As Integer) As DateTime
-            If seconds >= 0 Then
-                Return System.TimeZone.CurrentTimeZone.ToLocalTime((New DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(seconds))
-            Else
-                Return New DateTime
-            End If
-        End Function
-    End Class
-
-    Private _infoapi As New ApiInfo
-
     Public Function GetInfoApi(ByVal info As ApiInfo) As Boolean
         If Twitter.AccountState <> ACCOUNT_STATE.Valid Then Return True
 
@@ -2497,8 +2426,7 @@ Public Class Twitter
         Try
             res = twCon.RateLimitStatus(content)
         Catch ex As Exception
-            _infoapi.Initialize()
-            info.Initialize()
+            TwitterApiInfo.Initialize()
             Return False
         End Try
 
@@ -2507,19 +2435,22 @@ Public Class Twitter
         Dim xdoc As New XmlDocument
         Try
             xdoc.LoadXml(content)
-            info.MaxCount = Integer.Parse(xdoc.SelectSingleNode("/hash/hourly-limit").InnerText)
-            info.RemainCount = Integer.Parse(xdoc.SelectSingleNode("/hash/remaining-hits").InnerText)
-            info.ResetTime = DateTime.Parse(xdoc.SelectSingleNode("/hash/reset-time").InnerText)
-            info.ResetTimeInSeconds = Integer.Parse(xdoc.SelectSingleNode("/hash/reset-time-in-seconds").InnerText)
-
-            _infoapi.MaxCount = info.MaxCount
-            _infoapi.RemainCount = info.RemainCount
-            _infoapi.ResetTime = info.ResetTime
-            _infoapi.ResetTimeInSeconds = info.ResetTimeInSeconds
+            Dim arg As New ApiInformationChangedEventArgs
+
+            arg.ApiInfo.MaxCount = Integer.Parse(xdoc.SelectSingleNode("/hash/hourly-limit").InnerText)
+            arg.ApiInfo.RemainCount = Integer.Parse(xdoc.SelectSingleNode("/hash/remaining-hits").InnerText)
+            arg.ApiInfo.ResetTime = DateTime.Parse(xdoc.SelectSingleNode("/hash/reset-time").InnerText)
+            arg.ApiInfo.ResetTimeInSeconds = Integer.Parse(xdoc.SelectSingleNode("/hash/reset-time-in-seconds").InnerText)
+
+            info.MaxCount = arg.ApiInfo.MaxCount
+            info.RemainCount = arg.ApiInfo.RemainCount
+            info.ResetTime = arg.ApiInfo.ResetTime
+            info.ResetTimeInSeconds = arg.ApiInfo.ResetTimeInSeconds
+
+            RaiseEvent ApiInformationChanged(Me, arg)
             Return True
         Catch ex As Exception
-            _infoapi.Initialize()
-            info.Initialize()
+            TwitterApiInfo.Initialize()
             Return False
         End Try
     End Function
@@ -2547,4 +2478,8 @@ Public Class Twitter
 
     Public Property UserIdNo As String
 
+    Public Event ApiInformationChanged(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs)
+
+    Private Sub Twitter_ApiInformationChanged(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs) Handles Me.ApiInformationChanged
+    End Sub
 End Class