Beispiel #1
0
    protected void Submit_Click(object sender, EventArgs e)
    {
        code             = Code.Text;
        selectedLanguage = LanguageSelection.SelectedValue;
        int.TryParse(TextBox1.Text, out problemID);
        Common c = new Common();

        c.openConnection();
        string        query = "select input,output from problems where Id=" + problemID;
        SqlDataReader data  = c.executeReader(query);

        data.Read();
        input          = data.GetString(0);
        expectedOutput = data.GetString(1);
        data.Close();
        codeRun = new CodeRunner(selectedLanguage, code, input);
        codeRun.runCode();
        System.Threading.Thread.Sleep(15000);
        output      = codeRun.getOutput();
        Output.Text = "Output:\n" + output + "\n\nResult: ";
        if (output.Equals(expectedOutput))
        {
            Output.Text += "Accepted";
        }
        else
        {
            Output.Text += "Wrong Answer";
        }
        c.closeConnection();
    }
Beispiel #2
0
 public void It_returns_null_if_there_is_no_assembly_or_diagnostics()
 {
     using (var consoleState = new PreserveConsoleState())
     {
         var runRequest     = new WasmCodeRunnerRequest();
         var interopMessage = new InteropMessage <WasmCodeRunnerRequest>(0, runRequest);
         var text           = JObject.FromObject(interopMessage).ToString();
         CodeRunner.ProcessRunRequest(text).Should().Be(null);
         consoleState.OutputIsRedirected.Should().BeFalse();
     }
 }
        public void TimeoutLoggedTest()
        {
            // Arrange
            var        log    = new Mock <IExceptionLogger>();
            CodeRunner runner = new CodeRunner(log.Object);
            string     code   = GetUsings(new string[] { "System" })
                                .Append(WrapInMain(@"while(true) {}")).ToString();

            // Act
            Exception e = Assert.ThrowsAsync(typeof(TimeoutException), () =>
                                             runner.CompileAndRunAsync(code));

            // Assert
            log.Verify(l => l.LogException(e, code));
        }
        public void CompilerErrorNotLoggedTest()
        {
            // Arrange
            var        log    = new Mock <IExceptionLogger>();
            CodeRunner runner = new CodeRunner(log.Object);
            string     code   = GetUsings(new string[] { "System" })
                                .Append(WrapInMain(@"int i")).ToString();

            // Act
            Exception e = Assert.ThrowsAsync(typeof(CompilationErrorException), () =>
                                             runner.CompileAndRunAsync(code));

            // Assert
            log.Verify(l => l.LogException(It.IsAny <Exception>(), It.IsAny <string>()), Times.Never());
        }
Beispiel #5
0
        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();

            Code   = @"using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(""Hello World!"");
        }
    }
}";
            runner = new CodeRunner(s => Logger.LogInformation(s));
        }
Beispiel #6
0
        private void ExecuteMigrationCode(string migrationFile)
        {
            //pull the whole code bits in - we're going to compile this to code
            //and execute it :):):):)
            string migrationCode = Files.GetFileText(migrationFile);

            //get the extension
            string        codeExtension = Path.GetExtension(migrationFile);
            ICodeLanguage codeLang      = new CSharpCodeLanguage();

            if (codeExtension.EndsWith(FileExtension.VB, StringComparison.InvariantCultureIgnoreCase))
            {
                codeLang = new VBCodeLanguage();
            }

            object[] parameters = new object[2];
            parameters[0] = providerName;
            parameters[1] = direction;
            CodeRunner.RunAndExecute(codeLang, migrationCode, "Migrate", parameters);
        }
 private void createCodeRunner(string language)
 {
     switch (language.ToLower())
     {
         case "csharp":
             _codeRunner = CodeRunnerFactory.CreateRunner(RunnerType.CSharp, _variableRetriver);
             break;
         default:
             throw new LanguageNotImplementedException(language + " is not implemented.");
     }
 }