public async void PushBenchmarkResults() { Logger.Log.Info("Sending benchmark result"); try { BenchmarkResults.Clear(); using var client = new HttpClient(); var version = Assembly.GetExecutingAssembly().GetName().Version; client.DefaultRequestHeaders.Add("User-Agent", $"FloatTool/{App.VersionCode}"); string paramedURL = $"/AddBenchmark.php?cpu={CurrentCpuName}&threads={ThreadCount}&multicore={MultithreadedSpeed}&singlecore={SinglethreadedSpeed}"; HttpResponseMessage response = await client.GetAsync(Utils.API_URL + paramedURL); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); Logger.Log.Info("Sended benchmark result"); } catch (Exception ex) { Logger.Log.Error("Error sending benchmark result", ex); } CanPublish = false; PollBenchmarkResults(); }
public async void PollBenchmarkResults() { Logger.Log.Info("Getting benchmark results"); IsUpdatingEnabled = false; try { BenchmarkResults.Clear(); using var client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(Utils.API_URL + "/LoadBenchmarks.php"); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); dynamic result = JsonConvert.DeserializeObject(responseBody); if (result["status"] == 200 && result["count"] > 0) { float maxspeed = result.items[0].multithread; foreach (var benchmark in result.items) { float percentage = (float)benchmark.multithread / maxspeed; float reverse = 1 - percentage; string cpuName = Utils.ShortCpuName((string)benchmark.name); var currentFill = AMDBrush; if (cpuName == CurrentCpuName) { currentFill = CurrentBrush; MultithreadedSpeed = Math.Max((int)benchmark.multithread, MultithreadedSpeed); SinglethreadedSpeed = Math.Max((int)benchmark.singlethread, SinglethreadedSpeed); } else if (cpuName.StartsWith("Intel")) { currentFill = IntelBrush; } string threadsString = Application.Current.Resources["m_Threads"] as string; if ((int)benchmark.threads == 1) { threadsString = Application.Current.Resources["m_Thread"] as string; } BenchmarkResults.Add(new BenchmarkResult { CpuName = cpuName, ThreadCount = $"{benchmark.threads} {threadsString} [{benchmark.version}]", MultithreadedScore = $"{(int)benchmark.multithread:n0}", SinglethreadedScore = $"{(int)benchmark.singlethread:n0}", FillSize = new GridLength(percentage, GridUnitType.Star), EmptySize = new GridLength(reverse, GridUnitType.Star), FillBrush = currentFill }); } } Logger.Log.Info("Benchmark results loaded"); } catch (Exception ex) { BenchmarkResults.Add(new BenchmarkResult { CpuName = "Error loading benchmark table.", FillSize = new GridLength(0, GridUnitType.Star), EmptySize = new GridLength(1, GridUnitType.Star), }); Logger.Log.Error("Error getting benchmark results", ex); } IsUpdatingEnabled = true; }