-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure.cs
1253 lines (1015 loc) · 42.6 KB
/
configure.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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Yocto-Visualization, a free application to visualize Yoctopuce Sensors.
*
* USB / Network configuration window
*
* - - - - - - - - - License information: - - - - - - - - -
*
* Copyright (C) 2017 and beyond by Yoctopuce Sarl, Switzerland.
*
* Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
* non-exclusive license to use, modify, copy and integrate this
* file into your software for the sole purpose of interfacing
* with Yoctopuce products.
*
* You may reproduce and distribute copies of this file in
* source or object form, as long as the sole purpose of this
* code is to interface with Yoctopuce products. You must retain
* this notice in the distributed source file.
*
* You should refer to Yoctopuce General Terms and Conditions
* for additional information regarding your rights and
* obligations.
*
* THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
* WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
* WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
* EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
* COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
* SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
* LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
* CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
* BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
* WARRANTY, OR OTHERWISE.
*
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using YColors;
using YDataRendering;
using YoctoVisualization;
namespace YoctoVisualisation
{
public partial class ConfigForm : Form
{
string VirtualHubSerial = "";
List<Hub> hubList = new List<Hub>();
bool initdone = false;
// might not work on non English Windows
// System.Diagnostics.PerformanceCounter performance = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
public ConfigForm()
{
InitializeComponent();
editButton.Enabled = false;
deleteButton.Enabled = false;
if (constants.MonoRunning)
{
ExportToClipboard.Text = "Export to clipboard (2) (not available on Linux).";
ExportToClipboard.Enabled = false;
ExportToPNG.Checked = true;
}
new InputFieldManager(targetFolder, InputFieldManager.dataType.DATA_PATH, false, Double.NaN, Double.NaN, null);
new InputFieldManager(DpiTextBox, InputFieldManager.dataType.DATA_STRICT_POSITIVE_FLOAT, false, Double.NaN, Double.NaN, null);
new InputFieldManager(widthValue, InputFieldManager.dataType.DATA_STRICT_POSITIVE_FLOAT, false, Double.NaN, Double.NaN, null);
new InputFieldManager(heightValue, InputFieldManager.dataType.DATA_STRICT_POSITIVE_INT, false, Double.NaN, Double.NaN, null);
new InputFieldManager(MaxDataRecordsCount, InputFieldManager.dataType.DATA_POSITIVE_INT, false, Double.NaN, Double.NaN, null);
new InputFieldManager(MaxDataPointsCount, InputFieldManager.dataType.DATA_POSITIVE_INT, false, Double.NaN, Double.NaN, null);
new InputFieldManager(maxPointsPerDatalogger, InputFieldManager.dataType.DATA_INT, false, -1, Double.NaN, null);
}
private void Add_Click(object sender, EventArgs e)
{
HubEdit editor = new HubEdit();
Hub h;
if (editor.newHub(out h)) AddHub(h);
}
private void RemoveHub(Hub.HubType t, string fullURL)
{ if (t == Hub.HubType.LOCALUSB)
{
LogManager.Log("unRegistering USB ");
YAPI.UnregisterHub("usb");
usbFailed.Visible = false;
usbOk.Visible = false;
return;
}
else
{
if (t == Hub.HubType.LOCALHUB)
{
LogManager.Log("unRegistering Local VirtualHub (127.0.0.1) ");
YAPI.UnregisterHub("127.0.0.1");
hubFailed.Visible = false;
hubOk.Visible = false;
hubWaiting.Visible = false;
return;
}
}
for (int i = hubList.Count - 1; i >= 0; i--)
{
if (hubList[i].get_obfuscatedURL() == fullURL)
{
Hub h = hubList[i];
hubList.RemoveAt(i);
string url = h.get_obfuscatedURL();
LogManager.Log("unRegistering " + h.get_obfuscatedURL());
YAPI.UnregisterHub(h.get_fullUrl());
for (int j = listView1.Items.Count - 1; j >= 0; j--)
if (listView1.Items[j].Text == url)
listView1.Items.RemoveAt(j);
}
}
}
private void AddHub(Hub h)
{
string errmsg = "";
if (h.hubType == Hub.HubType.LOCALUSB)
{
LogManager.Log("preregistering USB ");
if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
{
LogManager.Log("[!] preregistering USB failed (" + errmsg + ")");
ToolTip tt = new ToolTip();
tt.SetToolTip(usbFailed, errmsg);
usbFailed.Visible = true;
}
else
{
usbOk.Visible = true;
if (UseVirtualHub.Checked)
{
hubOk.Visible = false;
hubWaiting.Visible = false;
hubFailed.Visible = true;
ToolTip tt = new ToolTip();
tt.SetToolTip(hubFailed, "Local VirtualHub is OFFLINE");
}
}
return;
}
if (h.hubType == Hub.HubType.LOCALHUB)
{
LogManager.Log("preregistering local VirtualHub (127.0.0.1)");
if (YAPI.PreregisterHub("127.0.0.1", ref errmsg) != YAPI.SUCCESS)
{
ToolTip tt = new ToolTip();
tt.SetToolTip(usbFailed, errmsg);
hubFailed.Visible = true;
LogManager.Log("[!] preregistering local VirtualHub failed (" + errmsg + ")");
}
else
{
hubWaiting.Visible = true;
}
return;
}
ListViewItem item = listView1.Items.Add(h.get_obfuscatedURL());
hubList.Add(h);
item.SubItems.Add("Contacting...");
item.SubItems.Add("");
item.ImageIndex = 0;
LogManager.Log("preregistering " + h.get_obfuscatedURL());
if (YAPI.PreregisterHub(h.get_fullUrl(), ref errmsg) != YAPI.SUCCESS)
{
LogManager.Log("[!] preregistering " + h.get_obfuscatedURL() + " failed (" + errmsg + ")");
item.SubItems.Add(errmsg);
item.ImageIndex = 1;
return;
}
}
public string GetXMLConfiguration()
{
string res = "<Config>\n"
+ " <UseUSB value=\"" + (useUSB.Checked ? "TRUE" : "FALSE") + "\"/>\n"
+ " <UseVirtualHub value=\"" + (UseVirtualHub.Checked ? "TRUE" : "FALSE") + "\"/>\n"
+ " <Hubs>\n";
for (int i = 0; i < hubList.Count; i++)
res += " " + hubList[i].XmlCode() + "\n";
res += " </Hubs>\n";
res += " <Colors>\n";
List<YColor> c = ColorEdit.colorHistory;
for (int i = c.Count - 1; i >= 0; i--)
res = res + " <Color value=\"" + c[i].ToString() + "\"/>\n";
res += " </Colors>\n";
res += " <MemoryUsage>\n";
res += " <maxPointsPerGraphSerie value= \"" + constants.maxPointsPerGraphSerie.ToString() + "\"/>\n";
res += " <maxDataRecordsPerSensor value= \"" + constants.maxDataRecordsPerSensor.ToString() + "\"/>\n";
res += " <maxPointsPerDataloggerSerie value= \"" + constants.maxPointsPerDataloggerSerie.ToString() + "\"/>\n";
res += " <deviceListValidity value= \"" + YAPI.GetDeviceListValidity().ToString() + "\"/>\n";
res += " </MemoryUsage>\n";
res += " <Capture>\n";
res += " <Target value= \"" + constants.captureTarget.ToString() + "\"/>\n";
res += " <Type value= \"" + constants.captureType.ToString() + "\"/>\n";
res += " <Size value= \"" + constants.captureSizePolicy.ToString() + "\"/>\n";
res += " <Resolution value= \"" + constants.captureDPI.ToString() + "\"/>\n";
res += " <Folder value= \"" + System.Security.SecurityElement.Escape(constants.captureFolder) + "\"/>\n";
res += " <Width value= \"" + constants.captureWidth.ToString() + "\"/>\n";
res += " <Height value= \"" + constants.captureHeight.ToString() + "\"/>\n";
res += " </Capture>\n";
res += " <Updates>\n";
res += " <checkForUpdate value = \"" + constants.checkForUpdate.ToString() + "\"/>\n";
res += " <ignoreBuild value = \"" + constants.updateIgnoreBuild.ToString() + "\"/>\n";
res += " </Updates>\n";
res += " <UI>\n";
res += " <VerticalDragZoom value= \"" + YGraph.VerticalDragZoomEnabled.ToString() + "\"/>\n";
res += " <DbleClickContextMenu value= \"" + constants.dbleClickBringsUpContextMenu.ToString() + "\"/>\n";
res += " </UI>\n";
res += "</Config>\n";
return res;
}
public void InitColorHistory(XmlNode ColorsNode)
{
foreach (XmlNode node in ColorsNode.ChildNodes)
{
switch (node.Name)
{
case "Color":
ColorEdit.AddColorToHistory(YColor.fromString(node.Attributes["value"].InnerText));
break;
}
}
}
public void InitUIParams(XmlNode uiNode)
{
foreach (XmlNode node in uiNode.ChildNodes)
{
bool value;
switch (node.Name)
{
case "VerticalDragZoom":
value = false;
if (Boolean.TryParse(node.Attributes["value"].InnerText, out value))
YGraph.VerticalDragZoomEnabled = value;
break;
case "DbleClickContextMenu":
value = false;
if (Boolean.TryParse(node.Attributes["value"].InnerText, out value))
constants.dbleClickBringsUpContextMenu = value;
break;
}
}
}
public void InitCheckForUpdateParams(XmlNode memNode)
{
foreach (XmlNode node in memNode.ChildNodes)
{
switch (node.Name)
{
case "checkForUpdate":
bool bvalue;
if (bool.TryParse(node.Attributes["value"].InnerText, out bvalue)) constants.checkForUpdate = bvalue;
break;
case "ignoreBuild":
int ivalue;
if (Int32.TryParse(node.Attributes["value"].InnerText, out ivalue)) constants.updateIgnoreBuild = ivalue;
break;
}
}
}
public void InitMemoryUsageParams(XmlNode memNode)
{
foreach (XmlNode node in memNode.ChildNodes)
{
int value;
switch (node.Name)
{
case "maxPointsPerGraphSerie":
value = 0;
if (Int32.TryParse(node.Attributes["value"].InnerText, out value))
if (value >= 0)
{
constants.maxPointsPerGraphSerie = value;
DataSerie.MaxPointsPerSeries = value;
}
break;
case "maxDataRecordsPerSensor":
value = 0;
if (Int32.TryParse(node.Attributes["value"].InnerText, out value))
if (value >= 0)
{
constants.maxDataRecordsPerSensor = value;
CustomYSensor.MaxDataRecords = value;
}
break;
case "maxPointsPerDataloggerSerie":
value = 0;
if (Int32.TryParse(node.Attributes["value"].InnerText, out value))
{
constants.maxPointsPerDataloggerSerie = value;
CustomYSensor.MaxLoggerRecords = value;
}
break;
case "deviceListValidity":
value = 0;
if (Int32.TryParse(node.Attributes["value"].InnerText, out value))
if (value > 0)
{
YAPI.SetDeviceListValidity(value);
}
break;
}
}
}
public void InitCaptureParams(XmlNode CaptureNode)
{ int value;
foreach (XmlNode node in CaptureNode.ChildNodes)
{
switch (node.Name)
{
case "Target":
if (node.Attributes["value"].InnerText == YDataRenderer.CaptureTargets.ToClipBoard.ToString()) constants.captureTarget = YDataRenderer.CaptureTargets.ToClipBoard;
if ((node.Attributes["value"].InnerText == YDataRenderer.CaptureTargets.ToFile.ToString()) || (constants.MonoRunning)) constants.captureTarget = YDataRenderer.CaptureTargets.ToFile;
break;
case "Type":
if (node.Attributes["value"].InnerText == YDataRenderer.CaptureType.PNG.ToString()) constants.captureType = YDataRenderer.CaptureType.PNG;
if (node.Attributes["value"].InnerText == YDataRenderer.CaptureType.SVG.ToString()) constants.captureType = YDataRenderer.CaptureType.SVG;
break;
case "Size":
if (node.Attributes["value"].InnerText == YDataRenderer.CaptureFormats.Fixed.ToString()) constants.captureSizePolicy = YDataRenderer.CaptureFormats.Fixed;
if (node.Attributes["value"].InnerText == YDataRenderer.CaptureFormats.Keep.ToString()) constants.captureSizePolicy = YDataRenderer.CaptureFormats.Keep;
if (node.Attributes["value"].InnerText == YDataRenderer.CaptureFormats.FixedWidth.ToString()) constants.captureSizePolicy = YDataRenderer.CaptureFormats.FixedWidth;
if (node.Attributes["value"].InnerText == YDataRenderer.CaptureFormats.FixedHeight.ToString()) constants.captureSizePolicy = YDataRenderer.CaptureFormats.FixedHeight;
break;
case "Resolution":
value = 0;
if (Int32.TryParse(node.Attributes["value"].InnerText, out value))
if (value > 0) constants.captureDPI = value;
break;
case "Width":
value = 0;
if (Int32.TryParse(node.Attributes["value"].InnerText, out value))
if ((value >= 16) && (value <= 4096)) constants.captureWidth = value;
break;
case "Height":
value = 0;
if (Int32.TryParse(node.Attributes["value"].InnerText, out value))
if ((value >= 16) && (value <= 4096)) constants.captureHeight = value;
break;
case "Folder":
constants.captureFolder = node.Attributes["value"].InnerText;
break;
}
}
}
public void updateCaptureUI()
{
targetFolder.Enabled = constants.captureTarget != YDataRenderer.CaptureTargets.ToClipBoard;
CaptureFolderbutton.Enabled = targetFolder.Enabled;
Color activeColor = SystemColors.ControlText;
Color inactiveColor = SystemColors.GrayText;
sizePolicy.BackColor = Color.White;
switch (sizePolicy.SelectedIndex)
{
case (int)YDataRendering.YDataRenderer.CaptureFormats.Fixed:
widthValue.Enabled = true;
widthLabel.ForeColor = activeColor;
widthUnit.ForeColor = activeColor;
heightValue.Enabled = true;
heightLabel.ForeColor = activeColor;
heightUnit.ForeColor = activeColor;
break;
case (int)YDataRendering.YDataRenderer.CaptureFormats.FixedHeight:
widthValue.Enabled = false;
widthLabel.ForeColor = inactiveColor;
widthUnit.ForeColor = inactiveColor;
heightValue.Enabled = true;
heightLabel.ForeColor = activeColor;
heightUnit.ForeColor = activeColor;
break;
case (int)YDataRendering.YDataRenderer.CaptureFormats.FixedWidth:
widthValue.Enabled = true;
widthLabel.ForeColor = activeColor;
widthUnit.ForeColor = activeColor;
heightValue.Enabled = false;
heightLabel.ForeColor = inactiveColor;
heightUnit.ForeColor = inactiveColor;
break;
case (int)YDataRendering.YDataRenderer.CaptureFormats.Keep:
widthValue.Enabled = false;
widthLabel.ForeColor = inactiveColor;
widthUnit.ForeColor = inactiveColor;
heightValue.Enabled = false;
heightLabel.ForeColor = inactiveColor;
heightUnit.ForeColor = inactiveColor;
break;
}
DpiTextBox.Text = constants.captureDPI.ToString();
heightUnit.Text = "px (" + (25.4 * (double)constants.captureHeight / (constants.captureDPI)).ToString("0.#") + "mm)";
widthUnit.Text = "px (" + (25.4 * (double)constants.captureWidth / (constants.captureDPI)).ToString("0.#") + "mm)";
}
public void initCaptureParameters()
{
ExportToClipboard.Checked = constants.captureTarget == YDataRenderer.CaptureTargets.ToClipBoard;
ExportToPNG.Checked = constants.captureTarget == YDataRenderer.CaptureTargets.ToFile;
rasterType.Checked = constants.captureType == YDataRenderer.CaptureType.PNG;
vectorType.Checked = constants.captureType == YDataRenderer.CaptureType.SVG;
targetFolder.Text = constants.captureFolder;
VerticalDragZoom.Checked = YGraph.VerticalDragZoomEnabled;
dbleClickBringsUpContextMenu.Checked = constants.dbleClickBringsUpContextMenu;
int n = 0;
foreach (YDataRenderer.CaptureFormats v in Enum.GetValues(typeof(YDataRenderer.CaptureFormats)))
{
FieldInfo fi = typeof(YDataRenderer.CaptureFormats).GetField(Enum.GetName(typeof(YDataRenderer.CaptureFormats), v));
DescriptionAttribute dna = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));
sizePolicy.Items.Add(dna.Description);
if (constants.captureSizePolicy == v) sizePolicy.SelectedIndex = n;
n++;
}
widthValue.Text = constants.captureWidth.ToString();
heightValue.Text = constants.captureHeight.ToString();
updateCaptureUI();
}
public void DefaultInit()
{
useUSB.Checked = true;
AddHub(new Hub(Hub.HubType.LOCALUSB));
UseVirtualHub.CheckedChanged += UseVirtualHub_CheckedChanged;
useUSB.CheckedChanged += useUSB_CheckedChanged;
}
public void Init(XmlNode initData)
{
initdone = true;
foreach (XmlNode node in initData.ChildNodes)
{
switch (node.Name)
{
case "UseUSB":
useUSB.Checked = (node.Attributes["value"].InnerText.ToUpper() == "TRUE");
if (useUSB.Checked) AddHub(new Hub(Hub.HubType.LOCALUSB));
break;
case "Colors":
InitColorHistory(node);
break;
case "Capture":
InitCaptureParams(node);
break;
case "UI":
InitUIParams(node);
break;
case "Updates":
InitCheckForUpdateParams(node);
break;
case "MemoryUsage":
InitMemoryUsageParams(node);
break;
case "UseVirtualHub":
UseVirtualHub.Checked = (node.Attributes["value"].InnerText.ToUpper() == "TRUE");
if (UseVirtualHub.Checked) AddHub(new Hub(Hub.HubType.LOCALHUB));
break;
case "Hubs":
foreach (XmlNode subnode in node.ChildNodes)
if (subnode.Name == "Hub")
{
AddHub(new Hub(subnode));
}
break;
}
}
UseVirtualHub.CheckedChanged += UseVirtualHub_CheckedChanged;
useUSB.CheckedChanged += useUSB_CheckedChanged;
initCaptureParameters();
}
public void NetworkArrival(YNetwork net)
{
string ip = net.get_ipAddress();
string netname = net.get_logicalName();
string loginame = net.get_module().get_logicalName();
string url = net.get_module().get_url();
bool isLocalIP;
for (int j = 0; j < hubList.Count; j++)
if (hubList[j].get_connexionUrl() == url)
{
for (int i = 0; i < listView1.Items.Count; i++)
if (listView1.Items[i].Text == hubList[j].get_obfuscatedURL())
{
listView1.Items[i].ImageIndex = 2;
listView1.Items[i].SubItems[1].Text = (loginame != "" ? loginame : netname) + " OK";
listView1.Items[i].SubItems[2].Text = net.get_module().get_serialNumber();
return;
}
}
isLocalIP = (ip == "127.0.0.1") || (ip == "0.0.0.0");
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.Supports(NetworkInterfaceComponent.IPv4))
{
IPInterfaceProperties ipinfo = nic.GetIPProperties();
IPAddressInformationCollection ipaddr = ipinfo.AnycastAddresses;
foreach (IPAddressInformation any in ipaddr)
{
if (ip == any.Address.ToString()) isLocalIP = true;
}
}
}
if (isLocalIP)
{
hubFailed.Visible = false;
hubOk.Visible = true;
hubWaiting.Visible = false;
VirtualHubSerial = net.get_module().get_serialNumber();
return;
}
}
public void removal(string serialNumber)
{
if (serialNumber == VirtualHubSerial)
{
ToolTip tt = new ToolTip();
tt.SetToolTip(usbFailed, "OFFLINE");
hubFailed.Visible = true;
hubOk.Visible = false;
hubWaiting.Visible = false;
return;
}
for (int i = 0; i < listView1.Items.Count; i++)
if (listView1.Items[i].SubItems[2].Text == serialNumber)
{
listView1.Items[i].ImageIndex = 1;
listView1.Items[i].SubItems[1].Text = "OFFLINE";
}
}
private void ConfigForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
Hide();
}
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
Menuitemremove.Enabled = (listView1.SelectedItems.Count > 0);
}
private void Menuitemremove_Click(object sender, EventArgs e)
{
deleteButton_Click(sender, e);
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void UseVirtualHub_CheckedChanged(object sender, EventArgs e)
{
if (UseVirtualHub.Checked) AddHub(new Hub(Hub.HubType.LOCALHUB)); else RemoveHub(Hub.HubType.LOCALHUB, "");
}
private void useUSB_CheckedChanged(object sender, EventArgs e)
{
if (useUSB.Checked) AddHub(new Hub(Hub.HubType.LOCALUSB)); else RemoveHub(Hub.HubType.LOCALUSB, "");
}
public void CheckInit()
{
if (!initdone) useUSB.Checked = true;
}
private void newEntry_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Add_Click(null, null);
}
}
private void openThisHubConfigurationPageToolStripMenuItem_Click(object sender, EventArgs e)
{
int lindex, hindex;
findSelectedHub(out lindex, out hindex);
if (hindex >= 0)
{
System.Diagnostics.Process.Start(hubList[hindex].get_consoleUrl());
}
}
private void label10_Click(object sender, EventArgs e)
{
}
private void label10_Click_1(object sender, EventArgs e)
{
}
private void sizePolicy_SelectedIndexChanged(object sender, EventArgs e)
{
int n = 0;
foreach (YDataRenderer.CaptureFormats v in Enum.GetValues(typeof(YDataRenderer.CaptureFormats)))
{
if (sizePolicy.SelectedIndex == n)
{
constants.captureSizePolicy = v;
}
n++;
}
updateCaptureUI();
}
private void ExportToClipboard_CheckedChanged(object sender, EventArgs e)
{
constants.captureTarget = ExportToClipboard.Checked ? YDataRendering.YDataRenderer.CaptureTargets.ToClipBoard : YDataRendering.YDataRenderer.CaptureTargets.ToFile;
updateCaptureUI();
}
private void CaptureFolderbutton_Click(object sender, EventArgs e)
{
if (Directory.Exists(targetFolder.Text)) folderBrowserDialog1.SelectedPath = targetFolder.Text;
folderBrowserDialog1.Description = "Choose where screen-shots will be saved.";
folderBrowserDialog1.ShowDialog();
targetFolder.Text = folderBrowserDialog1.SelectedPath;
constants.captureFolder = targetFolder.Text;
}
private void targetFolder_Leave(object sender, EventArgs e)
{
if (!Directory.Exists(targetFolder.Text)) MessageBox.Show("Folder " + targetFolder.Text + " does not exists,\nCapture operations are likely to fail.",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
constants.captureFolder = targetFolder.Text;
}
private void DpiTextBox_Leave(object sender, EventArgs e)
{
int value;
if (Int32.TryParse(DpiTextBox.Text, out value))
{
if (value > 0) constants.captureDPI = value;
else MessageBox.Show("Resolution must be a strictly positive integer,\nchange will be ignored.",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
else
MessageBox.Show("Invalid resolution value,\nchange will be ignored.",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
updateCaptureUI();
}
private void widthValue_Leave(object sender, EventArgs e)
{
int value;
if (Int32.TryParse(widthValue.Text, out value))
{
if ((value >= 16) && (value <= 4096)) constants.captureWidth = value;
else MessageBox.Show("Width must be in the 16..4096 range,\nchange will be ignored.",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
else
MessageBox.Show("Invalid width value,\nchange will be ignored.",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
updateCaptureUI();
}
private void heightValue_Leave(object sender, EventArgs e)
{
int value;
if (Int32.TryParse(heightValue.Text, out value))
{
if ((value >= 16) && (value <= 4096)) constants.captureHeight = value;
else MessageBox.Show("Height must be in the 16..4096 range,\nchange will be ignored.",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
else
MessageBox.Show("Invalid height value,\nchange will be ignored.",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
updateCaptureUI();
}
private void MaxDataRecordsCount_Leave(object sender, EventArgs e)
{
int value;
if (Int32.TryParse(MaxDataRecordsCount.Text, out value) && (value >= 0))
{
constants.maxDataRecordsPerSensor = value;
CustomYSensor.MaxDataRecords = value;
}
else MessageBox.Show("Invalid Max Data records,\nshould be a positive integer or Zero.\nChange will be ignored. ",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
private void MaxDataPointsCount_Leave(object sender, EventArgs e)
{
int value;
if (Int32.TryParse(MaxDataPointsCount.Text, out value) && (value >= 0))
{
constants.maxPointsPerGraphSerie = value;
DataSerie.MaxPointsPerSeries = value;
}
else MessageBox.Show("Invalid Max Data points,\nshould be a positive integer or Zero.\nChange will be ignored. ",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
private void MemoryTimer_Tick(object sender, EventArgs e)
{/* might not work on non English Windows
if (constants.MonoRunning)
{
memoryLabel.Visible = false;
MemoryTimer.Enabled = false;
}
else memoryLabel.Text = "Available memory : " + performance.NextValue().ToString() +"MB";
*/
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 2)
{
MaxDataPointsCount.Text = constants.maxPointsPerGraphSerie.ToString();
MaxDataRecordsCount.Text = constants.maxDataRecordsPerSensor.ToString();
maxPointsPerDatalogger.Text = constants.maxPointsPerDataloggerSerie.ToString();
MemoryTimer_Tick(null, null);
MemoryTimer.Enabled = true;
}
else MemoryTimer.Enabled = false;
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
editButton.Enabled = listView1.SelectedItems.Count > 0;
deleteButton.Enabled = listView1.SelectedItems.Count > 0;
}
private void findSelectedHub(out int lindex, out int hindex)
{
lindex = -1;
hindex = -1;
if (listView1.SelectedItems.Count <= 0) return;
lindex = listView1.SelectedItems[0].Index;
{
for (int i = hubList.Count - 1; i >= 0; i--)
{
if (hubList[i].get_obfuscatedURL() == listView1.Items[lindex].Text) hindex = i;
}
}
}
private void editButton_Click(object sender, EventArgs e)
{
int lindex, hindex;
findSelectedHub(out lindex, out hindex);
if (hindex >= 0)
{
Hub h = new Hub(Hub.HubType.REMOTEHUB, hubList[hindex].protocol, hubList[hindex].user, "",
hubList[hindex].addr, hubList[hindex].port, hubList[hindex].path);
h.encryptedPassword = hubList[hindex].encryptedPassword;
HubEdit editor = new HubEdit();
if (editor.editHub(ref h))
{
YAPI.UnregisterHub(hubList[hindex].get_fullUrl());
hubList[hindex] = h;
listView1.Items[lindex].Text = h.get_obfuscatedURL();
listView1.Items[lindex].SubItems[1].Text = "Contacting...";
listView1.Items[lindex].ImageIndex = 0;
string errmsg = "";
YAPI.PreregisterHub(hubList[hindex].get_fullUrl(), ref errmsg);
}
}
}
private void deleteButton_Click(object sender, EventArgs e)
{
int lindex, hindex;
findSelectedHub(out lindex, out hindex);
if (hindex >= 0)
if (MessageBox.Show("Do you really want to remove " + hubList[hindex].get_obfuscatedURL() + " ?",
"Remove a Hub connection",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
YAPI.UnregisterHub(hubList[hindex].get_fullUrl());
hubList.RemoveAt(hindex);
listView1.Items.RemoveAt(lindex);
}
}
private void label16_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void maxPointsPerDatalogger_Leave(object sender, EventArgs e)
{
int value;
if (Int32.TryParse(maxPointsPerDatalogger.Text, out value))
{
constants.maxPointsPerDataloggerSerie = value;
CustomYSensor.MaxLoggerRecords = value;
}
else MessageBox.Show("Invalid Max Data points,\nshould be a integer.\nChange will be ignored. ",
"Parameter error", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
}
private void MaxDataPointsCount_TextChanged(object sender, EventArgs e)
{
}
private void label17_Click(object sender, EventArgs e)
{
}
private void editThisHubConnectionToolStripMenuItem_Click(object sender, EventArgs e)
{
editButton_Click(sender, e);
}
private void ZoomVerticalDragZoom_CheckedChanged(object sender, EventArgs e)
{
YGraph.VerticalDragZoomEnabled = VerticalDragZoom.Checked;
}
private void dbleClickBringsUpContextMenu_CheckedChanged(object sender, EventArgs e)
{
constants.dbleClickBringsUpContextMenu = dbleClickBringsUpContextMenu.Checked;