예제 #1
0
        public ReturnValue Run(string pythonLocationFullPath, string cmd, string args)
        {
            ReturnValue      result = null;
            ProcessStartInfo start  = new ProcessStartInfo();

            // Server ID,Sponsor,Server Name,Timestamp,Distance,Ping,Download,Upload,Share,IP Address
            start.FileName               = pythonLocationFullPath;
            start.Arguments              = string.Format("{0} {1}", cmd, args);
            start.UseShellExecute        = false;
            start.RedirectStandardOutput = true;

            string jsonString = null;

            using (Process process = Process.Start(start))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    jsonString = reader.ReadToEnd();
                }
            }

            try
            {
                SpeedTestData speedTestData = JsonSerializer.Deserialize <SpeedTestData>(jsonString);
                speedTestData.TimeStamp = DateTime.Now;
                result = new ReturnValue(true, speedTestData);
            } catch (Exception ex)
            {
                result = new ReturnValue(false, new SpeedTestData()
                {
                    TimeStamp    = DateTime.Now,
                    ErrorMessage = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message
                });
            }

            return(result);
        }
예제 #2
0
 public ReturnValue(bool isOk, SpeedTestData data)
 {
     this.IsSuccess = isOk;
     this.Data      = data;
 }