Esempio n. 1
0
        public void Submit(Problem problem)
        {
            string sourcePath = view.ReadString("Программаның файлы орналасқан адресті жазыңыз немесе тышқанмен сүйреп әкеліңіз\n", ConsoleColor.Green);

            if (!File.Exists(sourcePath))
            {
                view.ShowError("Файл табылмады!");
                return;
            }

            string             sourceText   = File.ReadAllText(sourcePath);
            CSharpCodeProvider codeProvider = new CSharpCodeProvider();
            ICodeCompiler      icc          = codeProvider.CreateCompiler();

            CompilerParameters parameters = new CompilerParameters();

            parameters.GenerateExecutable = true;
            parameters.OutputAssembly     = "test.exe";
            CompilerResults results = icc.CompileAssemblyFromSource(parameters, sourceText);

            Attempt attempt = model.AddAttemption(CurrentUser, problem);

            if (results.Errors.HasErrors)
            {
                view.Print("Компиляция барысында қате шықты!\n", ConsoleColor.Red);
                attempt.Verdict = Verdict.Complation_error;
            }
            else
            {
                RunSolution(problem, results.PathToAssembly, ref attempt);
            }
            model.Attempts.Add(attempt);
            ReadKey();
        }
Esempio n. 2
0
        public void Submit(Problem problem)
        {
            string sourcePath =
                view.ReadString("Программаның файлы орналасқан адресті жазыңыз немесе тышқанмен сүйреп әкеліңіз\n",
                                ConsoleColor.Green);

            sourcePath = sourcePath.Trim('\'', '\"');
            if (!File.Exists(sourcePath))
            {
                view.ShowError("Файл табылмады!");
                return;
            }

            Attempt attempt = model.AddAttemption(CurrentUser, problem);

            Thread thread = new Thread(o =>
            {
                compiler.Sumbit(attempt, problem, sourcePath);
                // әрбір жіберілген попыткаларды базада сақтау
                model.AppContext.SaveChanges();
            });

            thread.Start();
            UserAttemptsPage();
        }
Esempio n. 3
0
        public void Submit(Problem problem)
        {
            string sourcePath =
                view.ReadString("Программаның файлы орналасқан адресті жазыңыз немесе тышқанмен сүйреп әкеліңіз\n",
                                ConsoleColor.Green);

            sourcePath = sourcePath.Trim(new[] { '\'', '\"' });
            if (!File.Exists(sourcePath))
            {
                view.ShowError("Файл табылмады!");
                return;
            }

            var syntaxTree    = SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(sourcePath)));
            var assemblyPath  = "test.exe";
            var dotNetCoreDir = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location);
            var compilation   = CSharpCompilation.Create(Path.GetFileName(assemblyPath))
                                .WithOptions(new CSharpCompilationOptions(OutputKind.ConsoleApplication)).AddReferences(
                MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location),
                MetadataReference.CreateFromFile(typeof(Console).GetTypeInfo().Assembly.Location),
                MetadataReference.CreateFromFile(Path.Combine(dotNetCoreDir, "System.Runtime.dll")))
                                .AddSyntaxTrees(syntaxTree);
            var result = compilation.Emit(assemblyPath);

            File.WriteAllText(Path.ChangeExtension(assemblyPath, "runtimeconfig.json"), GenerateRuntimeConfig());
            Attempt attempt = model.AddAttemption(CurrentUser, problem);

            if (!result.Success)
            {
                view.Print("Компиляция барысында қате шықты!\n", ConsoleColor.Red);
                attempt.Verdict = Verdict.Complation_error;
            }
            else
            {
                RunSolution(problem, assemblyPath, ref attempt);
            }

            model.AppContext.SaveChanges(); // әрбір жіберілген попыткаларды базада сақтау
            // TODO: model.Attempts.Add(attempt);
        }