[Tween-svn] [1119] とりあえず関連発言表示が動くように。いずれDataContractでのシリアライズに変更する予定。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 11月 26日 (金) 12:01:03 JST


Revision: 1119
          http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1119
Author:   kiri_feather
Date:     2010-11-26 12:01:03 +0900 (Fri, 26 Nov 2010)

Log Message:
-----------
とりあえず関連発言表示が動くように。いずれDataContractでのシリアライズに変更する予定。
PostClassにIClonable実装
System.Runtime.Serialization、System.Xml.Linqの参照追加

Modified Paths:
--------------
    trunk/Tween/StatusDictionary.vb
    trunk/Tween/Tween.vb
    trunk/Tween/Tween.vbproj
    trunk/Tween/Twitter.vb


-------------- next part --------------
Modified: trunk/Tween/StatusDictionary.vb
===================================================================
--- trunk/Tween/StatusDictionary.vb	2010-11-25 17:28:10 UTC (rev 1118)
+++ trunk/Tween/StatusDictionary.vb	2010-11-26 03:01:03 UTC (rev 1119)
@@ -29,6 +29,7 @@
 Imports System.Text
 
 Public NotInheritable Class PostClass
+    Implements ICloneable
     Private _Nick As String
     Private _Data As String
     Private _ImageUrl As String
@@ -356,6 +357,18 @@
             _searchTabName = value
         End Set
     End Property
+
+    Public Function Copy() As PostClass
+        Dim post As PostClass = DirectCast(Me.Clone, PostClass)
+        post.ReplyToList = New List(Of String)(Me.ReplyToList)
+        Return post
+    End Function
+
+#Region "IClonable.Clone"
+    Private Function Clone() As Object Implements ICloneable.Clone
+        Return Me.MemberwiseClone()
+    End Function
+#End Region
 End Class
 
 Public NotInheritable Class TabInformations

Modified: trunk/Tween/Tween.vb
===================================================================
--- trunk/Tween/Tween.vb	2010-11-25 17:28:10 UTC (rev 1118)
+++ trunk/Tween/Tween.vb	2010-11-26 03:01:03 UTC (rev 1119)
@@ -7148,13 +7148,19 @@
 
     Private Sub ClearTabMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearTabMenuItem.Click, ClearTbMenuItem.Click
         If String.IsNullOrEmpty(_rclickTabName) Then Exit Sub
