chore: minor refactoring
This commit is contained in:
parent
b06964169e
commit
ee038ca7cf
|
@ -13,7 +13,7 @@ namespace PortProxyGUI.Data
|
||||||
public int ConnectPort { get; set; }
|
public int ConnectPort { get; set; }
|
||||||
public string Comment { get; set; }
|
public string Comment { get; set; }
|
||||||
public string Group { get; set; }
|
public string Group { get; set; }
|
||||||
public string PingStatus { get; set; }
|
public string PingStatus { get; set; } = "Checking...";
|
||||||
|
|
||||||
public bool Valid => ListenPort > 0 && ConnectPort > 0;
|
public bool Valid => ListenPort > 0 && ConnectPort > 0;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using NStandard;
|
using NStandard;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
@ -13,7 +15,7 @@ namespace PortProxyGUI
|
||||||
public SetProxy SetProxyForm;
|
public SetProxy SetProxyForm;
|
||||||
public About AboutForm;
|
public About AboutForm;
|
||||||
private ListViewColumnSorter lvwColumnSorter;
|
private ListViewColumnSorter lvwColumnSorter;
|
||||||
|
private List<KeyValuePair<string, IPStatus>> hostStatus { get; set; } = new List<KeyValuePair<string, IPStatus>>();
|
||||||
public PortProxyGUI()
|
public PortProxyGUI()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -156,7 +158,13 @@ namespace PortProxyGUI
|
||||||
new ListViewSubItem(item, rule.ListenPort.ToString()) { Tag = "Number" },
|
new ListViewSubItem(item, rule.ListenPort.ToString()) { Tag = "Number" },
|
||||||
new ListViewSubItem(item, rule.ConnectTo),
|
new ListViewSubItem(item, rule.ConnectTo),
|
||||||
new ListViewSubItem(item, rule.ConnectPort.ToString ()) { Tag = "Number" },
|
new ListViewSubItem(item, rule.ConnectPort.ToString ()) { Tag = "Number" },
|
||||||
new ListViewSubItem(item, rule.PingStatus ?? string.Empty),
|
new ListViewSubItem(item, rule.PingStatus ?? string.Empty)
|
||||||
|
{
|
||||||
|
Tag ="Connect To Ping Status",
|
||||||
|
ForeColor = rule.PingStatus.Equals("Success") ? Color.Green
|
||||||
|
: rule.PingStatus.Equals("Checking...") ? Color.DarkGray
|
||||||
|
: Color.MediumVioletRed
|
||||||
|
},
|
||||||
new ListViewSubItem(item, rule.Comment ?? string.Empty)
|
new ListViewSubItem(item, rule.Comment ?? string.Empty)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -324,16 +332,32 @@ namespace PortProxyGUI
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var items = listViewProxies.Items.OfType<ListViewItem>();
|
var items = listViewProxies.Items.OfType<ListViewItem>();
|
||||||
|
hostStatus = new List<KeyValuePair<string, IPStatus>>();
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var rule = ParseRule(item);
|
//Custom Color for cells
|
||||||
//Ping Host
|
item.UseItemStyleForSubItems = false;
|
||||||
|
//Proceed
|
||||||
|
Data.Rule rule = ParseRule(item);
|
||||||
|
//Check if host already pinged host
|
||||||
|
var alreadyChkdHost = hostStatus.FirstOrDefault(x => x.Key.Equals(rule.ConnectTo, StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (!string.IsNullOrEmpty(alreadyChkdHost.Key))
|
||||||
|
{
|
||||||
|
//Skip Checking Status since already checked
|
||||||
|
rule.PingStatus = alreadyChkdHost.Value.ToString();
|
||||||
|
UpdateListViewItem(item, rule, item.ImageIndex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//If not yet checked
|
||||||
PingCheckerUtil.GetPingResult(rule.ConnectTo, 2, out IPStatus ipStatus, out _, out _);
|
PingCheckerUtil.GetPingResult(rule.ConnectTo, 2, out IPStatus ipStatus, out _, out _);
|
||||||
|
hostStatus.Add(new KeyValuePair<string, IPStatus>(rule.ConnectTo, ipStatus));
|
||||||
rule.PingStatus = ipStatus.ToString();
|
rule.PingStatus = ipStatus.ToString();
|
||||||
UpdateListViewItem(item, rule, item.ImageIndex);
|
UpdateListViewItem(item, rule, item.ImageIndex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue