-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
208 lines (170 loc) · 6.2 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.Win32;
namespace CommunicatorWPF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Communicator.Communicator communicator = new Communicator.Communicator();
public MainWindow()
{
InitializeComponent();
Timer statusUpdater = new Timer();
statusUpdater.Elapsed += StatusBarUpdater;
statusUpdater.Interval = 300;
statusUpdater.Enabled = true;
}
private void SendText(object sender, RoutedEventArgs e)
{
if (!communicator.loggedIn)
{
MessageBox.Show("Not Logged In");
return;
}
RowDefinition rowdef = new RowDefinition();
rowdef.MinHeight = 0.1;
this.MessageBoxGrid.RowDefinitions.Add(new RowDefinition());
TextBlock message = new TextBlock();
message.MinHeight = 0.1;
message.Text = this.SendBox.Text;
message.TextAlignment = System.Windows.TextAlignment.Right;
message.Background = new SolidColorBrush(Colors.Green);
message.TextWrapping = System.Windows.TextWrapping.Wrap;
message.VerticalAlignment = System.Windows.VerticalAlignment.Top;
Grid.SetRow(message, MessageBoxGrid.RowDefinitions.Count - 1);
Grid.SetColumn(message, 1);
this.MessageBoxGrid.Children.Add(message);
this.MessageBoxScroll.ScrollToBottom();
communicator.SendEncryptedText(this.SendBox.Text);
this.SendBox.Text = "";
}
private void FileChooser(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if(openFileDialog.ShowDialog() == true)
{
Task send = new Task(() => communicator.SendEncryptedFile(openFileDialog.FileName,SendProgressBar));
send.Start();
/*communicator.SendEncryptedFile(openFileDialog.FileName)*/;
}
}
private void LoginFunc(object sender, RoutedEventArgs e)
{
communicator.Login();
}
private void LogoutFunc(object sender, RoutedEventArgs e)
{
communicator.Logout();
}
private void Register(object sender, RoutedEventArgs e)
{
communicator.Register();
}
private void UserChange(object sender, RoutedEventArgs e)
{
communicator.user = this.Login.Text;
}
private void PassChange(object sender, RoutedEventArgs e)
{
communicator.password= this.Password.Password;
}
private void Connect(object sender, RoutedEventArgs e)
{
if (!communicator.listen)
communicator.StartListener(MessageBoxGrid, DownloadProgressBar);
else
communicator.SendSessionKeyAndIV();
}
//Closing Window
private void Disconnect(object sender, EventArgs e)
{
communicator.StopListening();
}
//Button
private void Disconnect(object sender, RoutedEventArgs e)
{
communicator.StopListening();
}
private void RecipientChange(object sender, RoutedEventArgs e)
{
communicator.recipient = this.Recipient.Text;
communicator.ChangeRecipient();
}
private void RadioButtonCBC(object sender, RoutedEventArgs e)
{
communicator.mode = System.Security.Cryptography.CipherMode.CBC;
}
private void RadioButtonECB(object sender, RoutedEventArgs e)
{
communicator.mode = System.Security.Cryptography.CipherMode.ECB;
}
private void IPSendChange(object sender, TextChangedEventArgs e)
{
communicator.send_ip = this.ip_send_box.Text;
}
private void IPListenChange(object sender, TextChangedEventArgs e)
{
communicator.ip = this.ip_listen_box.Text;
}
private void PortChange(object sender, TextChangedEventArgs e)
{
communicator.port_listen = Int32.Parse(this.port_listen_box.Text);
}
private void SenderPortChange(object sender, TextChangedEventArgs e)
{
communicator.port_send = Int32.Parse(this.port_send_box.Text);
}
private void StatusBarUpdater(object source, ElapsedEventArgs e)
{
try
{
Dispatcher.Invoke(() =>
{
if (communicator.listening == 1)
{
ListeningStatus.Background = new SolidColorBrush(Colors.Orange);
}
else if (communicator.listening == 2)
{
ListeningStatus.Background = new SolidColorBrush(Colors.Green);
}
else
{
ListeningStatus.Background = new SolidColorBrush(Colors.Red);
}
if (communicator.session_key)
{
SessionStatus.Background = new SolidColorBrush(Colors.Green);
}
else
{
SessionStatus.Background = new SolidColorBrush(Colors.Red);
}
if (communicator.loggedIn)
{
LoginStatus.Background = new SolidColorBrush(Colors.Green);
}
else
{
LoginStatus.Background = new SolidColorBrush(Colors.Red);
}
});
}
//Catch Cancel of Timer.
catch (TaskCanceledException cancel_event)
{
Console.WriteLine(cancel_event.Message);
}
}
}
}