9
9
10
10
namespace ClipSync {
11
11
12
+ /// <summary>
13
+ /// Mail Home Form of ClipSync
14
+ /// </summary>
12
15
public partial class ClipSyncControlForm : Form {
13
16
17
+ /// <summary>
18
+ /// time interval for checking copying data
19
+ /// </summary>
14
20
public string mTime = DateTime . Now . ToLongTimeString ( ) ;
15
21
22
+ /// <summary>
23
+ /// Global Helper Instance
24
+ /// </summary>
16
25
private readonly GlobalHelper globalHelper ;
17
26
27
+ /// <summary>
28
+ /// Signal R Hub Proxy
29
+ /// </summary>
18
30
public IHubProxy _hub ;
19
31
32
+ /// <summary>
33
+ /// signal R Disposable Hub object
34
+ /// </summary>
20
35
private IDisposable signalRDisposable { get ; set ; }
21
36
22
37
bool isSignalRConnected = false ;
23
38
39
+ /// <summary>
40
+ /// User Id
41
+ /// </summary>
24
42
public string uid = "" ;
25
43
44
+ /// <summary>
45
+ /// Default Constructor
46
+ /// </summary>
26
47
internal ClipSyncControlForm ( ) {
27
48
InitializeComponent ( ) ;
28
49
this . globalHelper = new GlobalHelper ( ) ;
29
50
}
30
51
31
- private void LoginSignUpForm_Load ( object sender , EventArgs e ) {
52
+ private void ClipSyncControlForm_Load ( object sender , EventArgs e ) {
32
53
try {
33
54
34
55
this . LogWriter ( "-------------------" ) ;
@@ -42,13 +63,48 @@ private void LoginSignUpForm_Load(object sender, EventArgs e) {
42
63
this . connectUidTextBox . Text = new Random ( ) . Next ( 1000 , 9999 ) . ToString ( ) ;
43
64
44
65
45
- }
46
- catch ( Exception ex ) {
66
+ } catch ( Exception ex ) {
47
67
this . LogWriter ( ex . ToString ( ) ) ;
48
68
}
49
69
}
50
70
51
- private void LoginButtonClick ( object sender , EventArgs e ) {
71
+ /// <summary>
72
+ /// Server Port text box key press event
73
+ /// </summary>
74
+ /// <param name="sender"></param>
75
+ /// <param name="e"></param>
76
+ private void serverPortTextBox_KeyPress ( object sender , KeyPressEventArgs e ) {
77
+ if ( ! ( Char . IsDigit ( e . KeyChar ) || ( e . KeyChar == ( char ) Keys . Back ) ) )
78
+ e . Handled = true ;
79
+ }
80
+
81
+ /// <summary>
82
+ /// Connect To Server Port Key Press Event
83
+ /// </summary>
84
+ /// <param name="sender"></param>
85
+ /// <param name="e"></param>
86
+ private void connectServerPortTextBox_KeyPress ( object sender , KeyPressEventArgs e ) {
87
+ if ( ! ( Char . IsDigit ( e . KeyChar ) || ( e . KeyChar == ( char ) Keys . Back ) ) )
88
+ e . Handled = true ;
89
+ }
90
+
91
+ /// <summary>
92
+ /// Connect Uid Key Press Event
93
+ /// </summary>
94
+ /// <param name="sender"></param>
95
+ /// <param name="e"></param>
96
+ private void connectUidTextBox_KeyPress ( object sender , KeyPressEventArgs e ) {
97
+
98
+ if ( ! ( Char . IsDigit ( e . KeyChar ) || ( e . KeyChar == ( char ) Keys . Back ) ) )
99
+ e . Handled = true ;
100
+ }
101
+
102
+ /// <summary>
103
+ /// Login Button Click
104
+ /// </summary>
105
+ /// <param name="sender"></param>
106
+ /// <param name="e"></param>
107
+ private void LoginButton_Click ( object sender , EventArgs e ) {
52
108
53
109
Login_Button . Enabled = false ;
54
110
@@ -68,17 +124,15 @@ private void LoginButtonClick(object sender, EventArgs e) {
68
124
this . _hub = connection . CreateHubProxy ( ConfigurationManager . AppSettings [ "hub_name" ] ) ;
69
125
connection . Start ( ) . Wait ( ) ;
70
126
isSignalRConnected = true ;
71
- }
72
- catch ( Exception ex ) {
127
+ } catch ( Exception ex ) {
73
128
isSignalRConnected = false ;
74
129
Login_Button . Enabled = true ;
75
130
this . LogWriter ( "Exception in connecting to SignalR Hub : " + ex . ToString ( ) ) ;
76
131
}
77
132
78
133
if ( ! isSignalRConnected ) {
79
134
MessageBox . Show ( "ClipSync Server is not running, so Please close the whole app and try again after sometime." , "Warning" ) ;
80
- }
81
- else {
135
+ } else {
82
136
83
137
MessageBox . Show ( "ClipSync Server is now connected, You need to connect to this uid: " + uid + " from all your devices. Now you can minimise this window" , "Success" ) ;
84
138
this . LogWriter ( "ClipSync Server is now connected, You need to connect to this uid: " + uid + " from all your devices. Now you can minimise this window" ) ;
@@ -101,6 +155,11 @@ private void LoginButtonClick(object sender, EventArgs e) {
101
155
102
156
}
103
157
158
+ /// <summary>
159
+ /// Start Server Button Click
160
+ /// </summary>
161
+ /// <param name="sender"></param>
162
+ /// <param name="e"></param>
104
163
private void StartServerButton_Click ( object sender , EventArgs e ) {
105
164
this . startServerButton . Enabled = false ;
106
165
this . LogWriter ( "Starting server on " ) ;
@@ -117,20 +176,55 @@ private void StartServerButton_Click(object sender, EventArgs e) {
117
176
this . connectServerAddressTextBox . Text = globalHelper . GetMachineIpAddress ( ) ;
118
177
this . connectServerPortTextBox . Text = this . serverPortTextBox . Text ;
119
178
this . startServerButton . Enabled = false ;
120
- }
121
- catch ( System . Reflection . TargetInvocationException ex ) {
179
+
180
+ this . OpenPortButton . PerformClick ( ) ;
181
+ } catch ( System . Reflection . TargetInvocationException ex ) {
122
182
this . LogWriter ( "You need to run as administrator" ) ;
123
183
this . LogWriter ( "Only server address localhost is allowed without administrator permissions" ) ;
124
184
MessageBox . Show ( "You need to run as administrator" , "Error" ) ;
125
185
Console . WriteLine ( ex . ToString ( ) ) ;
126
186
this . startServerButton . Enabled = true ;
127
- }
128
- catch ( Exception ex ) {
187
+ } catch ( Exception ex ) {
129
188
this . LogWriter ( ex . ToString ( ) ) ;
130
189
this . startServerButton . Enabled = true ;
131
190
}
132
191
}
133
192
193
+ /// <summary>
194
+ /// Open Port Button Click
195
+ /// </summary>
196
+ /// <param name="sender"></param>
197
+ /// <param name="e"></param>
198
+ private void OpenPortButton_Click ( object sender , EventArgs e ) {
199
+ try {
200
+
201
+ this . OpenPortButton . Enabled = false ;
202
+ int serverPort = Convert . ToInt32 ( this . serverPortTextBox . Text ) ;
203
+
204
+ this . LogWriter ( "Checking the status of inbound port: " + serverPort + " Please wait..." ) ;
205
+ if ( this . globalHelper . IsPortOpened ( serverPort , "ClipSync" ) ) {
206
+ this . LogWriter ( "Port " + serverPort + " is already open" ) ;
207
+ } else {
208
+ this . LogWriter ( "Opening the inbound port: " + serverPort + " Please wait..." ) ;
209
+ if ( this . globalHelper . OpenInboundFirewallPort ( serverPort , "ClipSync" , serverPort . ToString ( ) ) ) {
210
+ this . LogWriter ( "Successfully opened the inbound port : " + serverPort ) ;
211
+ } else {
212
+ this . LogWriter ( "Failed to open the inbound port : " + serverPort ) ;
213
+ this . LogWriter ( "Try running as administrator" ) ;
214
+ MessageBox . Show ( "Try running as administrator" , "Error" ) ;
215
+ }
216
+ }
217
+ this . OpenPortButton . Enabled = true ;
218
+ } catch ( System . Reflection . TargetInvocationException ex ) {
219
+ this . LogWriter ( "You need to run as administrator" ) ;
220
+ MessageBox . Show ( "You need to run as administrator" , "Error" ) ;
221
+ Console . WriteLine ( ex . ToString ( ) ) ;
222
+ } catch ( Exception ex ) {
223
+ this . OpenPortButton . Enabled = true ;
224
+ this . LogWriter ( ex . ToString ( ) ) ;
225
+ }
226
+ }
227
+
134
228
/// <summary>
135
229
/// Log Writer on Form
136
230
/// </summary>
@@ -143,26 +237,24 @@ internal void LogWriter(string t) {
143
237
) ) ;
144
238
return ;
145
239
}
146
- consoleTextBox . AppendText ( Environment . NewLine + t ) ;
240
+ consoleTextBox . AppendText ( Environment . NewLine + Environment . NewLine + t ) ;
147
241
consoleTextBox . SelectionStart = consoleTextBox . Text . Length ;
148
242
consoleTextBox . ScrollToCaret ( ) ;
149
243
150
244
}
151
245
246
+ /// <summary>
247
+ /// Adds ClipBoard Listener to the Window
248
+ /// </summary>
152
249
private void AddClipBoardListener ( ) {
153
250
//NativeMethods.SetParent(Handle, NativeMethods.HWND_MESSAGE);
154
251
NativeMethods . AddClipboardFormatListener ( Handle ) ;
155
252
}
156
253
157
- private void websocket_MessageReceived ( object sender , EventArgs e ) {
158
- this . LogWriter ( "websocket_MessageReceived" ) ;
159
- }
160
-
161
- private void websocket_Closed ( object sender , EventArgs e ) {
162
- this . LogWriter ( "websocket_Closed" ) ;
163
- }
164
-
165
-
254
+ /// <summary>
255
+ /// WindProc for getting ClipBoard Data
256
+ /// </summary>
257
+ /// <param name="m"></param>
166
258
protected override void WndProc ( ref Message m ) {
167
259
if ( m . Msg == NativeMethods . WM_CLIPBOARDUPDATE ) {
168
260
@@ -179,8 +271,7 @@ protected override void WndProc(ref Message m) {
179
271
_hub . Invoke ( ConfigurationManager . AppSettings [ "send_copied_text_signalr_method_name" ] , copied_content ) ;
180
272
}
181
273
}
182
- }
183
- else if ( iData . GetDataPresent ( DataFormats . Bitmap ) ) {
274
+ } else if ( iData . GetDataPresent ( DataFormats . Bitmap ) ) {
184
275
//Bitmap image = (Bitmap)iData.GetData(DataFormats.Bitmap); // Clipboard image
185
276
//do something with it
186
277
}
@@ -189,6 +280,7 @@ protected override void WndProc(ref Message m) {
189
280
base . WndProc ( ref m ) ;
190
281
}
191
282
283
+
192
284
}
193
285
194
286
internal static class NativeMethods {
0 commit comments