-        Dim tmp As String = String.Format(My.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine)
-        If MessageBox.Show(tmp, _rclickTabName + " " + My.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Cancel Then
-            Exit Sub
+        ClearTab(_rclickTabName, True)
+    End Sub
+
+    Private Sub ClearTab(ByVal tabName As String, ByVal showWarning As Boolean)
+        If showWarning Then
+            Dim tmp As String = String.Format(My.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine)
+            If MessageBox.Show(tmp, tabName + " " + My.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Cancel Then
+                Exit Sub
+            End If
         End If
 
-        _statuses.ClearTabIds(_rclickTabName)
-        If ListTab.SelectedTab.Text = _rclickTabName Then
+        _statuses.ClearTabIds(tabName)
+        If ListTab.SelectedTab.Text = tabName Then
             _anchorPost = Nothing
             _anchorFlag = False
             _itemCache = Nothing
@@ -7164,7 +7170,7 @@
             _curPost = Nothing
         End If
         For Each tb As TabPage In ListTab.TabPages
-            If tb.Text = _rclickTabName Then
+            If tb.Text = tabName Then
                 tb.ImageIndex = -1
                 DirectCast(tb.Tag, DetailsListView).VirtualListSize = 0
                 Exit For
@@ -9686,6 +9692,7 @@
 
             Dim tb As TabClass = _statuses.GetTabByType(TabUsageType.Related)
             tb.RelationTargetId = _curPost.Id
+            Me.ClearTab(tb.TabName, False)
             For i As Integer = 0 To ListTab.TabPages.Count - 1
                 If tb.TabName = ListTab.TabPages(i).Text Then
                     ListTab.SelectedIndex = i

Modified: trunk/Tween/Tween.vbproj
===================================================================
--- trunk/Tween/Tween.vbproj	2010-11-25 17:28:10 UTC (rev 1118)
+++ trunk/Tween/Tween.vbproj	2010-11-26 03:01:03 UTC (rev 1119)
@@ -92,9 +92,11 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Drawing" />
+    <Reference Include="System.Runtime.Serialization" />
     <Reference Include="System.Web" />
     <Reference Include="System.Windows.Forms" />
     <Reference Include="System.XML" />
+    <Reference Include="System.Xml.Linq" />
   </ItemGroup>
   <ItemGroup>
     <Import Include="Microsoft.VisualBasic" />

Modified: trunk/Tween/Twitter.vb
===================================================================
--- trunk/Tween/Twitter.vb	2010-11-25 17:28:10 UTC (rev 1118)
+++ trunk/Tween/Twitter.vb	2010-11-26 03:01:03 UTC (rev 1119)
@@ -32,8 +32,10 @@
 Imports System.Net
 Imports System.Reflection
 Imports System.Reflection.MethodBase
+Imports System.Runtime.Serialization.Json
+Imports System.Linq
+Imports System.Xml.Linq
 
-
 Public Class Twitter
     Delegate Sub GetIconImageDelegate(ByVal post As PostClass)
     Private ReadOnly LockObj As New Object
@@ -1477,8 +1479,91 @@
             Case Else
                 Return "Err:" + res.ToString() + "(" + GetCurrentMethod.Name + ")"
         End Select
-        Dim min As Long = 0
-        Return CreatePostsFromXml(content, WORKERTYPE.Related, tab, read, 0, min)
+
+        Using jsonReader As XmlDictionaryReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(content), XmlDictionaryReaderQuotas.Max)
+            Dim xElm As XElement = XElement.Load(jsonReader)
+            Dim query As IEnumerable(Of PostClass) = From item In xElm.Descendants("value")
+                        Select New PostClass(
+                            Id:=Long.Parse(item.Element("id").Value),
+                            PDate:=DateTime.ParseExact(item.Element("created_at").Value, "ddd MMM dd HH:mm:ss zzzz yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.None),
+                            Data:=item.Element("text").Value,
+                            Source:=item.Element("source").Value,
+                            InReplyToId:=If(item.Element("in_reply_to_status_id").Attribute("type").Value = "null", 0, Long.Parse(item.Element("in_reply_to_status_id").Value)),
+                            InReplyToUser:=item.Element("in_reply_to_screen_name").Value,
+                            IsFav:=Boolean.Parse(item.Element("favorited").Value),
+                            Uid:=Long.Parse(CType(item.Element("user"), XElement).Element("id").Value),
+                            Name:=CType(item.Element("user"), XElement).Element("screen_name").Value,
+                            Nickname:=CType(item.Element("user"), XElement).Element("name").Value,
+                            imageurl:=CType(item.Element("user"), XElement).Element("profile_image_url").Value,
+                            IsProtect:=Boolean.Parse(CType(item.Element("user"), XElement).Element("protected").Value),
+                            IsMe:=_UserIdNo.Equals(Long.Parse(CType(item.Element("user"), XElement).Element("id").Value)),
+                            FilterHit:=False,
+                            IsDm:=False,
+                            IsExcludeReply:=False,
+                            IsMark:=False,
+                            IsOwl:=False,
+                            IsRead:=False,
+                            IsReply:=False,
+                            OriginalData:="",
+                            ReplyToList:=New List(Of String),
+                            RetweetedBy:="",
+                            RetweetedId:=0,
+                            SourceHtml:="")
+
+            Dim arIdx As Integer = -1
+            Dim dlgt(300) As GetIconImageDelegate    'countQueryに合わせる
+            Dim ar(300) As IAsyncResult              'countQueryに合わせる
+
+            For Each item As PostClass In query
+                item.IsMe = item.Name.ToLower.Equals(_uid)
+                If item.IsMe Then _UserIdNo = item.Uid.ToString()
+                item.OriginalData = CreateHtmlAnchor(item.Data, item.ReplyToList)
+                item.Data = HttpUtility.HtmlDecode(item.Data)
+                item.Data = item.Data.Replace("<3", "♡")
+                CreateSource(item)
+                item.IsRead = read
+                item.IsRead = item.ReplyToList.Contains(_uid)
+                If item.IsMe Then
+                    item.IsOwl = False
+                Else
+                    If followerId.Count > 0 Then item.IsOwl = Not followerId.Contains(item.Uid)
+                End If
+                If item.IsMe AndAlso Not read AndAlso _readOwnPost Then item.IsRead = True
+                If tab IsNot Nothing Then item.RelTabName = tab.TabName
+                ''二重取得回避
+                'SyncLock LockObj
+                '    If tab Is Nothing Then
+                '        If TabInformations.GetInstance.ContainsKey(item.Id) Then Continue For
+                '    Else
+                '        If TabInformations.GetInstance.ContainsKey(item.Id, tab.TabName) Then Continue For
+                '    End If
+                'End SyncLock
+                '非同期アイコン取得&StatusDictionaryに追加
+                arIdx += 1
+                dlgt(arIdx) = New GetIconImageDelegate(AddressOf GetIconImage)
+                ar(arIdx) = dlgt(arIdx).BeginInvoke(item, Nothing, Nothing)
+            Next
+            Dim targetItem As PostClass = TabInformations.GetInstance.Item(tab.RelationTargetId).Copy()
+            targetItem.RelTabName = tab.TabName
+            arIdx += 1
+            dlgt(arIdx) = New GetIconImageDelegate(AddressOf GetIconImage)
+            ar(arIdx) = dlgt(arIdx).BeginInvoke(targetItem, Nothing, Nothing)
+
+            'アイコン取得完了待ち
+            For i As Integer = 0 To arIdx
+                Try
+                    dlgt(i).EndInvoke(ar(i))
+                Catch ex As IndexOutOfRangeException
+                    Throw New IndexOutOfRangeException(String.Format("i={0},dlgt.Length={1},ar.Length={2},arIdx={3}", i, dlgt.Length, ar.Length, arIdx))
+                Catch ex As Exception
+                    '最後までendinvoke回す(ゾンビ化回避)
+                    ex.Data("IsTerminatePermission") = False
+                    Throw
+                End Try
+            Next
+        End Using
+
+        Return ""
     End Function
 
     Private Function CreatePostsFromXml(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



Tween-svn メーリングリストの案内
Back to archive index