Exemple #1
0
        public void Validate()
        {
            if (string.IsNullOrWhiteSpace(AssemblyFile) && string.IsNullOrWhiteSpace(InputDirectory))
            {
                throw new ArgException("Please provide an assembly file or an input directory.");
            }

            if (!string.IsNullOrWhiteSpace(AssemblyFile) && !string.IsNullOrWhiteSpace(InputDirectory))
            {
                throw new ArgException("Both a single assembly file and an input directory cannot be used at the same time.");
            }

            if (string.IsNullOrWhiteSpace(OutputDirectory) && KeepStructure)
            {
                throw new ArgException("Keep structure is only available when output directory is provided.");
            }

            if (!string.IsNullOrWhiteSpace(InputDirectory))
            {
                foreach (var inputDir in InputDirectory.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (!inputDir.Contains("*") && !Directory.Exists(inputDir))
                    {
                        throw new ArgException(string.Format("Directory not found: '{0}'", inputDir));
                    }
                }
            }
        }
Exemple #2
0
        private void ComboBoxItemDirChoice2_OnSelected(object sender, RoutedEventArgs e)
        {
            Window win2 = new InputDirectory();

            win2.DataContext = this;
            win2.ShowDialog();
        }
Exemple #3
0
        /// <exception cref="CopeException"><c>CopeException</c>.</exception>
        public ArchivePackerInfo PackArchive(string outputPath)
        {
            if (!ArchiveToolHelper.IsArchiveToolPresent())
            {
                string msg = "Archive tool has not been found! Searched at: " +
                             ArchiveToolHelper.GetArchiveToolPath();
                LoggingManager.SendError("ArchiveCreator - " + msg);
                throw new CopeException(msg);
            }
            if (!outputPath.EndsWith('\\'))
            {
                outputPath += '\\';
            }

            string uniqueName     = ArchiveName + '_' + DateTime.Now.ToProperString('_');
            string designFilePath = ArchiveToolHelper.GetArchiveToolDirectory() + uniqueName + ".sga_design";

            WriteDesignFile(designFilePath, outputPath + ArchiveName);

            string  arguments = string.Format(ARCHIVE_ARGUMENTS, InputDirectory.RemoveLast(1), outputPath + ArchiveName, uniqueName);
            Process packer    = StartPacker(arguments);

            if (packer == null || packer.Id == 0 || packer.Id == 1)
            {
                LoggingManager.SendError("ArchiveCreator - failed to start packer. Arguments: " + arguments);
                throw new CopeException("Failed to start archive.exe");
            }

            return(new ArchivePackerInfo(packer, designFilePath, outputPath + ArchiveName));
        }
        public FileInfo[] GetConfigFiles()
        {
            var configs = InputDirectory.GetFiles("*.cfg", SearchOption.AllDirectories);

            if (configs.Length > 0)
            {
                return(configs);
            }

            return(null);
        }
        public IEnumerable <object[]> TestData()
        {
            var inputDirectories = InputDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly).ToList();

            if (!inputDirectories.Any())
            {
                CreateVersionCompatData().Wait();
                throw new Exception("No test data for version compat test encoded data created at: " + _ouputTempVersionDataDirectory.FullName);
            }

            return(inputDirectories.Select(directory => new [] { directory }));
        }
