Ejemplo n.º 1
0
        public override RuntimeInfo ExecuteProgram(RuntimeInfo ri)
        {
            _output.Clear();
            var       stream = _process.StandardOutput.BaseStream;
            int       ch;
            Stopwatch sw = Stopwatch.StartNew();

            while ((ch = stream.ReadByte()) > 0)
            {
                _output.Append((char)ch);
            }
            sw.Stop();
            if (ch == -1)
            {
                ri.Success = false;
                Console.WriteLine("Stdout finished, waiting for process exit...");
                _process.WaitForExit();
                Console.WriteLine($"Exit code: {_process.ExitCode}");
                Console.WriteLine(_process.StandardError.ReadToEnd());
                _startProcess();
            }
            else
            {
                ri.Success = true;
            }
            ri.Output  = _output.ToString();
            ri.Runtime = sw.Elapsed.TotalSeconds;
            return(ri);
        }
Ejemplo n.º 2
0
        public RuntimeInfo ExecuteProgram(RuntimeInfo ri)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:" + _port);

            request.KeepAlive = false;
            request.Timeout   = 15000;
            request.Method    = "POST";
            Stream reqStream = request.GetRequestStream();

            reqStream.Write(_programStream.GetBuffer(), 0, (int)_programStream.Length);
            reqStream.Close();
            WebResponse response = request.GetResponse();

            ri.Success = bool.Parse(response.Headers.Get("X-Success"));
            ri.Runtime = double.Parse(response.Headers.Get("X-Execution-Time"), CultureInfo.InvariantCulture);
            if (ri.Success)
            {
                var xcc = response.Headers.Get("X-Complexity-Cyclomatic");
                if (xcc != null)
                {
                    ri.CyclomaticComplexity = int.Parse(xcc);
                }
                var xch = response.Headers.Get("X-Complexity-Halstead");
                if (xch != null)
                {
                    ri.HalsteadDifficulty = double.Parse(xch, CultureInfo.InvariantCulture);
                }
            }
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                ri.Output = reader.ReadToEnd();
            }
            return(ri);
        }
Ejemplo n.º 3
0
 public abstract RuntimeInfo ExecuteProgram(RuntimeInfo ri);