thassan
|
107
|
1
|
|
thassan
|
154
|
2
|
|
thassan
|
107
|
3
|
|
nmp
|
218
|
4
|
|
thassan
|
154
|
5
|
|
|
6
|
|
thassan
|
107
|
7
|
using System;
|
|
8
|
using System.Drawing;
|
|
9
|
using System.Collections;
|
|
10
|
using System.Windows.Forms;
|
thassan
|
154
|
11
|
using System.Threading;
|
thassan
|
107
|
12
|
using System.Data;
|
thassan
|
208
|
13
|
using System.Web;
|
thassan
|
143
|
14
|
using System.Text;
|
thassan
|
178
|
15
|
using System.IO;
|
thassan
|
165
|
16
|
using System.Xml;
|
nmp
|
200
|
17
|
using System.Xml.Schema;
|
thassan
|
143
|
18
|
using System.Collections.Generic;
|
nmp
|
234
|
19
|
|
|
20
|
using Ucla.Cens.Campaignr.Library;
|
thassan
|
165
|
21
|
using Ucla.Cens.Campaignr.Location;
|
thassan
|
177
|
22
|
using Ucla.Cens.Campaignr.Messaging;
|
nmp
|
234
|
23
|
using Ucla.Cens.Campaignr.Library.Upload;
|
|
24
|
using Ucla.Cens.Campaignr.Library.Sensors;
|
|
25
|
using Ucla.Cens.Campaignr.Library.Upload.Modules;
|
|
26
|
|
thassan
|
184
|
27
|
using System.Runtime.InteropServices;
|
nmp
|
216
|
28
|
using System.Reflection;
|
thassan
|
184
|
29
|
|
thassan
|
165
|
30
|
using SimpleDOMParserCSharp;
|
thassan
|
107
|
31
|
|
thassan
|
143
|
32
|
namespace Ucla.Cens.Campaignr.MobApp
|
thassan
|
107
|
33
|
{
|
|
34
|
|
thassan
|
193
|
35
|
|
thassan
|
107
|
36
|
|
thassan
|
143
|
37
|
|
thassan
|
107
|
38
|
public class MainForm : System.Windows.Forms.Form
|
|
39
|
{
|
nmp
|
296
|
40
|
private enum OperationModes { Upload, CollectUpload, Collect };
|
|
41
|
|
thassan
|
143
|
42
|
private MenuItem campaignMenuItem;
|
|
43
|
private MainMenu mainMenu1;
|
thassan
|
107
|
44
|
private MenuItem exitMenuItem;
|
nmp
|
216
|
45
|
|
thassan
|
107
|
46
|
private MenuItem menuCollect;
|
|
47
|
private MenuItem menuCollectUpload;
|
|
48
|
private MenuItem menuUpload;
|
|
49
|
|
nmp
|
296
|
50
|
|
nmp
|
299
|
51
|
|
nmp
|
213
|
52
|
|
nmp
|
296
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
|
thassan
|
193
|
57
|
private Delegate _delegateStatusUpdate;
|
nmp
|
296
|
58
|
|
thassan
|
262
|
59
|
private Delegate _delegateFeedbackUpdate;
|
nmp
|
296
|
60
|
|
thassan
|
193
|
61
|
private Delegate _delegateUploadUpdate;
|
nmp
|
213
|
62
|
|
nmp
|
296
|
63
|
|
nmp
|
299
|
64
|
|
|
65
|
private List<SensorDataManager> manualSensorDataManagers = new List<SensorDataManager>(1);
|
|
66
|
private List<SensorDataManager> automaticSensorDataManagers = new List<SensorDataManager>(1);
|
thassan
|
262
|
67
|
|
|
68
|
private FeedbackManager _feedbackManager;
|
nmp
|
296
|
69
|
|
thassan
|
193
|
70
|
private TimerCallback _timerDelegate;
|
nmp
|
296
|
71
|
|
thassan
|
193
|
72
|
private System.Threading.Timer _uploadMonitorTimer;
|
nmp
|
296
|
73
|
|
|
74
|
|
|
75
|
private const int uploadMonitorInterval = 10000;
|
|
76
|
|
|
77
|
private const int uploadInterval = 10000;
|
|
78
|
|
|
79
|
|
thassan
|
193
|
80
|
private object _lock = new object();
|
thassan
|
154
|
81
|
|
nmp
|
299
|
82
|
|
|
83
|
|
nmp
|
218
|
84
|
|
nmp
|
299
|
85
|
|
nmp
|
213
|
86
|
|
thassan
|
165
|
87
|
private string _campaignname = "";
|
nmp
|
299
|
88
|
private Boolean _uploadOnStart = true;
|
nmp
|
296
|
89
|
private Boolean _startOnLoad = false;
|
nmp
|
187
|
90
|
private Boolean _debugModeOn = false;
|
thassan
|
190
|
91
|
private Boolean _killUploadMonitor = false;
|
thassan
|
178
|
92
|
private MenuItem menuConfig;
|
nmp
|
296
|
93
|
|
nmp
|
185
|
94
|
private Label label1;
|
nmp
|
187
|
95
|
private Label status;
|
|
96
|
private Label upload;
|
nmp
|
218
|
97
|
private Panel loadingPanel;
|
|
98
|
private Label label2;
|
|
99
|
private ProgressBar progressBar1;
|
thassan
|
132
|
100
|
|
nmp
|
266
|
101
|
private bool _consoleMode = false;
|
|
102
|
private GraphicalInterface _graphicalInterface = null;
|
nmp
|
281
|
103
|
|
thassan
|
143
|
104
|
#region Public Delegates
|
thassan
|
132
|
105
|
|
nmp
|
299
|
106
|
|
thassan
|
154
|
107
|
public delegate void DelegateMenus(object sender, EventArgs args);
|
nmp
|
299
|
108
|
|
nmp
|
183
|
109
|
public delegate void DelegateStatusUpdate(Label ctrl, Object val);
|
nmp
|
299
|
110
|
|
thassan
|
262
|
111
|
public delegate void DelegateFeedbackUpdate(Label ctrl, Object val);
|
nmp
|
299
|
112
|
|
nmp
|
183
|
113
|
public delegate void DelegateUploadUpdate(Label ctrl, Object val);
|
thassan
|
132
|
114
|
|
thassan
|
143
|
115
|
#endregion
|
thassan
|
132
|
116
|
|
thassan
|
193
|
117
|
|
|
118
|
|
|
119
|
|
thassan
|
107
|
120
|
public MainForm()
|
|
121
|
{
|
nmp
|
265
|
122
|
|
|
123
|
string agreement = ConfigurationManager.AppSettings["UserAgreementStatus"];
|
nmp
|
281
|
124
|
|
nmp
|
265
|
125
|
if (agreement == null || agreement != "Accepted")
|
|
126
|
{
|
|
127
|
|
|
128
|
UserAgreement ua = new UserAgreement();
|
|
129
|
if (ua.ShowDialog() == DialogResult.Yes)
|
|
130
|
{
|
|
131
|
ConfigurationManager.AppSettings["UserAgreementStatus"] = "Accepted";
|
|
132
|
ConfigurationManager.Save();
|
nmp
|
273
|
133
|
|
|
134
|
ua.Close();
|
nmp
|
265
|
135
|
}
|
|
136
|
else
|
|
137
|
{
|
|
138
|
|
|
139
|
ConfigurationManager.AppSettings["UserAgreementStatus"] = "Declined";
|
|
140
|
ConfigurationManager.Save();
|
nmp
|
273
|
141
|
|
|
142
|
ua.Close();
|
|
143
|
|
nmp
|
265
|
144
|
this.Close();
|
|
145
|
return;
|
|
146
|
}
|
|
147
|
}
|
|
148
|
|
thassan
|
107
|
149
|
|
thassan
|
154
|
150
|
_delegateStatusUpdate = new DelegateStatusUpdate(StatusUpdate);
|
thassan
|
262
|
151
|
_delegateFeedbackUpdate = new DelegateFeedbackUpdate(FeedbackUpdate);
|
thassan
|
178
|
152
|
_delegateUploadUpdate = new DelegateUploadUpdate(UploadUpdate);
|
thassan
|
165
|
153
|
|
nmp
|
299
|
154
|
|
thassan
|
262
|
155
|
_feedbackManager = new FeedbackManager();
|
thassan
|
190
|
156
|
|
nmp
|
250
|
157
|
|
thassan
|
190
|
158
|
|
nmp
|
250
|
159
|
|
thassan
|
166
|
160
|
InitializeComponent();
|
thassan
|
178
|
161
|
|
nmp
|
298
|
162
|
LoadConfiguration(true);
|
thassan
|
107
|
163
|
}
|
thassan
|
193
|
164
|
|
thassan
|
107
|
165
|
|
|
166
|
|
|
167
|
|
thassan
|
143
|
168
|
protected override void Dispose(bool disposing)
|
thassan
|
107
|
169
|
{
|
thassan
|
143
|
170
|
base.Dispose(disposing);
|
thassan
|
107
|
171
|
}
|
thassan
|
143
|
172
|
|
thassan
|
107
|
173
|
#region Windows Form Designer generated code
|
|
174
|
|
|
175
|
|
|
176
|
|
|
177
|
|
|
178
|
private void InitializeComponent()
|
|
179
|
{
|
|
180
|
this.mainMenu1 = new System.Windows.Forms.MainMenu();
|
|
181
|
this.campaignMenuItem = new System.Windows.Forms.MenuItem();
|
|
182
|
this.menuCollect = new System.Windows.Forms.MenuItem();
|
|
183
|
this.menuCollectUpload = new System.Windows.Forms.MenuItem();
|
|
184
|
this.menuUpload = new System.Windows.Forms.MenuItem();
|
thassan
|
178
|
185
|
this.menuConfig = new System.Windows.Forms.MenuItem();
|
thassan
|
107
|
186
|
this.exitMenuItem = new System.Windows.Forms.MenuItem();
|
nmp
|
185
|
187
|
this.label1 = new System.Windows.Forms.Label();
|
nmp
|
187
|
188
|
this.status = new System.Windows.Forms.Label();
|
|
189
|
this.upload = new System.Windows.Forms.Label();
|
nmp
|
218
|
190
|
this.loadingPanel = new System.Windows.Forms.Panel();
|
nmp
|
234
|
191
|
this.label2 = new System.Windows.Forms.Label();
|
nmp
|
218
|
192
|
this.progressBar1 = new System.Windows.Forms.ProgressBar();
|
|
193
|
this.loadingPanel.SuspendLayout();
|
thassan
|
107
|
194
|
this.SuspendLayout();
|
|
195
|
|
|
196
|
|
|
197
|
|
|
198
|
this.mainMenu1.MenuItems.Add(this.campaignMenuItem);
|
|
199
|
this.mainMenu1.MenuItems.Add(this.exitMenuItem);
|
|
200
|
|
|
201
|
|
|
202
|
|
nmp
|
218
|
203
|
this.campaignMenuItem.Enabled = false;
|
thassan
|
107
|
204
|
this.campaignMenuItem.MenuItems.Add(this.menuCollect);
|
|
205
|
this.campaignMenuItem.MenuItems.Add(this.menuCollectUpload);
|
|
206
|
this.campaignMenuItem.MenuItems.Add(this.menuUpload);
|
thassan
|
178
|
207
|
this.campaignMenuItem.MenuItems.Add(this.menuConfig);
|
nmp
|
183
|
208
|
this.campaignMenuItem.Text = "Options";
|
thassan
|
107
|
209
|
|
|
210
|
|
|
211
|
|
thassan
|
190
|
212
|
this.menuCollect.Text = "Collect / Save";
|
thassan
|
107
|
213
|
this.menuCollect.Click += new System.EventHandler(this.menuCollect_Click);
|
|
214
|
|
|
215
|
|
|
216
|
|
thassan
|
190
|
217
|
this.menuCollectUpload.Text = "Collect / Upload";
|
thassan
|
132
|
218
|
this.menuCollectUpload.Click += new System.EventHandler(this.menuCollectUpload_Click);
|
thassan
|
107
|
219
|
|
|
220
|
|
|
221
|
|
thassan
|
190
|
222
|
this.menuUpload.Text = "Upload Saved";
|
thassan
|
143
|
223
|
this.menuUpload.Click += new System.EventHandler(this.menuUpload_Click);
|
thassan
|
107
|
224
|
|
thassan
|
178
|
225
|
|
|
226
|
|
thassan
|
191
|
227
|
this.menuConfig.Text = "Change Configuration";
|
nmp
|
298
|
228
|
this.menuConfig.Click += new System.EventHandler(this.LoadConfiguration);
|
thassan
|
178
|
229
|
|
thassan
|
107
|
230
|
|
|
231
|
|
nmp
|
218
|
232
|
this.exitMenuItem.Enabled = false;
|
nmp
|
204
|
233
|
this.exitMenuItem.Text = "Exit";
|
thassan
|
107
|
234
|
this.exitMenuItem.Click += new System.EventHandler(this.exitMenuItem_Click);
|
|
235
|
|
nmp
|
187
|
236
|
|
|
237
|
|
|
238
|
this.label1.Location = new System.Drawing.Point(0, 153);
|
|
239
|
this.label1.Name = "label1";
|
|
240
|
this.label1.Size = new System.Drawing.Size(320, 10);
|
|
241
|
|
thassan
|
107
|
242
|
|
|
243
|
|
nmp
|
187
|
244
|
this.status.Font = new System.Drawing.Font("Segoe Condensed", 8F, System.Drawing.FontStyle.Regular);
|
|
245
|
this.status.Location = new System.Drawing.Point(4, 2);
|
thassan
|
107
|
246
|
this.status.Name = "status";
|
nmp
|
187
|
247
|
this.status.Size = new System.Drawing.Size(313, 158);
|
thassan
|
177
|
248
|
|
|
249
|
|
|
250
|
|
nmp
|
187
|
251
|
this.upload.Font = new System.Drawing.Font("Segoe Condensed", 8F, System.Drawing.FontStyle.Regular);
|
|
252
|
this.upload.Location = new System.Drawing.Point(4, 167);
|
thassan
|
177
|
253
|
this.upload.Name = "upload";
|
nmp
|
187
|
254
|
this.upload.Size = new System.Drawing.Size(313, 20);
|
|
255
|
this.upload.TextAlign = System.Drawing.ContentAlignment.TopCenter;
|
nmp
|
185
|
256
|
|
nmp
|
218
|
257
|
|
|
258
|
|
nmp
|
273
|
259
|
this.loadingPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
|
260
|
| System.Windows.Forms.AnchorStyles.Left)
|
|
261
|
| System.Windows.Forms.AnchorStyles.Right)));
|
|
262
|
this.loadingPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
|
nmp
|
218
|
263
|
this.loadingPanel.Controls.Add(this.label2);
|
|
264
|
this.loadingPanel.Controls.Add(this.progressBar1);
|
nmp
|
273
|
265
|
this.loadingPanel.Location = new System.Drawing.Point(25, 43);
|
nmp
|
218
|
266
|
this.loadingPanel.Name = "loadingPanel";
|
nmp
|
273
|
267
|
this.loadingPanel.Size = new System.Drawing.Size(269, 91);
|
nmp
|
218
|
268
|
|
|
269
|
|
|
270
|
|
nmp
|
273
|
271
|
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
|
272
|
| System.Windows.Forms.AnchorStyles.Right)));
|
nmp
|
218
|
273
|
this.label2.Location = new System.Drawing.Point(3, 24);
|
|
274
|
this.label2.Name = "label2";
|
nmp
|
273
|
275
|
this.label2.Size = new System.Drawing.Size(263, 30);
|
nmp
|
218
|
276
|
this.label2.Text = "Loading please wait...";
|
|
277
|
this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
|
|
278
|
|
nmp
|
234
|
279
|
|
|
280
|
|
nmp
|
273
|
281
|
this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
|
282
|
| System.Windows.Forms.AnchorStyles.Right)));
|
nmp
|
234
|
283
|
this.progressBar1.Location = new System.Drawing.Point(3, 57);
|
|
284
|
this.progressBar1.Name = "progressBar1";
|
nmp
|
273
|
285
|
this.progressBar1.Size = new System.Drawing.Size(263, 19);
|
nmp
|
234
|
286
|
|
thassan
|
107
|
287
|
|
|
288
|
|
|
289
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
|
290
|
this.ClientSize = new System.Drawing.Size(320, 186);
|
nmp
|
218
|
291
|
this.Controls.Add(this.loadingPanel);
|
thassan
|
177
|
292
|
this.Controls.Add(this.upload);
|
nmp
|
187
|
293
|
this.Controls.Add(this.status);
|
nmp
|
185
|
294
|
this.Controls.Add(this.label1);
|
thassan
|
107
|
295
|
this.Menu = this.mainMenu1;
|
|
296
|
this.Name = "MainForm";
|
|
297
|
this.Text = "Campaignr";
|
thassan
|
203
|
298
|
this.Load += new System.EventHandler(this.MainForm_Load);
|
thassan
|
107
|
299
|
this.Closed += new System.EventHandler(this.MainForm_Closed);
|
nmp
|
218
|
300
|
this.loadingPanel.ResumeLayout(false);
|
thassan
|
107
|
301
|
this.ResumeLayout(false);
|
|
302
|
|
|
303
|
}
|
|
304
|
#endregion
|
|
305
|
|
|
306
|
|
|
307
|
|
|
308
|
|
thassan
|
143
|
309
|
static void Main()
|
thassan
|
107
|
310
|
{
|
nmp
|
301
|
311
|
|
nmp
|
273
|
312
|
|
nmp
|
265
|
313
|
try
|
|
314
|
{
|
|
315
|
Application.Run(new MainForm());
|
|
316
|
}
|
nmp
|
273
|
317
|
catch (ObjectDisposedException ex)
|
nmp
|
265
|
318
|
{
|
|
319
|
|
nmp
|
273
|
320
|
string trace = ex.StackTrace;
|
nmp
|
265
|
321
|
}
|
thassan
|
107
|
322
|
}
|
|
323
|
|
thassan
|
193
|
324
|
|
|
325
|
|
|
326
|
|
thassan
|
178
|
327
|
private void monitorUpload(Object o)
|
|
328
|
{
|
|
329
|
lock (_lock)
|
|
330
|
{
|
|
331
|
Message msg;
|
nmp
|
296
|
332
|
|
thassan
|
190
|
333
|
try
|
|
334
|
{
|
thassan
|
262
|
335
|
while (!_killUploadMonitor && (msg = DatabaseManager.MessageQueue.GetItem()) != null)
|
thassan
|
178
|
336
|
{
|
thassan
|
190
|
337
|
|
nmp
|
293
|
338
|
if (msg.MType == MessageType.Error)
|
thassan
|
190
|
339
|
{
|
|
340
|
|
nmp
|
296
|
341
|
|
nmp
|
187
|
342
|
|
thassan
|
190
|
343
|
if (_debugModeOn)
|
|
344
|
Invoke(_delegateStatusUpdate, new Object[] { status, msg.ToString() });
|
|
345
|
}
|
nmp
|
293
|
346
|
else if (msg.MType == MessageType.Warning)
|
thassan
|
190
|
347
|
{
|
|
348
|
if (_debugModeOn)
|
|
349
|
Invoke(_delegateStatusUpdate, new Object[] { status, msg.ToString() });
|
|
350
|
}
|
nmp
|
293
|
351
|
else if (msg.MType == MessageType.Status)
|
thassan
|
193
|
352
|
{
|
nmp
|
296
|
353
|
Invoke(_delegateStatusUpdate, new Object[] { status, msg.ToString() });
|
thassan
|
193
|
354
|
}
|
nmp
|
293
|
355
|
else if (msg.MType == MessageType.Information)
|
nmp
|
188
|
356
|
{
|
thassan
|
190
|
357
|
if (_debugModeOn)
|
nmp
|
188
|
358
|
Invoke(_delegateStatusUpdate, new Object[] { status, msg.ToString() });
|
|
359
|
}
|
nmp
|
293
|
360
|
else if (msg.MType == MessageType.UploadSuccess)
|
thassan
|
190
|
361
|
{
|
|
362
|
if (msg.Text.Length == 0)
|
nmp
|
296
|
363
|
Invoke(_delegateUploadUpdate, new Object[] { upload, "" });
|
thassan
|
193
|
364
|
else
|
nmp
|
296
|
365
|
Invoke(_delegateUploadUpdate, new Object[] { upload, msg.ToString() });
|
thassan
|
190
|
366
|
}
|
nmp
|
293
|
367
|
else if (msg.MType == MessageType.Feedback)
|
thassan
|
262
|
368
|
{
|
|
369
|
if (msg.Text.Length > 0)
|
nmp
|
296
|
370
|
|
|
371
|
Invoke(_delegateFeedbackUpdate, new Object[] { status, msg.ToString() });
|
thassan
|
262
|
372
|
}
|
nmp
|
293
|
373
|
else if (msg.MType == MessageType.TaskComplete)
|
thassan
|
190
|
374
|
{
|
nmp
|
296
|
375
|
Invoke(_delegateUploadUpdate, new Object[] { status, msg.ToString() });
|
thassan
|
190
|
376
|
}
|
thassan
|
178
|
377
|
}
|
thassan
|
190
|
378
|
|
nmp
|
296
|
379
|
|
|
380
|
|
|
381
|
} catch {
|
|
382
|
|
thassan
|
190
|
383
|
}
|
thassan
|
177
|
384
|
}
|
thassan
|
154
|
385
|
}
|
|
386
|
|
thassan
|
193
|
387
|
|
|
388
|
|
|
389
|
|
nmp
|
183
|
390
|
private void StatusUpdate(Label ctrl, Object val)
|
thassan
|
154
|
391
|
{
|
nmp
|
183
|
392
|
if (ctrl.Text.Length + val.ToString().Length < 5000)
|
thassan
|
178
|
393
|
{
|
nmp
|
187
|
394
|
ctrl.Text = val.ToString() + "\r\n" + ctrl.Text;
|
thassan
|
178
|
395
|
}
|
thassan
|
177
|
396
|
else
|
|
397
|
{
|
nmp
|
183
|
398
|
ctrl.Text = val.ToString() + "\r\n" + ctrl.Text.Substring(0, 1000);
|
thassan
|
177
|
399
|
}
|
nmp
|
266
|
400
|
|
|
401
|
if (this._graphicalInterface != null)
|
|
402
|
{
|
|
403
|
_graphicalInterface.OutputText = val.ToString().Substring(10);
|
|
404
|
}
|
thassan
|
262
|
405
|
}
|
nmp
|
253
|
406
|
|
thassan
|
262
|
407
|
|
|
408
|
|
|
409
|
|
|
410
|
private void FeedbackUpdate(Label ctrl, Object val)
|
|
411
|
{
|
|
412
|
if (ctrl.Text.Length + val.ToString().Length < 5000)
|
nmp
|
253
|
413
|
{
|
thassan
|
262
|
414
|
ctrl.Text = val.ToString() + "\r\n" + ctrl.Text;
|
|
415
|
}
|
|
416
|
else
|
|
417
|
{
|
|
418
|
ctrl.Text = val.ToString() + "\r\n" + ctrl.Text.Substring(0, 1000);
|
nmp
|
253
|
419
|
}
|
thassan
|
154
|
420
|
}
|
|
421
|
|
thassan
|
193
|
422
|
|
|
423
|
|
|
424
|
|
nmp
|
183
|
425
|
private void UploadUpdate(Label ctrl, Object val)
|
thassan
|
178
|
426
|
{
|
nmp
|
266
|
427
|
ctrl.Text = val.ToString();
|
|
428
|
|
|
429
|
if (this._graphicalInterface != null)
|
|
430
|
{
|
|
431
|
_graphicalInterface.OutputText = val.ToString().Substring(10);
|
|
432
|
}
|
thassan
|
178
|
433
|
}
|
|
434
|
|
nmp
|
298
|
435
|
|
thassan
|
262
|
436
|
private void exitMenuItem_Click(object sender, EventArgs e)
|
thassan
|
107
|
437
|
{
|
nmp
|
299
|
438
|
if (manualSensorDataManagers.Count > 0 || automaticSensorDataManagers.Count > 0)
|
nmp
|
265
|
439
|
{
|
nmp
|
293
|
440
|
DatabaseManager.MessageQueue.PostItem(new Message("Closing Campaignr", MessageType.Status));
|
nmp
|
299
|
441
|
|
|
442
|
foreach(SensorDataManager manager in manualSensorDataManagers)
|
|
443
|
manager.Log = false;
|
|
444
|
foreach (SensorDataManager manager in automaticSensorDataManagers)
|
|
445
|
manager.Log = false;
|
nmp
|
265
|
446
|
}
|
|
447
|
|
|
448
|
try
|
|
449
|
{
|
|
450
|
Close();
|
|
451
|
}
|
nmp
|
273
|
452
|
catch (Exception ex)
|
nmp
|
265
|
453
|
{
|
|
454
|
|
nmp
|
273
|
455
|
string exs2 = ex.Message;
|
nmp
|
265
|
456
|
}
|
thassan
|
107
|
457
|
}
|
thassan
|
262
|
458
|
|
nmp
|
298
|
459
|
|
thassan
|
262
|
460
|
private void MainForm_Load(object sender, System.EventArgs e)
|
|
461
|
{
|
|
462
|
status.Width = Screen.PrimaryScreen.WorkingArea.Width;
|
|
463
|
status.Height = Screen.PrimaryScreen.WorkingArea.Height;
|
|
464
|
}
|
|
465
|
|
nmp
|
296
|
466
|
|
thassan
|
262
|
467
|
private void MainForm_Closed(object sender, System.EventArgs e)
|
|
468
|
{
|
nmp
|
296
|
469
|
closeSensors();
|
thassan
|
262
|
470
|
}
|
|
471
|
|
nmp
|
298
|
472
|
|
thassan
|
262
|
473
|
private void startMonitor()
|
|
474
|
{
|
|
475
|
status.Text = "";
|
|
476
|
_killUploadMonitor = false;
|
|
477
|
AutoResetEvent autoEvent = new AutoResetEvent(false);
|
|
478
|
_timerDelegate = new TimerCallback(monitorUpload);
|
nmp
|
296
|
479
|
_uploadMonitorTimer = new System.Threading.Timer(_timerDelegate, autoEvent, 0, uploadMonitorInterval);
|
|
480
|
}
|
|
481
|
|
|
482
|
private void uploadData() { }
|
|
483
|
|
|
484
|
private void collectData() { }
|
|
485
|
|
|
486
|
private void closeSensors(){
|
|
487
|
if (_uploadMonitorTimer != null)
|
|
488
|
{
|
|
489
|
_killUploadMonitor = true;
|
|
490
|
_uploadMonitorTimer.Dispose();
|
|
491
|
}
|
nmp
|
299
|
492
|
|
|
493
|
foreach (SensorDataManager manager in manualSensorDataManagers)
|
|
494
|
{
|
|
495
|
manager.CloseSensors();
|
|
496
|
}
|
|
497
|
foreach (SensorDataManager manager in automaticSensorDataManagers)
|
|
498
|
{
|
|
499
|
manager.CloseSensors();
|
|
500
|
}
|
nmp
|
296
|
501
|
}
|
|
502
|
|
|
503
|
private OperationModes _operationMode;
|
|
504
|
|
|
505
|
|
|
506
|
|
|
507
|
private OperationModes Mode
|
|
508
|
{
|
|
509
|
set
|
|
510
|
{
|
|
511
|
_operationMode = value;
|
|
512
|
|
|
513
|
|
nmp
|
299
|
514
|
|
nmp
|
296
|
515
|
|
|
516
|
bool activityOn = false;
|
|
517
|
|
|
518
|
switch (_operationMode)
|
|
519
|
{
|
|
520
|
case OperationModes.Upload:
|
|
521
|
menuCollect.Checked = false;
|
|
522
|
menuCollectUpload.Checked = false;
|
|
523
|
|
|
524
|
activityOn = menuUpload.Checked = !menuUpload.Checked;
|
|
525
|
|
nmp
|
299
|
526
|
if (activityOn)
|
|
527
|
{
|
|
528
|
foreach (SensorDataManager manager in manualSensorDataManagers)
|
|
529
|
{
|
|
530
|
manager.UploadOnly();
|
|
531
|
}
|
|
532
|
foreach (SensorDataManager manager in automaticSensorDataManagers)
|
|
533
|
{
|
|
534
|
manager.UploadOnly();
|
|
535
|
}
|
|
536
|
}
|
nmp
|
296
|
537
|
|
|
538
|
break;
|
|
539
|
case OperationModes.Collect:
|
|
540
|
menuUpload.Checked = false;
|
|
541
|
menuCollectUpload.Checked = false;
|
thassan
|
262
|
542
|
|
nmp
|
296
|
543
|
activityOn = menuCollect.Checked = !menuCollect.Checked;
|
|
544
|
|
nmp
|
299
|
545
|
if (activityOn)
|
|
546
|
{
|
|
547
|
|
|
548
|
|
|
549
|
|
|
550
|
|
|
551
|
foreach (SensorDataManager manager in automaticSensorDataManagers)
|
|
552
|
{
|
|
553
|
manager.Collect(false);
|
|
554
|
}
|
|
555
|
}
|
nmp
|
296
|
556
|
|
|
557
|
break;
|
|
558
|
case OperationModes.CollectUpload:
|
|
559
|
menuUpload.Checked = false;
|
|
560
|
menuCollect.Checked = false;
|
|
561
|
|
|
562
|
activityOn = menuCollectUpload.Checked = !menuCollectUpload.Checked;
|
|
563
|
|
nmp
|
299
|
564
|
if (activityOn && automaticSensorDataManagers.Count > 0)
|
|
565
|
{
|
|
566
|
foreach (SensorDataManager manager in automaticSensorDataManagers)
|
|
567
|
{
|
|
568
|
manager.Collect(true);
|
|
569
|
}
|
|
570
|
}
|
nmp
|
296
|
571
|
|
|
572
|
break;
|
|
573
|
}
|
|
574
|
|
|
575
|
if (activityOn)
|
|
576
|
startMonitor();
|
|
577
|
}
|
thassan
|
262
|
578
|
}
|
|
579
|
|
nmp
|
296
|
580
|
|
thassan
|
262
|
581
|
private void menuCollect_Click(object sender, EventArgs e)
|
thassan
|
132
|
582
|
{
|
nmp
|
296
|
583
|
this.Mode = OperationModes.Collect;
|
thassan
|
143
|
584
|
}
|
thassan
|
132
|
585
|
|
thassan
|
262
|
586
|
|
nmp
|
253
|
587
|
public void menuCollectUpload_Click(object sender, EventArgs e)
|
thassan
|
132
|
588
|
{
|
nmp
|
296
|
589
|
this.Mode = OperationModes.CollectUpload;
|
|
590
|
}
|
|
591
|
|
|
592
|
|
|
593
|
private void menuUpload_Click(object sender, EventArgs e)
|
|
594
|
{
|
|
595
|
this.Mode = OperationModes.Upload;
|
thassan
|
143
|
596
|
}
|
thassan
|
132
|
597
|
|
nmp
|
296
|
598
|
|
nmp
|
299
|
599
|
private void ParseXMLConfiguration(string filename, string path)
|
thassan
|
165
|
600
|
{
|
|
601
|
try
|
|
602
|
{
|
nmp
|
299
|
603
|
XmlTextReader rdr = new XmlTextReader(path + filename);
|
thassan
|
165
|
604
|
SimpleDOMParser sdp = new SimpleDOMParser();
|
|
605
|
SimpleElement se = sdp.parse(rdr);
|
thassan
|
178
|
606
|
|
nmp
|
292
|
607
|
bool flushDatabase = false;
|
|
608
|
|
nmp
|
299
|
609
|
foreach (SensorDataManager manager in manualSensorDataManagers)
|
|
610
|
{
|
|
611
|
manager.CloseSensors();
|
|
612
|
}
|
|
613
|
foreach (SensorDataManager manager in automaticSensorDataManagers)
|
|
614
|
{
|
|
615
|
manager.CloseSensors();
|
|
616
|
}
|
|
617
|
|
|
618
|
manualSensorDataManagers.Clear();
|
|
619
|
automaticSensorDataManagers.Clear();
|
thassan
|
190
|
620
|
|
thassan
|
165
|
621
|
if (se.TagName.ToLower().Equals("campaign"))
|
|
622
|
{
|
|
623
|
_campaignname = se.Attributes["name"];
|
nmp
|
183
|
624
|
|
nmp
|
296
|
625
|
|
nmp
|
292
|
626
|
if (se.Attribute("flushDatabase") != null && se.Attribute("flushDatabase") == "true")
|
|
627
|
flushDatabase = true;
|
|
628
|
|
nmp
|
183
|
629
|
this.Text = "Campaignr - "+ _campaignname;
|
|
630
|
|
nmp
|
296
|
631
|
|
nmp
|
299
|
632
|
if(se.Attributes["uploadOnStart"] != null && System.Convert.ToBoolean(se.Attributes["uploadOnStart"]) == false)
|
|
633
|
_uploadOnStart = false;
|
nmp
|
296
|
634
|
|
nmp
|
187
|
635
|
_debugModeOn = System.Convert.ToBoolean(se.Attributes["debug"]);
|
thassan
|
165
|
636
|
|
|
637
|
SimpleElements elements = se.ChildElements;
|
nmp
|
218
|
638
|
|
nmp
|
299
|
639
|
if (elements.Count == 0)
|
nmp
|
218
|
640
|
{
|
thassan
|
262
|
641
|
DatabaseManager.MessageQueue.PostItem(new Message("Configuration file missing automatic or manual section", MessageType.Error));
|
nmp
|
218
|
642
|
return;
|
|
643
|
}
|
nmp
|
296
|
644
|
|
nmp
|
299
|
645
|
for (int i = 0; i < elements.Count; i++)
|
|
646
|
{
|
|
647
|
SimpleElement collection = elements.Item(i);
|
nmp
|
296
|
648
|
|
nmp
|
299
|
649
|
SensorDataManager manager = new SensorDataManager(flushDatabase);
|
|
650
|
manager.CollectInterval = uploadInterval;
|
|
651
|
manager.Log = _debugModeOn;
|
|
652
|
manager.CampaignId = filename;
|
|
653
|
|
|
654
|
if (collection.TagName == "automatic")
|
|
655
|
{
|
|
656
|
|
|
657
|
_startOnLoad = System.Convert.ToBoolean(se.Attributes["startOnLoad"]);
|
thassan
|
165
|
658
|
|
nmp
|
299
|
659
|
manager.Automatic = true;
|
nmp
|
218
|
660
|
|
nmp
|
299
|
661
|
automaticSensorDataManagers.Add(manager);
|
|
662
|
}
|
|
663
|
else if (collection.TagName == "manual")
|
thassan
|
165
|
664
|
{
|
nmp
|
299
|
665
|
manualSensorDataManagers.Add(manager);
|
|
666
|
}
|
|
667
|
else
|
|
668
|
{
|
|
669
|
manager = null;
|
|
670
|
continue;
|
|
671
|
}
|
|
672
|
|
|
673
|
progressBar1.Value += 10;
|
|
674
|
int step = (int)Math.Floor(((20 / elements.Count) / collection.ChildElements.Count));
|
thassan
|
165
|
675
|
|
nmp
|
299
|
676
|
foreach (SimpleElement child in collection.ChildElements)
|
|
677
|
{
|
|
678
|
progressBar1.Value += Math.Min(progressBar1.Maximum - progressBar1.Value, step);
|
nmp
|
228
|
679
|
|
nmp
|
299
|
680
|
string name = child.TagName;
|
|
681
|
if (name.ToLower().Equals("sensor"))
|
|
682
|
{
|
|
683
|
string type = child.Attributes["type"];
|
nmp
|
273
|
684
|
|
nmp
|
299
|
685
|
if (type != null)
|
|
686
|
{
|
|
687
|
try
|
nmp
|
273
|
688
|
{
|
nmp
|
299
|
689
|
|
|
690
|
string sensorName = child.Attributes["name"];
|
|
691
|
if (sensorName == null)
|
|
692
|
|
|
693
|
sensorName = type.Trim();
|
thassan
|
233
|
694
|
else
|
nmp
|
299
|
695
|
sensorName = sensorName.Trim();
|
|
696
|
|
|
697
|
if (type.ToLower().Equals("imei"))
|
|
698
|
{
|
|
699
|
string hashed = child.Attributes["hash"];
|
|
700
|
|
|
701
|
if (hashed != null && hashed == "true")
|
|
702
|
manager.AssignSensor(new DeviceId("campaignrwm"), sensorName);
|
|
703
|
else
|
|
704
|
manager.AssignSensor(new Imei(), sensorName);
|
|
705
|
}
|
|
706
|
else if (type.ToLower().Equals("cellid"))
|
|
707
|
manager.AssignSensor(new CellTower(), sensorName);
|
|
708
|
else if (type.ToLower().Equals("timestamp"))
|
|
709
|
manager.AssignSensor(new Timestamp(), sensorName);
|
|
710
|
else if (type.ToLower().Equals("bt_stumble"))
|
thassan
|
233
|
711
|
{
|
nmp
|
299
|
712
|
if (child.ChildElements.Count == 0)
|
|
713
|
manager.AssignSensor(new BTStumbler(true), sensorName);
|
|
714
|
else
|
thassan
|
233
|
715
|
{
|
nmp
|
299
|
716
|
foreach (SimpleElement btchild in child.ChildElements)
|
|
717
|
{
|
|
718
|
if (btchild.TagName == "address_only")
|
|
719
|
manager.AssignSensor(new BTStumbler(false), sensorName);
|
|
720
|
}
|
thassan
|
233
|
721
|
}
|
nmp
|
299
|
722
|
|
thassan
|
233
|
723
|
}
|
nmp
|
299
|
724
|
else if (type.ToLower().Equals("location"))
|
|
725
|
{
|
|
726
|
Gps gps = new Gps();
|
|
727
|
gps.Open();
|
|
728
|
gps.LocationChanged += new LocationChangedEventHandler(LocationChanged);
|
thassan
|
233
|
729
|
|
nmp
|
299
|
730
|
manager.AssignSensor(gps, sensorName);
|
|
731
|
}
|
|
732
|
else if (type.ToLower().Equals("audio"))
|
|
733
|
manager.AssignSensor(new Microphone(), sensorName);
|
|
734
|
else if (type.ToLower().Equals("tag"))
|
|
735
|
{
|
|
736
|
SimpleElement prompt = child.ChildElements.Item("prompt");
|
|
737
|
SimpleElement input = child.ChildElements.Item("text");
|
nmp
|
218
|
738
|
|
nmp
|
299
|
739
|
if (input != null)
|
|
740
|