pinger
This commit is contained in:
parent
f4c5232547
commit
0fc356df19
|
|
@ -4,9 +4,48 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace Reseter2
|
||||
{
|
||||
internal class Pinger
|
||||
internal class Pinger
|
||||
{
|
||||
private string NameOrAddress;
|
||||
private int TimeoutCount;
|
||||
|
||||
public Pinger(string nameOrAddress)
|
||||
{
|
||||
this.NameOrAddress = nameOrAddress;
|
||||
}
|
||||
public int Timeout() {
|
||||
return TimeoutCount;
|
||||
}
|
||||
public long PingHost()
|
||||
{
|
||||
bool pingable = false;
|
||||
long ping = 0;
|
||||
Ping pinger = null;
|
||||
try
|
||||
{
|
||||
pinger = new Ping();
|
||||
PingReply reply = pinger.Send(this.NameOrAddress);
|
||||
pingable = reply.Status == IPStatus.TimedOut;
|
||||
ping = reply.RoundtripTime;
|
||||
}
|
||||
catch (PingException)
|
||||
{
|
||||
// Discard PingExceptions and return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (pinger != null)
|
||||
{
|
||||
pinger.Dispose();
|
||||
}
|
||||
}
|
||||
if (pingable) TimeoutCount++;
|
||||
return ping;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,14 @@ namespace Reseter2
|
|||
private IComp Comp;
|
||||
private AStatusTask StatusTask;
|
||||
private TaskControl taskControl;
|
||||
private Pinger Pingers;
|
||||
|
||||
public ReseterTask(IComp comp, TaskControl taskCntrl)
|
||||
{
|
||||
Comp = comp;
|
||||
taskControl = taskCntrl;
|
||||
StatusTask = new StatusPreReboot(this);
|
||||
Pingers = new Pinger(Comp.GetName());
|
||||
}
|
||||
public string GetName()
|
||||
{
|
||||
|
|
@ -28,9 +30,18 @@ namespace Reseter2
|
|||
StatusTask.Tick();
|
||||
}
|
||||
|
||||
public void DataContrl(string srt)
|
||||
public long Ping()
|
||||
{
|
||||
taskControl.DataContrl(srt);
|
||||
return Pingers.PingHost();
|
||||
}
|
||||
|
||||
public int Timeout() {
|
||||
return Pingers.Timeout();
|
||||
}
|
||||
|
||||
public void DataContrl(string ping, string timeout)
|
||||
{
|
||||
taskControl.DataContrl(ping, timeout);
|
||||
}
|
||||
private void Clear()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ namespace Reseter2
|
|||
public override void Tick()
|
||||
{
|
||||
time++;
|
||||
resetertask.DataContrl(time.ToString());
|
||||
|
||||
resetertask.DataContrl(resetertask.Ping().ToString(), resetertask.Timeout().ToString());
|
||||
}
|
||||
public override void Next()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.lb_ping = new System.Windows.Forms.Label();
|
||||
this.Timeout = new System.Windows.Forms.Label();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.lb_timeout = new System.Windows.Forms.Label();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
|
|
@ -116,14 +116,13 @@
|
|||
this.Timeout.TabIndex = 7;
|
||||
this.Timeout.Text = "Timeout";
|
||||
//
|
||||
// label5
|
||||
// lb_timeout
|
||||
//
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(225, 49);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(25, 13);
|
||||
this.label5.TabIndex = 8;
|
||||
this.label5.Text = "123";
|
||||
this.lb_timeout.AutoSize = true;
|
||||
this.lb_timeout.Location = new System.Drawing.Point(225, 49);
|
||||
this.lb_timeout.Name = "lb_timeout";
|
||||
this.lb_timeout.Size = new System.Drawing.Size(0, 13);
|
||||
this.lb_timeout.TabIndex = 8;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
|
|
@ -160,7 +159,7 @@
|
|||
this.Controls.Add(this.pictureBox1);
|
||||
this.Controls.Add(this.button2);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.label5);
|
||||
this.Controls.Add(this.lb_timeout);
|
||||
this.Controls.Add(this.Timeout);
|
||||
this.Controls.Add(this.lb_ping);
|
||||
this.Controls.Add(this.label4);
|
||||
|
|
@ -187,7 +186,7 @@
|
|||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.Label lb_ping;
|
||||
private System.Windows.Forms.Label Timeout;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label lb_timeout;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.PictureBox pictureBox1;
|
||||
|
|
|
|||
|
|
@ -26,9 +26,10 @@ namespace Reseter2
|
|||
lb_name.Text = reseterTask.GetName();
|
||||
}
|
||||
|
||||
public void DataContrl(string ping)
|
||||
public void DataContrl(string ping, string timeout)
|
||||
{
|
||||
label5.Text = ping;
|
||||
lb_ping.Text = ping;
|
||||
lb_timeout.Text = timeout;
|
||||
|
||||
}
|
||||
private void label1_Click(object sender, EventArgs e)
|
||||
|
|
|
|||
Loading…
Reference in New Issue