-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWIndow.cs.bak
1210 lines (1158 loc) · 52.7 KB
/
MainWIndow.cs.bak
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
using System;
using System.Collections.Generic;
using System.Deployment.Application;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
namespace LOTWQSL
{
public partial class MainWindow2 : Form
{
MapForm mapForm = new MapForm();
GridForm gridForm = new GridForm();
HelpForm help;
string mylogin = String.Empty; // can be just callsign or callsign+callsign
string mypassword = String.Empty;
string sinceLOTW = String.Empty;
string endLOTW = String.Empty;
string keeperFile = String.Empty;
string appData = String.Empty;
string errorStr = String.Empty;
string sinceLOTWStart = String.Empty;
HashSet<string> history;
HashSet<string> callsigns;
//public static HashSet<string> states; // List contains State/Band/Mode
public static HashSet<string> allWAS = new HashSet<string>();
HashSet<string> dxcc;
HashSet<string> countries;
HashSet<string> prefixes;
public static Dictionary<string, Dictionary<string, int>> popularStates;
//Dictionary<string,int> popularCalls;
int nstates = 0;
int ndxcc = 0;
int ncountries = 0;
int nprefixes = 0;
int nqsls = 0;
int ncallsigns = 0;
Boolean mergeCalls = true; // if user does call+call login do we want to merge or keep separate?
Boolean qslMisMatchHeaderFlag = true;
public MainWindow2()
{
InitializeComponent();
//InstallUpdateSyncWithInfo();
appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "LOTWQSL");
string s = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "W9MDB");
try
{
if (!Directory.Exists(appData))
{
Directory.CreateDirectory(appData);
}
if (Properties.Settings.Default.CallUpgrade)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.CallUpgrade = false;
}
}
catch (Exception e)
{
MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show(appData+":"+e.Message);
}
mypassword = Properties.Settings.Default.password;
mylogin = Properties.Settings.Default.login;
keeperFile = appData + "\\" + mylogin.Replace('/','_') + ".txt";
if (mylogin.Contains("+"))
{ // then this is a merged file
string[] tokens = Regex.Split(mylogin, "[@+]");
keeperFile = appData + "\\" + tokens[0].Replace('/','_') + ".txt";
}
string keeperFileOld = appData + "\\lotwqsl.txt";
if (File.Exists(keeperFileOld))
{
try
{
File.Move(keeperFileOld, keeperFile);
}
catch (Exception ex)
{
MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show(ex.Message);
return;
}
}
history = new HashSet<string>();
states = new HashSet<string>();
dxcc = new HashSet<string>();
countries = new HashSet<string>();
prefixes = new HashSet<string>();
callsigns = new HashSet<string>();
popularStates = new Dictionary<string,Dictionary<string,int>>();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Top = Properties.Settings.Default.RestoreBounds.Top;
this.Left = Properties.Settings.Default.RestoreBounds.Left;
this.Height = Properties.Settings.Default.RestoreBounds.Height;
this.Width = Properties.Settings.Default.RestoreBounds.Width;
Rectangle rect = SystemInformation.VirtualScreen;
if (this.Location.X < 0 || this.Location.Y < 0)
{
this.Top = 0;
this.Left = 0;
this.Width = 300;
this.Height = 400;
}
if (this.Location.X > rect.Width || this.Location.Y > rect.Bottom)
{
this.Top = 0;
this.Left = 0;
}
sinceLOTW = Properties.Settings.Default.lastLOTW;
//sinceLOTWStart = Properties.Settings.Default.
textBoxSince.Text = sinceLOTW;
textBoxLogin.Text = mylogin; // this will force keeperLoad()
password.Text = mypassword;
KeeperLoad(keeperFile);
timer1.Interval = 3000;
timer1.Start();
//Thread oThread = new Thread(new ThreadStart(checkForUpdate));
//oThread.Start();
System.Windows.Forms.ToolTip toolTip1 = new System.Windows.Forms.ToolTip();
toolTip1.SetToolTip(this.textBoxLogin, "Your LOTW login name");
toolTip1.SetToolTip(this.labelLogin, "Your LOTW login name");
toolTip1.SetToolTip(this.password, "Your LOTW password");
toolTip1.SetToolTip(this.labelPassword, "Your LOTW password");
toolTip1.SetToolTip(this.buttonHelp, "Help");
toolTip1.SetToolTip(this.textBoxSince, "QSL since date YYYY-MM-DD\n(updates itself automatically)\n1900-01-01 resets everything");
toolTip1.SetToolTip(this.labelSince, "QSL since date YYYY-MM-DD\n(updates itself automatically)\n1900-01-01 resets everything");
toolTip1.SetToolTip(this.textBoxEnd, "QSL end date YYYY-MM-DD\nOnly needed if having download problems\nto limit # of QSOs");
toolTip1.SetToolTip(this.labelEnd, "QSL end date YYYY-MM-DD\nOnly needed if having download problems\nto limit # of QSOs");
toolTip1.SetToolTip(this.buttonRefresh, "Download new LOTW QSLs");
toolTip1.SetToolTip(this.buttonMap, "Show map window");
toolTip1.SetToolTip(this.buttonGrid, "Show grid window");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Rectangle restore;
if (gridForm.IsHandleCreated)
{
gridForm.WindowState = FormWindowState.Normal;
gridForm.Update();
restore = new Rectangle(gridForm.Left, gridForm.Top, gridForm.Width, gridForm.Height);
Properties.Settings.Default.GridRestoreBounds = restore;
}
gridForm.Close();
if (mapForm.IsHandleCreated)
{
mapForm.WindowState = FormWindowState.Normal;
mapForm.Update();
restore = new Rectangle(mapForm.Left, mapForm.Top, mapForm.Width, mapForm.Height);
Properties.Settings.Default.MapRestoreBounds = restore;
Properties.Settings.Default.StatesLabeled = mapForm.showLabels;
}
mapForm.Close();
this.WindowState = FormWindowState.Normal;
this.Update();
restore = new Rectangle(this.Left,this.Top,this.Width,this.Height);
Properties.Settings.Default.RestoreBounds = restore;
// RestoreBounds doesn't seemt to get the current location
//Properties.Settings.Default.RestoreBounds = this.RestoreBounds;
Properties.Settings.Default.lastLOTW = sinceLOTW;
Properties.Settings.Default.Save();
}
void AddToPopular(string state,string callsign)
{
if (!popularStates.ContainsKey(state))
{
Dictionary<string, int> newdict = new Dictionary<string, int>
{
{ callsign, 1 }
};
popularStates.Add(state, newdict);
return;
}
Dictionary<string, int> dict = popularStates[state];
if (dict.ContainsKey(callsign))
{
++dict[callsign];
}
else
{
dict[callsign] = 1;
}
popularStates[state] = dict;
}
void KeeperLoad(string callsign)
{
string lastDate = "19000101";
try
{
System.IO.StreamReader file = new System.IO.StreamReader(keeperFile);
string line;
nqsls = 0;
ncallsigns = 0;
line = file.ReadLine();
if (!line.Equals("Version 1.1"))
{
file.Close();
file.Dispose();
File.Delete(keeperFile);
richTextBox1.AppendText("QSL file " + keeperFile + " is wrong version\n");
richTextBox1.AppendText("Old version deleted\nPlease check date and click Refresh\n");
sinceLOTW = textBoxSince.Text = "1990-01-01";
Properties.Settings.Default.lastLOTW = sinceLOTW;
}
else
{
// Somehow we're getting dups...this is a temporary fix until figured out
while ((line = file.ReadLine()) != null)
{
string thisDate = line.Substring(0, 8);
if (string.Compare(thisDate, lastDate) > 0)
{
lastDate = thisDate;
sinceLOTW = lastDate;
}
var tokens = line.Split(new[] { ',', '\r', '\n' });
if (!line.Contains("none") && !allWAS.Contains(line))
{
allWAS.Add(tokens[1]);
}
++nqsls;
history.Add(tokens[0]);
// [0] = "20131203 13:19 40M JT65 AJ4HW"
var tokens1 = tokens[0].Split(' ');
callsign = tokens1[4];
if (!callsigns.Contains(callsign))
callsigns.Add(callsign);
var tokens2 = tokens[2].Split(' ');
string country = tokens2[2]; // should be country info
if (tokens2.Count() > 3)
{
for (int i = 3; i < tokens2.Count(); ++i)
{
country += " " + tokens2[i];
}
}
if (!countries.Contains(country))
{
countries.Add(country);
}
tokens1 = tokens[1].Split(' ');
if (tokens1.Count() < 3) continue;
string state = tokens1[2];
AddToPopular(state,callsign);
if ((!states.Contains(tokens[1])) && (!tokens[1].Equals("none")))
{
states.Add(tokens[1]);
}
if (!prefixes.Contains(tokens[3]))
{
prefixes.Add(tokens[3]);
}
//if (!dxcc.Contains(tokens[2]))
//{
// dxcc.Add(tokens[2]);
//}
}
}
file.Close();
// Sort our popularStates for the grid display
foreach (KeyValuePair<string, Dictionary<string, int>> kvpair in popularStates)
{
//richTextBox1.AppendText(kvpair.Key + "\n");
Dictionary<string, int> tdict = popularStates[kvpair.Key];
//tdict = tdict.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
//popularStates[kvpair.Key] = tdict;
//foreach (KeyValuePair<string, int> kvpair2 in tdict)
//{
// richTextBox1.AppendText(kvpair2.Key + ":" + kvpair2.Value + "\n");
//}
}
richTextBox1.AppendText(nqsls + " QSLs loaded\n");
richTextBox1.AppendText(callsigns.Count() + " callsigns\n");
richTextBox1.AppendText(prefixes.Count() + " prefixes\n");
//richTextBox1.AppendText(states.Count() + " state entries\n");
//richTextBox1.AppendText(dxcc.Count() + " dxcc entries\n");
richTextBox1.AppendText(countries.Count() + " countries\n");
ncallsigns = callsigns.Count();
nstates = states.Count();
nprefixes = prefixes.Count();
ndxcc = dxcc.Count();
ncountries = countries.Count();
}
catch (FileNotFoundException e)
{
if (textBoxLogin.Text.Length < 3)
{
MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show("Please enter LOTW login information");
sinceLOTW = "1900-01-01";
textBoxSince.Text = sinceLOTW;
richTextBox1.Clear();
}
else
{
MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show(e.Message + "\n" + "Resetting Since date to 1900-01-01...please Refresh\nIf this is first time you've run this error is expected");
sinceLOTW = "1900-01-01";
textBoxSince.Text = sinceLOTW;
richTextBox1.Clear();
}
}
catch (Exception e)
{
MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show(keeperFile + ":" + e.Message);
}
textBoxSince.Text = lastDate.Substring(0, 4) + "-" + lastDate.Substring(4, 2) + "-" + lastDate.Substring(6, 2);
}
private void CheckForUpdate() {
int currentVersion = 192; // Matches 3-digit version number
try
{
string uri1 = "https://www.dropbox.com/s/s78p4i7yyng1rg9/LOTWQSL.ver?dl=1";
HttpWebRequest connection = (HttpWebRequest)HttpWebRequest.Create(uri1);
connection.Method = "GET";
HttpWebResponse response = (HttpWebResponse)connection.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string version = sr.ReadLine(); // 1st line is one-up version #
string uri2 = sr.ReadLine(); // 2nd line is reference for user to download
sr.Close();
response.Close();
int newVersion = Int32.Parse(version);
if (newVersion > currentVersion)
{
Update myform = new Update();
myform.ShowDialog();
/*
//MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
DialogResult result = MessageBox.Show("New version available\n"+uri2,
"LOTWQSL Update",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1,
0,
"http://www.qrz.com/db/w9mdb",
""
);
* */
}
//else
//{
// MessageBox.Show("No new version");
//}
}
catch (Exception ex)
{
MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show("Error checking for update: "+ex.Message);
}
}
private void DoADIF(ref string responseData)
{
qslMisMatchHeaderFlag = true;
var lines = responseData.Split(new[] { '\r', '\n' });
int nLines = 0;
int nNew = 0;
string callsign = String.Empty;
string band = String.Empty;
string mode = String.Empty;
string modegroup = "MODEGROUP";
string qsodate = String.Empty;
string timeon = String.Empty;
string creditGranted = String.Empty;
string state = String.Empty;
string country = String.Empty;
string prefix = String.Empty;
richTextBox1.Clear();
bool qsl_rcvd = false;
richTextBox1.AppendText("Processing ADIF file\n");
this.Update();
string QSODate = textBoxSince.Text;
bool resetall = QSODate.Equals("1900-01-01") || QSODate.Substring(0,1)=="!";
if (QSODate.Substring(0, 1) == "!")
{
QSODate = QSODate.Substring(1);
textBoxSince.Text = QSODate;
}
string QSODate2 = QSODate.Remove(7, 1); // we need this format to compare with the ADIF file
QSODate2 = QSODate2.Remove(4, 1);
if (resetall)
{ // This indicates we're downloading the whole history so clear everything out
// Remember our first date entered as the QSO date for base reference
Properties.Settings.Default.QSODate = QSODate;
Properties.Settings.Default.Save();
try
{
File.Delete(keeperFile);
}
catch (Exception ex)
{
MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
MessageBox.Show(ex.Message);
errorStr = ex.Message;
}
countries.Clear();
dxcc.Clear();
states.Clear();
history.Clear();
prefixes.Clear();
callsigns.Clear();
nqsls = 0;
ncountries = 0;
ndxcc = 0;
nstates = 0;
nprefixes = 0;
ncallsigns = 0;
}
else
{
// if not a reset then set our QSO date to the saved value
QSODate = Properties.Settings.Default.QSODate;
}
richTextBox1.AppendText("QSO Start: " + QSODate + "\n");
Boolean verbose = true;
if (lines.Length > 2000)
{
//verbose = false;
}
foreach (string s in lines)
{
if (s.Contains("Generated"))
{
richTextBox1.AppendText("Generated: " + s.Substring(13) + "\n");
// Gotta parse two format
// EQSL.CC gives this: Generated on Friday, August 8, 2014 at 18:57:47 PM UTC
// LOTW gives this: Generated at 2014-08-08 18:59:08
if (s.Contains("Generated on")) // ESQL.CC format
{
string[] tokens = s.Split(new[] { ',', ' ' });
string myDate = tokens[4] + " " + tokens[5] + ", " + tokens[7];
DateTime myDateTime = DateTime.Parse(myDate);
sinceLOTW = myDateTime.ToString("yyyy-MM-dd");
}
else // LOTW Format
{
if (textBoxEnd.Text.Length != 10) // Only if we didn't set the end date
{
sinceLOTW = s.Substring(13, 10);
textBoxSince.Text = sinceLOTW;
}
}
}
else if (s.Contains("LASTQSL:"))
{
if (verbose)
{
richTextBox1.AppendText("Last QSL : " + s.Substring(21) + "\n");
}
}
else if (s.Contains("<CALL:"))
{
++nLines;
if (!verbose && ((nLines % 500) == 0))
{
//if (nLines > 500) richTextBox1.Undo();
richTextBox1.AppendText("#QSLs=" + nLines + "\r");
this.Update();
}
var tokens = s.Split(new[] { '>', '\r', '\n' });
callsign = tokens[1];
if (!callsigns.Contains(callsign))
{
callsigns.Add(callsign);
++ncallsigns;
}
}
else if (s.Contains("<PFX:"))
{
prefix = s.Substring(7);
}
else if (s.Contains("<BAND:"))
{
var tokens = s.Split(new[] { '>', '\r', '\n' });
band = tokens[1];
}
else if (s.Contains("<MODE:"))
{
var tokens = s.Split(new[] { '>', '\r', '\n' });
mode = tokens[1];
}
else if (s.Contains("<APP_LoTW_MODEGROUP"))
{
var tokens = s.Split(new[] { '>', '\r', '\n' });
modegroup = tokens[1];
}
else if (s.Contains("<QSO_DATE:"))
{
var tokens = s.Split(new[] { '>', '\r', '\n' });
qsodate = tokens[1];
}
else if (s.Contains("<TIME_ON:"))
{
var tokens = s.Split(new[] { '>', '\r', '\n' });
timeon = tokens[1].Substring(0, 2) + ":" + tokens[1].Substring(2, 2) + ":" + tokens[1].Substring(4, 2);
}
else if (s.Contains("<QSL_RCVD:1>Y"))
{
qsl_rcvd = true;
}
else if (s.Contains("<STATE:"))
{
int offset = s.IndexOf(">");
state = s.Substring(offset + 1);
}
else if (s.Contains("<APP_LoTW_QSLMODE:"))
{
if (qslMisMatchHeaderFlag)
{
richTextBox1.AppendText("ERRORMSG\tQSODATE\tTIME\tCALL\tYOURMODE\tTHEIRMODE\n");
qslMisMatchHeaderFlag = false;
}
var tokens = s.Split(new[] { '>', '\r', '\n' });
String qslmode = tokens[1];
richTextBox1.AppendText("Mismatched mode\t"+qsodate+"\t"+timeon+"\t"+callsign+"\t"+mode+" \t"+qslmode+"\n");
}
else if (s.Contains("<COUNTRY:"))
{
int offset = s.IndexOf(">");
country = s.Substring(offset + 1);
if (country.Contains("UNITED STATES OF AMERICA"))
{
country = "USA";
}
if (country.Contains("FEDERAL REPUBLIC OF GERMANY"))
{
country = "GERMANY";
}
}
// The GRANTED is apparently only created after you apply for an award
// So it's pretty useless
else if (s.Contains("<APP_LoTW_CREDIT_GRANTED:"))
{
//int offset = s.IndexOf(">");
//creditGranted = s.Substring(offset+1);
}
else if (s.Contains("<eor>"))
{
String sinceLOTWCompare = sinceLOTW.Remove(7, 1);
sinceLOTWCompare = sinceLOTWCompare.Remove(4, 1);
int mycompare = qsodate.CompareTo(QSODate2);
if (qsodate.CompareTo(QSODate2)<0)
continue;
string key = qsodate + " " + timeon + " " + band + " " + mode + " " + callsign;
string keyDisplay = qsodate + " " + timeon + " " + band.PadRight(4) + " " + mode.PadRight(5) + " " + callsign.PadRight(6);
// Update our WAS info
string wasinfo = "none";
bool newWAS = false;
bool newDXCC = false;
bool updateFile = false;
if (!state.Equals(String.Empty) && (country.Equals("USA") || country.Equals("ALASKA") || country.Equals("HAWAII")))
{
wasinfo = band + " " + mode + " " + state;
if (!states.Contains(wasinfo))
{
MainWindow2.allWAS.Add(wasinfo);
//states.Add(wasinfo);
newWAS = true;
updateFile = true;
}
}
// Update our Country info and modegroup
string dxccinfo = band + " " + modegroup + " " + country;
if (!dxcc.Contains(dxccinfo))
{
dxcc.Add(dxccinfo);
newDXCC = true;
}
if (!history.Contains(key) && qsl_rcvd)
{
history.Add(key);
if (!state.Equals(String.Empty) && country.Equals("USA"))
{
//country = String.Empty;
}
if (verbose)
{
richTextBox1.AppendText(keyDisplay + " " + state + " " + country + "\n");
}
updateFile = true;
if ((!prefix.Equals(String.Empty)) && (!prefixes.Contains(prefix)))
{
prefixes.Add(prefix);
if (verbose)
{
richTextBox1.AppendText(" New Prefix: " + prefix + "\n");
}
}
}
if (!countries.Contains(country) && country.Length > 0)
{
countries.Add(country);
if (verbose)
{
richTextBox1.AppendText(" New Country: " + country + "\n");
}
}
if (newWAS)
{
updateFile = true;
if (verbose)
{
richTextBox1.AppendText(" New WAS: " + wasinfo + "\n");
}
MapForm form2 = new MapForm();
HashSet<string> remain = form2.statesRemain(states);
form2.Dispose();
if (remain.Count == 0)
{
if (verbose)
{
richTextBox1.AppendText(" **** WAS Award Achieved ****\n");
}
}
}
if (newDXCC)
{
//if (verbose)
//{
// richTextBox1.AppendText(" New DXCC: " + dxccinfo + "\n");
//}
}
if (!File.Exists(keeperFile))
{
StreamWriter newfile = File.AppendText(keeperFile);
newfile.WriteLine("Version 1.1");
newfile.Close();
updateFile = true;
}
if (updateFile)
{
StreamWriter file = File.AppendText(keeperFile);
file.WriteLine(key + "," + wasinfo + "," + dxccinfo + "," + prefix);
file.Close();
++nNew;
}
else
{
// richTextBox1.AppendText("Skipping " + key + "," + wasinfo + "," + dxccinfo + "," + prefix+"\n");
}
qsl_rcvd = false;
creditGranted = String.Empty;
state = String.Empty;
country = String.Empty;
}
}
if (nLines >= 500) richTextBox1.Undo();
if (nLines == 0)
{
nLines = nqsls; // in case we have an error retrieving data
}
else
{
nLines = nqsls + nNew;
}
if (nNew == 0)
{
richTextBox1.AppendText("No New QSLs\n");
}
string bumpup = (nqsls == nLines) ? "+0" : ("+" + (nLines - nqsls));
richTextBox1.AppendText(nLines + " QSLs \t" + bumpup + "\n");
bumpup = (ncallsigns == callsigns.Count()) ? "+0" : ("+" + (callsigns.Count() - ncallsigns));
richTextBox1.AppendText(ncallsigns + " Calls \t" + bumpup + "\n");
bumpup = (nprefixes == prefixes.Count()) ? "+0" : ("+" + (prefixes.Count() - nprefixes));
richTextBox1.AppendText(prefixes.Count() + " prefix entries\t" + bumpup + "\n");
bumpup = (nstates == states.Count()) ? "+0" : ("+" + (states.Count() - nstates));
richTextBox1.AppendText(states.Count() + " was entries\t" + bumpup + "\n");
//bumpup = (ndxcc == dxcc.Count()) ? "+0" : ("+" + (dxcc.Count() - ndxcc));
//richTextBox1.AppendText(dxcc.Count() + " dxcc entries\t" + bumpup + "\n");
bumpup = (ncountries == countries.Count()) ? "+0" : ("+" + (countries.Count() - ncountries));
richTextBox1.AppendText(countries.Count() + " country entries\t" + bumpup + "\n");
nqsls = nLines;
nstates = states.Count();
nprefixes = prefixes.Count();
ndxcc = dxcc.Count();
ncountries = countries.Count();
ncallsigns = callsigns.Count();
if (nLines == 0)
{
richTextBox1.AppendText("Check your login\n");
}
}
/*
private void getEQSL()
{
//string uri = "https://lotw.arrl.org/lotwuser/lotwreport.adi?login=" + mylogin + "&password=" + mypassword + "&qso_query=1&qso_qsl=yes&qso_qslsince=" + sinceLOTW + "&qso_qsldetail=yes";
string uri = "http://eqsl.cc/qslcard/DownloadInBox.cfm?UserName=w9mdb&Password=xxxxx&QTHNickname=Home&RcvdSince=201408080000";
String responseData = String.Empty;
try
{
richTextBox1.Clear();
richTextBox1.AppendText("Requesting EQSL.CC data...\n");
//ActiveForm.Update();
WebClient client = new WebClient();
// Without adding a header it seemed like LOTW was not liking very many queries together while debugging
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0");
Stream data = client.OpenRead(uri);
data.ReadTimeout = 60 * 5 * 1000; // 5 minute timeout
richTextBox1.AppendText("Request accepted...reading ADIF data\n");
//ActiveForm.Update();
StreamReader reader = new StreamReader(data);
responseData = reader.ReadToEnd();
data.Close();
reader.Close();
// Now we get the link for the ADI file from the response we got
int offset = responseData.IndexOf("downloadedfiles");
offset += responseData.Substring(offset).IndexOf("/");
int offset2 = responseData.Substring(offset).IndexOf('\"');
string s = responseData.Substring(offset, offset2);
uri = "http://eqsl.cc/qslcard/downloadedfiles"+s;
//string x = "http://eqsl.cc/qslcard/downloadedfiles/2WMWB4618.adi"
data = client.OpenRead(uri);
reader = new StreamReader(data);
responseData = reader.ReadToEnd();
data.Close();
reader.Close();
}
catch (Exception e)
{
richTextBox1.AppendText(e.Message + "\n");
}
richTextBox1.WordWrap = false;
if (responseData.Length == 0)
{
richTextBox1.AppendText("Invalid reponse from EQSL,CC...\nTry again\n");
return;
}
string filepath = appData + "\\lotw.adi";
StreamWriter writer = new StreamWriter(filepath);
writer.Write(responseData);
writer.Close();
doADIF(ref responseData);
}
* */
private string ReadAllLines(StreamReader reader)
{
StringBuilder sb = new StringBuilder();
string line = string.Empty;
int n = 0;
richTextBox1.AppendText("Downloading log...\r");
while ((line = reader.ReadLine()) != null)
{
sb.Append(line+"\n");
++n;
if ((n % 1000) == 0)
{
if (n > 1000) richTextBox1.Undo();
richTextBox1.AppendText("# lines="+n+"\r");
try
{
this.Update();
}
catch (Exception e)
{
errorStr = e.Message;
}
}
}
if (n >= 1000) richTextBox1.Undo();
return sb.ToString();
}
private void GetLOTW()
{
sinceLOTW = textBoxSince.Text;
string startDate = "";
if (sinceLOTW.Substring(0, 1) == "!") // then we reset things
{
sinceLOTW = sinceLOTW.Substring(1);
startDate = "&qso_qsorxsince=" + sinceLOTW;
richTextBox1.AppendText("New log starts at "+startDate);
}
else {
Type t = this.GetType();
System.Reflection.PropertyInfo p = t.GetProperty("QSODate");
if (p != null)
{
startDate = "&qso_qsorxsince=" + Properties.Settings.Default.QSODate;
}
else
{
startDate = "&qso_qsorxsince=" + sinceLOTW;
}
}
//string mylogin = login.ToString();
//string mypassword = password.ToString();
// This one producs only some records with all the detail
// https://lotw.arrl.org/lotwuser/lotwreport.adi?login=w9mdb&password=xxxxxxxx&qso_query=1&qso_qsl=no&qso_startdate=1900-01-01&qso_qsldetail=yes
// This one gives all QSLs with detail for each that includes state and country
// https://lotw.arrl.org/lotwuser/lotwreport.adi?login=w9mdb&password=xxxxxxxx&qso_query=1&qso_qsl=yes&qso_startdate=1900-01-01&qso_qsldetail=yes
//string uri = "https://lotw.arrl.org/lotwuser/lotwreport.adi?login=" + mylogin + "&password=" + mypassword + "&qso_query=1&qso_qsl=yes&qso_startdate=1900-01-01&qso_qsldetail=yes";
//string uri = "https://lotw.arrl.org/lotwuser/lotwreport.adi?login=w9mdb&password=xxxxxxxx&qso_query=1&qso_qsl=yes&qso_qslsince="2014-06-13 00:00:00"&qso_qsldetail=yes
string[] tokens = Regex.Split(mylogin, "[+@]");
string login = tokens[0];
String mypassword_uri = Uri.EscapeDataString(mypassword);
string uri = "https://lotw.arrl.org/lotwuser/lotwreport.adi?login=" + login + "&password=" + mypassword_uri + "&qso_query=1&qso_qsl=yes&qso_qsldetail=yes&qso_qslsince=" + sinceLOTW;
//string ownCall = "&qso_owncall="+login;
string endDate = "";
string ownCall = "";
if (mylogin.Contains("@")) // then we add another filter to the URI
{ // this will restrict records to the requested call sign
ownCall = "&qso_owncall=" + tokens[1];
}
if (textBoxEnd.Text.Length == 10)
{
endDate = "&qso_enddate=" + textBoxEnd.Text;
//uri = "https://lotw.arrl.org/lotwuser/lotwreport.adi?login=" + mylogin + "&password=" + mypassword + "&qso_query=1&qso_qsl=yes&qso_qsldetail=yes&qso_qslsince=" + sinceLOTW + "&qso_startdate=" + sinceLOTW + "&qso_enddate=" + textBoxEnd.Text;
//uri = "https://lotw.arrl.org/lotwuser/lotwreport.adi?login=" + mylogin + "&password=" + mypassword + "&qso_query=1&qso_qsl=yes&qso_qsldetail=yes&qso_qslsince=" + sinceLOTW + "&qso_enddate=" + textBoxEnd.Text+ownCall;
}
uri += ownCall + startDate + endDate; // add these if they were filled in
String responseData = String.Empty;
//string[] lines = new string[] {""};
try
{
richTextBox1.Clear();
DateTime mydate = DateTime.Now;
richTextBox1.AppendText(mydate.ToString() + "\n");
richTextBox1.AppendText("Requesting LOTW data...please be patient...\nThis can take several minutes\n");
richTextBox1.AppendText(uri + "\n");
Clipboard.SetText(uri);
richTextBox1.AppendText("URL copied to clipboard\n");
try
{
MainWindow2.ActiveForm.Update();
}
catch (Exception e)
{
errorStr = e.Message;
}
MyWebClient client = new MyWebClient();
// Without adding a header it seemed like LOTW was not liking very many queries together while debugging
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0");
System.Net.WebRequest.DefaultWebProxy = null;
client.Proxy = System.Net.WebRequest.DefaultWebProxy;
using (Stream data = client.OpenRead(uri))
{
richTextBox1.AppendText("Request accepted...reading ADI data\n");
try
{
MainWindow2.ActiveForm.Update();
}
catch (Exception e)
{
errorStr = e.Message;
}
data.ReadTimeout = 60 * 120 * 1000; // 2 hour timeout
using (BufferedStream buffer = new BufferedStream(data,4096*16))
{
using (StreamReader reader = new StreamReader(buffer))
{
responseData = ReadAllLines(reader);
}
}
}
}
catch (Exception e)
{
richTextBox1.AppendText(e.Message+"\n");
}
DateTime mydate2 = DateTime.Now;
richTextBox1.AppendText(mydate2.ToString());
richTextBox1.WordWrap = false;
if (responseData.Length == 0)
{
richTextBox1.AppendText("Invalid reponse from LOTW...\nTry again\n");
return;
}
string filepath = appData + "\\lotw.adi";
StreamWriter writer = new StreamWriter(filepath);
writer.Write(responseData);
writer.Close();
if (!responseData.Contains("<CALL"))
{
if (responseData.Contains("forgot"))
{
richTextBox1.AppendText("\nLOTW returned an error\n");
richTextBox1.AppendText("Looks like wrong password\n");
}
else if (responseData.Contains("<APP_LoTW_NUMREC:1>0"))
{
richTextBox1.AppendText("\nNo new QSLs\n");
}
else {
richTextBox1.AppendText("\nUnknown LOTW error\nFile will display in browser\n");
string htmlfilepath = appData + "\\lotw.htm";
writer = new StreamWriter(htmlfilepath);
writer.Write(responseData);
writer.Close();
System.Diagnostics.Process.Start(htmlfilepath);
richTextBox1.AppendText("Another Refresh may fix it\n");
}
return;
}
DoADIF(ref responseData);
if (textBoxEnd.Text.Length == 10)
{
textBoxSince.Text = textBoxEnd.Text;
sinceLOTW = textBoxEnd.Text;
}
}
private void Login_TextChanged(object sender, EventArgs e)
{
// no action here -- wait until we leave
}
private void Login_Leave(object sender, EventArgs e)
{
Properties.Settings.Default.login = mylogin;
Properties.Settings.Default.Save();
if (!textBoxLogin.Text.Equals(mylogin)) // Only do this is if we change what's already there
{
mylogin = textBoxLogin.Text;
string call1 = mylogin; // by default
string call2 = string.Empty;
// we've change logins -- check if asking for added callsign filter
if (mylogin.Contains("+"))
{
string[] tokens = Regex.Split(mylogin,@"\+");
call1 = tokens[0];
call2 = tokens[1];
MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
DialogResult result = MessageBox.Show("This will merge "+call2+" with "+call1+"?\nAre you sure?\nUse callsign@login format to keep separate...see Help file","Merge",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (result == DialogResult.No) return;
mergeCalls = true;
}
else if (mylogin.Contains("@")) // the the log willb be separate
{
mergeCalls = false;
}
if (mergeCalls) // then we just keep the main login
{
keeperFile = appData + "\\" + call1.Replace('/','_') + ".txt";
}
else // we'll keep the call1+call2 in a separate log
{
keeperFile = appData + "\\" + mylogin.Replace('/','_') + ".txt";
}
KeeperLoad(keeperFile);
Properties.Settings.Default.login = mylogin;
Properties.Settings.Default.Save();
}
}
private void Password_Get(String call, String passwordList)
{
passwordList = "w9mdb:mdb001;w9mdb@w9mdb:mdb002";
String[] tokens = passwordList.Split(';');
foreach (String s in tokens)
{
}
}
private void Password_TextChanged(object sender, EventArgs e)
{
mypassword = password.Text;
Properties.Settings.Default.password = mypassword;
Properties.Settings.Default.Save();
}
private void SinceLOTWBox_Leave(object sender, EventArgs e)
{
try
{
string tmp = textBoxSince.Text;
tmp = tmp.ToUpper();