コード例 #1
0
        public static IEnumerable<string> GetPatternsCollection(JsonObject rawProject,
                                                                string projectDirectory,
                                                                string projectFilePath,
                                                                string propertyName,
                                                                IEnumerable<string> defaultPatterns = null,
                                                                bool literalPath = false)
        {
            defaultPatterns = defaultPatterns ?? Enumerable.Empty<string>();

            try
            {
                if (!rawProject.Keys.Contains(propertyName))
                {
                    return CreateCollection(projectDirectory, propertyName, defaultPatterns, literalPath);
                }

                var valueInString = rawProject.ValueAsString(propertyName);
                if (valueInString != null)
                {
                    return CreateCollection(projectDirectory, propertyName, new string[] { valueInString }, literalPath);
                }

                var valuesInArray = rawProject.ValueAsStringArray(propertyName);
                if (valuesInArray != null)
                {
                    return CreateCollection(projectDirectory, propertyName, valuesInArray.Select(s => s.ToString()), literalPath);
                }
            }
            catch (Exception ex)
            {
                throw FileFormatException.Create(ex, rawProject.Value(propertyName), projectFilePath);
            }

            throw FileFormatException.Create("Value must be either string or array.", rawProject.Value(propertyName), projectFilePath);
        }
コード例 #2
0
ファイル: ProcessingQueue.cs プロジェクト: rajeevkb/dnx
        private static List<DiagnosticMessage> ValueAsCompilationMessages(JsonObject obj, string key)
        {
            var messages = new List<DiagnosticMessage>();

            var arrayValue = obj.Value(key) as JsonArray;
            for (int i = 0; i < arrayValue.Length; i++)
            {
                var item = arrayValue[i] as JsonObject;

                var message = new DiagnosticMessage(
                    item.ValueAsString(nameof(DiagnosticMessage.ErrorCode)),
                    item.ValueAsString(nameof(DiagnosticMessage.Message)),
                    item.ValueAsString(nameof(DiagnosticMessage.FormattedMessage)),
                    item.ValueAsString(nameof(DiagnosticMessage.SourceFilePath)),
                    (DiagnosticMessageSeverity)item.ValueAsInt(nameof(DiagnosticMessage.Severity)),
                    item.ValueAsInt(nameof(DiagnosticMessage.StartColumn)),
                    item.ValueAsInt(nameof(DiagnosticMessage.StartLine)),
                    item.ValueAsInt(nameof(DiagnosticMessage.EndColumn)),
                    item.ValueAsInt(nameof(DiagnosticMessage.EndLine)));

                messages.Add(message);
            }

            return messages;
        }
コード例 #3
0
ファイル: NamedResourceReader.cs プロジェクト: rajeevkb/dnx
        public static IDictionary<string, string> ReadNamedResources(JsonObject rawProject, string projectFilePath)
        {
            if (!rawProject.Keys.Contains("namedResource"))
            {
                return new Dictionary<string, string>();
            }

            var namedResourceToken = rawProject.ValueAsJsonObject("namedResource");
            if (namedResourceToken == null)
            {
                throw FileFormatException.Create("Value must be object.", rawProject.Value("namedResource"), projectFilePath);
            }

            var namedResources = new Dictionary<string, string>();

            foreach (var namedResourceKey in namedResourceToken.Keys)
            {
                var resourcePath = namedResourceToken.ValueAsString(namedResourceKey);
                if (resourcePath == null)
                {
                    throw FileFormatException.Create("Value must be string.", namedResourceToken.Value(namedResourceKey), projectFilePath);
                }

                if (resourcePath.Value.Contains("*"))
                {
                    throw FileFormatException.Create("Value cannot contain wildcards.", resourcePath, projectFilePath);
                }

                var resourceFileFullPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(projectFilePath), resourcePath));

                if (namedResources.ContainsKey(namedResourceKey))
                {
                    throw FileFormatException.Create(
                        string.Format("The named resource {0} already exists.", namedResourceKey),
                        resourcePath,
                        projectFilePath);
                }

                namedResources.Add(
                    namedResourceKey,
                    resourceFileFullPath);
            }

            return namedResources;
        }
コード例 #4
0
ファイル: PatternGroup.cs プロジェクト: henghu-bai/dnx
        internal static PatternGroup Build(JsonObject rawProject,
                                           string projectDirectory,
                                           string projectFilePath,
                                           string name,
                                           string legacyName,
                                           IEnumerable<string> fallbackIncluding = null,
                                           IEnumerable<string> additionalIncluding = null,
                                           IEnumerable<string> additionalExcluding = null,
                                           bool includePatternsOnly = false,
                                           ICollection<DiagnosticMessage> warnings = null)
        {
            string includePropertyName = name;

            if (!rawProject.Keys.Contains(name) &&
                legacyName != null &&
                rawProject.Keys.Contains(legacyName))
            {
                includePropertyName = legacyName;
                if (warnings != null)
                {
                    var legacyToken = rawProject.Value(legacyName);
                    warnings.Add(new DiagnosticMessage(
                        $"Property \"{legacyName}\" is deprecated. It is replaced by \"{name}\".",
                        projectFilePath,
                        DiagnosticMessageSeverity.Warning,
                        legacyToken.Line,
                        legacyToken.Column));
                }
            }

            additionalIncluding = additionalIncluding ?? Enumerable.Empty<string>();
            var includePatterns = PatternsCollectionHelper.GetPatternsCollection(rawProject, projectDirectory, projectFilePath, includePropertyName, defaultPatterns: fallbackIncluding)
                                                          .Concat(additionalIncluding)
                                                          .Distinct();

            if (includePatternsOnly)
            {
                return new PatternGroup(includePatterns);
            }

            additionalExcluding = additionalExcluding ?? Enumerable.Empty<string>();
            var excludePatterns = PatternsCollectionHelper.GetPatternsCollection(rawProject, projectDirectory, projectFilePath, propertyName: name + "Exclude")
                                                          .Concat(additionalExcluding)
                                                          .Distinct();

            var includeLiterals = PatternsCollectionHelper.GetPatternsCollection(rawProject, projectDirectory, projectFilePath, propertyName: name + "Files", literalPath: true)
                                                          .Distinct();

            return new PatternGroup(includePatterns, excludePatterns, includeLiterals);
        }