static void LoadInventory(Fougerite.Player player) { JsonAPI json = JsonAPI.GetInstance; User user = Data.Globals.usersOnline.Find(x => x.Name == player.Name); if (user != null) { List <UserInventoryItem> playerItems = json.DeSerializeJsonToObject <List <UserInventoryItem> >(user.InternalInventory); foreach (UserInventoryItem item in playerItems) { if (item != null && item.Name != "" && item.Quantity != -1) { player.Inventory.AddItemTo(item.Name, item.Slot, item.Quantity); Inventory inventory = player.PlayerClient.controllable.GetComponent <Inventory>(); PlayerItem playerItem = new PlayerItem(ref inventory, item.Slot); IInventoryItem dataItem = playerItem.RInventoryItem as IInventoryItem; dataItem.SetCondition(item.Condition); if (playerItem != null) { if (playerItem.isWeapon) { dataItem.SetUses(item.WeaponBullets); playerItem.heldItem.SetTotalModSlotCount(item.WeaponSlots); if (item.WeaponSlot1 != null) { playerItem.addWeaponMod(item.WeaponSlot1); } if (item.WeaponSlot2 != null && item.WeaponSlot2 != "null") { playerItem.addWeaponMod(item.WeaponSlot2); } if (item.WeaponSlot3 != null && item.WeaponSlot3 != "null") { playerItem.addWeaponMod(item.WeaponSlot3); } if (item.WeaponSlot4 != null && item.WeaponSlot4 != "null") { playerItem.addWeaponMod(item.WeaponSlot4); } if (item.WeaponSlot5 != null && item.WeaponSlot5 != "null") { playerItem.addWeaponMod(item.WeaponSlot5); } } } else { Logger.LogError("LoadInventory - playerItem is Null"); } } } } }
public static async Task <Boolean> CheckValidAPIAsync(String apiKey) { if (!CheckAPI(apiKey)) { return(false); } DerpiImage search = await JsonAPI.GetDerpiImageAsync(null, 1, apiKey, false).ConfigureAwait(true); return(search != null && search.total > 0); }
private void PopulateCommonApiData(ref JsonAPI api, ref double divisor) { try { var networkInterface = m_miners.Select(m => m.NetworkInterface).FirstOrDefault(m => m != null); var totalHashRate = 0ul; var hashRateUnit = string.Empty; foreach (var miner in m_miners) { totalHashRate += miner.GetTotalHashrate(); } if (totalHashRate > 0) { GetHashRateUnit(totalHashRate, ref divisor, ref hashRateUnit); } else { GetHashRateUnit((networkInterface?.GetEffectiveHashrate() ?? 0), ref divisor, ref hashRateUnit); } var timeLeftToSolveBlock = networkInterface?.GetTimeLeftToSolveBlock(totalHashRate) ?? TimeSpan.Zero; if (timeLeftToSolveBlock != TimeSpan.Zero) { api.EstimateTimeLeftToSolveBlock = (long)timeLeftToSolveBlock.TotalSeconds; } api.EffectiveHashRate = (float)((networkInterface?.GetEffectiveHashrate() ?? 0) / divisor); api.TotalHashRate = (float)(totalHashRate / divisor); api.HashRateUnit = hashRateUnit; api.MinerAddress = networkInterface.MinerAddress ?? string.Empty; api.MiningURL = networkInterface.SubmitURL ?? string.Empty; if (networkInterface.CurrentChallenge != null) { api.CurrentChallenge = Utils.Numerics.Byte32ArrayToHexString(networkInterface.CurrentChallenge); } api.CurrentDifficulty = networkInterface.Difficulty.Value; api.LastSubmitLatencyMS = networkInterface?.LastSubmitLatency ?? -1; api.LatencyMS = networkInterface?.Latency ?? -1; api.Uptime = (long)(DateTime.Now - Program.LaunchTime).TotalSeconds; api.RejectedShares = m_miners.Select(m => m.NetworkInterface).Distinct().Sum(i => (long)(i.RejectedShares)); api.AcceptedShares = m_miners.Select(m => m.NetworkInterface).Distinct().Sum(i => (long)(i.SubmittedShares)) - api.RejectedShares; } catch (Exception ex) { var errorMessage = string.Empty; var currentEx = ex; while (currentEx != null) { if (!string.IsNullOrEmpty(errorMessage)) { errorMessage += " "; } errorMessage += currentEx.Message; currentEx = currentEx.InnerException; } Program.Print(string.Format("[ERROR] {0}", errorMessage)); } }
private void ProcessApiDataResponse(HttpListenerResponse response) { Task.Factory.StartNew(() => { try { double divisor = 1; var api = new JsonAPI(); PopulateCommonApiData(ref api, ref divisor); foreach (var miner in m_miners) { foreach (var device in miner.Devices.Where(d => d.AllowDevice)) { if (miner.HasMonitoringAPI) { switch (device.Type) { case "CUDA": JsonAPI.CUDA_Miner cudaMiner = null; PopulateCudaApiData((Miner.CUDA)miner, (Miner.Device.CUDA)device, divisor, ref cudaMiner); if (cudaMiner != null) { api.Miners.Add(cudaMiner); } break; case "OpenCL": JsonAPI.AMD_Miner amdMiner = null; PopulateAmdApiData((Miner.OpenCL)miner, (Miner.Device.OpenCL)device, divisor, ref amdMiner); if (amdMiner != null) { api.Miners.Add(amdMiner); } break; } } else { switch (device.Type) { case "OpenCL": JsonAPI.OpenCLMiner openClMiner = null; PopulateOpenCLApiData((Miner.OpenCL)miner, (Miner.Device.OpenCL)device, divisor, ref openClMiner); if (openClMiner != null) { api.Miners.Add(openClMiner); } break; case "CPU": default: JsonAPI.Miner cpuMiner = null; PopulateCpuApiData((Miner.CPU)miner, (Miner.Device.CPU)device, divisor, ref cpuMiner); if (cpuMiner != null) { api.Miners.Add(cpuMiner); } break; } } } } api.Miners.Sort((x, y) => x.PciBusID.CompareTo(y.PciBusID)); byte[] buffer = Encoding.UTF8.GetBytes(Utils.Json.SerializeFromObject(api, Utils.Json.BaseClassFirstSettings)); using (var output = response.OutputStream) { if (buffer != null) { output.Write(buffer, 0, buffer.Length); output.Flush(); } } } catch (Exception ex) { response.StatusCode = (int)HttpStatusCode.InternalServerError; var errorMessage = string.Empty; var currentEx = ex; while (currentEx != null) { if (!string.IsNullOrEmpty(errorMessage)) { errorMessage += " "; } errorMessage += currentEx.Message; currentEx = currentEx.InnerException; } Program.Print(string.Format("[ERROR] {0}", errorMessage)); } finally { try { if (response != null) { response.Close(); } } catch (Exception ex) { var errorMessage = string.Empty; var currentEx = ex; while (currentEx != null) { if (!string.IsNullOrEmpty(errorMessage)) { errorMessage += " "; } errorMessage += currentEx.Message; currentEx = currentEx.InnerException; } Program.Print(string.Format("[ERROR] {0}", errorMessage)); } } }, TaskCreationOptions.LongRunning); }
public void Generate() { // header Output.WriteLine( "<p>This page contains the API documentation for this MPExtended service, as automatically generated on {0} for version {1} (build {2}). " + "Please do not edit, as your changes will be overwritten.</p>", DateTime.Now.ToString("dd MMM yyy HH:mm", System.Globalization.CultureInfo.InvariantCulture), VersionUtil.GetVersion(Assembly), VersionUtil.GetBuildVersion(Assembly)); UserStream.WriteLine("Generating documentation for assembly {0}", Assembly.GetName().Name); // get all items IEnumerable <DocGenItem> typesToDocument = new List <DocGenItem>(); if (JsonAPI != null) { typesToDocument = JsonAPI.GetMethods().Select(x => new DocGenItem() { URLPrefix = "/json", Reflected = x, Name = x.Name, Order = GenerateSortOrder(x.Name) }); } if (StreamAPI != null) { typesToDocument = typesToDocument.Union(StreamAPI.GetMethods().Select(x => new DocGenItem() { URLPrefix = "/stream", Reflected = x, Name = x.Name, Order = GenerateSortOrder(x.Name) })); } if (Enumerations != null) { typesToDocument = typesToDocument.Union(Enumerations.Select(x => new DocGenItem() { URLPrefix = "", Reflected = x, Name = x.Name, Order = GenerateSortOrder(x.Name), })); } // sort all types typesToDocument = typesToDocument .OrderBy(x => x.Order) .ThenBy(x => x.Name); // print navigation int lastOrder = -1; UserStream.WriteLine("=> Generating documentation header"); Output.WriteLine("<h3>Navigation</h3>"); foreach (var item in typesToDocument) { if (lastOrder != item.Order) { if (lastOrder != -1) { Output.WriteLine("</ul>"); } Output.WriteLine("<h4>{0}</h4><ul>", GetHeadings()[item.Order]); lastOrder = item.Order; } Output.WriteLine("<li><a href=\"#{0}\">{0}</a></li>", item.Name); } Output.WriteLine("</ul>"); // generate all documentation lastOrder = -1; foreach (var item in typesToDocument) { if (lastOrder != item.Order) { Output.WriteLine(String.Format("<h3>{0}</h3>", GetHeadings()[item.Order])); lastOrder = item.Order; } if (item.Reflected is MethodInfo) { GenerateMethodDocumentation(item.Reflected as MethodInfo, item.URLPrefix); } else if (item.Reflected is Type) { GenerateEnumDocumentation(item.Reflected as Type); } } UserStream.WriteLine("=> Done"); Output.Flush(); Output.Close(); }
private void Process(HttpListener listener) { listener.Start(); Program.Print(string.Format("[INFO] JSON-API service started at {0}...", listener.Prefixes.ElementAt(0))); while (m_isOngoing) { HttpListenerResponse response = listener.GetContext().Response; var api = new JsonAPI(); float divisor = 0; ulong totalHashRate = 0ul; foreach (var miner in m_miners) { totalHashRate += miner.GetTotalHashrate(); } var sTotalHashRate = totalHashRate.ToString(); if (sTotalHashRate.Length > 12 + 1) { divisor = 1000000000000; api.HashRateUnit = "TH/s"; api.TotalHashRate = totalHashRate / divisor; } else if (sTotalHashRate.Length > 9 + 1) { divisor = 1000000000; api.HashRateUnit = "GH/s"; api.TotalHashRate = totalHashRate / divisor; } else if (sTotalHashRate.Length > 6 + 1) { divisor = 1000000; api.HashRateUnit = "MH/s"; api.TotalHashRate = totalHashRate / divisor; } else if (sTotalHashRate.Length > 3 + 1) { divisor = 1000; api.HashRateUnit = "KH/s"; api.TotalHashRate = totalHashRate / divisor; } foreach (var miner in m_miners) { foreach (var device in miner.Devices.Where(d => d.DeviceID > -1)) { JsonAPI.Miner newMiner = null; if (miner.HasMonitoringAPI) { switch (device.Type) { case "CUDA": { var solver = ((Miner.CUDA)miner).Solver; newMiner = new JsonAPI.CudaMiner() { Type = device.Type, DeviceID = device.DeviceID, ModelName = device.Name, HashRate = miner.GetHashrateByDevice(device.Platform, device.DeviceID) / divisor, HasMonitoringAPI = miner.HasMonitoringAPI, SettingIntensity = device.Intensity, SettingMaxCoreClockMHz = solver.getDeviceSettingMaxCoreClock(device.DeviceID), SettingMaxMemoryClockMHz = solver.getDeviceSettingMaxMemoryClock(device.DeviceID), SettingPowerLimitPercent = solver.getDeviceSettingPowerLimit(device.DeviceID), SettingThermalLimitC = solver.getDeviceSettingThermalLimit(device.DeviceID), SettingFanLevelPercent = solver.getDeviceSettingFanLevelPercent(device.DeviceID), CurrentFanTachometerRPM = solver.getDeviceCurrentFanTachometerRPM(device.DeviceID), CurrentTemperatureC = solver.getDeviceCurrentTemperature(device.DeviceID), CurrentCoreClockMHz = solver.getDeviceCurrentCoreClock(device.DeviceID), CurrentMemoryClockMHz = solver.getDeviceCurrentMemoryClock(device.DeviceID), CurrentUtilizationPercent = solver.getDeviceCurrentUtilizationPercent(device.DeviceID), CurrentPState = solver.getDeviceCurrentPstate(device.DeviceID), CurrentThrottleReasons = solver.getDeviceCurrentThrottleReasons(device.DeviceID) }; } break; case "OpenCL": { var solver = ((Miner.OpenCL)miner).Solver; newMiner = new JsonAPI.AMD_Miner() { Type = device.Type, DeviceID = device.DeviceID, ModelName = device.Name, HashRate = miner.GetHashrateByDevice(device.Platform, device.DeviceID) / divisor, HasMonitoringAPI = miner.HasMonitoringAPI, Platform = device.Platform, SettingIntensity = device.Intensity, SettingMaxCoreClockMHz = solver.getDeviceSettingMaxCoreClock(device.Platform, device.DeviceID), SettingMaxMemoryClockMHz = solver.getDeviceSettingMaxMemoryClock(device.Platform, device.DeviceID), SettingPowerLimitPercent = solver.getDeviceSettingPowerLimit(device.Platform, device.DeviceID), SettingThermalLimitC = solver.getDeviceSettingThermalLimit(device.Platform, device.DeviceID), SettingFanLevelPercent = solver.getDeviceSettingFanLevelPercent(device.Platform, device.DeviceID), CurrentFanTachometerRPM = solver.getDeviceCurrentFanTachometerRPM(device.Platform, device.DeviceID), CurrentTemperatureC = solver.getDeviceCurrentTemperature(device.Platform, device.DeviceID), CurrentCoreClockMHz = solver.getDeviceCurrentCoreClock(device.Platform, device.DeviceID), CurrentMemoryClockMHz = solver.getDeviceCurrentMemoryClock(device.Platform, device.DeviceID), CurrentUtilizationPercent = solver.getDeviceCurrentUtilizationPercent(device.Platform, device.DeviceID) }; } break; } } else { switch (device.Type) { case "OpenCL": newMiner = new JsonAPI.OpenCLMiner() { Type = device.Type, DeviceID = device.DeviceID, ModelName = device.Name, HashRate = miner.GetHashrateByDevice(device.Platform, device.DeviceID) / divisor, HasMonitoringAPI = miner.HasMonitoringAPI, Platform = device.Platform, SettingIntensity = device.Intensity }; break; default: newMiner = new JsonAPI.Miner() { Type = device.Type, DeviceID = device.DeviceID, ModelName = device.Name, HashRate = miner.GetHashrateByDevice(device.Platform, (device.Type == "CPU") ? Array.IndexOf(miner.Devices, device) : device.DeviceID) / divisor, HasMonitoringAPI = miner.HasMonitoringAPI }; break; } } if (newMiner != null) { api.Miners.Add(newMiner); } } } byte[] buffer = Encoding.UTF8.GetBytes(Utils.Json.SerializeFromObject(api, Utils.Json.BaseClassFirstSettings)); response.ContentLength64 = buffer.Length; using (var output = response.OutputStream) if (buffer != null) { output.Write(buffer, 0, buffer.Length); } response.Close(); } }
private void Process(HttpListener listener) { listener.Start(); Program.Print(string.Format("[INFO] JSON-API service started at {0}...", listener.Prefixes.ElementAt(0))); while (m_isOngoing) { HttpListenerResponse response = listener.GetContext().Response; var api = new JsonAPI(); float divisor = 1; ulong totalHashRate = 0ul; foreach (var miner in m_miners) { totalHashRate += miner.GetTotalHashrate(); } var sTotalHashRate = totalHashRate.ToString(); if (sTotalHashRate.Length > 12 + 1) { divisor = 1000000000000; api.HashRateUnit = "TH/s"; } else if (sTotalHashRate.Length > 9 + 1) { divisor = 1000000000; api.HashRateUnit = "GH/s"; } else if (sTotalHashRate.Length > 6 + 1) { divisor = 1000000; api.HashRateUnit = "MH/s"; } else if (sTotalHashRate.Length > 3 + 1) { divisor = 1000; api.HashRateUnit = "KH/s"; } var networkInterface = m_miners.Select(m => m.NetworkInterface).FirstOrDefault(m => m != null); api.EffectiveHashRate = (networkInterface?.GetEffectiveHashrate() ?? 0f) / divisor; api.TotalHashRate = totalHashRate / divisor; api.MinerAddress = networkInterface.MinerAddress ?? string.Empty; api.MiningURL = networkInterface.SubmitURL ?? string.Empty; api.CurrentChallenge = networkInterface.CurrentChallenge ?? string.Empty; api.CurrentDifficulty = networkInterface.Difficulty; api.LastSubmitLatencyMS = networkInterface?.LastSubmitLatency ?? -1; api.LatencyMS = networkInterface?.Latency ?? -1; api.Uptime = (long)(DateTime.Now - Program.LaunchTime).TotalSeconds; api.RejectedShares = m_miners.Select(m => m.NetworkInterface).Distinct().Sum(i => (long)(i.RejectedShares)); api.AcceptedShares = m_miners.Select(m => m.NetworkInterface).Distinct().Sum(i => (long)(i.SubmittedShares)) - api.RejectedShares; foreach (var miner in m_miners) { foreach (var device in miner.Devices.Where(d => d.AllowDevice)) { JsonAPI.Miner newMiner = null; if (miner.HasMonitoringAPI) { switch (device.Type) { case "CUDA": { var tempValue = 0; var tempSize = 0ul; var tempStr = new StringBuilder(1024); var instancePtr = ((Miner.CUDA)miner).m_instance; newMiner = new JsonAPI.CUDA_Miner() { Type = device.Type, DeviceID = device.DeviceID, PciBusID = device.PciBusID, ModelName = device.Name, HashRate = miner.GetHashrateByDevice(device.Platform, device.DeviceID) / divisor, HasMonitoringAPI = miner.HasMonitoringAPI, SettingIntensity = device.Intensity }; if (((Miner.CUDA)miner).UseNvSMI) { ((JsonAPI.CUDA_Miner)newMiner).SettingMaxCoreClockMHz = -1; ((JsonAPI.CUDA_Miner)newMiner).SettingMaxMemoryClockMHz = -1; tempValue = Miner.API.NvSMI.GetDeviceSettingPowerLimit(device.PciBusID); ((JsonAPI.CUDA_Miner)newMiner).SettingPowerLimitPercent = tempValue; tempValue = Miner.API.NvSMI.GetDeviceSettingThermalLimit(device.PciBusID); ((JsonAPI.CUDA_Miner)newMiner).SettingThermalLimitC = tempValue; tempValue = Miner.API.NvSMI.GetDeviceSettingFanLevelPercent(device.PciBusID); ((JsonAPI.CUDA_Miner)newMiner).SettingFanLevelPercent = tempValue; ((JsonAPI.CUDA_Miner)newMiner).CurrentFanTachometerRPM = -1; tempValue = Miner.API.NvSMI.GetDeviceCurrentTemperature(device.PciBusID); ((JsonAPI.CUDA_Miner)newMiner).CurrentTemperatureC = tempValue; tempValue = Miner.API.NvSMI.GetDeviceCurrentCoreClock(device.PciBusID); ((JsonAPI.CUDA_Miner)newMiner).CurrentCoreClockMHz = tempValue; tempValue = Miner.API.NvSMI.GetDeviceCurrentMemoryClock(device.PciBusID); ((JsonAPI.CUDA_Miner)newMiner).CurrentMemoryClockMHz = tempValue; tempValue = Miner.API.NvSMI.GetDeviceCurrentUtilizationPercent(device.PciBusID); ((JsonAPI.CUDA_Miner)newMiner).CurrentUtilizationPercent = tempValue; tempValue = Miner.API.NvSMI.GetDeviceCurrentPstate(device.PciBusID); ((JsonAPI.CUDA_Miner)newMiner).CurrentPState = tempValue; tempStr.Append(Miner.API.NvSMI.GetDeviceCurrentThrottleReasons(device.PciBusID)); ((JsonAPI.CUDA_Miner)newMiner).CurrentThrottleReasons = tempStr.ToString(); } else { Miner.CUDA.Solver.GetDeviceSettingMaxCoreClock(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).SettingMaxCoreClockMHz = tempValue; Miner.CUDA.Solver.GetDeviceSettingMaxMemoryClock(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).SettingMaxMemoryClockMHz = tempValue; Miner.CUDA.Solver.GetDeviceSettingPowerLimit(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).SettingPowerLimitPercent = tempValue; Miner.CUDA.Solver.GetDeviceSettingThermalLimit(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).SettingThermalLimitC = tempValue; Miner.CUDA.Solver.GetDeviceSettingFanLevelPercent(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).SettingFanLevelPercent = tempValue; Miner.CUDA.Solver.GetDeviceCurrentFanTachometerRPM(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).CurrentFanTachometerRPM = tempValue; Miner.CUDA.Solver.GetDeviceCurrentTemperature(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).CurrentTemperatureC = tempValue; Miner.CUDA.Solver.GetDeviceCurrentCoreClock(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).CurrentCoreClockMHz = tempValue; Miner.CUDA.Solver.GetDeviceCurrentMemoryClock(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).CurrentMemoryClockMHz = tempValue; Miner.CUDA.Solver.GetDeviceCurrentUtilizationPercent(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).CurrentUtilizationPercent = tempValue; Miner.CUDA.Solver.GetDeviceCurrentPstate(instancePtr, device.DeviceID, ref tempValue); ((JsonAPI.CUDA_Miner)newMiner).CurrentPState = tempValue; Miner.CUDA.Solver.GetDeviceCurrentThrottleReasons(instancePtr, device.DeviceID, tempStr, ref tempSize); ((JsonAPI.CUDA_Miner)newMiner).CurrentThrottleReasons = tempStr.ToString(); } } break; case "OpenCL": { var tempValue = 0; var tempStr = new StringBuilder(1024); var instancePtr = ((Miner.OpenCL)miner).m_instance; newMiner = new JsonAPI.AMD_Miner() { Type = device.Type, DeviceID = device.DeviceID, PciBusID = device.PciBusID, ModelName = device.Name, HashRate = miner.GetHashrateByDevice(device.Platform, device.DeviceID) / divisor, HasMonitoringAPI = miner.HasMonitoringAPI, Platform = device.Platform, SettingIntensity = device.Intensity }; if (((Miner.OpenCL)miner).UseLinuxQuery) { ((JsonAPI.AMD_Miner)newMiner).SettingMaxCoreClockMHz = -1; ((JsonAPI.AMD_Miner)newMiner).SettingMaxMemoryClockMHz = -1; ((JsonAPI.AMD_Miner)newMiner).SettingPowerLimitPercent = -1; ((JsonAPI.AMD_Miner)newMiner).SettingThermalLimitC = int.MinValue; ((JsonAPI.AMD_Miner)newMiner).SettingFanLevelPercent = Miner.API.AmdLinuxQuery.GetDeviceSettingFanLevelPercent(device.PciBusID); ((JsonAPI.AMD_Miner)newMiner).CurrentFanTachometerRPM = Miner.API.AmdLinuxQuery.GetDeviceCurrentFanTachometerRPM(device.PciBusID); ((JsonAPI.AMD_Miner)newMiner).CurrentTemperatureC = Miner.API.AmdLinuxQuery.GetDeviceCurrentTemperature(device.PciBusID); ((JsonAPI.AMD_Miner)newMiner).CurrentCoreClockMHz = Miner.API.AmdLinuxQuery.GetDeviceCurrentCoreClock(device.PciBusID); ((JsonAPI.AMD_Miner)newMiner).CurrentMemoryClockMHz = Miner.API.AmdLinuxQuery.GetDeviceCurrentCoreClock(device.PciBusID); ((JsonAPI.AMD_Miner)newMiner).CurrentUtilizationPercent = Miner.API.AmdLinuxQuery.GetDeviceCurrentUtilizationPercent(device.PciBusID); } else { Miner.OpenCL.Solver.GetDeviceSettingMaxCoreClock(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).SettingMaxCoreClockMHz = tempValue; Miner.OpenCL.Solver.GetDeviceSettingMaxMemoryClock(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).SettingMaxMemoryClockMHz = tempValue; Miner.OpenCL.Solver.GetDeviceSettingPowerLimit(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).SettingPowerLimitPercent = tempValue; Miner.OpenCL.Solver.GetDeviceSettingThermalLimit(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).SettingThermalLimitC = tempValue; Miner.OpenCL.Solver.GetDeviceSettingFanLevelPercent(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).SettingFanLevelPercent = tempValue; Miner.OpenCL.Solver.GetDeviceCurrentFanTachometerRPM(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).CurrentFanTachometerRPM = tempValue; Miner.OpenCL.Solver.GetDeviceCurrentTemperature(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).CurrentTemperatureC = tempValue; Miner.OpenCL.Solver.GetDeviceCurrentCoreClock(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).CurrentCoreClockMHz = tempValue; Miner.OpenCL.Solver.GetDeviceCurrentMemoryClock(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).CurrentMemoryClockMHz = tempValue; Miner.OpenCL.Solver.GetDeviceCurrentUtilizationPercent(instancePtr, new StringBuilder(device.Platform), device.DeviceID, ref tempValue); ((JsonAPI.AMD_Miner)newMiner).CurrentUtilizationPercent = tempValue; } } break; } } else { switch (device.Type) { case "OpenCL": newMiner = new JsonAPI.OpenCLMiner() { Type = device.Type, DeviceID = device.DeviceID, ModelName = device.Name, HashRate = miner.GetHashrateByDevice(device.Platform, device.DeviceID) / divisor, HasMonitoringAPI = miner.HasMonitoringAPI, Platform = device.Platform, SettingIntensity = device.Intensity }; break; default: newMiner = new JsonAPI.Miner() { Type = device.Type, DeviceID = device.DeviceID, ModelName = device.Name, HashRate = miner.GetHashrateByDevice(device.Platform, (device.Type == "CPU") ? Array.IndexOf(miner.Devices, device) : device.DeviceID) / divisor, HasMonitoringAPI = miner.HasMonitoringAPI }; break; } } if (newMiner != null) { api.Miners.Add(newMiner); } } } api.Miners.Sort((x, y) => x.PciBusID.CompareTo(y.PciBusID)); byte[] buffer = Encoding.UTF8.GetBytes(Utils.Json.SerializeFromObject(api, Utils.Json.BaseClassFirstSettings)); response.ContentLength64 = buffer.Length; using (var output = response.OutputStream) if (buffer != null) { output.Write(buffer, 0, buffer.Length); } response.Close(); } }
private async Task <DerpiImage> GetPageAsync(Int32 page) { try { const Int32 maximumCounts = 10; const Int32 waitDelay = 30000; Int32 count = 0; do { using CancellationTokenSource source = new CancellationTokenSource(); CancellationToken token = source.Token; if (_token.IsCancellationRequested) { source.Cancel(); } await WaitAsync(token).ConfigureAwait(true); token.ThrowIfCancellationRequested(); Task <DerpiImage> pageTask = JsonAPI.GetDerpiImageAsync(SearchQuery, page, token: token); try { if (await Task.WhenAny(pageTask, Task.Delay(waitDelay, token)).ConfigureAwait(true) == pageTask) { DerpiImage derpiImage = await pageTask.ConfigureAwait(true); try { pageTask.Dispose(); } catch (InvalidOperationException) { //ignored } return(derpiImage); } } catch (TaskCanceledException) { //ignored } Log.Add(new LogMessage(Globals.Localization.PageWaitToLongRetry, MessageType.Warning, new[] { page.ToString() })); source.Cancel(); try { pageTask.Dispose(); } catch (InvalidOperationException) { //ignored } count++; } while (count < maximumCounts); Log.Add(new LogMessage(Globals.Localization.GetPageError, MessageType.CriticalWarning, new[] { page.ToString() })); return(null); } catch (OperationCanceledException) { return(null); } }
private async Task GenerateTasksAsync() { Task[] tasks = new Task[ImagesPerPage]; DerpiImage nextPage = new DerpiImage(); for (Int32 page = _firstPageNumber; page <= Pages; page++) { if (page == _firstPageNumber) { await Task.Delay(2000, _token).ConfigureAwait(true); } await WaitAsync(_token).ConfigureAwait(true); Task <DerpiImage> nextPageTask = null; if (_token.IsCancellationRequested) { return; } if (page < Pages) { nextPageTask = GetPageAsync(page + 1); } DerpiImage derpiPage = page == _firstPageNumber ? _firstPage : nextPage; if (nextPage == null) { if (nextPageTask != null) { nextPage = await nextPageTask.ConfigureAwait(true); } continue; } for (Int32 index = 0; index < derpiPage.images.Count; index++) { if (IsInvalid || _token.IsCancellationRequested) { return; } Image image = derpiPage.images[index]; while (image?.duplicate_of != null) { Log.Add(new LogMessage("Image id:{0} duplicate of id:{1}", MessageType.Warning, new[] { image.id.ToString(), image.duplicate_of.ToString() })); try { image = (await JsonAPI.GetDerpiImageAsync($"id:{image.duplicate_of}", token: _token).ConfigureAwait(true)).images[0]; } catch (IndexOutOfRangeException) { Log.Add(new LogMessage(Globals.Localization.CantFoundDuplicateImage, MessageType.Warning)); } } if (image == null) { continue; } ImageDataSupplement(image); tasks[index] = DownloadImageAsync(image); } await Task.WhenAll(tasks).ConfigureAwait(true); if (page >= Pages) { continue; } if (nextPageTask != null) { nextPage = await nextPageTask.ConfigureAwait(true); } } IsCompleted = true; }
private void PopulateCommonApiData(ref JsonAPI api, ref float divisor) { try { ulong totalHashRate = 0ul; foreach (var miner in m_miners) { totalHashRate += miner.GetTotalHashrate(); } var sTotalHashRate = totalHashRate.ToString(); if (sTotalHashRate.Length > 12 + 1) { divisor = 1000000000000; api.HashRateUnit = "TH/s"; } else if (sTotalHashRate.Length > 9 + 1) { divisor = 1000000000; api.HashRateUnit = "GH/s"; } else if (sTotalHashRate.Length > 6 + 1) { divisor = 1000000; api.HashRateUnit = "MH/s"; } else if (sTotalHashRate.Length > 3 + 1) { divisor = 1000; api.HashRateUnit = "KH/s"; } var networkInterface = m_miners.Select(m => m.NetworkInterface).FirstOrDefault(m => m != null); var timeLeftToSolveBlock = networkInterface?.GetTimeLeftToSolveBlock(totalHashRate) ?? TimeSpan.Zero; if (timeLeftToSolveBlock != TimeSpan.Zero) { api.EstimateTimeLeftToSolveBlock = (long)timeLeftToSolveBlock.TotalSeconds; } api.EffectiveHashRate = (networkInterface?.GetEffectiveHashrate() ?? 0f) / divisor; api.TotalHashRate = totalHashRate / divisor; api.MinerAddress = networkInterface.MinerAddress ?? string.Empty; api.MiningURL = networkInterface.SubmitURL ?? string.Empty; api.CurrentChallenge = networkInterface.CurrentChallenge ?? string.Empty; api.CurrentDifficulty = networkInterface.Difficulty; api.LastSubmitLatencyMS = networkInterface?.LastSubmitLatency ?? -1; api.LatencyMS = networkInterface?.Latency ?? -1; api.Uptime = (long)(DateTime.Now - Program.LaunchTime).TotalSeconds; api.RejectedShares = m_miners.Select(m => m.NetworkInterface).Distinct().Sum(i => (long)(i.RejectedShares)); api.AcceptedShares = m_miners.Select(m => m.NetworkInterface).Distinct().Sum(i => (long)(i.SubmittedShares)) - api.RejectedShares; } catch (Exception ex) { var errorMessage = string.Empty; var currentEx = ex; while (currentEx != null) { if (!string.IsNullOrEmpty(errorMessage)) { errorMessage += " "; } errorMessage += currentEx.Message; currentEx = currentEx.InnerException; } Program.Print(string.Format("[ERROR] {0}", errorMessage)); } }