From b882ddac6adfea9f966d3cb0721084847fea5a74 Mon Sep 17 00:00:00 2001 From: "Wainaina George (Swagfin)" Date: Fri, 10 Mar 2023 00:22:48 +0300 Subject: [PATCH] chore: added refresh ping statuses --- PortProxyGUI/Data/Rule.cs | 2 +- PortProxyGUI/PortProxyGUI.Designer.cs | 16 +++---- PortProxyGUI/PortProxyGUI.cs | 57 ++++++++++++++----------- PortProxyGUI/PortProxyGUI.resx | 61 +++++++++++++++++---------- 4 files changed, 80 insertions(+), 56 deletions(-) diff --git a/PortProxyGUI/Data/Rule.cs b/PortProxyGUI/Data/Rule.cs index 1d3bb9b..8d75ea6 100644 --- a/PortProxyGUI/Data/Rule.cs +++ b/PortProxyGUI/Data/Rule.cs @@ -13,7 +13,7 @@ namespace PortProxyGUI.Data public int ConnectPort { get; set; } public string Comment { get; set; } public string Group { get; set; } - public string PingStatus { get; set; } = "Checking..."; + public string PingStatus { get; set; } = "Not checked"; public bool Valid => ListenPort > 0 && ConnectPort > 0; diff --git a/PortProxyGUI/PortProxyGUI.Designer.cs b/PortProxyGUI/PortProxyGUI.Designer.cs index 55c580e..276fff1 100644 --- a/PortProxyGUI/PortProxyGUI.Designer.cs +++ b/PortProxyGUI/PortProxyGUI.Designer.cs @@ -44,6 +44,7 @@ this.toolStripMenuItem_Disable = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem_Refresh = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem_RefreshPingStatus = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem_FlushDnsCache = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem_New = new System.Windows.Forms.ToolStripMenuItem(); @@ -52,7 +53,6 @@ this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem_About = new System.Windows.Forms.ToolStripMenuItem(); this.imageListProxies = new System.Windows.Forms.ImageList(this.components); - this.TimerPingTargets = new System.Windows.Forms.Timer(this.components); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -122,6 +122,7 @@ this.toolStripMenuItem_Disable, this.toolStripSeparator3, this.toolStripMenuItem_Refresh, + this.toolStripMenuItem_RefreshPingStatus, this.toolStripMenuItem_FlushDnsCache, this.toolStripSeparator2, this.toolStripMenuItem_New, @@ -153,6 +154,11 @@ this.toolStripMenuItem_Refresh.Name = "toolStripMenuItem_Refresh"; resources.ApplyResources(this.toolStripMenuItem_Refresh, "toolStripMenuItem_Refresh"); // + // toolStripMenuItem_RefreshPingStatus + // + this.toolStripMenuItem_RefreshPingStatus.Name = "toolStripMenuItem_RefreshPingStatus"; + resources.ApplyResources(this.toolStripMenuItem_RefreshPingStatus, "toolStripMenuItem_RefreshPingStatus"); + // // toolStripMenuItem_FlushDnsCache // this.toolStripMenuItem_FlushDnsCache.Name = "toolStripMenuItem_FlushDnsCache"; @@ -196,12 +202,6 @@ this.imageListProxies.Images.SetKeyName(0, "disable.png"); this.imageListProxies.Images.SetKeyName(1, "enable.png"); // - // TimerPingTargets - // - this.TimerPingTargets.Enabled = true; - this.TimerPingTargets.Interval = 5000; - this.TimerPingTargets.Tick += new System.EventHandler(this.TimerPingTargets_Tick); - // // PortProxyGUI // resources.ApplyResources(this, "$this"); @@ -238,7 +238,7 @@ internal System.Windows.Forms.ListView listViewProxies; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem_FlushDnsCache; private System.Windows.Forms.ColumnHeader columnPingStatus; - private System.Windows.Forms.Timer TimerPingTargets; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem_RefreshPingStatus; } } diff --git a/PortProxyGUI/PortProxyGUI.cs b/PortProxyGUI/PortProxyGUI.cs index f84dfcc..5db85ba 100644 --- a/PortProxyGUI/PortProxyGUI.cs +++ b/PortProxyGUI/PortProxyGUI.cs @@ -162,7 +162,7 @@ namespace PortProxyGUI { Tag ="Connect To Ping Status", ForeColor = rule.PingStatus.Equals("Success") ? Color.Green - : rule.PingStatus.Equals("Checking...") ? Color.DarkGray + : rule.PingStatus.Equals("Pending") ? Color.DarkGray : Color.MediumVioletRed }, new ListViewSubItem(item, rule.Comment ?? string.Empty) @@ -183,28 +183,36 @@ namespace PortProxyGUI public void RefreshProxyList() { - var proxies = CmdUtil.GetProxies(); - var rules = Program.SqliteDbScope.Rules.ToArray(); - foreach (var proxy in proxies) + try { - var matchedRule = rules.FirstOrDefault(r => r.EqualsWithKeys(proxy)); - proxy.Id = matchedRule?.Id; + + var proxies = CmdUtil.GetProxies(); + var rules = Program.SqliteDbScope.Rules.ToArray(); + foreach (var proxy in proxies) + { + var matchedRule = rules.FirstOrDefault(r => r.EqualsWithKeys(proxy)); + proxy.Id = matchedRule?.Id; + } + + var pendingAdds = proxies.Where(x => x.Valid && x.Id == null); + var pendingUpdates = + from proxy in proxies + let exsist = rules.FirstOrDefault(r => r.Id == proxy.Id) + where exsist is not null + where proxy.Valid && proxy.Id is not null + select proxy; + + Program.SqliteDbScope.AddRange(pendingAdds); + Program.SqliteDbScope.UpdateRange(pendingUpdates); + + rules = Program.SqliteDbScope.Rules.ToArray(); + InitProxyGroups(rules); + InitProxyItems(rules, proxies); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error Refreshing"); } - - var pendingAdds = proxies.Where(x => x.Valid && x.Id == null); - var pendingUpdates = - from proxy in proxies - let exsist = rules.FirstOrDefault(r => r.Id == proxy.Id) - where exsist is not null - where proxy.Valid && proxy.Id is not null - select proxy; - - Program.SqliteDbScope.AddRange(pendingAdds); - Program.SqliteDbScope.UpdateRange(pendingUpdates); - - rules = Program.SqliteDbScope.Rules.ToArray(); - InitProxyGroups(rules); - InitProxyItems(rules, proxies); } public void FlushDnsCache() @@ -248,6 +256,9 @@ namespace PortProxyGUI case ToolStripMenuItem item when item == toolStripMenuItem_Refresh: RefreshProxyList(); break; + case ToolStripMenuItem item when item == toolStripMenuItem_RefreshPingStatus: + RefreshConnectHostPingStatus(); + break; case ToolStripMenuItem item when item == toolStripMenuItem_FlushDnsCache: FlushDnsCache(); break; @@ -326,9 +337,8 @@ namespace PortProxyGUI } } - private void TimerPingTargets_Tick(object sender, EventArgs e) + private void RefreshConnectHostPingStatus() { - TimerPingTargets.Stop(); try { var items = listViewProxies.Items.OfType(); @@ -362,7 +372,6 @@ namespace PortProxyGUI } } catch { } - TimerPingTargets.Start(); } } } diff --git a/PortProxyGUI/PortProxyGUI.resx b/PortProxyGUI/PortProxyGUI.resx index 4e3163a..2a36ddc 100644 --- a/PortProxyGUI/PortProxyGUI.resx +++ b/PortProxyGUI/PortProxyGUI.resx @@ -111,67 +111,85 @@ - 164, 22 + 180, 22 Enable (&E) + + Enable current Proxy + - 164, 22 + 180, 22 Disable (&I) + + Disable Current Proxy + - 161, 6 + 177, 6 - 164, 22 + 180, 22 Refresh (&F) + + Refresh Port Proxies + + + 180, 22 + + + Refresh Ping Status + + + Refresh Host Ping Statuses + - 164, 22 + 180, 22 Flush DNS Cache - Will perform ipconfig/flushDNS + Click to perform ipconfig/flushDNS - 161, 6 + 177, 6 - 164, 22 + 180, 22 New (&N) ... - 164, 22 + 180, 22 Modify (&M) ... - 164, 22 + 180, 22 Delete (&D) - 161, 6 + 177, 6 - 164, 22 + 180, 22 About - 165, 198 + 181, 242 contextMenuStrip1 @@ -203,7 +221,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAEZTeXN0ZW0uV2luZG93cy5Gb3JtcywgQ3VsdHVyZT1uZXV0cmFs LCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAmU3lzdGVtLldpbmRvd3MuRm9ybXMu SW1hZ2VMaXN0U3RyZWFtZXIBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA3AgAAAJNU0Z0AUkBTAIBAQIB - AAFYAQEBWAEBARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMAAUADAAEQAwABAQEAAQgG + AAFwAQEBcAEBARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMAAUADAAEQAwABAQEAAQgG AAEEGAABgAIAAYADAAKAAQABgAMAAYABAAGAAQACgAIAA8ABAAHAAdwBwAEAAfABygGmAQABMwUAATMB AAEzAQABMwEAAjMCAAMWAQADHAEAAyIBAAMpAQADVQEAA00BAANCAQADOQEAAYABfAH/AQACUAH/AQAB kwEAAdYBAAH/AewBzAEAAcYB1gHvAQAB1gLnAQABkAGpAa0CAAH/ATMDAAFmAwABmQMAAcwCAAEzAwAC @@ -258,9 +276,6 @@ 1 - - 324, 17 - True @@ -2512,6 +2527,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + toolStripMenuItem_RefreshPingStatus + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + toolStripMenuItem_FlushDnsCache @@ -2560,12 +2581,6 @@ System.Windows.Forms.ImageList, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - TimerPingTargets - - - System.Windows.Forms.Timer, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 - PortProxyGUI