-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
1321 lines (1182 loc) · 46.3 KB
/
MainWindow.xaml.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Net.Http;
using System.Collections.Concurrent;
using System.Security.Cryptography;
using Microsoft.Win32;
using System.Net.Cache;
namespace ProxyTester
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private ObservableCollection<ListOfSites> listOfSites = new ObservableCollection<ListOfSites>();
private ObservableCollection<ListOfProxies> listOfProxies = new ObservableCollection<ListOfProxies>();
private ObservableCollection<ListOfProxyTests> listOfProxyTests = new ObservableCollection<ListOfProxyTests>();
private ObservableCollection<ListOfProxyTests> listOfProxyTestsForDisplay = new ObservableCollection<ListOfProxyTests>();
private string proxyCsvFilePath = "";
private bool isImportOrAdd = false;
private bool isTested = false;
private bool isFilterUsed = false;
private int tabId = 0;
private string siteUrl = "";
private CancellationTokenSource cts;
public MainWindow()
{
InitializeComponent();
listOfSites = ReadSitesCSV();
lv_sites.ItemsSource = listOfSites;
cb_sites.ItemsSource = listOfSites;
cb_sites.DisplayMemberPath = "sitename";
cb_sites.SelectedIndex = 0;
lv_proxytests.ItemsSource = listOfProxyTests;
}
private async void testAll_click(object sender, RoutedEventArgs e)
{
if (this.siteUrl.Equals(""))
{
MessageBox.Show("Site Url is empty!", "Trek Proxy Tester");
return;
}
cts = new CancellationTokenSource();
this.isTested = false;
this.listOfProxyTests = ReadListProxyTests();
this.listOfProxyTestsForDisplay = this.listOfProxyTests;
lv_proxytests.ItemsSource = this.listOfProxyTests;
int numberPerOnce = 20;
int amountProxy = this.listOfProxyTestsForDisplay.Count;
int remainder = this.listOfProxyTestsForDisplay.Count % numberPerOnce;
int i = 0;
bool f = false;
int timeout = Int32.Parse(tb_ms.Text);
if (timeout == 0)
timeout = 1000;
List<ListOfProxyTests> listOfProxyTestss = new List<ListOfProxyTests>();
try
{
foreach (ListOfProxyTests lopt in this.listOfProxyTestsForDisplay)
{
//listOfProxyTestss.Add(lopt);
Task dd = lopt.TestProxyAsync(this.siteUrl, timeout, cts.Token);
//if (i++ > 2)
// break;
//listOfProxyTestss.Add(lopt);
//obj[i][i] = lopt;
//if (((i + 1) % numberPerOnce == 0) || f)
// {
// Task d = proxyTester(listOfProxyTestss);
//}
//if ((amountProxy - remainder) == (1 + i++)) f = true;
}
}
catch (OperationCanceledException e1)
{
Console.WriteLine(e1.ToString());
MessageBox.Show("Canceled");
}
catch (Exception ee)
{
Console.WriteLine(ee.ToString());
}
this.isTested = true;
}
async Task ddd(CancellationToken ct)
{
var tasks = new ConcurrentBag<Task>();
//Task t;
int i = 0;
await Task.Run(() =>
{
ct.ThrowIfCancellationRequested();
bool f = false;
Task t = Task.Run(() =>
{
while (i++ < 5)
{
Thread.Sleep(1000);
}
//if(f) ct.ThrowIfCancellationRequested();
if (f) return;
else MessageBox.Show("Hi");
}, ct);
while (true)
{
if (ct.IsCancellationRequested)
{
f = true;
//t.Dispose();
ct.ThrowIfCancellationRequested();
}
}
}, ct);
// tasks.Add(t);
}
private async Task proxyTester(List<ListOfProxyTests> listOfProxyTestss)
{
int timeout = Int32.Parse(tb_ms.Text);
if (timeout == 0)
timeout = 1000;
Task[] task = new Task[listOfProxyTestss.Count];
await Task.Run(() =>
{
try
{
int i = 0;
foreach (ListOfProxyTests lopt in listOfProxyTestss)
{
task[i++] = lopt.TestProxyAsync(this.siteUrl, timeout, cts.Token);
}
listOfProxyTestss.Clear();
}
catch (OperationCanceledException e1)
{
Console.WriteLine(e1.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
});
}
private void deleteFailed_click(object sender, RoutedEventArgs e)
{
ObservableCollection<ListOfProxyTests> temp = new ObservableCollection<ListOfProxyTests>();
foreach (ListOfProxyTests lopt in this.listOfProxyTests)
{
if (!lopt.speed.Equals("X"))
{
//this.listOfProxyTests.Remove(lopt);
temp.Add(lopt);
}
}
this.listOfProxyTests = temp;
lv_proxytests.ItemsSource = this.listOfProxyTests;
}
private void unactiveFailed_click(object sender, RoutedEventArgs e)
{
ObservableCollection<ListOfProxyTests> temp = new ObservableCollection<ListOfProxyTests>();
ObservableCollection<ListOfProxyTests> temp1 = new ObservableCollection<ListOfProxyTests>();
ObservableCollection<ListOfProxies> templist = new ObservableCollection<ListOfProxies>();
var csv = new StringBuilder();
foreach (ListOfProxyTests lopt in this.listOfProxyTests)
{
if (!lopt.speed.Equals("X"))
{
//this.listOfProxyTests.Remove(lopt);
temp.Add(lopt);
}
else
{
temp1.Add(lopt);
}
}
foreach (ListOfProxies lop in this.listOfProxies)
{
foreach (ListOfProxyTests lopt in temp1)
{
if (lop.ip.Equals(lopt.proxy.Split(':')[0]) && lop.port.Equals(lopt.proxy.Split(':')[1]))
{
lop.status = false;
lop.btnContent = "Unactive";
lop.color = "Red";
break;
}
}
string status = "0";
if (lop.status) status = "1";
var newLine = string.Format("{0},{1},{2},{3},{4}", lop.ip, lop.port, lop.username, lop.password, status);
csv.AppendLine(newLine);
templist.Add(lop);
}
this.listOfProxies = templist;
lv_proxies.ItemsSource = this.listOfProxies;
this.listOfProxyTests = temp;
lv_proxytests.ItemsSource = this.listOfProxyTests;
if (this.isImportOrAdd)
{
File.WriteAllText(this.proxyCsvFilePath, csv.ToString());
}
}
private void reload_click(object sender, RoutedEventArgs e)
{
if (cts != null)
{
cts.Cancel();
Console.WriteLine("Cancel clicked!");
}
this.isTested = false;
this.listOfProxyTests = ReadListProxyTests();
this.listOfProxyTestsForDisplay = this.listOfProxyTests;
lv_proxytests.ItemsSource = this.listOfProxyTests;
}
private void site_delete(object sender, RoutedEventArgs e)
{
cb_sites.SelectedIndex = 0;
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
{
var selected = lv_sites.SelectedItems.Cast<Object>().ToArray();
foreach (var item in selected)
{
ListOfSites site = (item as ListOfSites);
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\TrekProxyTester"))
{
string[] siteKeys = key.GetValueNames();
foreach (string sitekey in siteKeys)
if (key.GetValue(sitekey).Equals(site.sitedomain))
{
key.DeleteValue(sitekey);
}
}
}
foreach (var item in selected) this.listOfSites.Remove(item as ListOfSites);
}
}
private void proxytests_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
var temp = (e.AddedItems[0] as ListOfSites);
this.siteUrl = temp.sitedomain;
return;
}
this.siteUrl = "";
}
private void importProxy_clicked(object sender, RoutedEventArgs e)
{
isImportOrAdd = true;
string filename = "";
// Create OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".txt";
dlg.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
// Open document
filename = dlg.FileName;
this.proxyCsvFilePath = filename;
this.listOfProxies = ReadProxyCSV(filename);
lv_proxies.ItemsSource = this.listOfProxies;
}
}
public ObservableCollection<ListOfSites> ReadSitesCSV()
{
ObservableCollection<ListOfSites> templist = new ObservableCollection<ListOfSites>();
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\TrekProxyTester"))
{
string[] siteKeys = key.GetValueNames();
int amountOfSite = siteKeys.Length;
if (amountOfSite > 0)
{
foreach (string sitekey in siteKeys)
{
string stieUrl = key.GetValue(sitekey).ToString();
templist.Add(new ListOfSites { sitedomain = stieUrl, sitename = sitekey });
}
}
else
{
var path = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "DefaultSiteUrls.txt");
if (!File.Exists(path))
{
using (System.IO.FileStream fs = System.IO.File.Create(path)) { }
}
else
{
string[] lines = File.ReadAllLines(System.IO.Path.ChangeExtension(path, ".txt"));
foreach (string line in lines)
{
string[] data = line.Split(',');
templist.Add(new ListOfSites { sitedomain = data[0], sitename = data[1] });
key.SetValue(data[1], data[0]);
}
}
}
key.Close();
}
return templist;
}
public ObservableCollection<ListOfProxies> ReadProxyCSV(string fileName)
{
string[] lines = File.ReadAllLines(System.IO.Path.ChangeExtension(fileName, ".txt"));
ObservableCollection<ListOfProxies> templist = new ObservableCollection<ListOfProxies>();
int i = 0;
try
{
foreach (string line in lines)
{
string[] data = line.Split(':');
bool status = false;
string username = "", password = "";
if (data.Length > 2)
{
username = data[2];
password = data[3];
}
if (data.Length != 5 || data[4].Equals("1"))
{
status = true;
}
templist.Add(new ListOfProxies { id = i, ip = data[0], port = data[1], username = username, password = password, status = status });
i++;
}
}
catch (Exception)
{
}
return templist;
}
private void addSite_clicked(object sender, RoutedEventArgs e)
{
string Url = tb_domain.Text;
string siteName = tb_siteName.Text;
if (Url.Trim().Equals("") || siteName.Trim().Equals(""))
{
return;
}
tb_domain.Text = "";
tb_siteName.Text = "";
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\TrekProxyTester"))
{
key.SetValue(siteName, Url);
}
this.listOfSites.Add(new ListOfSites { sitedomain = Url, sitename = siteName });
}
private void Status_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
var csv = new StringBuilder();
var path = this.proxyCsvFilePath;
if (isImportOrAdd)
{
File.Delete(path);
}
foreach (ListOfProxies lop in this.listOfProxies)
{
string status = "1";
if (!lop.status)
status = "0";
if (lop.id == Int64.Parse(btn.Tag.ToString()))
{
if (lop.status)
{
lop.status = false;
btn.Content = "Unactive";
btn.Foreground = Brushes.Red;
status = "0";
}
else
{
lop.status = true;
btn.Content = "Active";
btn.Foreground = Brushes.Blue;
}
}
if (isImportOrAdd)
{
var newLine = string.Format("{0}:{1}:{2}:{3}:{4}", lop.ip, lop.port, lop.username, lop.password, status);
csv.AppendLine(newLine);
}
}
if (isImportOrAdd)
{
File.AppendAllText(path, csv.ToString());
}
}
private void SaveProxyClick(object sender, RoutedEventArgs e)
{
string[] lines = tb_newproxy.Text.Split('\n');
var csv = new StringBuilder();
bool f = false;
foreach (string line in lines)
{
if (line.Equals("") || line.Equals("\r"))
break;
string[] data = line.Split(':');
if (data.Length < 2)
{
f = true;
break;
}
string ip = "", port = "", username = "", password = "", status = "1";
int i = 0;
foreach (string temp in data)
{
string temp1 = temp.Replace("\r", "");
switch (i)
{
case 0: ip = temp1; break;
case 1: port = temp1; break;
case 2: username = temp1; break;
case 3: password = temp1; break;
default: break;
}
i++;
}
var newLine = string.Format("{0},{1},{2},{3},{4}", ip, port, username, password, status);
csv.AppendLine(newLine);
}
if (f)
{
MessageBox.Show("Proxy data wrong!\n Please check it", "Wrong");
}
else
{
var filename = "";
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".txt";
dlg.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
// Open document
filename = dlg.FileName;
File.WriteAllText(filename, csv.ToString());
this.proxyCsvFilePath = filename;
}
}
}
private void AddProxyClick(object sender, RoutedEventArgs e)
{
isImportOrAdd = false;
ObservableCollection<ListOfProxies> templist = new ObservableCollection<ListOfProxies>();
bool f = false;
if (tb_newproxy.Text.Trim().Equals(""))
{
f = true;
}
string[] lines = tb_newproxy.Text.Split('\n');
int j = 0;
foreach (string line in lines)
{
if (line.Equals("") || line.Equals("\r"))
continue;
string[] data = line.Split(':');
if (data.Length < 2)
{
f = true;
break;
}
string ip = "", port = "", username = "", password = "";
bool status = true;
int i = 0;
foreach (string temp in data)
{
string temp1 = temp.Replace("\r", "");
switch (i)
{
case 0: ip = temp1; break;
case 1: port = temp1; break;
case 2: username = temp1; break;
case 3: password = temp1; break;
default: break;
}
i++;
}
templist.Add(new ListOfProxies { id = j, ip = ip, port = port, username = username, password = password, status = status });
j++;
}
if (f)
{
MessageBox.Show("Proxy data wrong!\n Please check it", "Wrong");
}
else
{
this.listOfProxies = templist;
lv_proxies.ItemsSource = this.listOfProxies;
}
}
private ObservableCollection<ListOfProxyTests> ReadListProxyTests()
{
ObservableCollection<ListOfProxyTests> listOfProxyTests = new ObservableCollection<ListOfProxyTests>();
int id = 0;
foreach (ListOfProxies lop in this.listOfProxies)
{
string proxy = lop.ip + ":" + lop.port;
if (lop.status)
{
listOfProxyTests.Add(new ListOfProxyTests { id = id, proxy = proxy, status = "Ready", username = lop.username, password = lop.password, speed = "0", isChecked = false });
id++;
}
}
return listOfProxyTests;
}
private void tabclick(object sender, SelectionChangedEventArgs e)
{
if (tabproxy != null && tabproxy.IsSelected)
{
tabId = 1;
if (tabId != 1)
{
//ObservableCollection<ListOfProxies> tt = new ObservableCollection<ListOfProxies>();
//tt.Add(new ListOfProxies { id = 0, ip = "123123", port = "345", username = "username", password = "password", status = false });
////lv_proxies.ItemsSource = this.listOfProxies;
//this.listOfProxies = tt;
//lv_proxies.ItemsSource = tt;
}
}
// do your staff
if (tabsite != null && tabsite.IsSelected)
{
tabId = 2;
}
// do your staff
if (tabproxytest != null && tabproxytest.IsSelected)
{
if (tabId != 3)
{
this.listOfProxyTests = ReadListProxyTests();
this.listOfProxyTestsForDisplay = this.listOfProxyTests;
lv_proxytests.ItemsSource = this.listOfProxyTests;
cb_sites.SelectedIndex = 0;
tb_ms.Text = "5000";
tabId = 3;
this.isTested = false;
}
}
}
private void export_click(object sender, RoutedEventArgs e)
{
if (!this.isTested) return;
var csv = new StringBuilder();
bool f = false;
ObservableCollection<ListOfProxyTests> datas = new ObservableCollection<ListOfProxyTests>();
if (this.isFilterUsed)
{
datas = this.listOfProxyTestsForDisplay;
}
else
{
datas = this.listOfProxyTests;
}
foreach (ListOfProxyTests lopt in datas)
{
if (!lopt.isChecked)
{
f = true;
break;
}
if (lopt.status.ToLower().Equals("good"))
{
var newLine = string.Format("{0}:{1}:{2}", lopt.proxy, lopt.username, lopt.password);
csv.AppendLine(newLine);
}
}
if (f)
{
MessageBox.Show("Not Test Proxy!", "Message");
}
else
{
var filename = "";
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".txt";
dlg.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
// Open document
filename = dlg.FileName;
File.WriteAllText(filename, csv.ToString());
}
}
}
private void copy_click(object sender, RoutedEventArgs e)
{
if (!this.isTested) return;
var csv = new StringBuilder();
bool f = false;
ObservableCollection<ListOfProxyTests> datas = new ObservableCollection<ListOfProxyTests>();
if (this.isFilterUsed)
{
datas = this.listOfProxyTestsForDisplay;
}
else
{
datas = this.listOfProxyTests;
}
foreach (ListOfProxyTests lopt in datas)
{
if (!lopt.isChecked)
{
f = true;
break;
}
if (lopt.status.ToLower().Equals("good"))
{
var newLine = string.Format("{0}:{1}:{2}", lopt.proxy, lopt.username, lopt.password);
csv.AppendLine(newLine);
}
}
if (f)
{
MessageBox.Show("Not Test Proxy!", "Message");
}
else
{
Clipboard.SetText(csv.ToString());
MessageBox.Show("Good Proxies Copied!", "Message");
}
}
private void tb_ms_TextChanged(object sender, TextChangedEventArgs e)
{
if (tabId == 3)
{
TextBox tb = sender as TextBox;
int filterValue = 5000;
try
{
filterValue = Int32.Parse(tb.Text);
}
catch (Exception e1)
{
Console.WriteLine(e1.ToString());
tb.Text = "5000";
filterValue = 5000;
}
if (isTested)
{
listOfProxyTestsForDisplay = getFilterResult(this.listOfProxyTests, filterValue);
lv_proxytests.ItemsSource = listOfProxyTestsForDisplay;
this.isFilterUsed = true;
}
}
}
private ObservableCollection<ListOfProxyTests> getFilterResult(ObservableCollection<ListOfProxyTests> datas, int filterValue)
{
ObservableCollection<ListOfProxyTests> temp = new ObservableCollection<ListOfProxyTests>();
foreach (ListOfProxyTests lopt in datas)
{
if (lopt.speed.Equals("X")) continue;
if (Int64.Parse(lopt.speed) <= filterValue)
{
temp.Add(lopt);
}
}
return temp;
}
private void windowSize_change(object sender, SizeChangedEventArgs e)
{
gridHeight.Height = (sender as Window).ActualHeight - 200;
rowTab1Height.Height = new GridLength((sender as Window).ActualHeight - 300);
rowTab2Height.Height = new GridLength((sender as Window).ActualHeight - 350);
rowTab3Height.Height = new GridLength((sender as Window).ActualHeight - 350);
//columnWidth.Width = (sender as Window).ActualWidth;
//this.gridHeight = ((sender as Window).ActualHeight - ss).ToString();
}
private void proxyListViewSize_change(object sender, SizeChangedEventArgs e)
{
ListView listView = sender as ListView;
GridView gView = listView.View as GridView;
var workingWidth = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar
var col1 = 0.25;
var col2 = 0.15;
var col3 = 0.20;
var col4 = 0.20;
var col5 = 0.15;
gView.Columns[0].Width = workingWidth * col1;
gView.Columns[1].Width = workingWidth * col2;
gView.Columns[2].Width = workingWidth * col3;
gView.Columns[3].Width = workingWidth * col4;
gView.Columns[4].Width = workingWidth * col5;
}
private void siteListViewSize_change(object sender, SizeChangedEventArgs e)
{
ListView listView = sender as ListView;
GridView gView = listView.View as GridView;
var workingWidth = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar
var col1 = 0.15;
var col2 = 0.30;
var col3 = 0.50;
gView.Columns[0].Width = workingWidth * col1;
gView.Columns[1].Width = workingWidth * col2;
gView.Columns[2].Width = workingWidth * col3;
}
private void testListViewSize_change(object sender, SizeChangedEventArgs e)
{
ListView listView = sender as ListView;
GridView gView = listView.View as GridView;
var workingWidth = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar
var col1 = 0.20;
var col2 = 0.20;
var col3 = 0.20;
var col4 = 0.15;
var col5 = 0.20;
gView.Columns[0].Width = workingWidth * col1;
gView.Columns[1].Width = workingWidth * col2;
gView.Columns[2].Width = workingWidth * col3;
gView.Columns[3].Width = workingWidth * col4;
gView.Columns[4].Width = workingWidth * col5;
}
}
public class ListOfSites
{
public int index { get; set; }
public string sitename { get; set; }
public string sitedomain { get; set; }
}
public class ListOfProxies
{
private ICommand _btnStatusClick;
private string statusContent = "";
private string _btnContent;
public bool status = true;
public int id { get; set; }
public string ip { get; set; }
public string port { get; set; }
public string username { get; set; }
public string password { get; set; }
public string color
{
get
{
if (status)
{
return ("Blue");
}
else
{
return ("Red");
}
}
set { }
}
public string btnContent
{
get
{
if (this.status)
{
this.statusContent = "Active";
}
else
{
this.statusContent = "Unactive";
}
return this.statusContent;
}
set
{
_btnContent = value;
//NotifyPropertyChanged("btnContent");
//if (PropertyChanged != null)
// PropertyChanged(this, new PropertyChangedEventArgs(btnContent));
}
}
public ICommand btnStatusClick
{
get
{
return _btnStatusClick ?? (_btnStatusClick = new CommandHandler(() => MyAction(), () => CanExecute));
}
}
public bool CanExecute
{
get
{
// check if executing is allowed, i.e., validate, check if a process is running, etc.
return true;
}
}
public void MyAction()
{
if (!this.status)
{
this.statusContent = "Active";
this.status = true;
}
else
{
this.statusContent = "Unactive";
this.status = false;
}
this.btnContent = this.statusContent;
}
}
public class CommandHandler : ICommand
{
private Action _action;
private Func<bool> _canExecute;
/// <summary>
/// Creates instance of the command handler
/// </summary>
/// <param name="action">Action to be executed by the command</param>
/// <param name="canExecute">A bolean property to containing current permissions to execute the command</param>
public CommandHandler(Action action, Func<bool> canExecute)
{
_action = action;
_canExecute = canExecute;
}
/// <summary>
/// Wires CanExecuteChanged event
/// </summary>
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
/// <summary>
/// Forcess checking if execute is allowed
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
public bool CanExecute(object parameter)
{
return _canExecute.Invoke();
}
public void Execute(object parameter)
{
_action();
}
}
public class ListOfProxyTests : INotifyPropertyChanged
{
// Declare the event
public event PropertyChangedEventHandler PropertyChanged;
private string _status;
private string _progresshidden = "Collapsed";
private string _speedhidden = "Collapsed";
private string _speed = "";
private string _color = "Gray";
public int id { get; set; }
public string proxy { get; set; }
public string username { get; set; }
public string password { get; set; }
public bool isChecked { get; set; }
public bool isIp { get; set; }
private const int GOOD = 0;
private const int BANNED = 1;
private const int FAILED = 2;
public string status
{
get { return _status; }
set
{
_status = value;
// Call OnPropertyChanged whenever the property is updated
OnPropertyChanged();
}