OSDN Git Service

9835780832a228c920d198143e6803af62e52ece
[opentween/open-tween.git] / OpenTween / FavoriteQueue.vb
1 ' OpenTween - Client of Twitter
2 ' Copyright (c) 2011      kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 '           (c) 2011      fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
4 ' All rights reserved.
5
6 ' This file is part of OpenTween.
7
8 ' This program is free software; you can redistribute it and/or modify it
9 ' under the terms of the GNU General Public License as published by the Free
10 ' Software Foundation; either version 3 of the License, or (at your option)
11 ' any later version.
12
13 ' This program is distributed in the hope that it will be useful, but
14 ' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 ' for more details. 
17
18 ' You should have received a copy of the GNU General Public License along
19 ' with this program. If not, see <http://www.gnu.org/licenses/>, or write to
20 ' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
21 ' Boston, MA 02110-1301, USA.
22
23 Imports System.Threading.Tasks
24 Imports System.Net
25
26 Public Class FavoriteQueue
27     Implements IList(Of Long)
28
29     'Private Shared _instance As New FavoriteQueue
30     'Public Shared ReadOnly Property GetInstance As FavoriteQueue
31     '    Get
32     '        Return _instance
33     '    End Get
34     'End Property
35
36     Private tw As Twitter
37     Private FavoriteCache As New List(Of Long)
38
39     Public Sub AddRange(ByVal stsIds As IEnumerable(Of Long))
40         FavoriteCache.AddRange(stsIds)
41     End Sub
42
43     'Public Sub FavoriteCacheAdd(ByVal statusId As Long, ByVal res As HttpStatusCode, Optional ByRef isMsg As Boolean = True)
44     '    'If Not SettingInfo.Instance.IsUseFavoriteQueue Then Exit Sub
45     '    Select Case res
46     '        Case HttpStatusCode.BadGateway, HttpStatusCode.BadRequest, HttpStatusCode.ServiceUnavailable, HttpStatusCode.InternalServerError, HttpStatusCode.RequestTimeout
47     '            isMsg = False
48     '            FavoriteCache.Add(statusId)
49     '    End Select
50     'End Sub
51
52     Public Sub FavoriteCacheStart()
53         If Not FavoriteCache.Count = 0 Then
54             Dim _cacheList As New List(Of Long)(FavoriteCache)
55             Me.Clear()
56             Parallel.ForEach(Of Long)(_cacheList, New Action(Of Long)(Sub(stsId As Long)
57                                                                           tw.PostFavAdd(stsId)
58                                                                       End Sub))
59         End If
60     End Sub
61
62     Public Sub Add(ByVal item As Long) Implements System.Collections.Generic.ICollection(Of Long).Add
63         If Not Me.Contains(item) Then
64             FavoriteCache.Add(item)
65         End If
66     End Sub
67
68     Public Sub Clear() Implements System.Collections.Generic.ICollection(Of Long).Clear
69         FavoriteCache.Clear()
70         FavoriteCache.TrimExcess()
71     End Sub
72
73     Public Function Contains(ByVal item As Long) As Boolean Implements System.Collections.Generic.ICollection(Of Long).Contains
74         FavoriteCache.Contains(item)
75     End Function
76
77     Public Sub CopyTo(ByVal array() As Long, ByVal arrayIndex As Integer) Implements System.Collections.Generic.ICollection(Of Long).CopyTo
78         FavoriteCache.CopyTo(array, arrayIndex)
79     End Sub
80
81     Public ReadOnly Property Count As Integer Implements System.Collections.Generic.ICollection(Of Long).Count
82         Get
83             Return FavoriteCache.Count
84         End Get
85     End Property
86
87     Public ReadOnly Property IsReadOnly As Boolean Implements System.Collections.Generic.ICollection(Of Long).IsReadOnly
88         Get
89             Return False
90         End Get
91     End Property
92
93     Public Function Remove(ByVal item As Long) As Boolean Implements System.Collections.Generic.ICollection(Of Long).Remove
94         Return FavoriteCache.Remove(item)
95     End Function
96
97     Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of Long) Implements System.Collections.Generic.IEnumerable(Of Long).GetEnumerator
98         Return FavoriteCache.GetEnumerator()
99     End Function
100     Public Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
101         Return Me.GetEnumerator
102     End Function
103
104     Public Function IndexOf(ByVal item As Long) As Integer Implements System.Collections.Generic.IList(Of Long).IndexOf
105         Return FavoriteCache.IndexOf(item)
106     End Function
107
108     Public Sub Insert(ByVal index As Integer, ByVal item As Long) Implements System.Collections.Generic.IList(Of Long).Insert
109         FavoriteCache.Insert(index, item)
110     End Sub
111
112     Default Public Property Item(ByVal index As Integer) As Long Implements System.Collections.Generic.IList(Of Long).Item
113         Get
114             Return FavoriteCache(index)
115         End Get
116         Set(ByVal value As Long)
117             FavoriteCache(index) = value
118         End Set
119     End Property
120
121     Public Sub RemoveAt(ByVal index As Integer) Implements System.Collections.Generic.IList(Of Long).RemoveAt
122         FavoriteCache.RemoveAt(index)
123     End Sub
124
125     Public Sub New(ByVal twitter As Twitter)
126         Me.tw = twitter
127     End Sub
128 End Class