root/lang/vb2005/FuwaKumo/trunk/FuwaKumo/FuwaController.vb @ 34124

Revision 34124, 4.6 kB (checked in by kiri_feather, 5 years ago)
Line 
1Public Class FuwaController
2    Private _loginSyncObject As System.ComponentModel.ISynchronizeInvoke
3    Private _fform As Fuwafuwa
4
5    Public Event RequireAuth(ByVal sender As Object, ByVal e As EventArgs)
6    Public Event StartGetTimer(ByVal sender As Object, ByVal e As EventArgs)
7    Public Event StopGetTimer(ByVal sender As Object, ByVal e As EventArgs)
8
9    Private _visible As Boolean = True
10    Private _twitterModel As TwitterModel
11
12    Public Sub New()
13        _twitterModel = New TwitterModel
14    End Sub
15
16    Public Sub StartGet()
17        DisplayFuwaFuwa()
18        RaiseEvent StartGetTimer(Me, Nothing)
19    End Sub
20
21    Public Sub DisplayFuwaFuwa()
22        If _fform Is Nothing Then
23            _fform = New Fuwafuwa(Me)
24        Else
25            _fform.Visible = True
26        End If
27        _fform.Show()
28    End Sub
29
30    Public Sub StopGet()
31        SettingNet.Instance.Save()
32        SettingTwitter.Instance.Save()
33        RaiseEvent StopGetTimer(Me, Nothing)
34    End Sub
35
36    Public Sub GetAuthUrl()
37        Dim url As String = _twitterModel.GetAuthorizePageUrl()
38        If String.IsNullOrEmpty(url) Then
39            System.Windows.Forms.MessageBox.Show("�F�؃y�[�W�擾���s")
40        Else
41            System.Diagnostics.Process.Start(url)
42        End If
43    End Sub
44
45    Public Sub GetAuthToken(ByVal PIN As String)
46        If Trim(PIN).Length < 6 Then
47            System.Windows.Forms.MessageBox.Show("6����IN�R�[�h��͂��Ă��������B")
48            Exit Sub
49        End If
50        If Not _twitterModel.GetAccessToken(Trim(PIN)) Then
51            System.Windows.Forms.MessageBox.Show("�A�N�Z�X�g�[�N���擾���s")
52        Else
53            System.Windows.Forms.MessageBox.Show("�F�ؐ���
54        End If
55    End Sub
56
57    Private Sub Authorize()
58        If RequireAuthEvent IsNot Nothing AndAlso _loginSyncObject IsNot Nothing AndAlso _loginSyncObject.InvokeRequired Then
59            _loginSyncObject.BeginInvoke(RequireAuthEvent, New Object() {Me, New EventArgs()})
60        Else
61            RaiseEvent RequireAuth(Me, New EventArgs())
62        End If
63    End Sub
64
65    Public Function GetFriendsTimeline() As List(Of StatusElement)
66        Try
67            Return _twitterModel.GetTimeline
68        Catch ex As System.Net.WebException
69            If ex.Status = System.Net.WebExceptionStatus.ProtocolError AndAlso _
70               CType(ex.Response, System.Net.HttpWebResponse).StatusCode = _
71                   System.Net.HttpStatusCode.Unauthorized Then
72                Authorize()
73            Else
74                System.Windows.Forms.MessageBox.Show(ex.Message)
75            End If
76        Catch ex As Exception
77            System.Windows.Forms.MessageBox.Show(ex.Message)
78        End Try
79        Return Nothing
80    End Function
81
82    Public Property LoginSyncObject() As System.ComponentModel.ISynchronizeInvoke
83        Get
84            Return Me._loginSyncObject
85        End Get
86        Set(ByVal value As System.ComponentModel.ISynchronizeInvoke)
87            Me._loginSyncObject = value
88        End Set
89    End Property
90
91#Region "�񓯊�e�擾"
92    'Private Delegate Sub GetImageDelegate(ByVal Url As String, _
93    '                                        ByVal SyncObject As System.ComponentModel.ISynchronizeInvoke)
94    'Private worker As New GetImageDelegate(AddressOf GetImageWorker)
95    'Public Sub GetProfileImage(ByVal Url As String, ByVal SyncObject As System.ComponentModel.ISynchronizeInvoke)
96    '    Dim result As IAsyncResult = worker.BeginInvoke(Url, SyncObject, AddressOf CallbackMethod, worker)
97    'End Sub
98
99    'Private Sub GetImageWorker(ByVal Url As String, _
100    '                                ByVal SyncObject As System.ComponentModel.ISynchronizeInvoke)
101    '    Dim img As System.Drawing.Bitmap = _twitterModel.GetProfileImage(Url)
102    '    OnGetImageNotify(SyncObject, img)
103    '    SyncObject = Nothing
104    'End Sub
105
106    'Private Sub CallbackMethod(ByVal ar As IAsyncResult)
107    '    Dim worker As GetImageDelegate = CType(ar.AsyncState, GetImageDelegate)
108    '    worker.EndInvoke(ar)
109    'End Sub
110
111    'Private Sub OnGetImageNotify(ByVal SyncObj As System.ComponentModel.ISynchronizeInvoke, ByVal Image As System.Drawing.Bitmap)
112    '    If GetImageNotifyEvent IsNot Nothing AndAlso SyncObj IsNot Nothing AndAlso SyncObj.InvokeRequired Then
113    '        SyncObj.BeginInvoke(GetImageNotifyEvent, New Object() {Me, New GetImageNotifyEventArgs(Image, SyncObj)})
114    '    Else
115    '        RaiseEvent GetImageNotify(Me, New GetImageNotifyEventArgs(Image, SyncObj))
116    '    End If
117    'End Sub
118#End Region
119
120
121End Class
122
Note: See TracBrowser for help on using the browser.