Ejemplo n.º 1
0
        static bool LoadFromFile(NestingRulesProvider provider)
        {
            try {
                using var reader = new StreamReader(provider.SourceFile);
                var json = JObject.Parse(reader.ReadToEnd());
                if (json != null)
                {
                    var parentNode = json ["dependentFileProviders"] [TokenNameAdd] as JObject;
                    foreach (var jsonProp in parentNode.Properties())
                    {
                        JObject rpobj = null;
                        try {
                            rpobj = parentNode [jsonProp.Name] [TokenNameAdd].Value <JObject> ();
                        } catch {
                            LoggingService.LogWarning($"No patterns specified for {jsonProp.Name} nesting rule");
                        }

                        if (jsonProp.Name == RuleNameAddedExtension)
                        {
                            ParseRulesProvider(provider, NestingRuleKind.AddedExtension, rpobj);
                        }
                        else if (jsonProp.Name == RuleNameAllExtensions)
                        {
                            ParseRulesProvider(provider, NestingRuleKind.AllExtensions, rpobj);
                        }
                        else if (jsonProp.Name == RuleNameExtensionToExtension)
                        {
                            ParseRulesProvider(provider, NestingRuleKind.ExtensionToExtension, rpobj);
                        }
                        else if (jsonProp.Name == RuleNameFileSuffixToExtension)
                        {
                            ParseRulesProvider(provider, NestingRuleKind.FileSuffixToExtension, rpobj);
                        }
                        else if (jsonProp.Name == RuleNameFileToFile)
                        {
                            ParseRulesProvider(provider, NestingRuleKind.FileToFile, rpobj);
                        }
                        else if (jsonProp.Name == RuleNamePathSegment)
                        {
                            ParseRulesProvider(provider, NestingRuleKind.PathSegment, rpobj);
                        }
                    }

                    return(true);
                }
            } catch (Exception ex) {
                LoggingService.LogError($"Unable to parse {provider.SourceFile}: {ex}");
            }

            return(false);
        }
Ejemplo n.º 2
0
        static void ParseRulesProvider(NestingRulesProvider provider, NestingRuleKind kind, JObject jobj)
        {
            if (jobj == null)
            {
                // Fallback to create an empty rule for this NestingRuleKind
                provider.AddRule(kind, NestingRule.AllFilesWildcard, Array.Empty <string> ());
                return;
            }

            foreach (var prop in jobj.Properties())
            {
                if (prop.Value.Type == JTokenType.Array)
                {
                    provider.AddRule(kind, prop.Name, (prop.Value as JArray).Select(x => x.Value <string> ()));
                }
            }
        }