Started implementation of IPAddressConverter logic
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
@@ -8,14 +9,14 @@ namespace TimedShutdown
|
|||||||
{
|
{
|
||||||
public class PingWidget
|
public class PingWidget
|
||||||
{
|
{
|
||||||
IPAddress _ipAddress = IPAddress.None;
|
private string RemoteAddress { get; set; }
|
||||||
public bool WidgetHasInitialized { get; private set; } = false;
|
public bool WidgetHasInitialized { get; private set; } = false;
|
||||||
|
|
||||||
BackgroundWorker contPingBackgroundWorker = new BackgroundWorker();
|
BackgroundWorker contPingBackgroundWorker = new BackgroundWorker();
|
||||||
|
|
||||||
public void InitatePingRequest(IPAddress ipAddress)
|
public void InitatePingRequest(string _remoteAddress)
|
||||||
{
|
{
|
||||||
_ipAddress = ipAddress;
|
RemoteAddress = _remoteAddress;
|
||||||
|
|
||||||
contPingBackgroundWorker.WorkerSupportsCancellation = true;
|
contPingBackgroundWorker.WorkerSupportsCancellation = true;
|
||||||
contPingBackgroundWorker.DoWork += ContPingBackgroundWorkerDoWork;
|
contPingBackgroundWorker.DoWork += ContPingBackgroundWorkerDoWork;
|
||||||
@@ -46,7 +47,7 @@ namespace TimedShutdown
|
|||||||
while (contPingBackgroundWorker.CancellationPending == false)
|
while (contPingBackgroundWorker.CancellationPending == false)
|
||||||
{
|
{
|
||||||
Ping pingSender = new Ping();
|
Ping pingSender = new Ping();
|
||||||
IPAddress address = _ipAddress;
|
IPAddress address = IPAddressConverter(RemoteAddress);
|
||||||
PingReply reply = pingSender.Send(address);
|
PingReply reply = pingSender.Send(address);
|
||||||
|
|
||||||
if (reply.Status == IPStatus.Success)
|
if (reply.Status == IPStatus.Success)
|
||||||
@@ -61,5 +62,17 @@ namespace TimedShutdown
|
|||||||
Thread.Sleep(3000);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace TimedShutdown.ViewModels
|
|||||||
if (value == true)
|
if (value == true)
|
||||||
{
|
{
|
||||||
|
|
||||||
pingWidget.InitatePingRequest(IPAddress.Parse(IPRemoteShutdown));
|
pingWidget.InitatePingRequest(IPRemoteShutdown);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user