From 10f0cc0bb1fac91227549bd35c4870a892a8167d Mon Sep 17 00:00:00 2001 From: Dunestorm Date: Thu, 14 Nov 2019 17:22:07 +0000 Subject: [PATCH] Started implementation of IPAddressConverter logic --- TimedShutdown/PingWidget.cs | 23 +++++++++++++++---- .../ViewModels/ShellRootViewModel.cs | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/TimedShutdown/PingWidget.cs b/TimedShutdown/PingWidget.cs index 506e020..fd59aca 100644 --- a/TimedShutdown/PingWidget.cs +++ b/TimedShutdown/PingWidget.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.Diagnostics; using System.Net; using System.Net.NetworkInformation; @@ -8,14 +9,14 @@ namespace TimedShutdown { public class PingWidget { - IPAddress _ipAddress = IPAddress.None; + private string RemoteAddress { get; set; } public bool WidgetHasInitialized { get; private set; } = false; BackgroundWorker contPingBackgroundWorker = new BackgroundWorker(); - public void InitatePingRequest(IPAddress ipAddress) + public void InitatePingRequest(string _remoteAddress) { - _ipAddress = ipAddress; + RemoteAddress = _remoteAddress; contPingBackgroundWorker.WorkerSupportsCancellation = true; contPingBackgroundWorker.DoWork += ContPingBackgroundWorkerDoWork; @@ -46,7 +47,7 @@ namespace TimedShutdown while (contPingBackgroundWorker.CancellationPending == false) { Ping pingSender = new Ping(); - IPAddress address = _ipAddress; + IPAddress address = IPAddressConverter(RemoteAddress); PingReply reply = pingSender.Send(address); if (reply.Status == IPStatus.Success) @@ -61,5 +62,17 @@ namespace TimedShutdown Thread.Sleep(3000); } } + + private IPAddress IPAddressConverter (string remoteAddress) + { + IPAddress ip; + if (IPAddress.TryParse(remoteAddress, out ip)) + return ip; + else + { + IPHostEntry iphost = Dns.GetHostEntry(remoteAddress); + throw new NotImplementedException(); + } + } } } diff --git a/TimedShutdown/ViewModels/ShellRootViewModel.cs b/TimedShutdown/ViewModels/ShellRootViewModel.cs index d1777f2..e70e4cf 100644 --- a/TimedShutdown/ViewModels/ShellRootViewModel.cs +++ b/TimedShutdown/ViewModels/ShellRootViewModel.cs @@ -85,7 +85,7 @@ namespace TimedShutdown.ViewModels if (value == true) { - pingWidget.InitatePingRequest(IPAddress.Parse(IPRemoteShutdown)); + pingWidget.InitatePingRequest(IPRemoteShutdown); } else {