Пример #1
0
 public TaskController(IBlInterface service)
 {
     _tasksManager = service;
     path          = new ConfigurationPaths()
     {
         CompilerPath = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools",
         FolderPath   = @".\TestTask",
         //current - \API\APIQuiz\APIQuiz
         //CsFilePath = Directory.GetCurrentDirectory()
         CsFilePath = Directory.GetParent(@"..\").FullName
     };
 }
Пример #2
0
        public CheckTaskResponse CheckCode(CheckTaskRequest request, ConfigurationPaths paths)
        {
            CheckTaskResponse answer = new CheckTaskResponse()
            {
                Id = request.Id, Result = true
            };

            if (request.Code == null)
            {
                answer.Message = "Please, enter your code";
                answer.Result  = false;
                return(answer);
            }

            Compiler = new CodeCompiler();

            try
            {
                Compiler.CreateCs(paths.CsFilePath, "test", request.Code);
                ProcessResultModel result = Compiler.CompileProgram(paths.CompilerPath, paths.CsFilePath);

                if (result.ExitCode != 0)
                {
                    answer.Result  = false;
                    answer.Message = result.Result.Substring(371, result.Result.Length - 371);
                    return(answer);
                }

                SetTests(request.Id, paths);
                //answer.Message = "Running tests: \n";

                for (int i = 0; i < TestValues.Length && i < TestResults.Length; i++)
                {
                    var res = RunTest(TestValues[i], TestResults[i], paths.CsFilePath);
                    answer.Message += "\nTest № " + (i + 1).ToString();
                    if (res.ExitCode != 0)
                    {
                        answer.Result = false;
                    }
                    answer.Message += res.Result;
                }

                Compiler.DeleteFiles(paths.CsFilePath);
            }
            catch (Exception e)
            {
                answer.Result  = false;
                answer.Message = e.Message;
                return(answer);
            }

            return(answer);
        }
Пример #3
0
        //Reading test and expeced result values from file

        private void SetTests(int id, ConfigurationPaths paths)
        {
            var path = paths.FolderPath;

            path += "\\" + id.ToString() + "\\";

            if (!File.Exists(path + "Tests.txt") || !File.Exists(path + "Results.txt"))
            {
                throw new Exception("Test file doesn`t exist");
            }
            else
            {
                TestValues  = System.IO.File.ReadAllLines(path + "Tests.txt");
                TestResults = System.IO.File.ReadAllLines(path + "Results.txt");
            }
        }
Пример #4
0
        public IQuizTask GetTask(int id, ConfigurationPaths paths)
        {
            var path = paths.FolderPath;

            path += "\\" + id + "\\";

            IQuizTask task = new QuizTask()
            {
                Id = id
            };

            if (!Directory.Exists(path) || !File.Exists(path + "Name.txt") || !File.Exists(path + "ShortDescription.txt") || !File.Exists(path + "Description.txt"))
            {
                return(null);
            }
            else
            {
                task.Name             = System.IO.File.ReadAllText(path + "Name.txt");
                task.ShortDescription = System.IO.File.ReadAllText(path + "ShortDescription.txt");
                task.FullDescription  = System.IO.File.ReadAllText(path + "Description.txt");
                return(task);
            }
        }
 public ConfigurationRepository(IFileSystem fileSystem, IFileAndDirectoryRulesRepository fileAndDirectoryRulesRepository, ConfigurationPaths paths)
 {
   _fileSystem = fileSystem;
   _fileAndDirectoryRulesRepository = fileAndDirectoryRulesRepository;
   _paths = paths;
 }
Пример #6
0
 protected bool Equals(ConfigurationPaths other)
 {
     return string.Equals(ExportationPath, other.ExportationPath) &&
            string.Equals(ImagesFolder, other.ImagesFolder) &&
            string.Equals(SiteDir, other.SiteDir);
 }
Пример #7
0
        public bool CreateTask(string name, string description, string shortDescription, string tests, string results, ConfigurationPaths paths)
        {
            try
            {
                var path = paths.FolderPath;

                path += "\\" + (++tasksCount).ToString() + "\\";

                DirectoryInfo di = Directory.CreateDirectory(paths.FolderPath + "\\" + (tasksCount).ToString());

                var fileName = path + "Name.txt";
                var content  = name;

                WriteTextToFile(fileName, content);

                WriteTextToFile(path + "ShortDescription.txt", shortDescription);
                WriteTextToFile(path + "Description.txt", description);
                WriteTextToFile(path + "Results.txt", results);
                WriteTextToFile(path + "Tests.txt", tests);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }