10 using BBSensorConnection;
13 using System.Diagnostics;
16 using System.Text.RegularExpressions;
17 using System.Threading;
18 using System.Windows.Forms;
19 using Timer = System.Windows.Forms.Timer;
27 private Process PIRSensorTask =
new Process();
28 private Process ThermostatTask =
new Process();
29 private Process FitnessTask =
new Process();
30 private Process BBNetwork =
new Process();
31 private string BBNSetup =
@"netSetup.bat";
32 private string BBPpath =
@"BBPresenseSensor.exe";
33 private string BBTpath =
@"BBThermostatSensor.exe";
34 private string BBFpath =
@"MiBand-Heartrate.exe";
35 private BBSensorObjects BBSO =
new BBSensorObjects();
37 public static string StartDate =
"";
38 public static string StopDate =
"";
42 private bool BBPSStatus =
false;
46 private bool BBTSStatus =
false;
48 private string BBTSname =
"";
49 private bool BBTSGetModel =
false;
53 private bool BBFSStatus =
false;
55 private string fileName =
"";
57 private bool ScheduleSet =
false;
58 private DateTime startdate;
59 private DateTime enddate;
60 private DateTime today = DateTime.Today;
70 InitializeComponent();
72 StatusChecker =
new Timer();
73 StatusChecker.Tick +=
new EventHandler(StatusChecker_Tick);
74 StatusChecker.Interval = 5000;
75 StatusChecker.Enabled =
true;
79 #endregion Constructor 81 #region PluginProcessCheck 88 fileName = Path.GetFileName(BBPpath);
91 Process[] processName = Process.GetProcessesByName(fileName.Substring(0, fileName.LastIndexOf(
'.')));
92 if (processName.Length > 0)
94 MotionStatusIcon.Image = Properties.Resources.trafficlight_green;
97 BBPSStatus = BBSO.isRunning;
102 MotionStatusIcon.Image = Properties.Resources.trafficlight_green;
106 MotionStatusIcon.Image = Properties.Resources.trafficlight_yellow;
111 MotionStatusIcon.Image = Properties.Resources.trafficlight_red;
122 string fileName = Path.GetFileName(BBTpath);
125 Process[] processName = Process.GetProcessesByName(fileName.Substring(0, fileName.LastIndexOf(
'.')));
126 if (processName.Length > 0)
128 ThermostatStatusIcon.Image = Properties.Resources.trafficlight_green;
133 BBTSname = BBThermostatConnection.BBThermostatConnect.BBThermostatType();
137 BBTModel.Text = BBTSname;
147 ThermostatStatusIcon.Image = Properties.Resources.trafficlight_green;
151 ThermostatStatusIcon.Image = Properties.Resources.trafficlight_red;
156 ThermostatStatusIcon.Image = Properties.Resources.trafficlight_red;
168 StringBuilder stringBuilder =
new StringBuilder();
170 foreach (
object match
in Regex.Matches(input,
"[0-9nu BRevCTkMGHzVs%\\-.]"))
172 stringBuilder.Append(match.ToString());
175 return stringBuilder.ToString();
183 fileName = Path.GetFileName(BBFpath);
186 Process[] processName = Process.GetProcessesByName(fileName.Substring(0, fileName.LastIndexOf(
'.')));
187 if (processName.Length > 0)
189 FitnessStatusIcon.Image = Properties.Resources.trafficlight_green;
193 FitnessStatusIcon.Image = Properties.Resources.trafficlight_red;
198 #endregion PluginProcessCheck 200 #region ApplicationStartup 205 private void StartPIR()
209 PIRSensorTask.StartInfo.FileName = BBPpath;
210 PIRSensorTask.StartInfo.CreateNoWindow =
false;
211 PIRSensorTask.Start();
222 private void StartThermostate()
226 ThermostatTask.StartInfo.FileName = BBTpath;
227 ThermostatTask.StartInfo.CreateNoWindow =
false;
228 ThermostatTask.Start();
232 ThermostatStatusIcon.Image = Properties.Resources.trafficlight_red;
240 private void StartFitnessTracker()
244 FitnessTask.StartInfo.FileName = BBFpath;
245 FitnessTask.StartInfo.CreateNoWindow =
false;
254 #endregion ApplicationStartup 256 #region PluginStatusCheck 261 private void BBTaskCheck()
263 StatusIcon.Image = Properties.Resources.trafficlight_green;
268 if (BBFSStatus && BBPSStatus && BBTSStatus && ScheduleSet)
270 SchedulerIcon.Image = Properties.Resources.trafficlight_green;
272 if (BBFSStatus || BBPSStatus || BBTSStatus && ScheduleSet)
274 SchedulerIcon.Image = Properties.Resources.trafficlight_green;
276 if (!BBFSStatus && !BBPSStatus && !BBTSStatus && ScheduleSet)
278 SchedulerIcon.Image = Properties.Resources.trafficlight_yellow;
280 if (BBFSStatus && BBPSStatus && BBTSStatus && !ScheduleSet)
282 SchedulerIcon.Image = Properties.Resources.trafficlight_yellow;
288 SchedulerIcon.Image = Properties.Resources.trafficlight_red;
297 private void StatusChecker_Tick(
object sender, EventArgs e)
305 private void TSStatusChecker()
307 if ((startdate <= today) && (today <= enddate) && ScheduleSet)
316 StatusIcon.Image = Properties.Resources.trafficlight_red;
326 StatusIcon.Image = Properties.Resources.trafficlight_red;
338 MotionStatusIcon.Image = Properties.Resources.trafficlight_red;
339 StatusIcon.Image = Properties.Resources.trafficlight_red;
344 ResearchSpand.Value = (today).Day / startdate.Day;
346 if (ResearchSpand.Value == 100)
349 StatusChecker.Stop();
350 MessageBox.Show(
"You have come to the end of the\n research period, thank you for participating.");
352 PIRSensorTask.Kill();
353 ThermostatTask.Kill();
367 #endregion PluginStatusCheck 369 #region ButtonControls 376 private void BBSmartSetup_Click(
object sender, EventArgs e)
378 ProcessStartInfo proc1 =
new ProcessStartInfo();
380 proc1.UseShellExecute =
true;
381 Command =
@"netsh wlan show hostednetwork";
382 proc1.WorkingDirectory =
@"C:\Windows\System32";
383 proc1.FileName =
@"C:\Windows\System32\cmd.exe";
384 proc1.Verb =
"runas";
385 proc1.Arguments =
"/k " + Command;
386 proc1.WindowStyle = ProcessWindowStyle.Normal;
387 Process.Start(proc1);
395 private void BBAdvSetup_Click(
object sender, EventArgs e)
397 StartFitnessTracker();
404 private void BBtaskScheduler_Load(
object sender, EventArgs e)
412 private bool ScheduleChecker()
414 ResearchSpand.Value = 0;
415 startdate = Convert.ToDateTime(StartDateObj.Value.ToString(
"MM/dd/yyyy"));
416 enddate = Convert.ToDateTime(StopDateObj.Value.ToString(
"MM/dd/yyyy"));
418 if (startdate !=
null && enddate !=
null)
420 int value = (int)((enddate - startdate).TotalDays);
421 ResearchSpand.Maximum = value;
422 ResearchSpand.Minimum = 0;
424 StatusChecker.Start();
429 StatusChecker.Start();
441 private void BBRestart_Click(
object sender, EventArgs e)
443 PIRSensorTask.Kill();
444 ThermostatTask.Kill();
447 PIRSensorTask.Start();
449 ThermostatTask.Start();
454 #endregion ButtonControls 456 #region DashBoardControls 461 private void CheckDate()
463 DateTime today = DateTime.Today;
464 if ((startdate <= today) && (today <= enddate))
466 ScheduleSet = ScheduleChecker();
471 StatusChecker.Start();
475 StartFitnessTracker();
484 MessageBox.Show(
"Schedule date invalid");
492 private void submitBtn_Click(
object sender, EventArgs e)
502 private void offBtn_Click(
object sender, EventArgs e)
506 PIRSensorTask.Kill();
507 ThermostatTask.Kill();
523 private void networkDisconnect_Click(
object sender, EventArgs e)
525 ProcessStartInfo proc1 =
new ProcessStartInfo();
527 proc1.UseShellExecute =
true;
528 Command =
@"netsh wlan stop hostednetwork";
529 proc1.WorkingDirectory =
@"C:\Windows\System32";
530 proc1.FileName =
@"C:\Windows\System32\cmd.exe";
531 proc1.Verb =
"runas";
532 proc1.Arguments =
"/k " + Command;
533 proc1.WindowStyle = ProcessWindowStyle.Hidden;
534 Process.Start(proc1);
542 private void networkSetup_Click(
object sender, EventArgs e)
544 ProcessStartInfo proc1 =
new ProcessStartInfo();
546 proc1.UseShellExecute =
true;
547 Command =
@"netsh wlan start hostednetwork";
548 proc1.WorkingDirectory =
@"C:\Windows\System32";
549 proc1.FileName =
@"C:\Windows\System32\cmd.exe";
550 proc1.Verb =
"runas";
551 proc1.Arguments =
"/k " + Command;
552 proc1.WindowStyle = ProcessWindowStyle.Hidden;
553 Process.Start(proc1);
561 private void adaptorBtn_Click(
object sender, EventArgs e)
563 ProcessStartInfo proc1 =
new ProcessStartInfo();
565 proc1.UseShellExecute =
true;
566 Command =
@"ncpa.cpl";
567 proc1.WorkingDirectory =
@"C:\Windows\System32";
568 proc1.FileName =
@"C:\Windows\System32\cmd.exe";
569 proc1.Arguments =
"/k " + Command;
570 proc1.WindowStyle = ProcessWindowStyle.Hidden;
571 Process.Start(proc1);
579 private void NetSetup_Click(
object sender, EventArgs e)
584 string batDir =
string.Format(
@"NetSetup\");
585 proc =
new Process();
586 proc.StartInfo.WorkingDirectory = batDir;
587 proc.StartInfo.FileName = BBNSetup;
588 proc.StartInfo.CreateNoWindow =
false;
591 MessageBox.Show(
"Bat file executed !!");
595 MessageBox.Show(
"Error setting up access point",
"Configureation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
599 #endregion DashBoardControls
static void SaveErrorData(string error)
Log all the error that occurs in the program
string RemoveUnwantedChar(string input)
Parse model info