/
FormNightShift.cs
812 lines (742 loc) · 35.2 KB
/
FormNightShift.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Deployment.Application;
using System.IO;
namespace NightShift
{
public partial class FormNightShift : Form
{
const string HumasonFolderName = "Humason";
const string HumasonSessionControlFilename = "SessionControl.xml";
const string HumasonSessionControlXCName = "HumasonSessionControl";
const string CurrentTargetXName = "CurrentTargetName";
private Color RunningButtonColor = Color.LightSalmon;
private Color ReadyButtonColor = Color.LightGreen;
public FormNightShift()
{
InitializeComponent();
// Acquire the version information and put it in the form header
try { this.Text = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(); }
catch { this.Text = " in Debug"; } //probably in debug, no version info available
this.Text = "NightShift V" + this.Text;
TargetSpecs ts = new TargetSpecs("Sun");
SunRiseTextBox.Text = ts.RiseTime.ToString(@"hh\:mm");
SunSetTextBox.Text = ts.SetTime.ToString(@"hh\:mm");
TwilightTextBox.Text = ts.TwilightEODTime.ToString(@"hh\:mm");
DawnTextBox.Text = ts.TwilightSODTime.ToString(@"hh\:mm");
TargetSpecs tm = new TargetSpecs("Moon");
MoonRiseTextBox.Text = tm.RiseTime.ToString(@"hh\:mm");
MoonSetTextBox.Text = tm.SetTime.ToString(@"hh\:mm");
MoonTransitTextBox.Text = tm.TransitTime.ToString(@"hh\:mm");
MoonPhaseTextBox.Text = (tm.PhasePercent.ToString("0")) + "%";
//Test to see which buttons have installed applications
QualifyToolKitButtons();
//Load the Target Plan datagridview
WriteTargetList();
//Load the task list datagridview
LogXDataBase tldb = new LogXDataBase();
List<string> taskList = tldb.GetTasks();
TaskDataGrid.Rows.Clear();
int tidx = 0;
if (taskList != null)
{
foreach (string task in taskList)
{
TaskDataGrid.Rows.Add();
TaskDataGrid.Rows[tidx].Cells[0].Value = task;
TaskDataGrid.Rows[tidx].Cells[1].Value = false;
tidx++;
}
}
Show();
TaskDataGrid.ClearSelection();
//Set the display date the the current date
LogDateTimePicker.Value = DateTime.Now;
HumasonLogChoice.Checked = false;
HumasonLogChoice.Checked = true;
Show();
return;
}
private string CheckToolKitApp(string toolName)
{
//builds file path to toolName. returns empty if tool isn't installed
string ttdir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Windows\\Start Menu\\Programs\\TSXToolkit\\TSXToolkit";
string ifbPath = ttdir + "\\" + toolName + ".appref-ms";
if (System.IO.File.Exists(ifbPath))
return ifbPath;
else
return null;
}
private void QualifyToolKitButtons()
{
//Checks out each app start button, disables the ones that don't have tools installed
if (CheckToolKitApp("Image Planner") == null) DeactivateButton(PlannerButton);
if (CheckToolKitApp("Humason") == null) DeactivateButton(HumasonButton);
if (CheckToolKitApp("SuperScan") == null) DeactivateButton(SuperScanButton);
if (CheckToolKitApp("Seeing Analyzer") == null) DeactivateButton(SeeingAnalyzerButton);
if (CheckToolKitApp("Subframe Calculator") == null) DeactivateButton(SubFrameButton);
if (CheckToolKitApp("AtGuider2") == null) DeactivateButton(AtGuider2Button);
if (CheckToolKitApp("PEC Collect") == null) DeactivateButton(PECCollectButton);
if (CheckToolKitApp("PEC Merge") == null) DeactivateButton(PECMergeButton);
if (CheckToolKitApp("Auto Focus Profiler") == null) DeactivateButton(AFProfilerButton);
if (CheckToolKitApp("Autoguide Profiler 3") == null) DeactivateButton(AGProfilerButton);
if (CheckToolKitApp("Darks Knight") == null) DeactivateButton(DarksKnightButton);
if (CheckToolKitApp("Kilolani Power Control") == null) DeactivateButton(KilolaniPowerButton);
if (CheckToolKitApp("Kilolani Startup x64") == null) DeactivateButton(KilolaniStartUpButton);
if (CheckToolKitApp("Kilolani Shutdown x64") == null) DeactivateButton(KilolaniShutDownButton);
if (CheckToolKitApp("PreStack Kilolani") == null) DeactivateButton(PreStackButton);
if (CheckToolKitApp("Mobilizer") == null) DeactivateButton(MobilizerButton);
if (CheckToolKitApp("PreStackPI") == null) DeactivateButton(PreStackPIButton);
if (CheckToolKitApp("Hot Pursuit") == null) DeactivateButton(HotPursuitButton);
if (CheckToolKitApp("Kilolani Standard Configuration") == null) DeactivateButton(InitializeButton);
if (CheckToolKitApp("Transient Search") == null) DeactivateButton(TransientSearchButton);
return;
}
private void DeactivateButton(Button button)
{
//Changes the back color of the specified button to gray.
button.Enabled = false;
button.BackColor = Color.Gray;
}
private bool LaunchToolKitApp(string toolName)
{
//Launches the specified toolName
// returns true if successful, false otherwise
string toolPath = CheckToolKitApp(toolName);
if (toolPath != null)
{
Process pSystemExe = new Process();
pSystemExe.StartInfo.FileName = toolPath;
pSystemExe.Start();
return true;
}
else return false;
}
private void WriteTargetList()
{
//Load the Target Plan datagridview
TargetPlans tPlans = new TargetPlans();
List<string> tpList = tPlans.PlanList;
TargetDataGrid.Rows.Clear();
int ridx = 0;
foreach (string tp in tpList)
{
string targetName = tp.Split('.')[0];
TargetSpecs tt = new TargetSpecs(targetName);
TargetDataGrid.Rows.Add();
TargetDataGrid.Rows[ridx].Cells[0].Value = tt.TargetName;
TargetDataGrid.Rows[ridx].Cells[1].Value = tt.TargetType;
TargetDataGrid.Rows[ridx].Cells[2].Value = tt.RiseTime.ToString(@"hh\:mm");
TargetDataGrid.Rows[ridx].Cells[3].Value = tt.TransitTime.ToString(@"hh\:mm");
TargetDataGrid.Rows[ridx].Cells[4].Value = tt.SetTime.ToString(@"hh\:mm");
TargetDataGrid.Rows[ridx].Cells[5].Value = tt.Constellation;
ridx++;
}
TargetDataGrid.ClearSelection();
TargetDataGrid.Update();
Show();
return;
}
public void WriteTextLog(string logString)
{
//Writes the specified logString to the log text box, prepending the current time
NotesTextBox.AppendText("* " + DateTime.Now.ToShortTimeString() + ": " + logString + "\r\n");
}
private void PlannerButton_Click(object sender, EventArgs e)
{
PlannerButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Image Planner");
if (islaunched) PlannerButton.BackColor = ReadyButtonColor;
else PlannerButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Planner launched");
return;
}
private void HumasonButton_Click(object sender, EventArgs e)
{
HumasonButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Humason");
if (islaunched) HumasonButton.BackColor = ReadyButtonColor;
else HumasonButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Humason launched");
return;
}
private void SuperScanButton_Click(object sender, EventArgs e)
{
SuperScanButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("SuperScan");
if (islaunched) SuperScanButton.BackColor = ReadyButtonColor;
else SuperScanButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("SuperScan launched");
return;
}
private void VariScanButton_Click(object sender, EventArgs e)
{
VariScanButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("VariScan");
if (islaunched) VariScanButton.BackColor = ReadyButtonColor;
else VariScanButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("VariScan launched");
return;
}
private void ExoScanButton_Click(object sender, EventArgs e)
{
ExoScanButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("ExoScan");
if (islaunched) ExoScanButton.BackColor = ReadyButtonColor;
else ExoScanButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("ExoScan launched");
return;
}
private void HotPursuitButton_Click(object sender, EventArgs e)
{
HotPursuitButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Hot Pursuit");
if (islaunched) HotPursuitButton.BackColor = ReadyButtonColor;
else HotPursuitButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("HotPursuit launched");
return;
}
private void KilolaniStartUpButton_Click(object sender, EventArgs e)
{
KilolaniStartUpButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Kilolani Startup x64");
if (islaunched) KilolaniStartUpButton.BackColor = ReadyButtonColor;
else KilolaniStartUpButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Kilolani Startup launched");
return;
}
private void KilolaniShutDownButton_Click(object sender, EventArgs e)
{
KilolaniShutDownButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Kilolani Shutdown x64");
if (islaunched) KilolaniShutDownButton.BackColor = ReadyButtonColor;
else KilolaniShutDownButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Kilolani Shutdown launched");
return;
}
private void InitializeButton_Click(object sender, EventArgs e)
{
InitializeButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Kilolani Standard Configuration");
if (islaunched) InitializeButton.BackColor = ReadyButtonColor;
else InitializeButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Kilolani Standard Configuration launched");
return;
}
private void KilolaniPowerButton_Click(object sender, EventArgs e)
{
KilolaniPowerButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Kilolani Power Control");
if (islaunched) KilolaniPowerButton.BackColor = ReadyButtonColor;
else KilolaniPowerButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Kilolani Power Control launched");
return;
}
private void DarksKnightButton_Click(object sender, EventArgs e)
{
DarksKnightButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Darks Knight");
if (islaunched) DarksKnightButton.BackColor = ReadyButtonColor;
else DarksKnightButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Darks Knight launched");
return;
}
private void SeeingAnalyzerButton_Click(object sender, EventArgs e)
{
SeeingAnalyzerButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Seeing Analyzer");
if (islaunched) SeeingAnalyzerButton.BackColor = ReadyButtonColor;
else SeeingAnalyzerButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Seeing Analyzer launched");
return;
}
private void SubFrameButton_Click(object sender, EventArgs e)
{
SubFrameButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Subframe Calculator");
if (islaunched) SubFrameButton.BackColor = ReadyButtonColor;
else SubFrameButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Subframe Calculator launched");
return;
}
private void AtGuider2Button_Click(object sender, EventArgs e)
{
AtGuider2Button.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("AtGuider2");
if (islaunched) AtGuider2Button.BackColor = ReadyButtonColor;
else AtGuider2Button.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("AtGuider2 launched");
return;
}
private void PECCollectButton_Click(object sender, EventArgs e)
{
PECCollectButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("PEC Collect");
if (islaunched) PECCollectButton.BackColor = ReadyButtonColor;
else PECCollectButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("PEC Collect launched");
return;
}
private void PECMergeButton_Click(object sender, EventArgs e)
{
PECMergeButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("PEC Merge");
if (islaunched) PECMergeButton.BackColor = ReadyButtonColor;
else PECMergeButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("PEC Merge launched");
return;
}
private void AFProfilerButton_Click(object sender, EventArgs e)
{
AFProfilerButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Auto Focus Profiler");
if (islaunched) AFProfilerButton.BackColor = ReadyButtonColor;
else AFProfilerButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("AFProfiler launched");
return;
}
private void AGProfilerButton_Click(object sender, EventArgs e)
{
AGProfilerButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Autoguide Profiler 3");
if (islaunched) AGProfilerButton.BackColor = ReadyButtonColor;
else AGProfilerButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Autoguide Profiler 3 launched");
return;
}
private void GuideLogButton_Click(object sender, EventArgs e)
{
GuideLogButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Guide Log Analyzer");
if (islaunched) GuideLogButton.BackColor = ReadyButtonColor;
else GuideLogButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Guide Log Analyzer launched");
return;
}
private void MobilizerButton_Click(object sender, EventArgs e)
{
MobilizerButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Mobilizer");
if (islaunched) MobilizerButton.BackColor = ReadyButtonColor;
else MobilizerButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Mobilizer launched");
return;
}
private void PreStackPIButton_Click(object sender, EventArgs e)
{
PreStackPIButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("PreStackPI");
if (islaunched) PreStackPIButton.BackColor = ReadyButtonColor;
else PreStackPIButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("PreStackPI launched");
return;
}
private void PreStackButton_Click(object sender, EventArgs e)
{
PreStackButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("PreStack Kilolani");
if (islaunched) PreStackButton.BackColor = ReadyButtonColor;
else PreStackButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("PreStack Kilani Launched");
return;
}
private void TransientSearchButton_Click(object sender, EventArgs e)
{
TransientSearchButton.BackColor = RunningButtonColor;
bool islaunched = LaunchToolKitApp("Transient Search");
if (islaunched) TransientSearchButton.BackColor = ReadyButtonColor;
else TransientSearchButton.BackColor = RunningButtonColor;
if (islaunched) WriteTextLog("Transient Search Launched");
return;
}
private void CloseButton_Click(object sender, EventArgs e)
{
LogXDataBase lgdb = new LogXDataBase();
if (NotesTextBox.Text != null)
{
lgdb.AddNote(LogDateTimePicker.Value.ToShortDateString(), NotesTextBox.Text);
}
List<string> taskList = new List<string>();
foreach (DataGridViewRow task in TaskDataGrid.Rows)
{
var taskName = task.Cells[0].Value;
if (taskName != null)
{
bool taskDone = Convert.ToBoolean(task.Cells[1].Value);
if (!taskDone && (taskName != null))
{
taskList.Add(taskName.ToString());
}
}
}
lgdb.AddTasks(taskList);
Close();
return;
}
private void LogDateTimePicker_ValueChanged(object sender, EventArgs e)
{
//fill in notes
string[] lglines;
LogXDataBase lgdb = new LogXDataBase();
char[] splt = { '*' };
string lgstr = lgdb.GetNote(LogDateTimePicker.Value.ToShortDateString());
if (lgstr != null)
{
lglines = lgstr.Split(splt, StringSplitOptions.RemoveEmptyEntries);
foreach (string lg in lglines) NotesTextBox.AppendText("*" + lg + "\r\n");
return;
}
return;
}
private void TargetDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//Click on an entry in the Target list will cause:
//the target name to be sent to web to show target visual.
string tgtName;
try
{ tgtName = TargetDataGrid.SelectedRows[0].Cells[0].Value.ToString(); }
catch (Exception ex)
{
TargetDataGrid.ClearSelection();
Show();
return;
}
//FormPreview formPV = new FormPreview(tgtName);
WriteTextLog("Humason current target changed to " + tgtName);
return;
}
private void TargetDataGrid_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
//Click on an entry in the Target list will cause:
//the target name to be changed to the selected target name
//in the Humason Session Control xml file.
string tgtName;
try
{ tgtName = TargetDataGrid.SelectedRows[0].Cells[0].Value.ToString(); }
catch (Exception ex) { return; }
HumasonInterface.ChangeTargetDefault(tgtName);
WriteTextLog("Humason current target changed to " + tgtName);
return;
}
private void TargetListRefreshButton_Click(object sender, EventArgs e)
{
WriteTargetList();
return;
}
private void TargetLaunchImagePlannerButton_Click(object sender, EventArgs e)
{
//Load currently selected target into Humason "current target" configuration
// and launch image planner
string tgtName;
try
{ tgtName = TargetDataGrid.SelectedRows[0].Cells[0].Value.ToString(); }
catch (Exception ex)
{
tgtName = "";
}
//Create the Humason folder path for the base folder.
string DocumentsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string HumasonDirectoryPath = DocumentsDirectoryPath + "\\" + HumasonFolderName;
//Check for the Humason folder, if it doesnt exist then return
if (!Directory.Exists(HumasonDirectoryPath))
{
PlannerButton_Click(sender, e);
return;
}
else
{
//Create the session control file, if it doesn't exist, and save the token
string sCtlPath = HumasonDirectoryPath + "\\" + HumasonSessionControlFilename;
Axess DirectXcess = new Axess(sCtlPath, HumasonSessionControlXCName);
DirectXcess.ReplaceItem(CurrentTargetXName, tgtName);
WriteTextLog("Humason current target changed to " + tgtName);
PlannerButton_Click(sender, e);
return;
}
}
private void ParkButton_Click(object sender, EventArgs e)
{
//Do everything the same as "Close" but minimize the form instead
LogXDataBase lgdb = new LogXDataBase();
if (NotesTextBox.Text != null)
{
lgdb.AddNote(LogDateTimePicker.Value.ToShortDateString(), NotesTextBox.Text);
}
List<string> taskList = new List<string>();
foreach (DataGridViewRow task in TaskDataGrid.Rows)
{
var taskName = task.Cells[0].Value;
if (taskName != null)
{
bool taskDone = Convert.ToBoolean(task.Cells[1].Value);
if (!taskDone && (taskName != null))
{
taskList.Add(taskName.ToString());
}
}
}
lgdb.AddTasks(taskList);
this.WindowState = FormWindowState.Minimized;
return;
}
private void ClearLogButton_Click(object sender, EventArgs e)
{
//Clears out the Log text
NotesTextBox.Text = "";
Show();
return;
}
private void LogDateListBox_SelectedIndexChanged(object sender, EventArgs e)
{
//New date, new log
string writeLog = "";
List<string> parsedLog = new List<string>();
LogTextBox.Clear();
//figure out the new datetime from the selected log file name
if (LogDateListBox.SelectedItem == null)
return;
DateTime sdate = Convert.ToDateTime(LogDateListBox.SelectedItem.ToString());
if (HumasonLogChoice.Checked)
{
HumasonLogReader hReader = new HumasonLogReader(sdate);
if (hReader.JoinedLog != null)
{
foreach (string line in hReader.JoinedLog)
writeLog += line + "\r\n";
List<string> plog = hReader.ParseLog();
if (plog != null)
{
foreach (string line in plog) parsedLog.Add(line);
}
TargetSetBox.Items.Clear();
TargetSetBox.Items.AddRange(parsedLog.ToArray());
if (parsedLog.Count > 0)
TargetSetBox.SelectedIndex = 0;
}
}
else if (SuperScanLogChoice.Checked)
{
SuperScanLogReader sReader = new SuperScanLogReader(sdate);
if (sReader.JoinedLog != null)
{
foreach (string line in sReader.JoinedLog)
writeLog += line + "\r\n";
List<string> plog = sReader.ParseLog();
if (plog != null)
{
foreach (string line in plog) parsedLog.Add(line);
}
}
TargetSetBox.Items.Clear();
TargetSetBox.Items.AddRange(parsedLog.ToArray());
if (parsedLog.Count > 0)
TargetSetBox.SelectedIndex = 0;
}
else if (VariScanLogChoice.Checked)
{
VariScanLogReader vReader = new VariScanLogReader(sdate);
if (vReader.JoinedLog != null)
{
foreach (string line in vReader.JoinedLog)
writeLog += line + "\r\n";
TargetSetBox.Items.Clear();
foreach (string col in vReader.CollectionList)
parsedLog.Add(Path.GetFileName(col));
}
TargetSetBox.Items.Clear();
TargetSetBox.Items.AddRange(parsedLog.ToArray());
if (parsedLog.Count > 0)
TargetSetBox.SelectedIndex = 0;
}
else if (ExoScanChoice.Checked)
{
if (TargetSetBox.Items.Count > 0)
{
int tgt = 0;
if (TargetSetBox.SelectedItem != null)
tgt = TargetSetBox.SelectedIndex;
ExoScanLogReader exoReader = new ExoScanLogReader(sdate, TargetSetBox.Items[tgt].ToString());
if (exoReader.JoinedLog != null)
{
foreach (string line in exoReader.JoinedLog)
writeLog += line + "\r\n";
//TargetSetBox.Items.Clear();
foreach (string col in exoReader.CollectionList)
parsedLog.Add(Path.GetFileName(col));
}
}
}
LogTextBox.Text = writeLog;
LogTextBox.Select(0, 0);
return;
}
private void HumasonLogChoice_CheckedChanged(object sender, EventArgs e)
{
if (HumasonLogChoice.Checked)
{
//Create Humason Log content for Log tab
//Open log based on the most recent log
HumasonLogReader hReader = new HumasonLogReader(DateTime.Now);
//Get full list of logs in Log directory
LogDateListBox.Items.Clear();
TargetSetBox.Items.Clear();
List<DateTime> hLogList = hReader.LogDates;
foreach (DateTime ldate in hLogList)
LogDateListBox.Items.Add(ldate.ToShortDateString());
if (LogDateListBox.Items.Count > 0)
LogDateListBox.SelectedIndex = LogDateListBox.Items.Count - 1;
}
return;
}
private void SuperScanLogChoice_CheckedChanged(object sender, EventArgs e)
{
if (SuperScanLogChoice.Checked)
{
//Create SuperScan Log content for Log tab
//Open log based on the most recent log
SuperScanLogReader sReader = new SuperScanLogReader(DateTime.Now);
//Get full list of logs in Log directory
LogDateListBox.Items.Clear();
TargetSetBox.Items.Clear();
List<DateTime> sLogList = sReader.LogDates;
foreach (DateTime ldate in sLogList)
LogDateListBox.Items.Add(ldate.ToShortDateString());
if (LogDateListBox.Items.Count > 0)
LogDateListBox.SelectedIndex = LogDateListBox.Items.Count - 1;
}
return;
}
private void VariScanLogChoice_CheckedChanged(object sender, EventArgs e)
{
if (VariScanLogChoice.Checked)
{
//Create SuperScan Log content for Log tab
//Open log based on the most recent log
VariScanLogReader vReader = new VariScanLogReader(DateTime.Now);
//Get full list of logs in Log directory
LogDateListBox.Items.Clear();
TargetSetBox.Items.Clear();
List<DateTime> vLogList = vReader.LogDates;
foreach (DateTime ldate in vLogList)
LogDateListBox.Items.Add(ldate.ToShortDateString());
if (LogDateListBox.Items.Count > 0)
LogDateListBox.SelectedIndex = LogDateListBox.Items.Count - 1;
}
return;
}
private void ExoScanChoice_CheckedChanged(object sender, EventArgs e)
{
if (ExoScanChoice.Checked)
{
//Create SuperScan Log content for Log tab
//Open log based on the most recent log
ExoScanLogReader exoReader = new ExoScanLogReader(DateTime.Now, null);
//Get full list of logs in Log directory
TargetSetBox.Items.Clear();
foreach (string tgt in exoReader.CollectionList)
TargetSetBox.Items.Add(Path.GetFileNameWithoutExtension(tgt));
LogDateListBox.Items.Clear();
List<DateTime> exoLogList = exoReader.LogDates;
foreach (DateTime ldate in exoLogList)
LogDateListBox.Items.Add(ldate.ToShortDateString());
if (LogDateListBox.Items.Count > 0)
LogDateListBox.SelectedIndex = LogDateListBox.Items.Count - 1;
}
return;
}
private void TargetSetBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (ExoScanChoice.Checked)
{
//Initialize Log file listing
LogTextBox.Text = null;
string target = TargetSetBox.SelectedItem.ToString();
DateTime dateChoice;
if (LogDateListBox.SelectedItem != null)
dateChoice = Convert.ToDateTime(LogDateListBox.SelectedItem.ToString());
else
dateChoice = DateTime.Now;
ExoScanLogReader exoReader = new ExoScanLogReader(dateChoice, target);
//Fill in new log dates into list
LogDateListBox.Items.Clear();
List<DateTime> exoLogList = exoReader.LogDates;
foreach (DateTime ldate in exoLogList)
LogDateListBox.Items.Add(ldate.ToShortDateString());
//Select the last date in the list
if (LogDateListBox.Items.Count > 0)
LogDateListBox.SelectedIndex = LogDateListBox.Items.Count - 1;
}
return;
}
private void WaimeaWeatherButton_Click(object sender, EventArgs e)
{
Form waimeaWeatherForm = new FormWaimeaWeather();
waimeaWeatherForm.Show();
return;
}
private void OlympiaWeatherButton_Click(object sender, EventArgs e)
{
Form olyWeatherForm = new FormOlympiaWeather();
olyWeatherForm.Show();
return;
}
private void LoadTargetsButton_Click(object sender, EventArgs e)
{
//Loads a saved set of targets into Humason/Image Planner
//after saving the current set, if any, to a current or new folder
//inside of the Humason folder
bool overWrite = true;
string DocumentsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string HumasonDirectoryPath = DocumentsDirectoryPath + "\\" + HumasonFolderName;
TargetSubfolderDialog.SelectedPath = HumasonDirectoryPath;
DialogResult dResult = MessageBox.Show("Do you want to save the current target definitions?", "Swap Target Sets", MessageBoxButtons.YesNoCancel);
switch (dResult)
{
case DialogResult.Cancel:
return;
break;
case DialogResult.Yes:
TargetSubfolderDialog.Description = "Choose an existing or Create a new Group Folder";
DialogResult dr = TargetSubfolderDialog.ShowDialog();
string storeDir = TargetSubfolderDialog.SelectedPath;
List<string> currentTargetPaths = Directory.GetFiles(HumasonDirectoryPath).Where(x => x.Contains("TargetPlan")).ToList();
List<string> storeTargetPaths = Directory.GetFiles(storeDir).Where(x => x.Contains("TargetPlan")).ToList();
//Clear destination directory and move Humason target files there
foreach (string f in storeTargetPaths)
File.Delete(f);
foreach (string f in currentTargetPaths)
File.Move(f, storeDir + "\\" + Path.GetFileName(f));
//Get directory from which to load targets, then load them into the Humason directory
TargetSubfolderDialog.Description = "Choose an existing Group Folder from which to load";
dr = TargetSubfolderDialog.ShowDialog();
storeDir = TargetSubfolderDialog.SelectedPath;
List<string> newTargetPaths = Directory.GetFiles(storeDir).Where(x => x.Contains("TargetPlan")).ToList();
foreach (string f in newTargetPaths)
File.Copy(f, HumasonDirectoryPath + "\\" + Path.GetFileName(f), overWrite);
break;
case DialogResult.No:
//Get directory from which to load targets, then load them into the Humason directory
TargetSubfolderDialog.Description = "Choose an existing Group Folder from which to load";
dr = TargetSubfolderDialog.ShowDialog();
storeDir = TargetSubfolderDialog.SelectedPath;
currentTargetPaths = Directory.GetFiles(HumasonDirectoryPath).Where(x => x.Contains("TargetPlan")).ToList();
foreach (string f in currentTargetPaths)
File.Delete(f);
newTargetPaths = Directory.GetFiles(storeDir).Where(x => x.Contains("TargetPlan")).ToList();
foreach (string f in newTargetPaths)
File.Copy(f, HumasonDirectoryPath + "\\" + Path.GetFileName(f), overWrite);
break;
}
TargetListRefreshButton_Click(sender, new EventArgs());
}
}
}