Exemple #1
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);
            }
        }
Exemple #2
0
        } // OnUnexpectedHeaderVersionReceived

        private void OnRunEnded()
        {
            if (RunEnded == null)
            {
                return;
            }

            var args = new RunEndedEventArgs()
            {
                PayloadId            = _lastHeader.PayloadId,
                ReceivedPayloadBytes = _receivedPayloadBytes,
                SegmentId            = _lastHeader.SegmentId,
                LastSectionNumber    = _lastHeader.LastSectionNumber,
                SegmentVersion       = _lastHeader.SegmentVersion,
                StartSectionNumber   = _startSectionNumber,
                EndSectionNumber     = _lastHeader.SectionNumber,
                TotalSegmentSize     = _lastHeader.TotalSegmentSize,
            };

            RunEnded?.Invoke(this, args);
        } // OnRunEnded