示例#1
0
        private string ReadProperty(XDocument doc, string name, bool safe, Contract.ConfigHelper configHelper)
        {
            var nodes = from n in doc.Descendants()
                        where string.Compare(n.Name.LocalName, name, true) == 0 &&
                        EvaluateCondition(n.Parent.Attribute("Condition")?.Value)
                        select n;

            if (nodes.Count() != 1)
            {
                if (safe)
                {
                    return(null);
                }

                Bridge.Translator.TranslatorException.Throw(
                    "Unable to determine "
                    + name
                    + " in the project file with conditions " + EvaluationConditionsAsString());
            }

            var value = nodes.First().Value;

            value = configHelper.ConvertPath(value);

            return(value);
        }
        private string ReadProperty(Project doc, string name, bool safe, Contract.ConfigHelper configHelper)
        {
            var node = (from n in doc.AllEvaluatedProperties
                        where string.Compare(n.Name, name, true) == 0
                        select n).LastOrDefault();

            if (node == null)
            {
                if (safe)
                {
                    return(null);
                }

                Bridge.Translator.TranslatorException.Throw(
                    "Unable to determine "
                    + name
                    + " in the project file with conditions " + EvaluationConditionsAsString());
            }

            var value = node.EvaluatedValue;

            value = configHelper.ConvertPath(value);

            return(value);
        }
        protected virtual IList <string> GetSourceFiles(Project project)
        {
            this.Log.Trace("Getting source files by xml...");
            var configHelper = new Contract.ConfigHelper();

            IList <string> sourceFiles = new List <string>();

            if (this.Source == null)
            {
                foreach (var projectItem in project.AllEvaluatedItems.Where(i => i.ItemType == "Compile"))
                {
                    sourceFiles.Add(configHelper.ConvertPath(projectItem.EvaluatedInclude));
                }

                if (!sourceFiles.Any())
                {
                    throw new Bridge.Translator.TranslatorException("Unable to get source file list from project file '" +
                                                                    this.Location + "'. In order to use bridge, you have to have at least one source code file " +
                                                                    "with the 'compile' property set (usually .cs files have it by default in C# projects).");
                }
                ;
            }
            else
            {
                sourceFiles = GetSourceFiles(Path.GetDirectoryName(this.Location));
            }

            this.Log.Trace("Getting source files by xml done");

            return(sourceFiles);
        }
        protected virtual string GetOutputPaths(Project project)
        {
            var configHelper = new Contract.ConfigHelper();

            var outputPath = ProjectProperties.OutputPath;

            if (outputPath == null && _shouldReadProjectFile)
            {
                // Read OutputPath if not defined already
                // Throw exception if not found
                outputPath = ReadProperty(project, ProjectPropertyNames.OUTPUT_PATH_PROP, false, configHelper);
            }

            outputPath = outputPath ?? "";

            ProjectProperties.OutputPath = outputPath;

            var outDir = ProjectProperties.OutDir;

            if (outDir is null && _shouldReadProjectFile)
            {
                // Read OutDir if not defined already
                outDir = ReadProperty(project, ProjectPropertyNames.OUT_DIR_PROP, true, configHelper);
            }

            // If OutDir value is not found then use OutputPath value
            ProjectProperties.OutDir = outDir ?? outputPath;

            var fullPath = ProjectProperties.OutDir;

            if (!Path.IsPathRooted(fullPath))
            {
                fullPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Location), fullPath));
            }

            fullPath = configHelper.ConvertPath(fullPath);

            return(fullPath);
        }