Ejemplo n.º 1
0
        public void Run()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("using CodeRank.CSharpProblems.Ruleset.Base;");
            sb.Append("namespace CodeRank.CSharpProblems.Ruleset.Solution");
            sb.Append("{");
            sb.Append("public class SampleTestRuleSolution : ISampleTest");
            sb.Append("{");
            sb.Append("public int Sum(int a, int b)");
            sb.Append("{");
            sb.Append("return a + b;");
            sb.Append("}");
            sb.Append("}");
            sb.Append("}");

            CompilerEngine engine = new CompilerEngine();
            var response = engine.Compile(new CompileArgs { SourceCode = sb.ToString() });

            string pathToDlls = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            var assemblyFilePath = Path.Combine(pathToDlls, response.AssemblyFileName);

            Console.WriteLine(AppDomain.CurrentDomain.FriendlyName);
            AppDomain.CurrentDomain.Load(response.LoadedStream.ToArray());

            CoreExtensions.Host.InstallBuiltins();

            var runner = new InMemoryNunitTestRunner().RunTests(new TestRunRequest { TestAssembly = Assembly.Load("CodeRank.CSharpProblems.Ruleset"), SourceAssemblyStream = response.LoadedStream });

            Console.WriteLine(runner);
            Console.Read();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The compile operation to compile the requested code unit.
        /// </summary>
        /// <param name="compileRequest">
        /// The compile request.
        /// </param>
        /// <returns>
        /// The <see cref="CompileResponse"/>.
        /// </returns>
        public CompileResponse Compile(CompileRequest compileRequest)
        {
            // TODO: Future version execution
            /*
            FlowRequirement requirement = new FlowRequirement(compileRequest.SourceCode);
            ExecutionFlowBuilder.Build().Execute(ContextProvider.Context, requirement);
             * */

            ICompiler csharpCompiler = new CompilerEngine();
            CompileArgs arguments = new CompileArgs { SourceCode = compileRequest.SourceCode };

            var result = csharpCompiler.Compile(arguments);

            return new CompileResponse { CompileResult = result };
        }