svnno****@sourc*****
svnno****@sourc*****
2010年 11月 30日 (火) 19:02:01 JST
Revision: 1141 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1141 Author: kiri_feather Date: 2010-11-30 19:02:01 +0900 (Tue, 30 Nov 2010) Log Message: ----------- DataModel関連の命名変更 Deleteイベントに対応 デシリアライズ用のジェネリックメソッド追加 Modified Paths: -------------- branches/UserStream/Tween/DataModel.vb branches/UserStream/Tween/Tween.vb branches/UserStream/Tween/Twitter.vb -------------- next part -------------- Modified: branches/UserStream/Tween/DataModel.vb =================================================================== --- branches/UserStream/Tween/DataModel.vb 2010-11-30 02:41:01 UTC (rev 1140) +++ branches/UserStream/Tween/DataModel.vb 2010-11-30 10:02:01 UTC (rev 1141) @@ -1,205 +1,218 @@ Imports System.Runtime.InteropServices Imports System.Runtime.Serialization -Public Class DataModel +Public Class TwitterDataModel <DataContract()> _ - Public Class urls - <DataMember(Name:="urls")> Public urls As String - <DataMember(Name:="indices")> Public indices(2) As Integer + Public Class Urls + <DataMember(Name:="urls")> Public Urls As String + <DataMember(Name:="indices")> Public Indices(2) As Integer End Class <DataContract()> _ - Public Class hashtags - <DataMember(Name:="indices")> Public indices(2) As Integer - <DataMember(Name:="text")> Public text As String + Public Class Hashtags + <DataMember(Name:="indices")> Public Indices(2) As Integer + <DataMember(Name:="text")> Public Text As String End Class <DataContract()> _ - Public Class user_mentions - <DataMember(Name:="indices")> Public indices(2) As Integer - <DataMember(Name:="screen_name")> Public screen_name As String - <DataMember(Name:="name")> Public _name As String - <DataMember(Name:="id")> Public id As Int64 + Public Class UserMentions + <DataMember(Name:="indices")> Public Indices(2) As Integer + <DataMember(Name:="screen_name")> Public ScreenName As String + <DataMember(Name:="name")> Public Name As String + <DataMember(Name:="id")> Public Id As Int64 End Class <DataContract()> _ - Public Class entities - <DataMember(Name:="urls")> Public urls() As urls - <DataMember(Name:="hashtags")> Public hashtags() As hashtags - <DataMember(Name:="user_mentions")> Public user_mentions() As user_mentions + Public Class Entities + <DataMember(Name:="urls")> Public Urls() As Urls + <DataMember(Name:="hashtags")> Public Hashtags() As Hashtags + <DataMember(Name:="user_mentions")> Public UserMentions() As UserMentions End Class <DataContract()> _ - Public Class user - <DataMember(Name:="statuses_count")> Public statuses_count As Int64 - <DataMember(Name:="profile_sidebar_fill_color")> Public profile_sidebar_fill_color As String - <DataMember(Name:="show_all_inline_media")> Public show_all_inline_media As Boolean - <DataMember(Name:="profile_use_background_image")> Public profile_use_background_image As Boolean - <DataMember(Name:="contributors_enabled")> Public contributors_enabled As Boolean - <DataMember(Name:="profile_sidebar_border_color")> Public profile_sidebar_border_color As String - <DataMember(Name:="location")> Public location As String - <DataMember(Name:="geo_enabled")> Public geo_enabled As Boolean - <DataMember(Name:="description")> Public description As String - <DataMember(Name:="friends_count")> Public friends_count As Integer - <DataMember(Name:="verified")> Public verified As Boolean - <DataMember(Name:="favourites_count")> Public favourites_count As Integer - <DataMember(Name:="created_at")> Public created_at As String - <DataMember(Name:="profile_background_color")> Public profile_background_color As String - <DataMember(Name:="follow_request_sent")> Public follow_request_sent As String - <DataMember(Name:="time_zone")> Public time_zone As String - <DataMember(Name:="followers_count")> Public followers_count As Integer - <DataMember(Name:="url")> Public url As String - <DataMember(Name:="profile_image_url")> Public profile_image_url As String - <DataMember(Name:="notifications")> Public notifications As String - <DataMember(Name:="profile_text_color")> Public profile_text_color As String - <DataMember(Name:="protected")> Public [protected] As Boolean - <DataMember(Name:="id_str")> Public id_str As String - <DataMember(Name:="lang")> Public lang As String - <DataMember(Name:="profile_background_image_url")> Public profile_background_image_url As String - <DataMember(Name:="screen_name")> Public screen_name As String - <DataMember(Name:="name")> Public _name As String - <DataMember(Name:="following")> Public following As String - <DataMember(Name:="profile_link_color")> Public profile_link_color As String - <DataMember(Name:="id")> Public id As Int64 - <DataMember(Name:="listed_count")> Public listed_count As Integer - <DataMember(Name:="profile_background_tile")> Public profile_background_tile As Boolean - <DataMember(Name:="utc_offset")> Public utc_offset As String - <DataMember(Name:="place", IsRequired:=False)> Public place As place + Public Class User + <DataMember(Name:="statuses_count")> Public StatusesCount As Int64 + <DataMember(Name:="profile_sidebar_fill_color")> Public ProfileSidebarFillColor As String + <DataMember(Name:="show_all_inline_media")> Public ShowAllInlineMedia As Boolean + <DataMember(Name:="profile_use_background_image")> Public ProfileUseBackgroundImage As Boolean + <DataMember(Name:="contributors_enabled")> Public ContributorsEnabled As Boolean + <DataMember(Name:="profile_sidebar_border_color")> Public ProfileSidebarBorderColor As String + <DataMember(Name:="location")> Public Location As String + <DataMember(Name:="geo_enabled")> Public GeoEnabled As Boolean + <DataMember(Name:="description")> Public Description As String + <DataMember(Name:="friends_count")> Public FriendsCount As Integer + <DataMember(Name:="verified")> Public Verified As Boolean + <DataMember(Name:="favourites_count")> Public FavouritesCount As Integer + <DataMember(Name:="created_at")> Public CreatedAt As String + <DataMember(Name:="profile_background_color")> Public ProfileBackgroundColor As String + <DataMember(Name:="follow_request_sent")> Public FollowRequestSent As String + <DataMember(Name:="time_zone")> Public TimeZone As String + <DataMember(Name:="followers_count")> Public FollowersCount As Integer + <DataMember(Name:="url")> Public Url As String + <DataMember(Name:="profile_image_url")> Public ProfileImageUrl As String + <DataMember(Name:="notifications")> Public Notifications As String + <DataMember(Name:="profile_text_color")> Public ProfileTextColor As String + <DataMember(Name:="protected")> Public [Protected] As Boolean + <DataMember(Name:="id_str")> Public IdStr As String + <DataMember(Name:="lang")> Public Lang As String + <DataMember(Name:="profile_background_image_url")> Public ProfileBackgroundImageUrl As String + <DataMember(Name:="screen_name")> Public ScreenName As String + <DataMember(Name:="name")> Public Name As String + <DataMember(Name:="following")> Public Following As String + <DataMember(Name:="profile_link_color")> Public ProfileLinkColor As String + <DataMember(Name:="id")> Public Id As Int64 + <DataMember(Name:="listed_count")> Public ListedCount As Integer + <DataMember(Name:="profile_background_tile")> Public ProfileBackgroundTile As Boolean + <DataMember(Name:="utc_offset")> Public UtcOffset As String + <DataMember(Name:="place", IsRequired:=False)> Public Place As Place End Class <DataContract()> _ - Public Class coordinates - <DataMember(Name:="type", IsRequired:=False)> Public type As String - <DataMember(Name:="coordinates", IsRequired:=False)> Public _coordinates(2) As Double + Public Class Coordinates + <DataMember(Name:="type", IsRequired:=False)> Public Type As String + <DataMember(Name:="coordinates", IsRequired:=False)> Public Coordinates(2) As Double End Class <DataContract()> _ - Public Class geo - <DataMember(Name:="type", IsRequired:=False)> Public type As String - <DataMember(Name:="coordinates", IsRequired:=False)> Public _coordinates(2) As Double + Public Class Geo + <DataMember(Name:="type", IsRequired:=False)> Public Type As String + <DataMember(Name:="coordinates", IsRequired:=False)> Public Coordinates(2) As Double End Class <DataContract()> _ - Public Class bounding_box - <DataMember(Name:="type", IsRequired:=False)> Public type As String - <DataMember(Name:="coordinates", IsRequired:=False)> Public _coordinates As List(Of List(Of Double())) + Public Class BoundingBox + <DataMember(Name:="type", IsRequired:=False)> Public Type As String + <DataMember(Name:="coordinates", IsRequired:=False)> Public Coordinates As List(Of List(Of Double())) End Class <DataContract()> _ - Public Class attributes - <DataMember(Name:="street_address", IsRequired:=False)> Public street_address As String + Public Class Attributes + <DataMember(Name:="street_address", IsRequired:=False)> Public StreetAddress As String End Class <DataContract()> _ - Public Class place - <DataMember(Name:="url")> Public url As String - <DataMember(Name:="bounding_box", IsRequired:=False)> Public bounding_box As bounding_box - <DataMember(Name:="street_address", IsRequired:=False)> Public street_address As String - <DataMember(Name:="full_name")> Public full_name As String - <DataMember(Name:="name")> Public _name As String + Public Class Place + <DataMember(Name:="url")> Public Url As String + <DataMember(Name:="bounding_box", IsRequired:=False)> Public BoundingBox As BoundingBox + <DataMember(Name:="street_address", IsRequired:=False)> Public StreetAddress As String + <DataMember(Name:="full_name")> Public FullName As String + <DataMember(Name:="name")> Public Name As String '<DataMember(Name:="attributes", IsRequired:=False)> Public attributes As attributes - <DataMember(Name:="country_code", IsRequired:=False)> Public country_code As String - <DataMember(Name:="id")> Public id As String - <DataMember(Name:="country")> Public country As String - <DataMember(Name:="place_type")> Public place_type As String + <DataMember(Name:="country_code", IsRequired:=False)> Public CountryCode As String + <DataMember(Name:="id")> Public Id As String + <DataMember(Name:="country")> Public Country As String + <DataMember(Name:="place_type")> Public PlaceType As String End Class <DataContract()> _ - Public Class retweeted_status - <DataMember(Name:="coordinates", IsRequired:=False)> Public coordinates As coordinates - <DataMember(Name:="geo", IsRequired:=False)> Public geo As geo - <DataMember(Name:="in_reply_to_user_id")> Public in_reply_to_user_id As String - <DataMember(Name:="source")> Public source As String - <DataMember(Name:="user")> Public user As user - <DataMember(Name:="in_reply_to_screen_name")> Public in_reply_to_screen_name As String - <DataMember(Name:="created_at")> Public created_at As String - <DataMember(Name:="contributors")> Public contributors As String - <DataMember(Name:="favorited")> Public favorited As Boolean - <DataMember(Name:="truncated")> Public truncated As Boolean - <DataMember(Name:="id")> Public id As Int64 - <DataMember(Name:="annotations", IsRequired:=False)> Public annotations As String - <DataMember(Name:="place", IsRequired:=False)> Public place As place - <DataMember(Name:="in_reply_to_status_id")> Public in_reply_to_status_id As String - <DataMember(Name:="text")> Public text As String + Public Class RetweetedStatus + <DataMember(Name:="coordinates", IsRequired:=False)> Public Coordinates As Coordinates + <DataMember(Name:="geo", IsRequired:=False)> Public Geo As Geo + <DataMember(Name:="in_reply_to_user_id")> Public InReplyToUserId As String + <DataMember(Name:="source")> Public Source As String + <DataMember(Name:="user")> Public User As User + <DataMember(Name:="in_reply_to_screen_name")> Public InReplyToScreenName As String + <DataMember(Name:="created_at")> Public CreatedAt As String + <DataMember(Name:="contributors")> Public Contributors As String + <DataMember(Name:="favorited")> Public Favorited As Boolean + <DataMember(Name:="truncated")> Public Truncated As Boolean + <DataMember(Name:="id")> Public Id As Int64 + <DataMember(Name:="annotations", IsRequired:=False)> Public Annotations As String + <DataMember(Name:="place", IsRequired:=False)> Public Place As Place + <DataMember(Name:="in_reply_to_status_id")> Public InReplyToStatusId As String + <DataMember(Name:="text")> Public Text As String End Class <DataContract()> _ - Public Class status - <DataMember(Name:="in_reply_to_status_id_str")> Public in_reply_to_status_id_str As String - <DataMember(Name:="contributors", IsRequired:=False)> Public contributors As String - <DataMember(Name:="in_reply_to_screen_name")> Public in_reply_to_screen_name As String - <DataMember(Name:="in_reply_to_status_id")> Public in_reply_to_status_id As String - <DataMember(Name:="in_reply_to_user_id_str")> Public in_reply_to_user_id_str As String - <DataMember(Name:="retweet_count")> Public retweet_count As String - <DataMember(Name:="created_at")> Public created_at As String - <DataMember(Name:="geo", IsRequired:=False)> Public geo As geo - <DataMember(Name:="retweeted")> Public retweeted As Boolean - <DataMember(Name:="in_reply_to_user_id")> Public in_reply_to_user_id As String - <DataMember(Name:="source")> Public source As String - <DataMember(Name:="id_str")> Public id_str As String - <DataMember(Name:="coordinates", IsRequired:=False)> Public coordinates As coordinates - <DataMember(Name:="truncated")> Public truncated As Boolean - <DataMember(Name:="place", IsRequired:=False)> Public place As place - <DataMember(Name:="user")> Public user As user - <DataMember(Name:="retweeted_status", IsRequired:=False)> Public retweeted_status As retweeted_status - <DataMember(Name:="id")> Public id As Int64 - <DataMember(Name:="favorited")> Public favorited As Boolean - <DataMember(Name:="text")> Public text As String + Public Class Status + <DataMember(Name:="in_reply_to_status_id_str")> Public InReplyToStatusIdStr As String + <DataMember(Name:="contributors", IsRequired:=False)> Public Contributors As String + <DataMember(Name:="in_reply_to_screen_name")> Public InReplyToScreenName As String + <DataMember(Name:="in_reply_to_status_id")> Public InReplyToStatusId As String + <DataMember(Name:="in_reply_to_user_id_str")> Public InReplyToUserIdStr As String + <DataMember(Name:="retweet_count")> Public RetweetCount As String + <DataMember(Name:="created_at")> Public CreatedAt As String + <DataMember(Name:="geo", IsRequired:=False)> Public Geo As Geo + <DataMember(Name:="retweeted")> Public Retweeted As Boolean + <DataMember(Name:="in_reply_to_user_id")> Public InReplyToUserId As String + <DataMember(Name:="source")> Public Source As String + <DataMember(Name:="id_str")> Public IdStr As String + <DataMember(Name:="coordinates", IsRequired:=False)> Public Coordinates As Coordinates + <DataMember(Name:="truncated")> Public Truncated As Boolean + <DataMember(Name:="place", IsRequired:=False)> Public Place As Place + <DataMember(Name:="user")> Public User As User + <DataMember(Name:="retweeted_status", IsRequired:=False)> Public RetweetedStatus As RetweetedStatus + <DataMember(Name:="id")> Public Id As Int64 + <DataMember(Name:="favorited")> Public Favorited As Boolean + <DataMember(Name:="text")> Public Text As String End Class <DataContract()> _ - Public Class directmessage - <DataMember(Name:="created_at")> Public created_at As String - <DataMember(Name:="sender_id")> Public sender_id As Int64 - <DataMember(Name:="sender_screen_name")> Public sender_screen_name As String - <DataMember(Name:="sender")> Public sender As user - <DataMember(Name:="id_str")> Public id_str As String - <DataMember(Name:="recipient")> Public recipient As user - <DataMember(Name:="recipient_screen_name")> Public recipient_screen_name As String - <DataMember(Name:="recipient_id")> Public recipient_id As Int64 - <DataMember(Name:="id")> Public id As Int64 - <DataMember(Name:="text")> Public text As String + Public Class Directmessage + <DataMember(Name:="created_at")> Public CreatedAt As String + <DataMember(Name:="sender_id")> Public SenderId As Int64 + <DataMember(Name:="sender_screen_name")> Public SenderScreenName As String + <DataMember(Name:="sender")> Public Sender As User + <DataMember(Name:="id_str")> Public IdStr As String + <DataMember(Name:="recipient")> Public Recipient As User + <DataMember(Name:="recipient_screen_name")> Public RecipientScreenName As String + <DataMember(Name:="recipient_id")> Public RecipientId As Int64 + <DataMember(Name:="id")> Public Id As Int64 + <DataMember(Name:="text")> Public Text As String End Class <DataContract()> _ - Public Class friendsevent - <DataMember(Name:="friends")> Public friends As Int64() + Public Class Friendsevent + <DataMember(Name:="friends")> Public Friends As Int64() End Class <DataContract()> _ - Public Class deletedstatus - <DataMember(Name:="id")> Public id As Int64 - <DataMember(Name:="user_id")> Public user_id As Int64 + Public Class DeletedStatusContent + <DataMember(Name:="id")> Public Id As Int64 + <DataMember(Name:="user_id")> Public UserId As Int64 End Class <DataContract()> _ - Public Class deleteevent - <DataMember(Name:="event")> Public [event] As String - <DataMember(Name:="status")> Public status As deletedstatus + Public Class DeletedStatus + <DataMember(Name:="status")> Public Status As DeletedStatusContent End Class <DataContract()> _ - Public Class directmessageevent - <DataMember(Name:="direct_message")> Public direct_message As directmessage + Public Class DeleteEvent + <DataMember(Name:="delete")> Public [Event] As DeletedStatus End Class <DataContract()> _ - Public Class trackcount - <DataMember(Name:="track")> Public track As Integer + Public Class DeletedDirectmessage + <DataMember(Name:="direct_message")> Public Directmessage As DeletedStatusContent End Class <DataContract()> _ - Public Class limitevent - <DataMember(Name:="limit")> Public limit As trackcount + Public Class DeleteDirectmessageEvent + <DataMember(Name:="delete")> Public [Event] As DeletedDirectmessage End Class + <DataContract()> _ + Public Class DirectmessageEvent + <DataMember(Name:="direct_message")> Public Directmessage As Directmessage + End Class <DataContract()> _ - Public Class eventdata - <DataMember(Name:="target")> Public target As user - <DataMember(Name:="target_object")> Public target_object As status - <DataMember(Name:="created_at")> Public created_at As String - <DataMember(Name:="event")> Public [event] As String - <DataMember(Name:="source")> Public source As user + Public Class TrackCount + <DataMember(Name:="track")> Public Track As Integer End Class + + <DataContract()> _ + Public Class LimitEvent + <DataMember(Name:="limit")> Public Limit As TrackCount + End Class + + <DataContract()> _ + Public Class EventData + <DataMember(Name:="target")> Public Target As User + <DataMember(Name:="target_object")> Public TargetObject As Status + <DataMember(Name:="created_at")> Public CreatedAt As String + <DataMember(Name:="event")> Public [Event] As String + <DataMember(Name:="source")> Public Source As User + End Class End Class Modified: branches/UserStream/Tween/Tween.vb =================================================================== --- branches/UserStream/Tween/Tween.vb 2010-11-30 02:41:01 UTC (rev 1140) +++ branches/UserStream/Tween/Tween.vb 2010-11-30 10:02:01 UTC (rev 1141) @@ -8170,6 +8170,7 @@ AddHandler tw.UserStreamStarted, AddressOf tw_UserStreamStarted AddHandler tw.UserStreamStopped, AddressOf tw_UserStreamStopped AddHandler tw.UserStreamPaused, AddressOf tw_UserStreamPaused + AddHandler tw.PostDeleted, AddressOf tw_PostDeleted PauseToolStripMenuItem.Text = "&Pause" PauseToolStripMenuItem.Enabled = False StopToolStripMenuItem.Text = "&Start" @@ -9559,6 +9560,58 @@ End Try End Sub + Private Sub tw_PostDeleted(ByVal id As Long) + Try + If InvokeRequired Then + Invoke(New Action(Of Long)(AddressOf tw_PostDeleted), id) + Exit Sub + End If + Catch ex As ObjectDisposedException + Exit Sub + End Try + + _statuses.RemovePost(id) + + If _curTab Is Nothing OrElse _curList Is Nothing Then Exit Sub + + Dim fidx As Integer + If _curList.FocusedItem IsNot Nothing Then + fidx = _curList.FocusedItem.Index + ElseIf _curList.TopItem IsNot Nothing Then + fidx = _curList.TopItem.Index + Else + fidx = 0 + End If + + _itemCache = Nothing 'キャッシュ破棄 + _postCache = Nothing + _curPost = Nothing + _curItemIndex = -1 + For Each tb As TabPage In ListTab.TabPages + DirectCast(tb.Tag, DetailsListView).VirtualListSize = _statuses.Tabs(tb.Text).AllCount + If _curTab.Equals(tb) Then + _curList.SelectedIndices.Clear() + If _statuses.Tabs(tb.Text).AllCount > 0 Then + If _statuses.Tabs(tb.Text).AllCount - 1 > fidx AndAlso fidx > -1 Then + _curList.SelectedIndices.Add(fidx) + Else + _curList.SelectedIndices.Add(_statuses.Tabs(tb.Text).AllCount - 1) + End If + 'If _curList.SelectedIndices.Count > 0 Then + ' _curList.EnsureVisible(_curList.SelectedIndices(0)) + ' _curList.FocusedItem = _curList.Items(_curList.SelectedIndices(0)) + 'End If + End If + End If + If _statuses.Tabs(tb.Text).UnreadCount = 0 Then + If SettingDialog.TabIconDisp Then + If tb.ImageIndex = 0 Then tb.ImageIndex = -1 'タブアイコン + End If + End If + Next + If Not SettingDialog.TabIconDisp Then ListTab.Refresh() + End Sub + Private Sub tw_NewPostFromStream() Try If InvokeRequired Then @@ -9569,6 +9622,10 @@ Exit Sub End Try + 'Static before As DateTime = Now + 'If before.Subtract(Now).Seconds > -5 Then Exit Sub + 'before = Now + Dim rsltAddCount As Integer = _statuses.DistributePosts() RefreshTimeline() SyncLock _syncObject Modified: branches/UserStream/Tween/Twitter.vb =================================================================== --- branches/UserStream/Tween/Twitter.vb 2010-11-30 02:41:01 UTC (rev 1140) +++ branches/UserStream/Tween/Twitter.vb 2010-11-30 10:02:01 UTC (rev 1141) @@ -1394,7 +1394,6 @@ End Select If gType = WORKERTYPE.Timeline Then - Return CreatePostsFromJson(content, gType, Nothing, read, count, Me.minHomeTimeline) 'Return CreatePostsFromXml(content, gType, Nothing, read, count, Me.minHomeTimeline) Else @@ -1423,39 +1422,27 @@ Return New Date End Function - Private Overloads Function CreatePostsFromJson(ByVal content As String, ByVal gType As WORKERTYPE, ByVal tab As TabClass, ByVal read As Boolean, ByVal count As Integer, ByRef minimumId As Long) As String - Using stream As New MemoryStream() - Dim buf As Byte() = Encoding.Unicode.GetBytes(content) - stream.Write(buf, 0, buf.Length) - stream.Seek(offset:=0, loc:=SeekOrigin.Begin) - Return CreatePostsFromJson(stream, gType, tab, read, count, minimumId) - End Using - End Function + Private Function CreatePostsFromJson(ByVal content As String, ByVal gType As WORKERTYPE, ByVal tab As TabClass, ByVal read As Boolean, ByVal count As Integer, ByRef minimumId As Long) As String - 'MemoryStreamの面倒は呼び出しもとで見ること - - Private Overloads Function CreatePostsFromJson(ByVal content As MemoryStream, ByVal gType As WORKERTYPE, ByVal tab As TabClass, ByVal read As Boolean, ByVal count As Integer, ByRef minimumId As Long) As String - Dim serializer As New DataContractJsonSerializer(GetType(List(Of DataModel.status))) - Dim item As List(Of DataModel.status) - Dim arIdx As Integer = -1 Dim dlgt(300) As GetIconImageDelegate 'countQueryに合わせる Dim ar(300) As IAsyncResult 'countQueryに合わせる + Dim items As List(Of TwitterDataModel.Status) Try - item = DirectCast(serializer.ReadObject(content), List(Of DataModel.status)) + items = CreateDataFromJson(Of List(Of TwitterDataModel.Status))(content) Catch ex As SerializationException - TraceOut(ex.Message + Environment.NewLine + Encoding.Unicode.GetString(content.GetBuffer())) + TraceOut(ex.Message + Environment.NewLine + content) Return "Json Parse Error(DataContractJsonSerializer)" Catch ex As Exception - TraceOut(Encoding.Unicode.GetString(content.GetBuffer())) + TraceOut(content) Return "Invalid Json!" End Try - For Each status As DataModel.status In item + For Each status As TwitterDataModel.Status In items Dim post As New PostClass Try - post.Id = status.id + post.Id = status.Id If minimumId > post.Id Then minimumId = post.Id '二重取得回避 SyncLock LockObj @@ -1465,51 +1452,51 @@ If TabInformations.GetInstance.ContainsKey(post.Id, tab.TabName) Then Continue For End If End SyncLock - If status.retweeted_status IsNot Nothing Then - Dim retweeted As DataModel.retweeted_status = status.retweeted_status + If status.RetweetedStatus IsNot Nothing Then + Dim retweeted As TwitterDataModel.RetweetedStatus = status.RetweetedStatus - post.PDate = DateTimeParse(retweeted.created_at) + post.PDate = DateTimeParse(retweeted.CreatedAt) 'Id - post.RetweetedId = retweeted.id + post.RetweetedId = retweeted.Id '本文 - post.Data = retweeted.text + post.Data = retweeted.Text 'Source取得(htmlの場合は、中身を取り出し) - post.Source = retweeted.source + post.Source = retweeted.Source 'Reply先 - Long.TryParse(retweeted.in_reply_to_status_id, post.InReplyToId) - post.InReplyToUser = retweeted.in_reply_to_screen_name + Long.TryParse(retweeted.InReplyToStatusId, post.InReplyToId) + post.InReplyToUser = retweeted.InReplyToScreenName post.IsFav = TabInformations.GetInstance.GetTabByType(TabUsageType.Favorites).Contains(post.RetweetedId) '以下、ユーザー情報 - Dim user As DataModel.user = retweeted.user - post.Uid = user.id - post.Name = user.screen_name - post.Nickname = user._name - post.ImageUrl = user.profile_image_url - post.IsProtect = user.protected + Dim user As TwitterDataModel.User = retweeted.User + post.Uid = user.Id + post.Name = user.ScreenName + post.Nickname = user.Name + post.ImageUrl = user.ProfileImageUrl + post.IsProtect = user.Protected If post.IsMe Then _UserIdNo = post.Uid.ToString() 'Retweetした人 - post.RetweetedBy = status.user.screen_name + post.RetweetedBy = status.User.ScreenName Else - post.PDate = DateTimeParse(status.created_at) + post.PDate = DateTimeParse(status.CreatedAt) '本文 - post.Data = status.text + post.Data = status.Text 'Source取得(htmlの場合は、中身を取り出し) - post.Source = status.source - Long.TryParse(status.in_reply_to_status_id, post.InReplyToId) - post.InReplyToUser = status.in_reply_to_screen_name + post.Source = status.Source + Long.TryParse(status.InReplyToStatusId, post.InReplyToId) + post.InReplyToUser = status.InReplyToScreenName - post.IsFav = status.favorited + post.IsFav = status.Favorited '以下、ユーザー情報 - Dim user As DataModel.user = status.user - post.Uid = user.id - post.Name = user.screen_name - post.Nickname = user._name - post.ImageUrl = user.profile_image_url - post.IsProtect = user.protected + Dim user As TwitterDataModel.User = status.User + post.Uid = user.Id + post.Name = user.ScreenName + post.Nickname = user.Name + post.ImageUrl = user.ProfileImageUrl + post.IsProtect = user.Protected post.IsMe = post.Name.ToLower.Equals(_uid) If post.IsMe Then _UserIdNo = post.Uid.ToString End If @@ -1538,7 +1525,7 @@ post.IsDm = False If tab IsNot Nothing Then post.RelTabName = tab.TabName Catch ex As Exception - TraceOut(Encoding.Unicode.GetString(content.GetBuffer())) + TraceOut(content) MessageBox.Show("Parse Error(CreatePostsFromJson)") Continue For End Try @@ -1567,13 +1554,6 @@ Return "" End Function - 'Public Overloads Function GetListStatus(ByVal read As Boolean, _ - ' ByVal tab As TabClass, _ - ' ByVal more As Boolean) As String - - ' Return GetListStatus(read, tab, more, -1) - 'End Function - Public Overloads Function GetListStatus(ByVal read As Boolean, _ ByVal tab As TabClass, _ ByVal more As Boolean, _ @@ -1884,46 +1864,34 @@ Return "" End Function - Private Function CreateDirectMessagesFromJson(ByVal content As MemoryStream, ByVal gType As WORKERTYPE, ByVal read As Boolean) As String - - 'Dim serializer As New DataContractJsonSerializer(GetType(List(Of DataModel.directmessage))) - Dim serializer As DataContractJsonSerializer - Dim item As New List(Of DataModel.directmessage) - + Private Function CreateDirectMessagesFromJson(ByVal content As String, ByVal gType As WORKERTYPE, ByVal read As Boolean) As String + Dim item As List(Of TwitterDataModel.Directmessage) Dim arIdx As Integer = -1 Dim dlgt(300) As GetIconImageDelegate 'countQueryに合わせる Dim ar(300) As IAsyncResult 'countQueryに合わせる - Dim typ As Type - If gType = WORKERTYPE.UserStream Then - typ = GetType(List(Of DataModel.directmessageevent)) - serializer = New DataContractJsonSerializer(typ) - Else - serializer = New DataContractJsonSerializer(GetType(List(Of DataModel.directmessage))) - End If - Try If gType = WORKERTYPE.UserStream Then - Dim itm As List(Of DataModel.directmessageevent) - itm = DirectCast(serializer.ReadObject(content), List(Of DataModel.directmessageevent)) - For Each dat As DataModel.directmessageevent In itm - item.Add(dat.direct_message) + Dim itm As List(Of TwitterDataModel.DirectmessageEvent) = CreateDataFromJson(Of List(Of TwitterDataModel.DirectmessageEvent))(content) + item = New List(Of TwitterDataModel.Directmessage) + For Each dat As TwitterDataModel.DirectmessageEvent In itm + item.Add(dat.Directmessage) Next Else - item = DirectCast(serializer.ReadObject(content), List(Of DataModel.directmessage)) + item = CreateDataFromJson(Of List(Of TwitterDataModel.Directmessage))(content) End If Catch ex As SerializationException - TraceOut(ex.Message + Environment.NewLine + Encoding.Unicode.GetString(content.GetBuffer())) + TraceOut(ex.Message + Environment.NewLine + content) Return "Json Parse Error(DataContractJsonSerializer)" Catch ex As Exception - TraceOut(Encoding.Unicode.GetString(content.GetBuffer())) + TraceOut(content) Return "Invalid Json!" End Try - For Each message As DataModel.directmessage In item + For Each message As TwitterDataModel.Directmessage In item Dim post As New PostClass Try - post.Id = message.id + post.Id = message.Id If gType <> WORKERTYPE.UserStream Then If gType = WORKERTYPE.DirectMessegeRcv Then If minDirectmessage > post.Id Then minDirectmessage = post.Id @@ -1938,9 +1906,9 @@ End SyncLock 'sender_id 'recipient_id - post.PDate = DateTimeParse(message.created_at) + post.PDate = DateTimeParse(message.CreatedAt) '本文 - post.Data = message.text + post.Data = message.Text 'HTMLに整形 post.OriginalData = CreateHtmlAnchor(post.Data, post.ReplyToList) post.Data = HttpUtility.HtmlDecode(post.Data) @@ -1948,42 +1916,42 @@ post.IsFav = False '以下、ユーザー情報 - Dim user As DataModel.user + Dim user As TwitterDataModel.User If gType = WORKERTYPE.UserStream Then - If twCon.AuthenticatedUsername.Equals(message.recipient.screen_name, StringComparison.CurrentCultureIgnoreCase) Then - user = message.sender + If twCon.AuthenticatedUsername.Equals(message.Recipient.ScreenName, StringComparison.CurrentCultureIgnoreCase) Then + user = message.Sender post.IsMe = False post.IsOwl = True Else - user = message.recipient + user = message.Recipient post.IsMe = True post.IsOwl = False End If Else If gType = WORKERTYPE.DirectMessegeRcv Then - user = message.sender + user = message.Sender post.IsMe = False post.IsOwl = True Else - user = message.recipient + user = message.Recipient post.IsMe = True post.IsOwl = False End If End If post.Uid = user.id - post.Name = user.screen_name - post.Nickname = user._name - post.ImageUrl = user.profile_image_url + post.Name = user.ScreenName + post.Nickname = user.Name + post.ImageUrl = user.ProfileImageUrl post.IsProtect = user.protected Catch ex As Exception - TraceOut(Encoding.Unicode.GetString(content.GetBuffer())) + TraceOut(content) MessageBox.Show("Parse Error(CreateDirectMessagesFromJson)") Continue For End Try post.IsRead = read - If gType = WORKERTYPE.DirectMessegeSnt AndAlso Not read AndAlso _readOwnPost Then post.IsRead = True + If post.IsMe AndAlso Not read AndAlso _readOwnPost Then post.IsRead = True post.IsReply = False post.IsExcludeReply = False post.IsDm = True @@ -2049,12 +2017,7 @@ Return "Err:" + res.ToString() + "(" + GetCurrentMethod.Name + ")" End Select - Using stream As New MemoryStream() - Dim buf As Byte() = Encoding.Unicode.GetBytes(content) - stream.Write(buf, 0, buf.Length) - stream.Seek(offset:=0, loc:=SeekOrigin.Begin) - Return CreateDirectMessagesFromJson(stream, gType, read) - End Using + Return CreateDirectMessagesFromJson(content, gType, read) End Function Public Function GetFavoritesApi(ByVal read As Boolean, _ @@ -2089,8 +2052,8 @@ Return "Err:" + res.ToString() + "(" + GetCurrentMethod.Name + ")" End Select - Dim serializer As New DataContractJsonSerializer(GetType(List(Of DataModel.status))) - Dim item As List(Of DataModel.status) + Dim serializer As New DataContractJsonSerializer(GetType(List(Of TwitterDataModel.Status))) + Dim item As List(Of TwitterDataModel.Status) Dim arIdx As Integer = -1 Dim dlgt(300) As GetIconImageDelegate 'countQueryに合わせる @@ -2101,7 +2064,7 @@ Dim buf As Byte() = Encoding.Unicode.GetBytes(content) stream.Write(buf, 0, buf.Length) stream.Seek(offset:=0, loc:=SeekOrigin.Begin) - item = DirectCast(serializer.ReadObject(stream), List(Of DataModel.status)) + item = DirectCast(serializer.ReadObject(stream), List(Of TwitterDataModel.Status)) End Using Catch ex As SerializationException TraceOut(ex.Message + Environment.NewLine + content) @@ -2111,18 +2074,18 @@ Return "Invalid Json!" End Try - For Each status As DataModel.status In item + For Each status As TwitterDataModel.Status In item Dim post As New PostClass Try - post.Id = status.id + post.Id = status.Id '二重取得回避 SyncLock LockObj If TabInformations.GetInstance.GetTabByType(TabUsageType.Favorites).Contains(post.Id) Then Continue For End SyncLock 'Retweet判定 - If status.retweeted_status IsNot Nothing Then - Dim retweeted As DataModel.retweeted_status = status.retweeted_status - post.PDate = DateTimeParse(retweeted.created_at) + If status.RetweetedStatus IsNot Nothing Then + Dim retweeted As TwitterDataModel.RetweetedStatus = status.RetweetedStatus + post.PDate = DateTimeParse(retweeted.CreatedAt) 'Id post.RetweetedId = post.Id @@ -2131,41 +2094,41 @@ 'Source取得(htmlの場合は、中身を取り出し) post.Source = retweeted.source 'Reply先 - Long.TryParse(retweeted.in_reply_to_status_id, post.InReplyToId) - post.InReplyToUser = retweeted.in_reply_to_screen_name + Long.TryParse(retweeted.InReplyToStatusId, post.InReplyToId) + post.InReplyToUser = retweeted.InReplyToScreenName post.IsFav = retweeted.favorited '以下、ユーザー情報 - Dim user As DataModel.user = retweeted.user - post.Uid = user.id - post.Name = user.screen_name - post.Nickname = user._name - post.ImageUrl = user.profile_image_url - post.IsProtect = user.protected + Dim user As TwitterDataModel.User = retweeted.User + post.Uid = user.Id + post.Name = user.ScreenName + post.Nickname = user.Name + post.ImageUrl = user.ProfileImageUrl + post.IsProtect = user.Protected post.IsMe = post.Name.ToLower.Equals(_uid) If post.IsMe Then _UserIdNo = post.Uid.ToString() 'Retweetした人 - post.RetweetedBy = status.user.screen_name + post.RetweetedBy = status.User.ScreenName Else - post.PDate = DateTimeParse(status.created_at) + post.PDate = DateTimeParse(status.CreatedAt) '本文 - post.Data = status.text + post.Data = status.Text 'Source取得(htmlの場合は、中身を取り出し) - post.Source = status.source - Long.TryParse(status.in_reply_to_status_id, post.InReplyToId) - post.InReplyToUser = status.in_reply_to_screen_name + post.Source = status.Source + Long.TryParse(status.InReplyToStatusId, post.InReplyToId) + post.InReplyToUser = status.InReplyToScreenName - post.IsFav = status.favorited + post.IsFav = status.Favorited '以下、ユーザー情報 - Dim user As DataModel.user = status.user - post.Uid = user.id - post.Name = user.screen_name - post.Nickname = user._name - post.ImageUrl = user.profile_image_url - post.IsProtect = user.protected + Dim user As TwitterDataModel.User = status.User + post.Uid = user.Id + post.Name = user.ScreenName + post.Nickname = user.Name + post.ImageUrl = user.ProfileImageUrl + post.IsProtect = user.Protected post.IsMe = post.Name.ToLower.Equals(_uid) If post.IsMe Then _UserIdNo = post.Uid.ToString End If @@ -2804,6 +2767,7 @@ Public Event UserStreamStopped() Public Event UserStreamPaused() Public Event UserStreamGetFriendsList() + Public Event PostDeleted(ByVal id As Long) Private WithEvents userStream As TwitterUserstream Private _streamBypass As Boolean @@ -2821,45 +2785,49 @@ Dim idx As Integer = line.IndexOf("{""") Dim idx2 As Integer = line.IndexOf(""":") If idx = 0 AndAlso idx2 > 0 Then - 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") - Exit Sub - ElseIf eventname.Equals("limit") Then - Debug.Print("limit") - Exit Sub - ElseIf eventname.Equals("target") Then - Dim data As DataModel.eventdata - Debug.Print("Event") - Using stream As New MemoryStream() - Dim serializer As New DataContractJsonSerializer(GetType(DataModel.eventdata)) - Dim sb As New StringBuilder - sb.Length = 0 - sb.Append(line) - Dim buf As Byte() = Encoding.Unicode.GetBytes(sb.ToString) - stream.Write(buf, offset:=0, count:=buf.Length) - stream.Seek(offset:=0, loc:=SeekOrigin.Begin) - data = DirectCast(serializer.ReadObject(stream), DataModel.eventdata) - End Using - 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 - End If + 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) + End If + Catch ex As SerializationException + TraceOut(ex.Message + Environment.NewLine + line) + Catch ex As Exception + TraceOut(line) + End Try End If @@ -2869,24 +2837,32 @@ res.Append(line) res.Append("]") - Dim isDM As Boolean = False - If line.StartsWith("{""direct_message"":") Then - isDM = True - End If - - Using stream As New MemoryStream() - Dim buf As Byte() = Encoding.Unicode.GetBytes(res.ToString) - stream.Write(buf, offset:=0, count:=buf.Length) - stream.Seek(offset:=0, loc:=SeekOrigin.Begin) - If isDM Then - CreateDirectMessagesFromJson(stream, WORKERTYPE.UserStream, False) + Try + If line.StartsWith("{""direct_message"":") Then + CreateDirectMessagesFromJson(res.ToString, WORKERTYPE.UserStream, False) Else - CreatePostsFromJson(stream, WORKERTYPE.Timeline, Nothing, False, Nothing, Nothing) + CreatePostsFromJson(res.ToString, WORKERTYPE.Timeline, Nothing, False, Nothing, Nothing) End If - End Using + Catch ex As SerializationException + TraceOut(ex.Message + Environment.NewLine + line) + Catch ex As Exception + TraceOut(line) + End Try + RaiseEvent NewPostFromStream() End Sub + Private Function CreateDataFromJson(Of T)(ByVal content As String) As T + Dim data As T + Using stream As New MemoryStream() + Dim buf As Byte() = Encoding.Unicode.GetBytes(content) + stream.Write(Encoding.Unicode.GetBytes(content), offset:=0, count:=buf.Length) + stream.Seek(offset:=0, loc:=SeekOrigin.Begin) + data = DirectCast((New DataContractJsonSerializer(GetType(T))).ReadObject(stream), T) + End Using + Return data + End Function + Private Sub userStream_Started() Handles userStream.Started RaiseEvent UserStreamStarted() End Sub