Skip to content

Commit cb549ce

Browse files
committed
Possible fix for app crash (when user copies data)
1 parent 4094246 commit cb549ce

14 files changed

Lines changed: 74 additions & 61 deletions

Source/NETworkManager/NETworkManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@
256256
<DesignTime>True</DesignTime>
257257
<DependentUpon>Strings.resx</DependentUpon>
258258
</Compile>
259+
<Compile Include="Utilities\CommonMethods.cs" />
259260
<Compile Include="Utilities\ArrayHelper.cs" />
260261
<Compile Include="Utilities\AutoRefreshTime.cs" />
261262
<Compile Include="Utilities\AutoRefreshTimeInfo.cs" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Windows;
2+
3+
namespace NETworkManager.Utilities
4+
{
5+
public static class CommonMethods
6+
{
7+
public static void SetClipboard(string text)
8+
{
9+
Clipboard.SetDataObject(text, true);
10+
}
11+
}
12+
}

Source/NETworkManager/ViewModels/ARPTableViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public ICommand CopySelectedIPAddressCommand
323323

324324
private void CopySelectedIPAddressAction()
325325
{
326-
Clipboard.SetText(SelectedARPTableInfo.IPAddress.ToString());
326+
CommonMethods.SetClipboard(SelectedARPTableInfo.IPAddress.ToString());
327327
}
328328

329329
public ICommand CopySelectedMACAddressCommand
@@ -333,7 +333,7 @@ public ICommand CopySelectedMACAddressCommand
333333

334334
private void CopySelectedMACAddressAction()
335335
{
336-
Clipboard.SetText(MACAddressHelper.GetDefaultFormat(SelectedARPTableInfo.MACAddress.ToString()));
336+
CommonMethods.SetClipboard(MACAddressHelper.GetDefaultFormat(SelectedARPTableInfo.MACAddress.ToString()));
337337
}
338338

339339
public ICommand CopySelectedMulticastCommand
@@ -343,7 +343,7 @@ public ICommand CopySelectedMulticastCommand
343343

344344
private void CopySelectedMulticastAction()
345345
{
346-
Clipboard.SetText(SelectedARPTableInfo.IsMulticast ? Resources.Localization.Strings.Yes : Resources.Localization.Strings.No);
346+
CommonMethods.SetClipboard(SelectedARPTableInfo.IsMulticast ? Resources.Localization.Strings.Yes : Resources.Localization.Strings.No);
347347
}
348348
#endregion
349349

Source/NETworkManager/ViewModels/ConnectionsViewModel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public ICommand CopySelectedLocalIpAddressCommand
217217

218218
private void CopySelectedLocalIpAddressAction()
219219
{
220-
Clipboard.SetText(SelectedConnectionInfo.LocalIPAddress.ToString());
220+
CommonMethods.SetClipboard(SelectedConnectionInfo.LocalIPAddress.ToString());
221221
}
222222

223223
public ICommand CopySelectedLocalPortCommand
@@ -227,7 +227,7 @@ public ICommand CopySelectedLocalPortCommand
227227

228228
private void CopySelectedLocalPortAction()
229229
{
230-
Clipboard.SetText(SelectedConnectionInfo.LocalPort.ToString());
230+
CommonMethods.SetClipboard(SelectedConnectionInfo.LocalPort.ToString());
231231
}
232232

233233
public ICommand CopySelectedRemoteIpAddressCommand
@@ -237,7 +237,7 @@ public ICommand CopySelectedRemoteIpAddressCommand
237237

238238
private void CopySelectedRemoteIpAddressAction()
239239
{
240-
Clipboard.SetText(SelectedConnectionInfo.RemoteIPAddress.ToString());
240+
CommonMethods.SetClipboard(SelectedConnectionInfo.RemoteIPAddress.ToString());
241241
}
242242

243243
public ICommand CopySelectedRemotePortCommand
@@ -247,7 +247,7 @@ public ICommand CopySelectedRemotePortCommand
247247

248248
private void CopySelectedRemotePortAction()
249249
{
250-
Clipboard.SetText(SelectedConnectionInfo.RemotePort.ToString());
250+
CommonMethods.SetClipboard(SelectedConnectionInfo.RemotePort.ToString());
251251
}
252252