Exemple #6
0
        /// <summary>
        /// Stops MDEX engine, copy files to the input folder and starts the engine
        /// </summary>
        /// <returns>true if successful</returns>
        public bool ApplyIndex()
        {
            if (IsActive)
            {
                Logger.Info(String.Format("{0} - Stopping dgraph ...", ComponentId));
                StopComponent(true);
            }

            var inputFolder = InputDirectory.Substring(0, InputDirectory.LastIndexOf(@"\"));

            CopyFilesAndApply(inputFolder);
            IndexApplied = IsActive;
            return(IndexApplied);
        }
Exemple #7
0
        /// <summary>
        /// Any files that are needed for linking should come from the expectations assembly so that these values
        /// can be controlled using #ifs regardless of the framework the NUnit test project is compiled against
        /// </summary>
        /// <param name="metadataProvider"></param>
        public virtual void PopulateFromExpectations(TestCaseMetadataProvider metadataProvider)
        {
            foreach (var res in metadataProvider.GetResponseFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetDescriptorFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetSubstitutionFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetLinkAttributesFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }
        }
Exemple #8
0
    private int InvokeCore()
    {
        if (!Input.HasValue() && !InputDirectory.HasValue())
        {
            ShowHelp();
            return(1);
        }

        if (Input.HasValue() && InputDirectory.HasValue())
        {
            ShowHelp();
            return(1);
        }

        if (!Output.HasValue())
        {
            Output.Values.Add("Out.generated.cs");
        }

        if (InputDirectory.HasValue())
        {
            Input.Values.AddRange(Directory.EnumerateFiles(InputDirectory.Value(), "*.json", SearchOption.AllDirectories));
        }

        Console.WriteLine($"Processing {Input.Values.Count} files...");
        var entries = new List <RouteEntry>();

        for (var i = 0; i < Input.Values.Count; i++)
        {
            var input = ReadInput(Input.Values[i]);
            ParseEntries(input, entries);
        }

        // We don't yet want to support complex segments.
        for (var i = entries.Count - 1; i >= 0; i--)
        {
            if (HasComplexSegment(entries[i]))
            {
                Out.WriteLine("Skipping route with complex segment: " + entries[i].Template.TemplateText);
                entries.RemoveAt(i);
            }
        }

        // The data that we're provided by might be unambiguous.
        // Remove any routes that would be ambiguous in our system.
        var routesByPrecedence = new Dictionary <decimal, List <RouteEntry> >();

        for (var i = entries.Count - 1; i >= 0; i--)
        {
            var entry      = entries[i];
            var precedence = RoutePrecedence.ComputeInbound(entries[i].Template);

            if (!routesByPrecedence.TryGetValue(precedence, out var matches))
            {
                matches = new List <RouteEntry>();
                routesByPrecedence.Add(precedence, matches);
            }

            if (IsDuplicateTemplate(entry, matches))
            {
                Out.WriteLine("Duplicate route template: " + entries[i].Template.TemplateText);
                entries.RemoveAt(i);
                continue;
            }

            matches.Add(entry);
        }

        // We're not too sophisticated with how we generate parameter values, just hoping for
        // the best. For parameters we generate a segment that is the same length as the parameter name
        // but with a minimum of 5 characters to avoid collisions.
        for (var i = entries.Count - 1; i >= 0; i--)
        {
            entries[i].RequestUrl = GenerateRequestUrl(entries[i].Template);
            if (entries[i].RequestUrl == null)
            {
                Out.WriteLine("Failed to create a request for: " + entries[i].Template.TemplateText);
                entries.RemoveAt(i);
                continue;
            }
        }

        Sort(entries);

        var text = Template.Execute(entries);

        File.WriteAllText(Output.Value(), text);
        return(0);
    }
        private void Init()
        {
            VitaNexCore.TryCatch(
                () =>
            {
                Status = CompileStatus.Initializing;

                if (!InputDirectory.Exists)
                {
                    Status        = CompileStatus.Aborted;
                    StatusMessage = "Input directory '" + InputDirectory + "' does not exist.";
                    return;
                }

                var infos = new List <FileInfo>();

                foreach (var file in FileMasks.SelectMany(
                             t => InputDirectory.GetFiles(t, SearchOption.AllDirectories).Where(file => !infos.Contains(file))))
                {
                    infos.Add(file);
                }

                var files = infos.ToArray();
                infos.Clear();

                if (files.Length == 0)
                {
                    Status        = CompileStatus.Aborted;
                    StatusMessage = "No files to compile.";
                    return;
                }

                var refs      = new List <string>();
                var fileNames = new List <string>();

                foreach (var fName in files.Select(t => t.FullName)
                         .Where(fName => !String.IsNullOrEmpty(fName))
                         .Where(fName => !fileNames.Contains(fName)))
                {
                    fileNames.Add(fName);
                }

                foreach (var t in DefaultReferences.Where(t => !String.IsNullOrEmpty(t)).Where(t => !refs.Contains(t)))
                {
                    refs.Add(t);
                }

                foreach (var t in References.Where(t => !String.IsNullOrEmpty(t)).Where(t => !refs.Contains(t)))
                {
                    refs.Add(t);
                }

                var configs = GetConfigFiles();

                if (configs != null)
                {
                    foreach (var t in configs.Select(GetConfigAssemblies)
                             .SelectMany(
                                 asm => asm.Where(t => !String.IsNullOrEmpty(t))
                                 .Where(t => File.Exists(IOUtility.GetSafeFilePath(IOUtility.GetBaseDirectory() + "/" + t, true)))
                                 .Where(t => !refs.Contains(t))))
                    {
                        refs.Add(t);
                    }
                }

                Status     = CompileStatus.Compiling;
                Parameters = new CompilerParameters(
                    refs.ToArray(),
                    IOUtility.GetUnusedFilePath(OutputDirectory.FullName, OutputFileName),
                    Debug)
                {
                    GenerateExecutable = false,
                    WarningLevel       = 4,
                    CompilerOptions    = String.Empty
                };

                foreach (var arg in Arguments)
                {
                    Parameters.CompilerOptions += arg + " ";
                }

                Results = Provider.CompileAssemblyFromFile(Parameters, fileNames.ToArray());

                if (Results.Errors.Count > 0)
                {
                    int errorCount = 0, warningCount = 0;

                    foreach (CompilerError e in Results.Errors)
                    {
                        if (e.IsWarning)
                        {
                            ++warningCount;
                        }
                        else
                        {
                            ++errorCount;
                        }
                    }

                    Errors = new string[Results.Errors.Count];

                    for (var e = 0; e < Results.Errors.Count; e++)
                    {
                        Errors[e] = String.Format(
                            "[{0}][{1}][{2}]: Line {3}, Column {4}\n{5}",
                            Results.Errors[e].IsWarning ? "Warning" : "Error",
                            Results.Errors[e].FileName,
                            Results.Errors[e].ErrorNumber,
                            Results.Errors[e].Line,
                            Results.Errors[e].Column,
                            Results.Errors[e].ErrorText);
                    }

                    StatusMessage = String.Format(
                        "Finished compiling with {0} error{1} and {2} warning{3}",
                        errorCount,
                        errorCount > 1 ? "s" : "",
                        warningCount,
                        warningCount > 1 ? "s" : "");

                    Status = CompileStatus.Completed;
                }
                else
                {
                    StatusMessage = "Finished compiling with no errors or warnings.";
                    Status        = CompileStatus.Completed;
                }
            },
                ex =>
            {
                Status        = CompileStatus.Aborted;
                StatusMessage = ex.Message;
            });

            if (CompiledCallback != null)
            {
                CompiledCallback(Results);
            }
        }
Exemple #10
0
        public virtual void Populate(TestCaseMetadaProvider metadataProvider)
        {
            _testCase.SourceFile.Copy(_directory);

            if (_testCase.HasLinkXmlFile)
            {
                _testCase.LinkXmlFile.Copy(InputDirectory);
            }

            CopyToInputAndExpectations(GetExpectationsAssemblyPath());

            foreach (var dep in metadataProvider.AdditionalFilesToSandbox())
            {
                var destination = _directory.Combine(dep.DestinationFileName);
                dep.Source.FileMustExist().Copy(destination);

                // In a few niche tests we need to copy pre-built assemblies directly into the input directory.
                // When this is done, we also need to copy them into the expectations directory so that if they are used
                // as references we can still compile the expectations version of the assemblies
                if (destination.Parent == InputDirectory)
                {
                    dep.Source.Copy(ExpectationsDirectory.Combine(destination.RelativeTo(InputDirectory)));
                }
            }

            // Copy non class library dependencies to the sandbox
            foreach (var fileName in metadataProvider.GetReferenceValues())
            {
                if (!fileName.StartsWith("System.", StringComparison.Ordinal) && !fileName.StartsWith("Mono.", StringComparison.Ordinal) && !fileName.StartsWith("Microsoft.", StringComparison.Ordinal))
                {
                    CopyToInputAndExpectations(_testCase.SourceFile.Parent.Combine(fileName.ToNPath()));
                }
            }

            foreach (var referenceDependency in metadataProvider.GetReferenceDependencies())
            {
                CopyToInputAndExpectations(_testCase.SourceFile.Parent.Combine(referenceDependency.ToNPath()));
            }

            foreach (var res in metadataProvider.GetResources())
            {
                res.Source.FileMustExist().Copy(ResourcesDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetResponseFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetDescriptorFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetSubstitutionFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var res in metadataProvider.GetLinkAttributesFiles())
            {
                res.Source.FileMustExist().Copy(InputDirectory.Combine(res.DestinationFileName));
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore())
            {
                var destination = BeforeReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);

                destination = BeforeReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();

                if (compileRefInfo.Resources == null)
                {
                    continue;
                }

                foreach (var res in compileRefInfo.Resources)
                {
                    res.Source.FileMustExist().Copy(destination.Combine(res.DestinationFileName));
                }
            }

            foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter())
            {
                var destination = AfterReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();
                compileRefInfo.SourceFiles.Copy(destination);

                destination = AfterReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists();

                if (compileRefInfo.Resources == null)
                {
                    continue;
                }

                foreach (var res in compileRefInfo.Resources)
                {
                    res.Source.FileMustExist().Copy(destination.Combine(res.DestinationFileName));
                }
            }
        }