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