253253
public ICommand CopySelectedProtocolCommand
@@ -257,7 +257,7 @@ public ICommand CopySelectedProtocolCommand
257257

258258
private void CopySelectedProtocolAction()
259259
{
260-
Clipboard.SetText(SelectedConnectionInfo.Protocol.ToString());
260+
CommonMethods.SetClipboard(SelectedConnectionInfo.Protocol.ToString());
261261
}
262262

263263
public ICommand CopySelectedStateCommand
@@ -267,7 +267,7 @@ public ICommand CopySelectedStateCommand
267267

268268
private void CopySelectedStateAction()
269269
{
270-
Clipboard.SetText(Resources.Localization.Strings.ResourceManager.GetString("TcpState_" + SelectedConnectionInfo.State));
270+
CommonMethods.SetClipboard(Resources.Localization.Strings.ResourceManager.GetString("TcpState_" + SelectedConnectionInfo.State));
271271
}
272272
#endregion
273273

Source/NETworkManager/ViewModels/DNSLookupViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public ICommand CopySelectedNameCommand
278278

279279
private void CopySelectedNameAction()
280280
{
281-
Clipboard.SetText(SelectedLookupResult.Name);
281+
CommonMethods.SetClipboard(SelectedLookupResult.Name);
282282
}
283283

284284
public ICommand CopySelectedTTLCommand
@@ -288,7 +288,7 @@ public ICommand CopySelectedTTLCommand
288288

289289
private void CopySelectedTTLAction()
290290
{
291-
Clipboard.SetText(SelectedLookupResult.TTL.ToString());
291+
CommonMethods.SetClipboard(SelectedLookupResult.TTL.ToString());
292292
}
293293

294294
public ICommand CopySelectedClassCommand
@@ -298,7 +298,7 @@ public ICommand CopySelectedClassCommand
298298

299299
private void CopySelectedClassAction()
300300
{
301-
Clipboard.SetText(SelectedLookupResult.Class);
301+
CommonMethods.SetClipboard(SelectedLookupResult.Class);
302302
}
303303

304304
public ICommand CopySelectedTypeCommand
@@ -308,7 +308,7 @@ public ICommand CopySelectedTypeCommand
308308

309309
private void CopySelectedTypeAction()
310310
{
311-
Clipboard.SetText(SelectedLookupResult.Type);
311+
CommonMethods.SetClipboard(SelectedLookupResult.Type);
312312
}
313313

314314
public ICommand CopySelectedResultCommand
@@ -318,7 +318,7 @@ public ICommand CopySelectedResultCommand
318318

319319
private void CopySelectedResultAction()
320320
{
321-
Clipboard.SetText(SelectedLookupResult.Result);
321+
CommonMethods.SetClipboard(SelectedLookupResult.Result);
322322
}
323323
#endregion
324324

Source/NETworkManager/ViewModels/IPScannerViewModel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public ICommand CopySelectedIPAddressCommand
397397

398398
private void CopySelectedIPAddressAction()
399399
{
400-
Clipboard.SetText(SelectedIPScanResult.PingInfo.IPAddress.ToString());
400+
CommonMethods.SetClipboard(SelectedIPScanResult.PingInfo.IPAddress.ToString());
401401
}
402402

403403
public ICommand CopySelectedHostnameCommand
@@ -407,7 +407,7 @@ public ICommand CopySelectedHostnameCommand
407407

408408
private void CopySelectedHostnameAction()
409409
{
410-
Clipboard.SetText(SelectedIPScanResult.Hostname);
410+
CommonMethods.SetClipboard(SelectedIPScanResult.Hostname);
411411
}
412412

413413
public ICommand CopySelectedMACAddressCommand
@@ -417,7 +417,7 @@ public ICommand CopySelectedMACAddressCommand
417417

418418
private void CopySelectedMACAddressAction()
419419
{
420-
Clipboard.SetText(MACAddressHelper.GetDefaultFormat(SelectedIPScanResult.MACAddress.ToString()));
420+
CommonMethods.SetClipboard(MACAddressHelper.GetDefaultFormat(SelectedIPScanResult.MACAddress.ToString()));
421421
}
422422

423423
public ICommand CopySelectedVendorCommand
@@ -427,7 +427,7 @@ public ICommand CopySelectedVendorCommand
427427

