svnno****@sourc*****
svnno****@sourc*****
2010年 12月 2日 (木) 15:15:02 JST
Revision: 1151 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1151 Author: kiri_feather Date: 2010-12-02 15:15:02 +0900 (Thu, 02 Dec 2010) Log Message: ----------- USのTrack、AllAt設定保存追加。 USイベントの解析方法変更 Modified Paths: -------------- trunk/Tween/Setting/SettingCommon.vb trunk/Tween/Tween.vb trunk/Tween/Twitter.vb -------------- next part -------------- Modified: trunk/Tween/Setting/SettingCommon.vb =================================================================== --- trunk/Tween/Setting/SettingCommon.vb 2010-12-02 00:36:30 UTC (rev 1150) +++ trunk/Tween/Setting/SettingCommon.vb 2010-12-02 06:15:02 UTC (rev 1151) @@ -172,4 +172,6 @@ Public FirstCountApi As Integer = 100 Public SearchCountApi As Integer = 100 Public FavoritesCountApi As Integer = 40 + Public TrackWord As String = "" + Public AllAtReply As Boolean = False End Class Modified: trunk/Tween/Tween.vb =================================================================== --- trunk/Tween/Tween.vb 2010-12-02 00:36:30 UTC (rev 1150) +++ trunk/Tween/Tween.vb 2010-12-02 06:15:02 UTC (rev 1151) @@ -885,6 +885,10 @@ ShortUrl.BitlyKey = SettingDialog.BitlyPwd HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl HttpTwitter.TwitterSearchUrl = _cfgCommon.TwitterSearchUrl + tw.TrackWord = _cfgCommon.TrackWord + TrackToolStripMenuItem.Checked = Not String.IsNullOrEmpty(tw.TrackWord) + tw.AllAtReply = _cfgCommon.AllAtReply + AllrepliesToolStripMenuItem.Checked = tw.AllAtReply Outputz.Key = SettingDialog.OutputzKey Outputz.Enabled = SettingDialog.OutputzEnabled @@ -5881,6 +5885,8 @@ _cfgCommon.FirstCountApi = SettingDialog.FirstCountApi _cfgCommon.SearchCountApi = SettingDialog.SearchCountApi _cfgCommon.FavoritesCountApi = SettingDialog.FavoritesCountApi + _cfgCommon.TrackWord = tw.TrackWord + _cfgCommon.AllAtReply = tw.AllAtReply _cfgCommon.Save() End SyncLock @@ -9870,7 +9876,7 @@ Private ReadOnly Property IsReceivedUserStream As Boolean Get - Static lastTime As DateTime = Now + Static lastTime As DateTime Dim changed As Boolean = (lastTime.CompareTo(tw.LastReceivedUserStream) < 0) lastTime = tw.LastReceivedUserStream Return changed @@ -9888,15 +9894,33 @@ End Sub Private Sub TrackToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackToolStripMenuItem.Click - Static track As String - track = InputBox("追跡するキーワードを入力してください") - tw.StopUserStream() - tw.StartUserStream(AllrepliesToolStripMenuItem.Checked, track) - TrackToolStripMenuItem.Checked = Not String.IsNullOrEmpty(track) + Static inputTrack As String = "" + If TrackToolStripMenuItem.Checked Then + Using inputForm As New InputTabName + inputForm.TabName = inputTrack + inputForm.FormTitle = "Input track word" + inputForm.FormDescription = "Track word" + If inputForm.ShowDialog() <> Windows.Forms.DialogResult.OK Then + TrackToolStripMenuItem.Checked = False + Exit Sub + End If + inputTrack = inputForm.TabName.Trim() + End Using + If Not inputTrack.Equals(tw.TrackWord) Then + tw.TrackWord = inputTrack + Me._modifySettingCommon = True + TrackToolStripMenuItem.Checked = Not String.IsNullOrEmpty(inputTrack) + tw.ReconnectUserStream() + End If + Else + tw.TrackWord = "" + tw.ReconnectUserStream() + End If End Sub - Private Sub AllrepliesToolStripMenuItem_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllrepliesToolStripMenuItem.CheckStateChanged - tw.StopUserStream() - tw.StartUserStream(AllrepliesToolStripMenuItem.Checked, "") + Private Sub AllrepliesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllrepliesToolStripMenuItem.Click + tw.AllAtReply = AllrepliesToolStripMenuItem.Checked + Me._modifySettingCommon = True + tw.ReconnectUserStream() End Sub End Class Modified: trunk/Tween/Twitter.vb =================================================================== --- trunk/Tween/Twitter.vb 2010-12-02 00:36:30 UTC (rev 1150) +++ trunk/Tween/Twitter.vb 2010-12-02 06:15:02 UTC (rev 1151) @@ -2768,8 +2768,9 @@ Private Sub Twitter_ApiInformationChanged(ByVal sender As Object, ByVal e As ApiInformationChangedEventArgs) Handles Me.ApiInformationChanged End Sub + Public Property TrackWord As String = "" + Public Property AllAtReply As Boolean = False - Public Event NewPostFromStream() Public Event UserStreamStarted() Public Event UserStreamStopped() @@ -2792,7 +2793,7 @@ If userStream IsNot Nothing Then Return userStream.LastTime Else - Return New DateTime + Return Now End If End Get End Property @@ -2800,72 +2801,47 @@ Private Sub userStream_StatusArrived(ByVal line As String) Handles userStream.StatusArrived If _streamBypass OrElse String.IsNullOrEmpty(line) Then Exit Sub - Dim idx As Integer = line.IndexOf("{""") - Dim idx2 As Integer = line.IndexOf(""":") - If idx = 0 AndAlso idx2 > 0 Then - Try - Dim eventname As String = line.Substring(idx + 2, idx2 - 2) - If eventname.Equals("friends") Then - Debug.Print("friends") - Exit Sub - ElseIf eventname.Equals("delete") Then - Debug.Print("delete") - If line.Contains("direct_message") Then - Dim data As TwitterDataModel.DeleteDirectmessageEvent = CreateDataFromJson(Of TwitterDataModel.DeleteDirectmessageEvent)(line) - RaiseEvent PostDeleted(data.Event.Directmessage.Id) - Else - Dim data As TwitterDataModel.DeleteEvent = CreateDataFromJson(Of TwitterDataModel.DeleteEvent)(line) - RaiseEvent PostDeleted(data.Event.Status.Id) - End If - Exit Sub - ElseIf eventname.Equals("limit") Then - Debug.Print("limit") - Exit Sub - ElseIf eventname.Equals("target") Then - Dim data As TwitterDataModel.EventData = CreateDataFromJson(Of TwitterDataModel.EventData)(line) - Select Case Array.IndexOf(EventNameTable, data.Event) - Case 0 ' favorite - Debug.Print("Event:favorite") - Case 1 ' unfavorite - Debug.Print("Event:unfavorite") - Case 2 ' follow - Debug.Print("Event:follow") - Case 3 ' list_member_added - Debug.Print("Event:list_member_added") - Case 4 ' list_member_removed - Debug.Print("Event:list_member_removed") - Case Else ' その他イベント - TraceOut("Unknown Event:" + data.Event + Environment.NewLine + line) - End Select - Exit Sub - ElseIf Not eventname.Equals("place") AndAlso Not eventname.Equals("in_reply_to_status_id_str") Then - Debug.Print(eventname) + Dim isDm As Boolean = False + + Using jsonReader As XmlDictionaryReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(line), XmlDictionaryReaderQuotas.Max) + Dim xElm As XElement = XElement.Load(jsonReader) + If xElm.Element("friends") IsNot Nothing Then + Debug.Print("friends") + Exit Sub + ElseIf xElm.Element("delete") IsNot Nothing Then + Debug.Print("delete") + If xElm.Element("delete").Element("direct_message") IsNot Nothing Then + RaiseEvent PostDeleted(CLng(xElm.Element("delete").Element("direct_message").Element("id").Value)) + Else + RaiseEvent PostDeleted(CLng(xElm.Element("delete").Element("status").Element("id").Value)) End If - Catch ex As SerializationException - TraceOut(ex.Message + Environment.NewLine + line) - Catch ex As Exception - TraceOut(line) - End Try + Exit Sub + ElseIf xElm.Element("limit") IsNot Nothing Then + Debug.Print("limit") + Exit Sub + ElseIf xElm.Element("event") IsNot Nothing Then + Debug.Print("event: " + xElm.Element("event").Value) + If Array.IndexOf(EventNameTable, xElm.Element("event").Name.LocalName) = -1 Then + TraceOut("Unknown Event:" + xElm.Element("event").Name.LocalName + Environment.NewLine + line) + End If + Exit Sub + ElseIf xElm.Element("direct_message") IsNot Nothing Then + Debug.Print("direct_message") + isDm = True + End If + End Using - End If - Dim res As New StringBuilder res.Length = 0 res.Append("[") res.Append(line) res.Append("]") - Try - If line.StartsWith("{""direct_message"":") Then - CreateDirectMessagesFromJson(res.ToString, WORKERTYPE.UserStream, False) - Else - CreatePostsFromJson(res.ToString, WORKERTYPE.Timeline, Nothing, False, Nothing, Nothing) - End If - Catch ex As SerializationException - TraceOut(ex.Message + Environment.NewLine + line) - Catch ex As Exception - TraceOut(line) - End Try + If isDm Then + CreateDirectMessagesFromJson(res.ToString, WORKERTYPE.UserStream, False) + Else + CreatePostsFromJson(res.ToString, WORKERTYPE.Timeline, Nothing, False, Nothing, Nothing) + End If RaiseEvent NewPostFromStream() End Sub @@ -2896,16 +2872,12 @@ End Property Public Overloads Sub StartUserStream() - StartUserStream(False, "") - End Sub - - Public Overloads Sub StartUserStream(ByVal allAtReplies As Boolean, ByVal trackWords As String) If userStream IsNot Nothing Then StopUserStream() Else Me._streamBypass = False userStream = New TwitterUserstream(twCon) - userStream.Start(allAtReplies, trackWords) + userStream.Start(Me.AllAtReply, Me.TrackWord) End If End Sub @@ -2951,13 +2923,9 @@ twCon = DirectCast(twitterConnection.Clone(), HttpTwitter) End Sub - Public Overloads Sub Start(ByVal allAtReplies As Boolean, ByVal trackwords As String) + Public Sub Start(ByVal allAtReplies As Boolean, ByVal trackwords As String) Me.AllAtReplies = allAtReplies Me.TrackWords = trackwords - Me.Start() - End Sub - - Public Overloads Sub Start() _streamActive = True If _streamThread IsNot Nothing AndAlso _streamThread.IsAlive Then Exit Sub _streamThread = New Thread(AddressOf UserStreamLoop) @@ -2990,7 +2958,7 @@ End Set End Property - Public Property LastTime As DateTime + Public Property LastTime As DateTime = Now Private Sub UserStreamLoop() Dim st As Stream = Nothing