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;
            }
        }
Example #2
0
        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);
     }
 }
Example #4
0
 public static void ExecuteCommand(string command)
 {
     if (IsLinux())
     {
         ExecuteCommandForLinux(command);
     }
     else if (IsWindows())
     {
         ExecuteCommandForWindows("");
     }
     else if (IsMac())
     {
         ExecuteCommandForMac("");
     }
     else
     {
         NotificationsHelper.DisplayMessage(Messages.OsNotDetected);
     }
 }
Example #5
0
 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));
        }