private static void ClearCoinInformation(DeviceViewModel deviceViewModel) { deviceViewModel.Price = 0; deviceViewModel.Profitability = 100; deviceViewModel.AdjustedProfitability = 100; deviceViewModel.AverageProfitability = 100; deviceViewModel.Exchange = 0; }
public Int32 CompareTo(DeviceViewModel value) { if (this.Equals(value)) { return(0); } DeviceViewModel d1 = this; DeviceViewModel d2 = value; int result = 0; result = d1.Kind.CompareTo(d2.Kind); if ((d1.Kind == DeviceKind.NET) && (d2.Kind == DeviceKind.NET)) { string[] parts1 = d1.Path.Split(':'); string[] parts2 = d2.Path.Split(':'); IPAddress ip1 = IPAddress.Parse(parts1[0]); IPAddress ip2 = IPAddress.Parse(parts2[0]); if (ip1.Equals(ip2)) { result = int.Parse(parts1[1]).CompareTo(int.Parse(parts2[1])); } else { result = ip1.CompareTo(ip2); } } if (result == 0) { result = d1.Driver.CompareTo(d2.Driver); } if (result == 0) { result = d1.Name.CompareTo(d2.Name); } if (result == 0) { result = d1.Path.CompareTo(d2.Path); } if (result == 0) { result = d1.RelativeIndex.CompareTo(d2.RelativeIndex); } return(result); }
//update temperatures by averaging worker temps private static void UpdateTemperaturesBasedOnWorkers(DeviceViewModel deviceViewModel) { IEnumerable <DeviceViewModel> workersWithData = deviceViewModel.Workers.Where(w => w.Temperature > 0); if (workersWithData.Count() == 0) { return; } deviceViewModel.Temperature = Math.Round(workersWithData.Average(w => w.Temperature), 1); }
public static DeviceViewModel ToViewModel(this NetworkDevices.NetworkDevice networkDevice) { DeviceViewModel deviceViewModel = new DeviceViewModel { Kind = DeviceKind.NET, Path = String.Format("{0}:{1}", networkDevice.IPAddress, networkDevice.Port), Name = networkDevice.IPAddress, Driver = "network" }; return deviceViewModel; }
public string GetFriendlyDeviceName(string deviceName, string devicePath) { string result = deviceName; DeviceViewModel deviceViewModel = Devices.SingleOrDefault(d => d.Path.Equals(devicePath)); if ((deviceViewModel != null) && !String.IsNullOrEmpty(deviceViewModel.FriendlyName)) { result = deviceViewModel.FriendlyName; } return(result); }
public DeviceViewModel GetNetworkDeviceByFriendlyName(string friendlyDeviceName) { DeviceViewModel result = null; IEnumerable <DeviceViewModel> networkDevices = Devices.Where(d => d.Kind == DeviceKind.NET); foreach (DeviceViewModel item in networkDevices) { if (GetFriendlyDeviceName(item.Path, item.Path).Equals(friendlyDeviceName, StringComparison.OrdinalIgnoreCase)) { result = item; break; } } return(result); }
//update percentage-based device stats by weighing each worker private static void UpdatePercentagesBasedOnWorkers(DeviceViewModel deviceViewModel) { double totalHashrate = deviceViewModel.Workers.Sum(w => w.AverageHashrate); double rejectedPercent = 0; double errorPercent = 0; foreach (DeviceViewModel worker in deviceViewModel.Workers) { double workerWeight = worker.AverageHashrate / totalHashrate; errorPercent += worker.HardwareErrorsPercent * workerWeight; rejectedPercent += worker.RejectedSharesPercent * workerWeight; } deviceViewModel.HardwareErrorsPercent = errorPercent; deviceViewModel.RejectedSharesPercent = rejectedPercent; }
public DeviceViewModel ApplyDeviceInformationResponseModel(DeviceDescriptor deviceModel, DeviceInformation deviceInformationResponseModel) { string[] excludedProperties = { "Name", //don't overwrite our "nice" name "Kind", //we have our own enum Kind "Enabled" //don't overwrite our own Enabled flag }; DeviceViewModel deviceViewModel = Devices.SingleOrDefault(d => d.Equals(deviceModel)); if (deviceViewModel != null) { if ((deviceModel.Kind == DeviceKind.PXY) || (deviceModel.Kind == DeviceKind.NET)) { deviceViewModel.PoolIndex = deviceInformationResponseModel.PoolIndex; //we will get multiple deviceInformationResponseModels for the same deviceModel in the case of a Stratum Proxy //bfgminer will report back for each Proxy Worker, but we only show a single entry in the ViewModel that rolls //up the stats for individual Proxy Workers deviceViewModel.AverageHashrate += deviceInformationResponseModel.AverageHashrate; deviceViewModel.CurrentHashrate += deviceInformationResponseModel.CurrentHashrate; deviceViewModel.AcceptedShares += deviceInformationResponseModel.AcceptedShares; deviceViewModel.RejectedShares += deviceInformationResponseModel.RejectedShares; deviceViewModel.HardwareErrors += deviceInformationResponseModel.HardwareErrors; deviceViewModel.Utility += deviceInformationResponseModel.Utility; deviceViewModel.WorkUtility += deviceInformationResponseModel.WorkUtility; //now add as a worker DeviceViewModel workerViewModel = new DeviceViewModel(); ObjectCopier.CopyObject(deviceInformationResponseModel, workerViewModel, excludedProperties); workerViewModel.WorkerName = deviceInformationResponseModel.Name; //set a default until (if) we get details deviceViewModel.Workers.Add(workerViewModel); UpdateTemperaturesBasedOnWorkers(deviceViewModel); //recalculate hardware and rejected share percentages - need to be weighted with worker hashrates UpdatePercentagesBasedOnWorkers(deviceViewModel); } else { ObjectCopier.CopyObject(deviceInformationResponseModel, deviceViewModel, excludedProperties); } } return(deviceViewModel); }
public static void ClearDeviceInformation(DeviceViewModel deviceViewModel) { deviceViewModel.AverageHashrate = 0; deviceViewModel.CurrentHashrate = 0; deviceViewModel.AcceptedShares = 0; deviceViewModel.RejectedShares = 0; deviceViewModel.HardwareErrors = 0; deviceViewModel.Utility = 0; deviceViewModel.WorkUtility = 0; deviceViewModel.RejectedSharesPercent = 0; deviceViewModel.HardwareErrorsPercent = 0; deviceViewModel.Pool = String.Empty; deviceViewModel.PoolIndex = -1; deviceViewModel.FanPercent = 0; deviceViewModel.Temperature = 0; deviceViewModel.Intensity = String.Empty; deviceViewModel.Workers.Clear(); }
public void ApplyDeviceDetailsResponseModels(List <DeviceDescriptor> processDevices, List <DeviceDetails> deviceDetailsList) { //for getting Proxy worker names DeviceViewModel proxyDevice = Devices.SingleOrDefault(d => d.Enabled && (d.Kind == DeviceKind.PXY) && (processDevices.Any(d2 => d2.Equals(d)))); if (proxyDevice != null) { foreach (DeviceDetails deviceDetailsResponse in deviceDetailsList) { if (deviceDetailsResponse.Name.Equals("PXY")) { //SingleOrDefault not a safe assumption here - rare DeviceViewModel worker = proxyDevice.Workers.FirstOrDefault(w => w.ID == deviceDetailsResponse.ID); if (worker != null) { worker.WorkerName = deviceDetailsResponse.DevicePath; } } } } }
public bool StopNetworkDevice(DeviceViewModel networkDevice) { return ToggleNetworkDevicePools(networkDevice, false); }
private void SetupNetworkDeviceDetails(DeviceViewModel deviceViewModel) { serialTitleLabel.Visible = deviceViewModel.Kind != DeviceKind.NET; serialValueLabel.Visible = deviceViewModel.Kind != DeviceKind.NET; processorsTitleLabel.Visible = deviceViewModel.Kind != DeviceKind.NET; processorsValueLabel.Visible = deviceViewModel.Kind != DeviceKind.NET; if (deviceViewModel.Kind == DeviceKind.NET) { pathValueLabel.Width = Width - pathValueLabel.Left - 6; nameLabel.Cursor = Cursors.Hand; nameLabel.Font = new Font(nameLabel.Font, FontStyle.Underline); nameLabel.ForeColor = Color.Blue; statusLabel.Text = String.Format("{0}{1}{2}", deviceViewModel.ChainStatus[0], Environment.NewLine, deviceViewModel.ChainStatus[1]); } else { pathValueLabel.Width = serialTitleLabel.Left - pathValueLabel.Left - 6; nameLabel.Cursor = Cursors.Default; nameLabel.Font = new Font(nameLabel.Font, FontStyle.Regular); nameLabel.ForeColor = Color.FromArgb(30, 57, 91); statusLabel.Text = String.Empty; } }
private void SetupDevicePicture(DeviceViewModel deviceViewModel) { switch (deviceViewModel.Kind) { case DeviceKind.CPU: pictureBox1.Image = imageList1.Images[3]; break; case DeviceKind.GPU: pictureBox1.Image = imageList1.Images[0]; break; case DeviceKind.USB: pictureBox1.Image = imageList1.Images[1]; break; case DeviceKind.PXY: pictureBox1.Image = imageList1.Images[2]; break; case DeviceKind.NET: pictureBox1.Image = imageList1.Images[4]; break; } }
private void CalculateDifficulty(DeviceViewModel device) { var difficulty = GetCachedNetworkDifficulty(device.Pool ?? String.Empty); if (difficulty != 0.0) device.Difficulty = difficulty; }
private void ProcessNetworkDeviceRemoteCommand(string commandText, DeviceViewModel networkDevice) { Uri uri = new Uri("http://" + networkDevice.Path); ApiContext apiContext = new ApiContext(uri.Port, uri.Host); //setup logging apiContext.LogEvent -= LogApiEvent; apiContext.LogEvent += LogApiEvent; string action = "accessing " + networkDevice.FriendlyName; try { if (commandText.StartsWith(RemoteCommandText.Switch, StringComparison.OrdinalIgnoreCase)) { action = "switching pools on " + networkDevice.FriendlyName; string[] parts = commandText.Split('|'); string poolName = parts[1]; //we may not have the pool info cached yet / anymore if (NetworkDevicePools.ContainsKey(networkDevice.Path)) { List<PoolInformation> pools = NetworkDevicePools[networkDevice.Path]; int poolIndex = pools.FindIndex(pi => pi.Url.DomainFromHost().Equals(poolName, StringComparison.OrdinalIgnoreCase)); apiContext.SwitchPool(poolIndex); } } else if (commandText.Equals(RemoteCommandText.Restart, StringComparison.OrdinalIgnoreCase)) { RestartNetworkDevice(networkDevice); } else if (commandText.Equals(RemoteCommandText.Stop, StringComparison.OrdinalIgnoreCase)) { StopNetworkDevice(networkDevice); } else if (commandText.Equals(RemoteCommandText.Start, StringComparison.OrdinalIgnoreCase)) { StartNetworkDevice(networkDevice); } } catch (SocketException ex) { PostNotification(String.Format("Error {0}: {1}", action, ex.Message), NotificationKind.Danger); } }
public void RenameDevice(DeviceViewModel deviceViewModel, string name) { //rename the device in the user metadata Metadata.DeviceMetadata deviceData = metadataConfiguration.Devices.SingleOrDefault(d => d.Equals(deviceViewModel)); if (deviceData == null) { deviceData = new Metadata.DeviceMetadata(); ObjectCopier.CopyObject(deviceViewModel, deviceData); metadataConfiguration.Devices.Add(deviceData); } deviceData.FriendlyName = name; metadataConfiguration.SaveDeviceMetadataConfiguration(); //rename the device ViewModel itself deviceViewModel.FriendlyName = name; }
private void RestartSuspectNetworkDevice(DeviceViewModel networkDevice, string reason) { //don't restart a Network Device we've stopped if (NetworkDeviceWasStopped(networkDevice)) return; string message = String.Format("Restarting {0} ({1})", networkDevice.FriendlyName, reason); try { if (!RestartNetworkDevice(networkDevice)) { if (!ApplicationConfiguration.ShowApiErrors) { //early exit - we aren't notifying for API errors return; } message = String.Format("Access denied restarting {0} ({1})", networkDevice.FriendlyName, reason); } } catch (SocketException) { message = String.Format("Timeout restarting {0} ({1})", networkDevice.FriendlyName, reason); } //code to update UI PostNotification(message, NotificationKind.Danger); }
private bool DeviceIsWarmedUp(DeviceViewModel deviceViewModel) { bool warm = false; List<MinerStatistics> statistics = GetCachedMinerStatisticsFromViewModel(deviceViewModel); //null in case of API failure if ((statistics != null) && (statistics.Count > 0)) warm = statistics.First().Elapsed > MiningEngine.SecondsToWarmUpMiner; //track this internally as well - in practice we cannot trust our //cached miner statistics data above 100%, especially in cases of a reboot if (warm) { warm = ((deviceViewModel.LastRestart == null) || ((DateTime.Now - deviceViewModel.LastRestart).Value.TotalSeconds > MiningEngine.SecondsToWarmUpMiner)) && ((deviceViewModel.LastReboot == null) || ((DateTime.Now - deviceViewModel.LastReboot).Value.TotalSeconds > MiningEngine.SecondsToWarmUpMiner)); } return warm; }
public bool ExecuteNetworkDeviceCommand(DeviceViewModel deviceViewModel, string commandText, bool unattended = false) { NetworkDevices.NetworkDevice networkDevice = GetNetworkDeviceByPath(deviceViewModel.Path); string username = networkDevice.Username; string password = networkDevice.Password; string devicePath = deviceViewModel.Path; string deviceName = devicePath; if (!String.IsNullOrEmpty(deviceViewModel.FriendlyName)) deviceName = deviceViewModel.FriendlyName; bool success = false; bool stop = false; bool prompt = String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password); if (unattended && prompt) return false; while (!success && !stop) { if (prompt) { CredentialsEventArgs ea = new CredentialsEventArgs { ProtectedResource = deviceName, Username = username, Password = password }; if (CredentialsRequested != null) CredentialsRequested(this, ea); if (ea.CredentialsProvided) { username = ea.Username; password = ea.Password; } else { stop = true; } } if (!stop) { Uri uri = new Uri("http://" + devicePath); using (SshClient client = new SshClient(uri.Host, username, password)) { try { client.Connect(); } catch (Exception ex) { if (ex is SshAuthenticationException) prompt = true; else if ((ex is SocketException) || (ex is SshOperationTimeoutException)) { stop = true; PostNotification(String.Format("{0}: {1}", deviceName, ex.Message), NotificationKind.Danger); } else throw; } if (client.IsConnected) { try { stop = true; success = ExecuteSshCommand(deviceName, client, commandText); } finally { client.Disconnect(); } } } } } if (success) { networkDevice.Username = username; networkDevice.Password = password; NetworkDevicesConfiguration.SaveNetworkDevicesConfiguration(); } return success; }
private List<MinerStatistics> GetCachedMinerStatisticsFromViewModel(DeviceViewModel deviceViewModel) { string[] portions = deviceViewModel.Path.Split(':'); string ipAddress = portions[0]; int port = int.Parse(portions[1]); return GetCachedMinerStatisticsFromAddress(ipAddress, port); }
public void ApplyDeviceModels(List <Xgminer.Data.Device> deviceModels, List <NetworkDevices.NetworkDevice> networkDeviceModels, List <Metadata.DeviceMetadata> deviceMetadata) { //add/update Devices from deviceModels if (deviceModels != null) { foreach (Xgminer.Data.Device deviceModel in deviceModels) { DeviceViewModel deviceViewModel = Devices.SingleOrDefault(d => d.Equals(deviceModel)); if (deviceViewModel == null) { deviceViewModel = new DeviceViewModel(); Devices.Add(deviceViewModel); } ObjectCopier.CopyObject(deviceModel, deviceViewModel); deviceViewModel.Visible = true; } } //add/update Devices from networkDeviceModels if (networkDeviceModels != null) { foreach (NetworkDevices.NetworkDevice networkDeviceModel in networkDeviceModels.Where(nd => !nd.Hidden)) { DeviceViewModel deviceViewModel = networkDeviceModel.ToViewModel(); if (Devices.SingleOrDefault(d => d.Equals(deviceViewModel)) == null) { //set Visible to false until we have details deviceViewModel.Visible = false; //network devices always enabled deviceViewModel.Enabled = true; //assume BTC until we have pool info deviceViewModel.Coin = new PoolGroup() { Name = KnownCoins.BitcoinName, Id = KnownCoins.BitcoinSymbol, Algorithm = AlgorithmNames.SHA256 }; Devices.Add(deviceViewModel); } } } //apply metadata ASAP for MobileMiner foreach (Metadata.DeviceMetadata metadata in deviceMetadata) { DeviceViewModel deviceViewModel = Devices.SingleOrDefault(d => d.Equals(metadata)); if (deviceViewModel != null) { //only assigned customized values, rest are keys for Equals() deviceViewModel.FriendlyName = metadata.FriendlyName; } } //remove entries from Devices not found in deviceModels or networkDeviceModels foreach (DeviceViewModel deviceViewModel in Devices.ToList()) { bool found = true; if (deviceViewModel.Kind == DeviceKind.NET) { found = networkDeviceModels.Any(d => d.ToViewModel().Equals(deviceViewModel) && !d.Hidden); } else { found = deviceModels.Any(d => d.Equals(deviceViewModel)); } if (!found) { Devices.Remove(deviceViewModel); } } }
public bool StartNetworkDevice(DeviceViewModel networkDevice) { return ToggleNetworkDevicePools(networkDevice, true); }
public Int32 CompareTo(DeviceViewModel value) { if (this.Equals(value)) return 0; DeviceViewModel d1 = this; DeviceViewModel d2 = value; int result = 0; result = d1.Kind.CompareTo(d2.Kind); if ((d1.Kind == DeviceKind.NET) && (d2.Kind == DeviceKind.NET)) { string[] parts1 = d1.Path.Split(':'); string[] parts2 = d2.Path.Split(':'); IPAddress ip1 = IPAddress.Parse(parts1[0]); IPAddress ip2 = IPAddress.Parse(parts2[0]); if (ip1.Equals(ip2)) result = int.Parse(parts1[1]).CompareTo(int.Parse(parts2[1])); else result = ip1.CompareTo(ip2); } if (result == 0) result = d1.Driver.CompareTo(d2.Driver); if (result == 0) result = d1.Name.CompareTo(d2.Name); if (result == 0) result = d1.Path.CompareTo(d2.Path); if (result == 0) result = d1.RelativeIndex.CompareTo(d2.RelativeIndex); return result; }
private bool ToggleNetworkDevicePools(DeviceViewModel networkDevice, bool enabled) { // networkDevicePools is keyed by IP:port, use .Path List<PoolInformation> poolInformation = GetCachedPoolInfoFromAddress(networkDevice.Path); if (poolInformation == null) //RPC API call timed out return false; Uri uri = new Uri("http://" + networkDevice.Path); ApiContext apiContext = new ApiContext(uri.Port, uri.Host); //setup logging apiContext.LogEvent -= LogApiEvent; apiContext.LogEvent += LogApiEvent; string verb = enabled ? "enablepool" : "disablepool"; for (int i = 0; i < poolInformation.Count; i++) { string response = apiContext.GetResponse(String.Format("{0}|{1}", verb, i)); if (!response.ToLower().Contains("STATUS=S".ToLower())) return false; } //remove cached data for pools NetworkDevicePools.Remove(networkDevice.Path); return true; }
private void RefreshNetworkDeviceStatsAsync(DeviceViewModel deviceViewModel) { string[] portions = deviceViewModel.Path.Split(':'); string ipAddress = portions[0]; int port = int.Parse(portions[1]); List<DeviceInformation> deviceInformationList = GetDeviceInfoFromAddress(ipAddress, port); //System.InvalidOperationException: Invoke or BeginInvoke cannot be called on a control until the window handle has been created. if (Context == null) return; //first clear stats for each row //this is because the NET row stats get summed Context.BeginInvoke((Action)(() => { //code to update UI MinerFormViewModel.ClearDeviceInformation(deviceViewModel); //deviceInformationList or poolInformationList may be down if the API was unreachable //at the time if (deviceInformationList != null) { List<MinerStatistics> minerStatistics = GetCachedMinerStatisticsFromAddress(ipAddress, port); //null if API call fails //check for minerStatistics.Count > 0 needed (error reported with callstack) if ((minerStatistics != null) && (minerStatistics.Count > 0)) { MinerStatistics firstStatistics = minerStatistics.First(); deviceViewModel.Frequency = firstStatistics.Frequency; deviceViewModel.ChainStatus = firstStatistics.ChainStatus; } int poolIndex = -1; foreach (DeviceInformation deviceInformation in deviceInformationList) { LocalViewModel.ApplyDeviceInformationResponseModel(deviceViewModel, deviceInformation); poolIndex = deviceInformation.PoolIndex >= 0 ? deviceInformation.PoolIndex : poolIndex; } List<PoolInformation> poolInformationList = GetCachedPoolInfoFromAddress(ipAddress, port); if ((poolInformationList != null) && //ensure poolIndex is valid for poolInformationList //user(s) reported index errors so we can't count on the RPC API here //https://github.com/nwoolls/MultiMiner/issues/64 ((poolIndex >= 0) && (poolIndex < poolInformationList.Count))) { PoolInformation poolInformation = poolInformationList[poolIndex]; deviceViewModel.Pool = poolInformation.Url; deviceViewModel.LastShareDifficulty = poolInformation.LastShareDifficulty; deviceViewModel.LastShareTime = poolInformation.LastShareTime; deviceViewModel.Url = poolInformation.Url; deviceViewModel.BestShare = poolInformation.BestShare; deviceViewModel.PoolStalePercent = poolInformation.PoolStalePercent; deviceViewModel.Visible = true; Coin coinConfiguration = CoinConfigurationForPoolUrl(poolInformation.Url); if (coinConfiguration != null) deviceViewModel.Coin = coinConfiguration.PoolGroup; } VersionInformation versionInfo = GetCachedMinerVersionFromAddress(ipAddress, port); //null if API call fails if (versionInfo != null) { //fix work utility for Network Devices using CGMiner-forks that mine alt coins if (!versionInfo.Name.Equals(MinerNames.BFGMiner, StringComparison.OrdinalIgnoreCase)) deviceViewModel.WorkUtility = AdjustWorkUtilityForPoolMultipliers(deviceViewModel.WorkUtility, deviceViewModel.Coin.Algorithm); } } if (!String.IsNullOrEmpty(deviceViewModel.Pool)) CheckAndSetNetworkDifficulty(ipAddress, port, deviceViewModel.Pool); }), null); }
public bool RebootNetworkDevice(DeviceViewModel deviceViewModel, bool unattended = false) { bool result = ExecuteNetworkDeviceCommand(deviceViewModel, "reboot", unattended); if (result) { //do not just flag this ViewModel rebooted //there may be several ViewModels with this IP, but only one //will be send the RebootNetworkDevice command string prefix = deviceViewModel.Path.Split(':').First() + ":"; List<DeviceViewModel> ipDevices = LocalViewModel.Devices .Where(d => (d.Kind == DeviceKind.NET) && d.Path.StartsWith(prefix)) .ToList(); ipDevices.ForEach(d => d.LastReboot = DateTime.Now); } return result; }
public void SetNetworkDevicePool(DeviceViewModel networkDevice, string poolUrl) { // networkDevicePools is keyed by IP:port, use .Path List<PoolInformation> poolInformation = NetworkDevicePools[networkDevice.Path]; if (poolInformation == null) //RPC API call timed out return; int poolIndex = poolInformation.FindIndex(pi => pi.Url.Equals(poolUrl)); if (poolIndex == -1) { //device doesn't have pool return; } SetNetworkDevicePoolIndex(networkDevice, poolIndex); }
//this is a high-traffic call, guard against making repeated RPC calls public bool NetworkDeviceWasStopped(DeviceViewModel networkDevice) { List<PoolInformation> poolInformation = null; //networkDevicePools is keyed by IP:port, use .Path //do not call GetCachedPoolInfoFromAddress() as it may make an RPC call //see method warning above if (NetworkDevicePools.ContainsKey(networkDevice.Path)) poolInformation = NetworkDevicePools[networkDevice.Path]; if (poolInformation == null) //RPC API call timed out return false; return poolInformation.All(pool => pool.Status.Equals("Disabled")); }
public bool SetNetworkDevicePoolIndex(DeviceViewModel networkDevice, int poolIndex) { if (poolIndex < 0) return false; //invalid index // networkDevicePools is keyed by IP:port, use .Path List<PoolInformation> poolInformation = NetworkDevicePools[networkDevice.Path]; if ((poolInformation != null) && (poolIndex >= poolInformation.Count)) return false; //invalid index Uri uri = new Uri("http://" + networkDevice.Path); ApiContext apiContext = new ApiContext(uri.Port, uri.Host); //setup logging apiContext.LogEvent -= LogApiEvent; apiContext.LogEvent += LogApiEvent; apiContext.SwitchPool(poolIndex); return true; }
private static void ClearChainStatus(DeviceViewModel networkDevice) { for (int i = 0; i < networkDevice.ChainStatus.Length; i++) networkDevice.ChainStatus[i] = String.Empty; }
public void ToggleNetworkDeviceHidden(DeviceViewModel deviceViewModel) { bool hidden; ToggleNetworkDeviceHidden(deviceViewModel, out hidden); }
public string GetExchangeRate(DeviceViewModel device) { var exchange = String.Empty; if ((device.Coin != null) && (device.Coin.Kind == PoolGroup.PoolGroupKind.SingleCoin)) { if (ShouldShowExchangeRates()) { ExchangeInformation exchangeInformation = SellPrices.Single(er => er.TargetCurrency.Equals(GetCurrentCultureCurrency()) && er.SourceCurrency.Equals("BTC")); double btcExchangeRate = exchangeInformation.ExchangeRate; double coinExchangeRate = device.Price * btcExchangeRate; exchange = String.Format("{0}{1}", exchangeInformation.TargetSymbol, coinExchangeRate.ToFriendlyString(true)); } } return exchange; }
public void ToggleNetworkDeviceHidden(DeviceViewModel deviceViewModel, out bool hidden) { NetworkDevices.NetworkDevice deviceConfiguration = NetworkDevicesConfiguration.Devices.Single( cfg => String.Format("{0}:{1}", cfg.IPAddress, cfg.Port).Equals(deviceViewModel.Path)); deviceConfiguration.Hidden = !deviceConfiguration.Hidden; NetworkDevicesConfiguration.SaveNetworkDevicesConfiguration(); ApplyDevicesToViewModel(); hidden = deviceConfiguration.Hidden; }
private void SaveDeviceTransferObjects(IEnumerable<Remoting.Data.Transfer.Device> devices) { RemoteViewModel.Devices.Clear(); foreach (Remoting.Data.Transfer.Device dto in devices) { DeviceViewModel viewModel = new DeviceViewModel(); ObjectCopier.CopyObject(dto, viewModel, "Workers"); foreach (Remoting.Data.Transfer.Device source in dto.Workers) { DeviceViewModel destination = new DeviceViewModel(); ObjectCopier.CopyObject(source, destination, "Workers"); viewModel.Workers.Add(destination); } RemoteViewModel.Devices.Add(viewModel); } }
public void ToggleNetworkDeviceSticky(DeviceViewModel deviceViewModel) { bool sticky; ToggleNetworkDeviceSticky(deviceViewModel, out sticky); }
private void CalculateDailyIncome(DeviceViewModel device) { if (device.Coin == null) return; CoinInformation info = CoinApiInformation .ToList() //get a copy - populated async & collection may be modified .SingleOrDefault(c => c.Symbol.Equals(device.Coin.Id, StringComparison.OrdinalIgnoreCase)); if (info != null) { if (device.Coin.Kind == PoolGroup.PoolGroupKind.SingleCoin) { double hashrate = device.CurrentHashrate * 1000; double fullDifficulty = device.Difficulty * DifficultyMuliplier; double secondsToCalcShare = fullDifficulty / hashrate; const double secondsPerDay = 86400; double sharesPerDay = secondsPerDay / secondsToCalcShare; double btcPerDay = sharesPerDay * info.Reward; device.Daily = btcPerDay; } else { //info.Price is in BTC/Ghs/Day device.Daily = info.Price * device.CurrentHashrate / 1000 / 1000; } }; }
public void ToggleNetworkDeviceSticky(DeviceViewModel deviceViewModel, out bool sticky) { NetworkDevices.NetworkDevice deviceConfiguration = NetworkDevicesConfiguration.Devices.Single( cfg => String.Format("{0}:{1}", cfg.IPAddress, cfg.Port).Equals(deviceViewModel.Path)); deviceConfiguration.Sticky = !deviceConfiguration.Sticky; NetworkDevicesConfiguration.SaveNetworkDevicesConfiguration(); sticky = deviceConfiguration.Sticky; }
private void SetupProxyDetails(DeviceViewModel deviceViewModel) { bool visible = false; if (deviceViewModel.Kind == DeviceKind.PXY) { string[] ports = deviceViewModel.Path.Split(':'); if (ports.Length == 2) { string localIPAddress = LocalNetwork.GetLocalIPAddress(); proxyGetworkLabel.Text = String.Format("http://{0}:{1}", localIPAddress, ports[0]); proxyStratumLabel.Text = String.Format("stratum+tcp://{0}:{1}", localIPAddress, ports[1]); visible = true; } } proxyInfoPanel.Visible = visible; if (visible) proxyInfoPanel.BringToFront(); }
public bool RestartNetworkDevice(DeviceViewModel networkDevice) { Uri uri = new Uri("http://" + networkDevice.Path); ApiContext apiContext = new ApiContext(uri.Port, uri.Host); //setup logging apiContext.LogEvent -= LogApiEvent; apiContext.LogEvent += LogApiEvent; string response = apiContext.RestartMining(); bool result = !response.ToLower().Contains("STATUS=E".ToLower()); if (result) networkDevice.LastRestart = DateTime.Now; return result; }
public void InspectDetails(DeviceViewModel deviceViewModel, bool showWorkUtility) { SetupFonts(); noDetailsPanel.Visible = false; hashrateLabel.Text = deviceViewModel.AverageHashrate.ToHashrateString(); currentRateLabel.Text = deviceViewModel.CurrentHashrate.ToHashrateString(); workersGridView.Visible = (deviceViewModel.Workers.Count > 0); workersTitleLabel.Visible = workersGridView.Visible; symbolLabel.Visible = (deviceViewModel.Coin != null) && (deviceViewModel.Coin.Kind == PoolGroup.PoolGroupKind.SingleCoin); SetupProxyDetails(deviceViewModel); SetupNetworkDeviceDetails(deviceViewModel); //device may not be configured if (deviceViewModel.Coin != null) cryptoCoinBindingSource.DataSource = deviceViewModel.Coin; else cryptoCoinBindingSource.DataSource = new PoolGroup(); cryptoCoinBindingSource.ResetBindings(false); deviceBindingSource.DataSource = deviceViewModel; deviceBindingSource.ResetBindings(false); workerBindingSource.DataSource = deviceViewModel.Workers; workerBindingSource.ResetBindings(false); SetupDevicePicture(deviceViewModel); nameLabel.Width = Width - nameLabel.Left - closeDetailsButton.Width; acceptedLabel.Text = deviceViewModel.AcceptedShares.ToString("#,#.###############"); rejectedLabel.Text = deviceViewModel.RejectedShares.ToString("#,#.###############"); errorsLabel.Text = deviceViewModel.HardwareErrors.ToString("#,#.###############"); Binding bestShareBinding = bestShareLabel.DataBindings[0]; if (deviceViewModel.BestShare > 32) bestShareBinding.FormatString = "#,#"; else if (deviceViewModel.BestShare > 1) bestShareBinding.FormatString = "#,#.##"; else bestShareBinding.FormatString = "#,#.######"; if (showWorkUtility) { utilityLabel.Text = deviceViewModel.WorkUtility.ToString("#,#.###"); utilityDataGridViewTextBoxColumn.DataPropertyName = "WorkUtility"; } else { utilityLabel.Text = deviceViewModel.Utility.ToString("#,#.###"); utilityDataGridViewTextBoxColumn.DataPropertyName = "Utility"; } utilityPrefixLabel.Text = showWorkUtility ? "Work utility:" : "Utility:"; if (deviceViewModel.Temperature > 0) tempLabel.Text = deviceViewModel.Temperature + "°"; else tempLabel.Text = String.Empty; if (deviceViewModel.FanPercent > 0) fanLabel.Text = deviceViewModel.FanPercent + "%"; else fanLabel.Text = String.Empty; UpdateColumnVisibility(); }
private static void ApplyCoinInformationToViewModel(List <CoinInformation> coinInformationModels, string coinSymbol, DeviceViewModel deviceViewModel) { CoinInformation coinInformationModel = coinInformationModels.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase)); if (coinInformationModel != null) { ObjectCopier.CopyObject(coinInformationModel, deviceViewModel, "Name", "Exchange"); } else { ClearCoinInformation(deviceViewModel); } }