Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 6
0
        private static void HandleDownloadProgress(object sender, DownloadProgressChangedEventArgs eventArgs)
        {
            var percentage = Math.Round(eventArgs.BytesReceived / (float)eventArgs.TotalBytesToReceive * 100);

            NotificationsHelper.DisplayDynamicMessage(Messages.DownloadProgress(percentage));
        }