svnno****@sourc*****
svnno****@sourc*****
2010年 11月 29日 (月) 12:14:17 JST
Revision: 1125 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1125 Author: syo68k Date: 2010-11-29 12:14:17 +0900 (Mon, 29 Nov 2010) Log Message: ----------- メニューからUserStreamを停止させると帰ってこなくなるのを修正 Modified Paths: -------------- branches/UserStream/Tween/Connection/HttpConnectionBasic.vb branches/UserStream/Tween/Connection/HttpConnectionOAuth.vb branches/UserStream/Tween/Connection/HttpTwitter.vb branches/UserStream/Tween/Connection/IHttpConnection.vb branches/UserStream/Tween/Twitter.vb -------------- next part -------------- Modified: branches/UserStream/Tween/Connection/HttpConnectionBasic.vb =================================================================== --- branches/UserStream/Tween/Connection/HttpConnectionBasic.vb 2010-11-29 01:44:59 UTC (rev 1124) +++ branches/UserStream/Tween/Connection/HttpConnectionBasic.vb 2010-11-29 03:14:17 UTC (rev 1125) @@ -26,7 +26,13 @@ '''</summary> Private credential As String = "" + '''<summary> + '''認証完了時の応答からuserIdentKey情報に基づいて取得するユーザー情報 + '''</summary> + Private streamReq As HttpWebRequest = Nothing + + '''<summary> '''BASIC認証で指定のURLとHTTP通信を行い、結果を返す '''</summary> '''<param name="method">HTTP通信メソッド(GET/HEAD/POST/PUT/DELETE)</param> @@ -114,15 +120,13 @@ '認証済かチェック If String.IsNullOrEmpty(Me.credential) Then Return HttpStatusCode.Unauthorized - Dim webReq As HttpWebRequest = CreateRequest(method, _ - requestUri, _ - param, _ - False) + streamReq = CreateRequest(method, requestUri, param, False) + 'BASIC認証用ヘッダを付加 - AppendApiInfo(webReq) + AppendApiInfo(streamReq) Try - Dim webRes As HttpWebResponse = CType(webReq.GetResponse(), HttpWebResponse) + Dim webRes As HttpWebResponse = CType(streamReq.GetResponse(), HttpWebResponse) content = webRes.GetResponseStream() Return webRes.StatusCode Catch ex As WebException @@ -135,6 +139,14 @@ End Function + Public Sub RequestAbort() Implements IHttpConnection.RequestAbort + Try + If streamReq IsNot Nothing Then + streamReq.Abort() + End If + Catch ex As Exception + End Try + End Sub '''<summary> '''BASIC認証とREST APIで必要なヘッダを付加 Modified: branches/UserStream/Tween/Connection/HttpConnectionOAuth.vb =================================================================== --- branches/UserStream/Tween/Connection/HttpConnectionOAuth.vb 2010-11-29 01:44:59 UTC (rev 1124) +++ branches/UserStream/Tween/Connection/HttpConnectionOAuth.vb 2010-11-29 03:14:17 UTC (rev 1125) @@ -57,6 +57,11 @@ Private authorizedUsername As String = "" '''<summary> + '''認証完了時の応答からuserIdentKey情報に基づいて取得するユーザー情報 + '''</summary> + Private streamReq As HttpWebRequest = Nothing + + '''<summary> '''OAuth認証で指定のURLとHTTP通信を行い、結果を返す '''</summary> '''<param name="method">HTTP通信メソッド(GET/HEAD/POST/PUT/DELETE)</param> @@ -144,15 +149,12 @@ '認証済かチェック If String.IsNullOrEmpty(token) Then Return HttpStatusCode.Unauthorized - Dim webReq As HttpWebRequest = CreateRequest(method, _ - requestUri, _ - param, _ - False) + streamReq = CreateRequest(method, requestUri, param, False) 'OAuth認証ヘッダを付加 - AppendOAuthInfo(webReq, param, token, tokenSecret) + AppendOAuthInfo(streamReq, param, token, tokenSecret) Try - Dim webRes As HttpWebResponse = CType(webReq.GetResponse(), HttpWebResponse) + Dim webRes As HttpWebResponse = CType(streamReq.GetResponse(), HttpWebResponse) content = webRes.GetResponseStream() Return webRes.StatusCode Catch ex As WebException @@ -165,7 +167,16 @@ End Function + Public Sub RequestAbort() Implements IHttpConnection.RequestAbort + Try + If streamReq IsNot Nothing Then + streamReq.Abort() + End If + Catch ex As Exception + End Try + End Sub + #Region "認証処理" '''<summary> '''OAuth認証の開始要求(リクエストトークン取得)。PIN入力用の前段 Modified: branches/UserStream/Tween/Connection/HttpTwitter.vb =================================================================== --- branches/UserStream/Tween/Connection/HttpTwitter.vb 2010-11-29 01:44:59 UTC (rev 1124) +++ branches/UserStream/Tween/Connection/HttpTwitter.vb 2010-11-29 03:14:17 UTC (rev 1125) @@ -698,4 +698,8 @@ param, _ content) End Function + + Public Sub RequestAbort() + httpCon.RequestAbort() + End Sub End Class Modified: branches/UserStream/Tween/Connection/IHttpConnection.vb =================================================================== --- branches/UserStream/Tween/Connection/IHttpConnection.vb 2010-11-29 01:44:59 UTC (rev 1124) +++ branches/UserStream/Tween/Connection/IHttpConnection.vb 2010-11-29 03:14:17 UTC (rev 1125) @@ -23,6 +23,8 @@ ByVal headerInfo As Dictionary(Of String, String), _ ByVal callback As CallbackDelegate) As HttpStatusCode + Sub RequestAbort() + Function Authenticate(ByVal url As Uri, ByVal username As String, ByVal password As String) As HttpStatusCode ReadOnly Property AuthUsername() As String Modified: branches/UserStream/Tween/Twitter.vb =================================================================== --- branches/UserStream/Tween/Twitter.vb 2010-11-29 01:44:59 UTC (rev 1124) +++ branches/UserStream/Tween/Twitter.vb 2010-11-29 03:14:17 UTC (rev 1125) @@ -2835,6 +2835,9 @@ "list_member_removed" } + + + Private Sub UserStreamLoop() Dim st As Stream = Nothing Dim sr As StreamReader = Nothing @@ -2923,7 +2926,10 @@ ExceptionOut(ex) Finally _streamActive = False - If sr IsNot Nothing Then sr.BaseStream.Close() + If sr IsNot Nothing Then + twCon.RequestAbort() + sr.BaseStream.Close() + End If RaiseEvent UserStreamStopped() If isRetry Then Thread.Sleep(10 * 1000)