diff --git a/Remontor/.vs/Remontor/FileContentIndex/04c71609-7605-4221-a27b-6699449e439d.vsidx b/Remontor/.vs/Remontor/FileContentIndex/04c71609-7605-4221-a27b-6699449e439d.vsidx deleted file mode 100644 index 5e78cf6..0000000 Binary files a/Remontor/.vs/Remontor/FileContentIndex/04c71609-7605-4221-a27b-6699449e439d.vsidx and /dev/null differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/0e2d1faa-13b7-44a3-8033-23709c1069aa.vsidx b/Remontor/.vs/Remontor/FileContentIndex/0e2d1faa-13b7-44a3-8033-23709c1069aa.vsidx new file mode 100644 index 0000000..08bf054 Binary files /dev/null and b/Remontor/.vs/Remontor/FileContentIndex/0e2d1faa-13b7-44a3-8033-23709c1069aa.vsidx differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/185f8a93-aeb7-4493-ab9e-2e84fac17a15.vsidx b/Remontor/.vs/Remontor/FileContentIndex/185f8a93-aeb7-4493-ab9e-2e84fac17a15.vsidx new file mode 100644 index 0000000..fdbc1fc Binary files /dev/null and b/Remontor/.vs/Remontor/FileContentIndex/185f8a93-aeb7-4493-ab9e-2e84fac17a15.vsidx differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/18f2b697-7b7f-460f-b5bc-b32d44e6b46b.vsidx b/Remontor/.vs/Remontor/FileContentIndex/18f2b697-7b7f-460f-b5bc-b32d44e6b46b.vsidx deleted file mode 100644 index 5ec400c..0000000 Binary files a/Remontor/.vs/Remontor/FileContentIndex/18f2b697-7b7f-460f-b5bc-b32d44e6b46b.vsidx and /dev/null differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/342db1f9-b822-47c6-8906-4f32734ad2e2.vsidx b/Remontor/.vs/Remontor/FileContentIndex/342db1f9-b822-47c6-8906-4f32734ad2e2.vsidx new file mode 100644 index 0000000..a8d74a1 Binary files /dev/null and b/Remontor/.vs/Remontor/FileContentIndex/342db1f9-b822-47c6-8906-4f32734ad2e2.vsidx differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/4a6b48c5-aa51-494a-8803-f41aa2388634.vsidx b/Remontor/.vs/Remontor/FileContentIndex/4a6b48c5-aa51-494a-8803-f41aa2388634.vsidx deleted file mode 100644 index 21eab0f..0000000 Binary files a/Remontor/.vs/Remontor/FileContentIndex/4a6b48c5-aa51-494a-8803-f41aa2388634.vsidx and /dev/null differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/572420f5-f22c-4bfe-95bf-67bbb0912573.vsidx b/Remontor/.vs/Remontor/FileContentIndex/572420f5-f22c-4bfe-95bf-67bbb0912573.vsidx deleted file mode 100644 index f89285f..0000000 Binary files a/Remontor/.vs/Remontor/FileContentIndex/572420f5-f22c-4bfe-95bf-67bbb0912573.vsidx and /dev/null differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/83c16984-46f9-4650-894d-557be5ae12e9.vsidx b/Remontor/.vs/Remontor/FileContentIndex/83c16984-46f9-4650-894d-557be5ae12e9.vsidx deleted file mode 100644 index 3662aa8..0000000 Binary files a/Remontor/.vs/Remontor/FileContentIndex/83c16984-46f9-4650-894d-557be5ae12e9.vsidx and /dev/null differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/84e6eb22-43c3-4722-9b8d-e0b844fd8bad.vsidx b/Remontor/.vs/Remontor/FileContentIndex/84e6eb22-43c3-4722-9b8d-e0b844fd8bad.vsidx deleted file mode 100644 index d03cef3..0000000 Binary files a/Remontor/.vs/Remontor/FileContentIndex/84e6eb22-43c3-4722-9b8d-e0b844fd8bad.vsidx and /dev/null differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/857cf4a3-e158-4597-bf0f-9907b129dd68.vsidx b/Remontor/.vs/Remontor/FileContentIndex/857cf4a3-e158-4597-bf0f-9907b129dd68.vsidx deleted file mode 100644 index 446f21e..0000000 Binary files a/Remontor/.vs/Remontor/FileContentIndex/857cf4a3-e158-4597-bf0f-9907b129dd68.vsidx and /dev/null differ diff --git a/Remontor/.vs/Remontor/FileContentIndex/d9d059a6-7f60-48eb-8bdb-c696a14ce270.vsidx b/Remontor/.vs/Remontor/FileContentIndex/d9d059a6-7f60-48eb-8bdb-c696a14ce270.vsidx deleted file mode 100644 index 84a7d7b..0000000 Binary files a/Remontor/.vs/Remontor/FileContentIndex/d9d059a6-7f60-48eb-8bdb-c696a14ce270.vsidx and /dev/null differ diff --git a/Remontor/.vs/Remontor/v17/.suo b/Remontor/.vs/Remontor/v17/.suo index fb42d47..7e44509 100644 Binary files a/Remontor/.vs/Remontor/v17/.suo and b/Remontor/.vs/Remontor/v17/.suo differ diff --git a/Remontor/Finder/Finder.Designer.cs b/Remontor/Finder/Finder.Designer.cs index a9cf184..783d32b 100644 --- a/Remontor/Finder/Finder.Designer.cs +++ b/Remontor/Finder/Finder.Designer.cs @@ -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); diff --git a/Remontor/Finder/Finder.cs b/Remontor/Finder/Finder.cs index ad17ee9..68a8498 100644 --- a/Remontor/Finder/Finder.cs +++ b/Remontor/Finder/Finder.cs @@ -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(); + } } } diff --git a/Remontor/Pinger/PingManager.cs b/Remontor/Pinger/PingManager.cs new file mode 100644 index 0000000..56655a0 --- /dev/null +++ b/Remontor/Pinger/PingManager.cs @@ -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 ResultPing = new Dictionary(); + static List TaskList = new List(); + 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 + { + + } + + } + + + + + } +} diff --git a/Remontor/Pinger/PingResult.cs b/Remontor/Pinger/PingResult.cs new file mode 100644 index 0000000..3ef122b --- /dev/null +++ b/Remontor/Pinger/PingResult.cs @@ -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; + } + } +} diff --git a/Remontor/Pinger/PingTask.cs b/Remontor/Pinger/PingTask.cs new file mode 100644 index 0000000..10833f3 --- /dev/null +++ b/Remontor/Pinger/PingTask.cs @@ -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; + //} + + } +} diff --git a/Remontor/Remontor.csproj b/Remontor/Remontor.csproj index e1f185e..b6c1986 100644 --- a/Remontor/Remontor.csproj +++ b/Remontor/Remontor.csproj @@ -107,6 +107,9 @@ + + + diff --git a/Remontor/SessionItemControl.Designer.cs b/Remontor/SessionItemControl.Designer.cs index ec4f12e..99ba393 100644 --- a/Remontor/SessionItemControl.Designer.cs +++ b/Remontor/SessionItemControl.Designer.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); diff --git a/Remontor/SessionItemControl.cs b/Remontor/SessionItemControl.cs index 0572841..aa627fa 100644 --- a/Remontor/SessionItemControl.cs +++ b/Remontor/SessionItemControl.cs @@ -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()); + } + + } } } diff --git a/Remontor/bin/Debug/Remontor.exe b/Remontor/bin/Debug/Remontor.exe index cc4cb20..8868c1e 100644 Binary files a/Remontor/bin/Debug/Remontor.exe and b/Remontor/bin/Debug/Remontor.exe differ diff --git a/Remontor/bin/Debug/Remontor.pdb b/Remontor/bin/Debug/Remontor.pdb index 011c88b..31d92be 100644 Binary files a/Remontor/bin/Debug/Remontor.pdb and b/Remontor/bin/Debug/Remontor.pdb differ diff --git a/Remontor/bin/Debug/res.dat b/Remontor/bin/Debug/res.dat index 9282053..7c84156 100644 Binary files a/Remontor/bin/Debug/res.dat and b/Remontor/bin/Debug/res.dat differ diff --git a/Remontor/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/Remontor/obj/Debug/DesignTimeResolveAssemblyReferences.cache index 0a18852..525f8ad 100644 Binary files a/Remontor/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/Remontor/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Remontor/obj/Debug/Remontor.csproj.CoreCompileInputs.cache b/Remontor/obj/Debug/Remontor.csproj.CoreCompileInputs.cache index 21b9c0a..558cb61 100644 --- a/Remontor/obj/Debug/Remontor.csproj.CoreCompileInputs.cache +++ b/Remontor/obj/Debug/Remontor.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -15aad57089c73c036769b7df150a74520e07d0a0 +8715987b8e28705d0f46bc923af3b41a4afd1d49 diff --git a/Remontor/obj/Debug/Remontor.csproj.GenerateResource.cache b/Remontor/obj/Debug/Remontor.csproj.GenerateResource.cache index 6e6417f..1c68251 100644 Binary files a/Remontor/obj/Debug/Remontor.csproj.GenerateResource.cache and b/Remontor/obj/Debug/Remontor.csproj.GenerateResource.cache differ diff --git a/Remontor/obj/Debug/Remontor.exe b/Remontor/obj/Debug/Remontor.exe index cc4cb20..8868c1e 100644 Binary files a/Remontor/obj/Debug/Remontor.exe and b/Remontor/obj/Debug/Remontor.exe differ diff --git a/Remontor/obj/Debug/Remontor.pdb b/Remontor/obj/Debug/Remontor.pdb index 011c88b..31d92be 100644 Binary files a/Remontor/obj/Debug/Remontor.pdb and b/Remontor/obj/Debug/Remontor.pdb differ