428428
private void CopySelectedVendorAction()
429429
{
430-
Clipboard.SetText(SelectedIPScanResult.Vendor);
430+
CommonMethods.SetClipboard(SelectedIPScanResult.Vendor);
431431
}
432432

433433
public ICommand CopySelectedBytesCommand
@@ -437,7 +437,7 @@ public ICommand CopySelectedBytesCommand
437437

438438
private void CopySelectedBytesAction()
439439
{
440-
Clipboard.SetText(SelectedIPScanResult.PingInfo.Bytes.ToString());
440+
CommonMethods.SetClipboard(SelectedIPScanResult.PingInfo.Bytes.ToString());
441441
}
442442

443443
public ICommand CopySelectedTimeCommand
@@ -447,7 +447,7 @@ public ICommand CopySelectedTimeCommand
447447

448448
private void CopySelectedTimeAction()
449449
{
450-
Clipboard.SetText(SelectedIPScanResult.PingInfo.Time.ToString());
450+
CommonMethods.SetClipboard(SelectedIPScanResult.PingInfo.Time.ToString());
451451
}
452452

453453
public ICommand CopySelectedTTLCommand
@@ -457,7 +457,7 @@ public ICommand CopySelectedTTLCommand
457457

458458
private void CopySelectedTTLAction()
459459
{
460-
Clipboard.SetText(SelectedIPScanResult.PingInfo.TTL.ToString());
460+
CommonMethods.SetClipboard(SelectedIPScanResult.PingInfo.TTL.ToString());
461461
}
462462

463463
public ICommand CopySelectedStatusCommand
@@ -467,7 +467,7 @@ public ICommand CopySelectedStatusCommand
467467

468468
private void CopySelectedStatusAction()
469469
{
470-
Clipboard.SetText(Resources.Localization.Strings.ResourceManager.GetString("IPStatus_" + SelectedIPScanResult.PingInfo.Status));
470+
CommonMethods.SetClipboard(Resources.Localization.Strings.ResourceManager.GetString("IPStatus_" + SelectedIPScanResult.PingInfo.Status));
471471
}
472472
#endregion
473473

Source/NETworkManager/ViewModels/ListenersViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public ICommand CopySelectedProtocolCommand
222222

223223
private void CopySelectedProtocolAction()
224224
{
225-
Clipboard.SetText(SelectedListenerInfo.Protocol.ToString());
225+
CommonMethods.SetClipboard(SelectedListenerInfo.Protocol.ToString());
226226
}
227227

228228
public ICommand CopySelectedIPAddressCommand
@@ -232,7 +232,7 @@ public ICommand CopySelectedIPAddressCommand
232232

233233
private void CopySelectedIPAddressAction()
234234
{
235-
Clipboard.SetText(SelectedListenerInfo.IPAddress.ToString());
235+
CommonMethods.SetClipboard(SelectedListenerInfo.IPAddress.ToString());
236236
}
237237

238238
public ICommand CopySelectedPortCommand
@@ -242,7 +242,7 @@ public ICommand CopySelectedPortCommand
242242

243243
private void CopySelectedPortAction()
244244
{
245-
Clipboard.SetText(SelectedListenerInfo.Port.ToString());
245+
CommonMethods.SetClipboard(SelectedListenerInfo.Port.ToString());
246246
}
247247
#endregion
248248

Source/NETworkManager/ViewModels/LookupOUILookupViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public ICommand CopySelectedMACAddressCommand
173173

174174
private void CopySelectedMACAddressAction()
175175
{
176-
Clipboard.SetText(SelectedOUILookup.MACAddress);
176+
CommonMethods.SetClipboard(SelectedOUILookup.MACAddress);
177177
}
178178

179179
public ICommand CopySelectedVendorCommand
@@ -183,7 +183,7 @@ public ICommand CopySelectedVendorCommand
183183

184184
private void CopySelectedVendorAction()
185185
{
186-
Clipboard.SetText(SelectedOUILookup.Vendor);
186+
CommonMethods.SetClipboard(SelectedOUILookup.Vendor);
187187
}
188188
#endregion
189189

Source/NETworkManager/ViewModels/LookupPortViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public ICommand CopySelectedPortCommand
207207

208208
private void CopySelectedPortAction()
209209
{
210-
Clipboard.SetText(SelectedPortLookupResult.Number.ToString());
210+
CommonMethods.SetClipboard(SelectedPortLookupResult.Number.ToString());
211211
}
212212

213213
public ICommand CopySelectedProtocolCommand
@@ -217,7 +217,7 @@ public ICommand CopySelectedProtocolCommand
217217

218218
private void CopySelectedProtocolAction()
219219
{
220-
Clipboard.SetText(SelectedPortLookupResult.Protocol.ToString());
220+
CommonMethods.SetClipboard(SelectedPortLookupResult.Protocol.ToString());
221221
}
222222

223223
public ICommand CopySelectedServiceCommand
@@ -227,7 +227,7 @@ public ICommand CopySelectedServiceCommand
227227

228228
private void CopySelectedServiceAction()
229229
{
230-
Clipboard.SetText(SelectedPortLookupResult.Service);
230+
CommonMethods.SetClipboard(SelectedPortLookupResult.Service);
231231
}
232232

233233
public ICommand CopySelectedDescriptionCommand
@@ -237,7 +237,7 @@ public ICommand CopySelectedDescriptionCommand
237237

238238
private void CopySelectedDescriptionAction()
239239
{
240-
Clipboard.SetText(SelectedPortLookupResult.Description);
240+
CommonMethods.SetClipboard(SelectedPortLookupResult.Description);
241241
}
242242
#endregion
243243

Source/NETworkManager/ViewModels/PingViewModel.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public ICommand CopySelectedTimestampCommand
340340

341341
private void CopySelectedTimestampAction()
342342
{
343-
Clipboard.SetText(SelectedPingResult.Timestamp.ToString(CultureInfo.CurrentCulture));
343+
CommonMethods.SetClipboard(SelectedPingResult.Timestamp.ToString(CultureInfo.CurrentCulture));
344344
}
345345

346346
public ICommand CopySelectedIPAddressCommand
@@ -350,7 +350,7 @@ public ICommand CopySelectedIPAddressCommand
350350

351351
private void CopySelectedIPAddressAction()
352352
{
353-
Clipboard.SetText(SelectedPingResult.IPAddress.ToString());
353+
CommonMethods.SetClipboard(SelectedPingResult.IPAddress.ToString());
354354
}
355355

356356
public ICommand CopySelectedHostnameCommand
@@ -360,7 +360,7 @@ public ICommand CopySelectedHostnameCommand
360360

361361
private void CopySelectedHostnameAction()
362362
{
363-
Clipboard.SetText(SelectedPingResult.Hostname);
363+
CommonMethods.SetClipboard(SelectedPingResult.Hostname);
364364
}
365365

366366
public ICommand CopySelectedBytesCommand
@@ -370,7 +370,7 @@ public ICommand CopySelectedBytesCommand
370370

371371
private void CopySelectedBytesAction()
372372
{
373-
Clipboard.SetText(SelectedPingResult.Bytes.ToString());
373+
CommonMethods.SetClipboard(SelectedPingResult.Bytes.ToString());
374374
}
375375

376376
public ICommand CopySelectedTimeCommand
@@ -380,7 +380,7 @@ public ICommand CopySelectedTimeCommand
380380

381381
private void CopySelectedTimeAction()
382382
{
383-
Clipboard.SetText(SelectedPingResult.Time.ToString());
383+
CommonMethods.SetClipboard(SelectedPingResult.Time.ToString());
384384
}
385385

386386
public ICommand CopySelectedTTLCommand
@@ -390,7 +390,7 @@ public ICommand CopySelectedTTLCommand
390390

391391
private void CopySelectedTTLAction()
392392
{
393-
Clipboard.SetText(SelectedPingResult.TTL.ToString());
393+
CommonMethods.SetClipboard(SelectedPingResult.TTL.ToString());
394394
}
395395

396396
public ICommand CopySelectedStatusCommand
@@ -400,7 +400,7 @@ public ICommand CopySelectedStatusCommand
400400

401401
private void CopySelectedStatusAction()
402402
{
403-
Clipboard.SetText(Resources.Localization.Strings.ResourceManager.GetString("IPStatus_" + SelectedPingResult.Status));
403+
CommonMethods.SetClipboard(Resources.Localization.Strings.ResourceManager.GetString("IPStatus_" + SelectedPingResult.Status));
404404
}
405405
#endregion
406406

0 commit comments

Comments
 (0)