public static void WaitForDecentInternetConnection(double minimumInternetSpeed, int goodPings, int minimumGoodPings, int waitingTime) { while (true) { if (goodPings >= 0) { double myConnectionSpeed; do { myConnectionSpeed = CheckInternetSpeed(); if (!(myConnectionSpeed < minimumInternetSpeed)) { continue; } goodPings = minimumGoodPings; NotificationsHelper.DisplayDynamicMessage(Messages.WaitForBetterInternet(myConnectionSpeed)); ThreadsHelper.Sleep(waitingTime); } while (myConnectionSpeed < minimumInternetSpeed); goodPings--; continue; } break; } }
private static void StartProcessWithResult(Process process) { var result = string.Empty; process.Start(); result += process.StandardOutput.ReadToEnd(); result += process.StandardError.ReadToEnd(); process.WaitForExit(); NotificationsHelper.DisplayMessage(Messages.DisplayProcessExecutionResult(result)); }
private static double CheckInternetSpeed() { try { var timeBeforeDownloadingFile = DateTime.Now; var data = WebClient.DownloadData("http://google.com"); var timeAfterDownloadingFile = DateTime.Now; return(Math.Round( data.Length / 1024.0 / (timeAfterDownloadingFile - timeBeforeDownloadingFile).TotalSeconds, 2)); } catch { NotificationsHelper.DisplayMessage(Messages.NoInternet); return(0d); } }
public static void ExecuteCommand(string command) { if (IsLinux()) { ExecuteCommandForLinux(command); } else if (IsWindows()) { ExecuteCommandForWindows(""); } else if (IsMac()) { ExecuteCommandForMac(""); } else { NotificationsHelper.DisplayMessage(Messages.OsNotDetected); } }
public static void Sleep() { if (!CommandsHelper.ShouldSleep()) { return; } if (IsLinux()) { ExecuteCommandForLinux("systemctl suspend"); } else if (IsWindows()) { ExecuteCommandForWindows(""); } else if (IsMac()) { ExecuteCommandForMac(""); } else { NotificationsHelper.DisplayMessage(Messages.OsNotDetected); } }
private static void HandleDownloadProgress(object sender, DownloadProgressChangedEventArgs eventArgs) { var percentage = Math.Round(eventArgs.BytesReceived / (float)eventArgs.TotalBytesToReceive * 100); NotificationsHelper.DisplayDynamicMessage(Messages.DownloadProgress(percentage)); }