Сделали пингование компов в поиске
This commit is contained in:
parent
ca9409a95e
commit
d955110a7d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -101,6 +101,7 @@
|
|||
this.Controls.Add(this.CompNameLB);
|
||||
this.Name = "Finder";
|
||||
this.Text = "Новое подключение";
|
||||
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Finder_FormClosed);
|
||||
this.SeaherPanel.ResumeLayout(false);
|
||||
this.SeaherPanel.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Remontor.Connector;
|
||||
using Remontor.Pinger;
|
||||
using Remontor.Seacher;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -43,16 +44,18 @@ namespace Remontor.Finder
|
|||
{
|
||||
PreSelected = -1;
|
||||
SelectedItem = null;
|
||||
SeaherPanel.SuspendLayout();
|
||||
SeaherPanel.Controls.Clear();
|
||||
int countItem = 0;
|
||||
|
||||
foreach (ISeacherResult item in Items)
|
||||
{
|
||||
SessionItemControl itemControl = new SessionItemControl(item, UpdateActiv, countItem++);
|
||||
SeaherPanel.Controls.Add(itemControl);
|
||||
|
||||
}
|
||||
|
||||
|
||||
SeaherPanel.ResumeLayout();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -123,5 +126,10 @@ namespace Remontor.Finder
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private void Finder_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
PingManager.StopPing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,111 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Remontor.Pinger
|
||||
{
|
||||
internal static class PingManager
|
||||
{
|
||||
static Dictionary<string, PingResult> ResultPing = new Dictionary<string, PingResult>();
|
||||
static List<PingTask> TaskList = new List<PingTask>();
|
||||
static int LifeTimePing = 20;
|
||||
static Thread PingerHost = new Thread(PingHost);
|
||||
|
||||
static public void NewTaskPing(Panel panel, IComp comp)
|
||||
{
|
||||
|
||||
if (ResultPing.ContainsKey(comp.GetNetName()))
|
||||
{
|
||||
if ((DateTime.Now - ResultPing[comp.GetNetName()].timePing).Seconds > LifeTimePing)
|
||||
{
|
||||
// panel.Visible = true;
|
||||
// panel.BackColor = Color.Gold;
|
||||
ResultPing.Remove(comp.GetNetName());
|
||||
PingTask pingTask = new PingTask(panel, comp);
|
||||
TaskList.Add(pingTask);
|
||||
}
|
||||
else
|
||||
{
|
||||
//panel.Visible = true;
|
||||
if (ResultPing[comp.GetNetName()].Succes)
|
||||
{
|
||||
panel.BackColor = Color.Lime;
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.BackColor = Color.OrangeRed;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//panel.Visible = true;
|
||||
// panel.BackColor = Color.Gold;
|
||||
PingTask pingTask = new PingTask(panel, comp);
|
||||
TaskList.Add(pingTask);
|
||||
//if(PingerHost.ThreadState == ThreadState.Unstarted)
|
||||
//{
|
||||
// PingerHost.Start();
|
||||
//}else if(PingerHost.ThreadState == ThreadState.Stopped)
|
||||
//{
|
||||
// PingerHost = new Thread(PingHost);
|
||||
// PingerHost.Start();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static public void PingHost()
|
||||
{
|
||||
// while ()
|
||||
// {
|
||||
Thread.Sleep(300);
|
||||
PingTask[] TaskListBuff = new PingTask[TaskList.Count];
|
||||
TaskList.CopyTo(TaskListBuff);
|
||||
TaskList.Clear();
|
||||
System.Console.WriteLine(TaskListBuff.Length.ToString());
|
||||
foreach (PingTask Task in TaskListBuff)
|
||||
{
|
||||
// Task.PingHost();
|
||||
}
|
||||
if (TaskList.Count > 0) PingHost();
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
static public void StopPing()
|
||||
{
|
||||
// PingerHost.Join();
|
||||
|
||||
}
|
||||
|
||||
static public void WriteResult(PingResult pingResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResultPing.Add(pingResult.NameOrAddress, pingResult);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Remontor.Pinger
|
||||
{
|
||||
internal class PingResult
|
||||
{
|
||||
public long Ping { get; set; }
|
||||
public int TimeoutPing { get; set; }
|
||||
public IPAddress Ip;
|
||||
public DateTime timePing;
|
||||
public bool TimedOut;
|
||||
public bool Succes;
|
||||
public string NameOrAddress;
|
||||
public PingResult(long ping, int timeoutPing, IPAddress ip, bool timedOut, bool succes, string NameOrAddress)
|
||||
{
|
||||
Ping = ping;
|
||||
TimeoutPing = timeoutPing;
|
||||
Ip = ip;
|
||||
TimedOut = timedOut;
|
||||
Succes = succes;
|
||||
timePing = DateTime.Now;
|
||||
this.NameOrAddress = NameOrAddress;
|
||||
}
|
||||
public PingResult(long ping, int timeoutPing, IPAddress ip, bool timedOut)
|
||||
{
|
||||
Ping = ping;
|
||||
TimeoutPing = timeoutPing;
|
||||
Ip = ip;
|
||||
TimedOut = timedOut;
|
||||
Succes = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Remontor.Pinger
|
||||
{
|
||||
internal class PingTask
|
||||
{
|
||||
private string NameOrAddress;
|
||||
private int TimeoutCount;
|
||||
private IPAddress Ip;
|
||||
private IComp Comp;
|
||||
private Panel panel;
|
||||
private Ping pinger;
|
||||
|
||||
public PingTask(Panel panel, IComp comp)
|
||||
{
|
||||
this.panel = panel;
|
||||
this.Comp = comp;
|
||||
this.NameOrAddress = comp.GetNetName();
|
||||
pinger = new Ping();
|
||||
pinger.PingCompleted += Pinger_PingCompleted;
|
||||
try
|
||||
{
|
||||
pinger.SendPingAsync(NameOrAddress,3);
|
||||
}
|
||||
catch
|
||||
{
|
||||
pinger.SendAsyncCancel();
|
||||
if (panel != null) panel.BackColor = Color.OrangeRed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Pinger_PingCompleted(object sender, PingCompletedEventArgs e)
|
||||
{
|
||||
if (e.Reply == null)
|
||||
{
|
||||
if (panel != null) panel.BackColor = Color.OrangeRed;
|
||||
return;
|
||||
}
|
||||
bool pingable;
|
||||
bool succes;
|
||||
long ping;
|
||||
pingable = e.Reply.Status == IPStatus.TimedOut;
|
||||
succes = e.Reply.Status == IPStatus.Success;
|
||||
ping = e.Reply.RoundtripTime;
|
||||
Ip = e.Reply.Address;
|
||||
if (!succes)
|
||||
{
|
||||
|
||||
if (panel != null) panel.BackColor = Color.OrangeRed;
|
||||
TimeoutCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (panel != null) panel.BackColor = Color.Lime;
|
||||
Comp.SetIP(Ip);
|
||||
}
|
||||
PingResult pingResult = new PingResult(ping, TimeoutCount, Ip, pingable, succes, NameOrAddress);
|
||||
PingManager.WriteResult(pingResult);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public PingTask(string nameOrAddress)
|
||||
{
|
||||
this.NameOrAddress = nameOrAddress;
|
||||
}
|
||||
public int Timeout()
|
||||
{
|
||||
return TimeoutCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// public PingResult PingHost()
|
||||
//{
|
||||
// bool pingable = false;
|
||||
// bool succes = false;
|
||||
// long ping = 0;
|
||||
|
||||
|
||||
// try
|
||||
// {
|
||||
// pinger = new Ping();
|
||||
// PingReply reply = pinger.Send(this.NameOrAddress);
|
||||
// pingable = reply.Status == IPStatus.TimedOut;
|
||||
// succes = reply.Status == IPStatus.Success;
|
||||
// ping = reply.RoundtripTime;
|
||||
// Ip = reply.Address;
|
||||
// }
|
||||
// catch (PingException)
|
||||
// {
|
||||
// // Discard PingExceptions and return false;
|
||||
// }
|
||||
|
||||
// finally
|
||||
// {
|
||||
// if (pinger != null)
|
||||
// {
|
||||
// pinger.Dispose();
|
||||
// }
|
||||
// }
|
||||
// if (!succes)
|
||||
// {
|
||||
|
||||
// if (panel != null) panel.BackColor = Color.OrangeRed;
|
||||
// TimeoutCount++;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (panel != null) panel.BackColor = Color.Lime;
|
||||
// Comp.SetIP(Ip);
|
||||
// }
|
||||
// PingResult pingResult = new PingResult(ping, TimeoutCount, Ip, pingable, succes, NameOrAddress);
|
||||
// PingManager.WriteResult(pingResult);
|
||||
// return pingResult;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -107,6 +107,9 @@
|
|||
<Compile Include="History\HistoryItem.cs" />
|
||||
<Compile Include="History\HistoryList.cs" />
|
||||
<Compile Include="History\SHistory.cs" />
|
||||
<Compile Include="Pinger\PingManager.cs" />
|
||||
<Compile Include="Pinger\PingResult.cs" />
|
||||
<Compile Include="Pinger\PingTask.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SCCMsearch\AuthLogin.cs" />
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@
|
|||
this.Margin = new System.Windows.Forms.Padding(1);
|
||||
this.Name = "SessionItemControl";
|
||||
this.Size = new System.Drawing.Size(353, 55);
|
||||
this.Load += new System.EventHandler(this.SessionItemControl_Load);
|
||||
this.Click += new System.EventHandler(this.SessionItemControl_Click);
|
||||
((System.ComponentModel.ISupportInitialize)(this.PbPerson)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Remontor.Seacher;
|
||||
using Remontor.Pinger;
|
||||
using Remontor.Seacher;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
|
@ -51,7 +52,7 @@ namespace Remontor
|
|||
LbData.Text = "last connect:" + result.GetLastConnect();
|
||||
Select += UpdateAct;
|
||||
Index = index;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -101,5 +102,15 @@ namespace Remontor
|
|||
|
||||
|
||||
}
|
||||
|
||||
private void SessionItemControl_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (seacherResult is HistoryResult)
|
||||
{
|
||||
HistoryResult result = (HistoryResult)seacherResult;
|
||||
PingManager.NewTaskPing(PPingStat, result.GetComp());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
15aad57089c73c036769b7df150a74520e07d0a0
|
||||
8715987b8e28705d0f46bc923af3b41a4afd1d49
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue