Exemplo n.º 1
0
        public static bool CopyDirectory(string source, string target, bool overwrite = false, bool recursive = true)
        {
            _logger.Trace($"CopyDirectory({source}, {target}, {overwrite}, {recursive}");
            if (string.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (string.IsNullOrEmpty(target))
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (!Path.IsPathRooted(source))
            {
                source = Path.Combine(DeploymentEnvironmentVariables.FilesDirectory, source);
                _logger.Trace($"Source path was a non absolute path. Changed path to '{source}'");
            }
            if (!Path.IsPathRooted(target))
            {
                target = Path.GetFullPath(target);
                _logger.Trace($"Target path was a non absolute path. Changed path to '{target}'");
            }

            if (!Directory.Exists(source))
            {
                _logger.Warn($"Source directory was not found in '{source}' or is not a directory");
                return(false);
            }

            if (!overwrite && Directory.Exists(target))
            {
                _logger.Info($"Overwrite not specified but target directory exists. Not copying '{source}' to '{target}'");
                return(false);
            }
            else if (overwrite && Directory.Exists(target))
            {
                _logger.Info($"Target directory exists. Deleting '{target}'");
                try
                {
                    Directory.Delete(target, recursive);
                }
                catch (IOException ex)
                {
                    // If recursive is set to false and the directory has subfolders, then this exception is thrown. Therefor exit ...
                    _logger.Warn(ex, $"Target directory exists and has subfolder or files. Recursive parameter was not specified. Aborting ...");
                    return(false);
                }
            }

            DirectoryExtensions.Copy(source, target);
            return(true);
        }
Exemplo n.º 2
0
        public void Configure(CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();

            Result = null; // sets result to InProgress
            try
            {
                var contentFolder =
                    Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(ConfigurationWizardViewModel).Assembly.Location),
                                                  @"..\Resources\FrontEnd"));

                // Copy template to project location
                DirectoryExtensions.Copy(new DirectoryInfo(contentFolder), new DirectoryInfo(ProjectLocation));
                ct.ThrowIfCancellationRequested();

                // create initial folders: import, reports
                Directory.CreateDirectory(Path.Combine(ProjectLocation, "App_Data\\Virto\\Storage\\import"));
                Directory.CreateDirectory(Path.Combine(ProjectLocation, "App_Data\\Virto\\Storage\\reports"));

                if (_databaseViewModel.InstallSamples)
                {
                    var catalogImagesFolder =
                        Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(ConfigurationWizardViewModel).Assembly.Location),
                                                      @"..\Resources\Catalog"));

                    // Copy test data images
                    DirectoryExtensions.Copy(new DirectoryInfo(catalogImagesFolder),
                                             new DirectoryInfo(string.Format("{0}\\App_Data\\Virto\\Storage\\Catalog", ProjectLocation)));
                    ct.ThrowIfCancellationRequested();
                }

                // Fix connection strings
                new InitializeFrontEndConfigs().Initialize(ProjectLocation, _confirmationViewModel.DatabaseConnectionString,
                                                           _confirmationViewModel.SearchConnection.ToString());

                // Create desktop shortcut

                Result = OperationResult.Successful;
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                Message = string.Format("{0} {1}: {2}", Resources.ProjectLocationAction, Resources.Failed, e.ExpandExceptionMessage());

                Result = OperationResult.Failed;
                throw;
            }
        }
Exemplo n.º 3
0
        public void TestStandart(Int32 ProblemID, Int32 SolutionID, string SolutionName,
                                 ProgrammingLanguages PL, TournamentFormats TF,
                                 out TestResults Result, out int Score, out List <Tuple <long, long, TestResults> > TestResults)
        {
            // TODO: FL
            Result      = Solomon.TypesExtensions.TestResults.RTE;
            TestResults = null;
            Score       = 0;

            File.Copy(LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\checker.exe",
                      LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\checker.exe", true);

            DirectoryExtensions.Copy(LocalPath.ProblemsDirectory + ProblemID.ToString() + "\\Tests",
                                     LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", false);

            if (!Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe"))
            {
                Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe");
            }
            if (!Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output"))
            {
                Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output");
            }

            CompilerSingleton.Instance.Compile(
                LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\" + SolutionName,
                LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName + ".exe", PL, out Result, SolutionID);

            if (Result != Solomon.TypesExtensions.TestResults.OK)
            {
                //Interlocked.Decrement(ref threadCount);
                return;
            }

            // Testing
            // TODO: FL
            Result      = Solomon.TypesExtensions.TestResults.RTE;
            TestResults = new List <Tuple <long, long, TestResults> >();
            Tuple <long, long, TestResults> tempTuple;

            // Get all "in" files
            String[] inFiles = null;

            inFiles = Directory.GetFiles(
                LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", "*.in");

            double   timeLimit;
            int      memoryLimit;
            string   name;
            long     solutionTime, solutionMemory;
            DateTime lastModifiedTime;

            ProblemLegend.Read(LocalPath.ProblemsDirectory + ProblemID.ToString(),
                               out name, out timeLimit, out memoryLimit, out lastModifiedTime);

            int testOK = 0;

            foreach (String inFile in inFiles)
            {
                solutionTime   = 0;
                solutionMemory = 0;

                try
                {
                    if (PL == ProgrammingLanguages.Java)
                    {
                        RunSolutionClass(
                            LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName,
                            inFile,
                            LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt",
                            timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory);
                    }
                    else if (PL == ProgrammingLanguages.Python)
                    {
                        RunSolutionPython(
                            LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName,
                            inFile,
                            LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt",
                            timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory);
                    }
                    else
                    {
                        RunSolutionExe(
                            LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\exe\\" + SolutionName + ".exe",
                            inFile,
                            LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt",
                            timeLimit, memoryLimit, out Result, out solutionTime, out solutionMemory);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Warning on solution {0} running: {1}", SolutionID, ex.Message);
                    Console.WriteLine(DateTime.Now.ToString(culture) + " - Warning on solution {0} running: {1}", SolutionID, ex.Message);
                }

                if (Result != Solomon.TypesExtensions.TestResults.OK)
                {
                    tempTuple = new Tuple <long, long, TestResults>(solutionTime, solutionMemory, Result);
                    TestResults.Add(tempTuple);

                    if (TF == TournamentFormats.ACM)
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

                Result = Solomon.TypesExtensions.TestResults.Executing;
                for (int i = 0; i < 5 && (int)Result >= 4; i++)
                {
                    CheckSolutionOutput(
                        LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\checker.exe",
                        inFile,
                        LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt",
                        LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests\\" + Path.GetFileNameWithoutExtension(inFile) + ".out",
                        out Result);
                }

                tempTuple = new Tuple <long, long, TestResults>(solutionTime, solutionMemory, Result);
                TestResults.Add(tempTuple);

                if (Result != Solomon.TypesExtensions.TestResults.OK)
                {
                    if (TF == TournamentFormats.ACM)
                    {
                        break;
                    }
                }
                else
                {
                    testOK++;
                }
            }

            if (TF == TournamentFormats.IOI)
            {
                Score  = 100 * testOK / inFiles.Length;
                Result = testOK == inFiles.Length ? Solomon.TypesExtensions.TestResults.OK : Solomon.TypesExtensions.TestResults.PS;
            }

            if (File.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt"))
            {
                File.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\output\\output.txt");
            }

            for (int i = 0; i < 5; i++)
            {
                try
                {
                    Directory.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\Tests", true);
                    break;
                }
                catch (Exception) { Thread.Sleep(100); }
            }
        }