Skip to content

Commit

Permalink
Add the option to show the port in the Pool column
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoolls committed Jan 20, 2018
1 parent e2ee0e8 commit 0cd941e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
26 changes: 26 additions & 0 deletions MultiMiner.UX.Tests/StringExtensionsTests.cs
Expand Up @@ -138,5 +138,31 @@ public void ParseHostAndPort_H_Succeeds()
Assert.AreEqual(81, port);
Assert.IsTrue(result);
}

[TestMethod]
public void PortFromHost_WithPort_ReturnsPort()
{
// arrange
var hostAndPort = "stratum+tcp://stratum.kano.is:81/#xnsub/#skipcbcheck";

// act
int? port = hostAndPort.PortFromHost();

// assert
Assert.AreEqual(81, port);
}

[TestMethod]
public void PortFromHost_WithoutPort_ReturnsNull()
{
// arrange
var hostAndPort = "stratum+tcp://stratum.kano.is/#xnsub/#skipcbcheck";

// act
int? port = hostAndPort.PortFromHost();

// assert
Assert.IsFalse(port.HasValue);
}
}
}
1 change: 1 addition & 0 deletions MultiMiner.UX/Data/Configuration/Application.cs
Expand Up @@ -67,6 +67,7 @@ public Application()
public bool AllowMultipleInstances { get; set; }
public string SubmittedStatsVersion { get; set; }
public bool ShowWorkUtility { get; set; }
public bool ShowPoolPort { get; set; }
public bool NetworkDeviceDetection { get; set; }
public bool NetworkDeviceScanClassB { get; set; }
public bool NetworkDeviceScanClassA { get; set; }
Expand Down
34 changes: 33 additions & 1 deletion MultiMiner.UX/Extensions/StringExtensions.cs
Expand Up @@ -29,7 +29,7 @@ public static string DomainFromHost(this string host)

string domainName = host.Trim();

if (!host.Contains(":"))
if (!host.Contains("://"))
host = "http://" + host;

try
Expand Down Expand Up @@ -63,6 +63,38 @@ public static string DomainFromHost(this string host)
return domainName;
}

private readonly static Dictionary<string, int> hostPorts = new Dictionary<string, int>();

public static int? PortFromHost(this string host)
{
if (String.IsNullOrEmpty(host))
return null;

if (hostPorts.ContainsKey(host))
return hostPorts[host];

int? port = null;

if (!host.Contains("://"))
host = "http://" + host;

try
{
Uri uri = new Uri(host);
if (uri.Port >= 0)
{
port = uri.Port;
}
}
catch (UriFormatException)
{
// System.UriFormatException: Invalid URI: The hostname could not be parsed.
// don't crash - fall back on domainName = host (initialized above)
}

return port;
}

public static string ShortHostFromHost(this string host)
{
return host.Replace("http://", "").Replace("stratum+tcp://", "").TrimEnd('/');
Expand Down
24 changes: 23 additions & 1 deletion MultiMiner.Win/Forms/MinerForm.cs
Expand Up @@ -559,11 +559,25 @@ private void RefreshListViewItemForDeviceViewModel(ListViewItem listViewItem, De
listViewItem.SubItems["Fan"].Text = deviceViewModel.FanPercent > 0 ? deviceViewModel.FanPercent + "%" : String.Empty;
listViewItem.SubItems["Intensity"].Text = deviceViewModel.Intensity;

listViewItem.SubItems["Pool"].Text = deviceViewModel.Pool.DomainFromHost();
RefreshPoolColumnForDeviceViewModel(listViewItem, deviceViewModel);

PopulateIncomeForListViewItem(listViewItem, deviceViewModel);
}

private void RefreshPoolColumnForDeviceViewModel(ListViewItem listViewItem, DeviceViewModel deviceViewModel)
{
var pool = deviceViewModel.Pool.DomainFromHost();
if (app.ApplicationConfiguration.ShowPoolPort)
{
var port = deviceViewModel.Pool.PortFromHost();
if (port.HasValue)
{
pool = String.Format("{0}:{1}", pool, port.Value);
}
}
listViewItem.SubItems["Pool"].Text = pool;
}

private void RefreshDetailsAreaIfVisible()
{
if (!detailsAreaContainer.Panel2Collapsed)
Expand Down Expand Up @@ -1559,6 +1573,14 @@ private void deviceListView_ColumnClick(object sender, ColumnClickEventArgs e)
AutoSizeListViewColumns();
RefreshDetailsAreaIfVisible();
}
else if (e.Column == poolColumnHeader.Index)
{
app.ApplicationConfiguration.ShowPoolPort = !app.ApplicationConfiguration.ShowPoolPort;
app.ApplicationConfiguration.SaveApplicationConfiguration();

app.RefreshAllDeviceStats();
AutoSizeListViewColumns();
}
}

private void columnHeaderMenu_Opening(object sender, CancelEventArgs e)
Expand Down

0 comments on commit 0cd941e

Please sign in to comment.