This repository has been archived by the owner on May 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.cs
305 lines (277 loc) · 9.08 KB
/
Queue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//This is a source code or part of Huggle project
//
//This file contains code for queues
/// <DOCUMENTATION>
/// There is no documentation for this
/// </DOCUMENTATION>
//Copyright (C) 2011-2012 Huggle team
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
using System;
using System.Collections.Generic;
using System.Text;
namespace huggle3
{
/// <summary>
/// Queue
/// </summary>
public class Queue
{
/// <summary>
/// List of all queues loaded in system
/// </summary>
public static Dictionary<string, Queue> All = new Dictionary<string, Queue>();
/// <summary>
/// The name.
/// </summary>
private string name = "";
public DiffMode _Diffs;
/// <summary>
/// Limit.
/// </summary>
public int Limit = 0;
/// <summary>
/// The type of the source.
/// </summary>
public string SourceType = "";
/// <summary>
/// The source.
/// </summary>
public string Source = "";
/// <summary>
/// Ignore pages
/// </summary>
public bool IgnorePages = false;
/// <summary>
/// The name of the list.
/// </summary>
public string ListName = "";
/// <summary>
/// Needs reset.
/// </summary>
public bool NeedsReset = false;
public System.Text.RegularExpressions.Regex _PageRegex = null;
public string Pages = null;
public bool Refreshing = false;
public bool RefreshAlways = false;
public bool RefreshReAdd = false;
public List<string> RemovedPages = null;
public bool RemoveOld = false;
public int RemoveAfter = 0;
public bool RemoveViewed = false;
public System.Text.RegularExpressions.Regex RevisionRegex = null;
public QueueSortOrder _SortOrder;
public List<Space> _Spaces = null;
public System.Text.RegularExpressions.Regex _SummaryRegex;
public bool _TrayNotification = false;
public QueueType _Type;
public System.Text.RegularExpressions.Regex _UserRegex;
public Controls.QueuePanel Panel = null;
public List<string> _Users = new List<string>();
public List<Edit> Edits = new List<Edit>();
public QueueFilter _FilterAnonymous = QueueFilter.None;
public QueueFilter _FilterAssisted = QueueFilter.None;
public QueueFilter _FilterBot = QueueFilter.None;
public QueueFilter _FilterHuggle = QueueFilter.None;
public QueueFilter _FilterIgnored = QueueFilter.None;
public QueueFilter _FilterMe = QueueFilter.None;
public QueueFilter _FilterNewPage = QueueFilter.None;
public QueueFilter _FilterNotifications = QueueFilter.None;
public QueueFilter _FilterOwnUserspace = QueueFilter.None;
public QueueFilter _FilterReverts = QueueFilter.None;
public QueueFilter _FilterTags = QueueFilter.None;
public QueueFilter _FilterWarnings = QueueFilter.None;
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
set { name = value; }
get { return name; }
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="Name">Name</param>
public Queue(string Name)
{
name = Name;
RemoveViewed = true;
}
public bool Matches(Edit _edit)
{
bool matches = false;
// check page name
if (_PageRegex != null && _edit._Page != null)
{
if (_PageRegex.IsMatch(_edit._Page.Name))
{
matches = true;
}
else
{
return false;
}
}
// check summary
if (_SummaryRegex != null && _edit.Summary != null)
{
if (_SummaryRegex.IsMatch(_edit.Summary))
{
matches = true;
}
else
{
return false;
}
}
if (_UserRegex != null && _edit.EditUser != null)
{
if (_UserRegex.IsMatch(_edit.EditUser.UserName))
{
matches = true;
}
else
{
return false;
}
}
return matches;
}
/// <summary>
/// Convert string to queue object, if exist
/// </summary>
/// <param name="name">Name</param>
/// <returns>Queue with the provided name</returns>
public static Queue fromString(string name)
{
Core.History("Queue.fromString(string)");
lock (All)
{
foreach (KeyValuePair<string, Queue> current_queue in All)
{
if (current_queue.Value.name == name)
{
return current_queue.Value;
}
}
}
return null;
}
/// <summary>
/// Return true in case that a queue panel is currently drawing this queue
/// </summary>
/// <returns></returns>
public bool MatchesPanel()
{
if (Panel != null)
{
if (Panel.queue == this)
{
return true;
}
}
return false;
}
/// <summary>
/// Check if the queue has this edit
/// </summary>
/// <param name="edit"></param>
/// <returns></returns>
public bool ContainsEdit(Edit edit)
{
lock (Edits)
{
if (edit == null)
{
throw new Exception("The edit you were about to check is null");
}
// performance tweak
if (Edits.Contains(edit))
{
return true;
}
foreach (Edit kk in Edits)
{
if (edit.Id != kk.Id)
{
continue;
}
if (edit.Summary != kk.Summary)
{
continue;
}
if (edit.Rcid != kk.Rcid)
{
continue;
}
if (edit._Page != null && kk._Page != null)
{
if (edit._Page.Name != kk._Page.Name)
{
continue;
}
}
if (edit.Oldid != kk.Oldid)
{
continue;
}
return true;
}
}
return false;
}
/// <summary>
/// Insert an edit to any queue which matches the data
/// </summary>
/// <param name="_edit"></param>
public static void Enqueue(Edit _edit)
{
lock (All)
{
foreach (KeyValuePair<string, Queue> x in All)
{
if (!x.Value.ContainsEdit(_edit))
{
if (x.Value.Matches(_edit))
{
lock (x.Value.Edits)
{
x.Value.Edits.Add(_edit);
}
// Check if this is currently selected queue
if (x.Value.MatchesPanel())
{
// $fixme$
//x.Value.Panel.Add(_edit);
}
}
}
}
}
}
public enum QueueSortOrder
{
Time, TimeReverse, Quality
}
public enum DiffMode
{
None, Preload, All
}
public enum QueueType
{
FixedList, LiveList, Live, Dynamic
}
public enum QueueFilter
{
Require, None, Exclude
}
}
}