Пример #1
0
 private void WriteToBinary(RunInfo info)
 {
     lock (writeLock)
     {
         using (BinaryWriter writer = new BinaryWriter(File.Open(runsFilePath, FileMode.Append)))
         {
             var json = JsonConvert.SerializeObject(info);
             writer.Write(json);
         }
     }
 }
Пример #2
0
 private void LoadNewResult(RunInfo info)
 {
     if (!listBox1.InvokeRequired)
     {
         listBox1.Items.Add(info);
     }
     else
     {
         SafeCallDelegate d = new SafeCallDelegate(LoadNewResult);
         listBox1.Invoke(d, new object[] { info });
     }
 }
Пример #3
0
        public RunInfo Run(int seconds)
        {
            ProcessStartInfo cmd = new ProcessStartInfo
            {
                FileName               = FilePath,
                Arguments              = $"-t {seconds}",
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true
            };

            var process = Process.Start(cmd);
            var reader  = process.StandardOutput;
            var output  = reader.ReadToEndAsync();

            process.WaitForExit();
            RunEnded?.Invoke(this, new EventArgs());
            if (process.ExitCode == 0)
            {
                output.Wait();
                var runInfo = new RunInfo(output.Result, process);
                lock (infoLock)
                {
                    Info.Add(runInfo);
                }
                WriteToBinary(runInfo);
                return(runInfo);
            }
            else
            {
                var runInfo = new RunInfo(process);
                lock (infoLock)
                {
                    Info.Add(runInfo);
                    WriteToBinary(runInfo);
                    var settings = new JsonSerializerSettings {
                        Error = HandleSerializationError
                    };
                    string jsonString = JsonConvert.SerializeObject(process, settings);
                    jsonString += $"\nOutput: {output.Result}";
                    jsonString += errors.ToString();
                    File.WriteAllText(runInfo.CrashLogPath, jsonString);
                    errors.Clear();
                }
                return(runInfo);
            }
        }
Пример #4
0
        private (List <float> time, List <float> speed) CalculateFrames(RunInfo info)
        {
            var frames = info.Frames;

            List <float> time      = new List <float>();
            List <float> delta_ang = new List <float>();
            List <float> speed     = new List <float>();

            time.Add(frames[0].TimeDelta);
            delta_ang.Add(0);
            speed.Add(0);
            for (int i = 1; i < info.Frames.Count; i++)
            {
                time.Add(frames[i].TimeDelta + time[i - 1]);
                var delta = frames[i].RotationAngle - frames[i - 1].RotationAngle;
                if (delta < 0)
                {
                    delta += 360;
                }
                delta_ang.Add(delta);
                speed.Add(delta_ang[i] / frames[i].TimeDelta);
            }
            return(time, speed);
        }