-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWindow.xaml.cs
115 lines (100 loc) · 3.77 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
using System;
using System.Collections.Generic;
using System.Linq;
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 Microsoft.Win32;
using System.IO;
using System.Threading;
namespace ProxyTester
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private OpenFileDialog _openFileDialog;
private SaveFileDialog _saveFileDialog;
private List<string> _proxyStringList;
private readonly List<Proxy.Proxy> _proxyList;
public MainWindow()
{
InitializeComponent();
_openFileDialog = new OpenFileDialog();
_openFileDialog.Title = "Please choose proxy file";
_saveFileDialog = new SaveFileDialog();
_saveFileDialog.Title = "Export working proxies";
_saveFileDialog.DefaultExt = ".txt";
_proxyList = new List<Proxy.Proxy>();
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Interval = 1000;
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = true;
}
private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
Application.Current.Dispatcher.BeginInvoke(new Action(delegate ()
{
Queue.Content = ThreadPool.PendingWorkItemCount;
}));
}
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//WPF wants to keep this
}
async private void Button_Click(object sender, RoutedEventArgs e)
{
if (_openFileDialog.ShowDialog() is true)
_proxyStringList = new List<string>(await File.ReadAllLinesAsync(_openFileDialog.FileName));
using(new Helpers.WaitCursor())
{
foreach (string _proxy in _proxyStringList)
{
try
{
_proxyList.Add(new Proxy.Proxy(_proxy, ProxyList, Application.Current.Dispatcher));
}
catch (Exception ex)
{
if (ex is FormatException || ex is Proxy.InvalidProxyException)
continue;
throw new Exception("Unknown error");
}
}
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
_proxyList.Clear();
_proxyStringList.Clear();
ProxyList.Items.Clear();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
_proxyList.ForEach(prox => prox.Run(Destination.Text));
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
List<string> exportFileLines = new List<string>();
if (_saveFileDialog.ShowDialog() is false)
return;
_proxyList.ForEach(prox =>
{
if (! (prox.ProxyItem.Status == "success")) return;
Console.WriteLine(prox.ProxyItem.IP + ":" + prox.ProxyItem.Port.ToString() + ":" + prox.ProxyItem.User + ":" + prox.ProxyItem.Pass);
exportFileLines.Add(prox.ProxyItem.IP + ":" + prox.ProxyItem.Port.ToString() + ":" + prox.ProxyItem.User + ":" + prox.ProxyItem.Pass);
});
File.WriteAllLinesAsync(_saveFileDialog.FileName, exportFileLines);
}
}
}