public static ISymbolModel FromJObject(JObject jObject) { ComputedSymbol sym = new ComputedSymbol { Value = jObject.ToString(nameof(Value)), Type = jObject.ToString(nameof(Type)) }; return(sym); }
public static ISymbolModel GetModelForObject(JObject jObject) { switch (jObject.ToString(nameof(ISymbolModel.Type))) { case "parameter": return(ParameterSymbol.FromJObject(jObject)); case "computed": return(ComputedSymbol.FromJObject(jObject)); case "generated": return(GeneratedSymbol.FromJObject(jObject)); default: return(null); } }
// Note: Only ParameterSymbol has a Description property, this it's the only one that gets localization // TODO: change how localization gets merged in, don't do it here. public static ISymbolModel GetModelForObject(JObject jObject, IParameterSymbolLocalizationModel localization, string defaultOverride) { switch (jObject.ToString(nameof(ISymbolModel.Type))) { case ParameterSymbol.TypeName: return(ParameterSymbol.FromJObject(jObject, localization, defaultOverride)); case ComputedSymbol.TypeName: return(ComputedSymbol.FromJObject(jObject)); case BindSymbolTypeName: case GeneratedSymbol.TypeName: return(GeneratedSymbol.FromJObject(jObject)); default: return(null); } }
internal void Evaluate(IParameterSet parameters, IVariableCollection rootVariableCollection, IFileSystemInfo configFile) { List <FileSource> sources = new List <FileSource>(); bool stable = _simpleConfigModel.Symbols == null; Dictionary <string, bool> computed = new Dictionary <string, bool>(); while (!stable) { stable = true; foreach (KeyValuePair <string, ISymbolModel> symbol in _simpleConfigModel.Symbols) { if (symbol.Value.Type == "computed") { ComputedSymbol sym = (ComputedSymbol)symbol.Value; bool value = CppStyleEvaluatorDefinition.EvaluateFromString(sym.Value, rootVariableCollection); bool currentValue; stable &= computed.TryGetValue(symbol.Key, out currentValue) && currentValue == value; rootVariableCollection[symbol.Key] = value; computed[symbol.Key] = value; } } } foreach (ExtendedFileSource source in _simpleConfigModel.Sources) { List <string> includePattern = JTokenToCollection(source.Include, SourceFile, new[] { "**/*" }).ToList(); List <string> excludePattern = JTokenToCollection(source.Exclude, SourceFile, new[] { "/[Bb]in/", "/[Oo]bj/", ".netnew.json", "**/*.filelist" }).ToList(); List <string> copyOnlyPattern = JTokenToCollection(source.CopyOnly, SourceFile, new[] { "**/node_modules/**/*" }).ToList(); if (source.Modifiers != null) { foreach (SourceModifier modifier in source.Modifiers) { if (CppStyleEvaluatorDefinition.EvaluateFromString(modifier.Condition, rootVariableCollection)) { includePattern.AddRange(JTokenToCollection(modifier.Include, SourceFile, new string[0])); excludePattern.AddRange(JTokenToCollection(modifier.Exclude, SourceFile, new string[0])); copyOnlyPattern.AddRange(JTokenToCollection(modifier.CopyOnly, SourceFile, new string[0])); } } } Dictionary <string, string> renames = new Dictionary <string, string>(); // Console.WriteLine(_simpleConfigModel.NameParameter); object resolvedValue; if (parameters.ResolvedValues.TryGetValue(_simpleConfigModel.NameParameter, out resolvedValue)) { foreach (IFileSystemInfo entry in configFile.Parent.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)) { string tmpltRel = entry.PathRelativeTo(configFile.Parent); string outRel = tmpltRel.Replace(_simpleConfigModel.SourceName, (string)resolvedValue); renames[tmpltRel] = outRel; //Console.WriteLine($"Mapping {tmpltRel} -> {outRel}"); } } sources.Add(new FileSource { CopyOnly = copyOnlyPattern.ToArray(), Exclude = excludePattern.ToArray(), Include = includePattern.ToArray(), Source = source.Source ?? "./", Target = source.Target ?? "./", Rename = renames }); } if (_simpleConfigModel.Sources.Count == 0) { IReadOnlyList <string> includePattern = new[] { "**/*" }; IReadOnlyList <string> excludePattern = new[] { "/[Bb]in/", "/[Oo]bj/", ".netnew.json", "**/*.filelist" }; IReadOnlyList <string> copyOnlyPattern = new[] { "**/node_modules/**/*" }; Dictionary <string, string> renames = new Dictionary <string, string>(); // Console.WriteLine(_simpleConfigModel.NameParameter); object resolvedValue; if (parameters.ResolvedValues.TryGetValue(_simpleConfigModel.NameParameter, out resolvedValue)) { foreach (IFileSystemInfo entry in configFile.Parent.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)) { string tmpltRel = entry.PathRelativeTo(configFile.Parent); string outRel = tmpltRel.Replace(_simpleConfigModel.SourceName, (string)resolvedValue); renames[tmpltRel] = outRel; //Console.WriteLine($"Mapping {tmpltRel} -> {outRel}"); } } sources.Add(new FileSource { CopyOnly = copyOnlyPattern, Exclude = excludePattern, Include = includePattern, Source = "./", Target = "./", Rename = renames }); } _sources = sources; }
public void Evaluate(IParameterSet parameters, IVariableCollection rootVariableCollection, IFileSystemInfo configFile) { List <FileSource> sources = new List <FileSource>(); bool stable = Symbols == null; Dictionary <string, bool> computed = new Dictionary <string, bool>(); while (!stable) { stable = true; foreach (KeyValuePair <string, ISymbolModel> symbol in Symbols) { if (symbol.Value.Type == "computed") { ComputedSymbol sym = (ComputedSymbol)symbol.Value; bool value = CppStyleEvaluatorDefinition.EvaluateFromString(sym.Value, rootVariableCollection); bool currentValue; stable &= computed.TryGetValue(symbol.Key, out currentValue) && currentValue == value; rootVariableCollection[symbol.Key] = value; computed[symbol.Key] = value; } } } // evaluate the file glob (specials) conditions // the result is needed for SpecialOperationConfig foreach (ICustomFileGlobModel fileGlobModel in SpecialCustomSetup) { fileGlobModel.EvaluateCondition(rootVariableCollection); } object resolvedNameParamValue; parameters.ResolvedValues.TryGetValue(NameParameter, out resolvedNameParamValue); // evaluate the conditions and resolve the paths for the PrimaryOutputs foreach (ICreationPathModel pathModel in PrimaryOutputs) { pathModel.EvaluateCondition(rootVariableCollection); if (pathModel.ConditionResult && (resolvedNameParamValue != null)) { // this path will be included in the outputs, replace the name (same thing we do to other file paths) pathModel.PathResolved = pathModel.PathOriginal.Replace(SourceName, (string)resolvedNameParamValue); } } foreach (ExtendedFileSource source in Sources) { if (!string.IsNullOrEmpty(source.Condition) && !CppStyleEvaluatorDefinition.EvaluateFromString(source.Condition, rootVariableCollection)) { continue; } List <string> includePattern = JTokenToCollection(source.Include, SourceFile, IncludePatternDefaults).ToList(); List <string> excludePattern = JTokenToCollection(source.Exclude, SourceFile, ExcludePatternDefaults).ToList(); List <string> copyOnlyPattern = JTokenToCollection(source.CopyOnly, SourceFile, CopyOnlyPatternDefaults).ToList(); if (source.Modifiers != null) { foreach (SourceModifier modifier in source.Modifiers) { if (string.IsNullOrEmpty(modifier.Condition) || CppStyleEvaluatorDefinition.EvaluateFromString(modifier.Condition, rootVariableCollection)) { includePattern.AddRange(JTokenToCollection(modifier.Include, SourceFile, new string[0])); excludePattern.AddRange(JTokenToCollection(modifier.Exclude, SourceFile, new string[0])); copyOnlyPattern.AddRange(JTokenToCollection(modifier.CopyOnly, SourceFile, new string[0])); } } } Dictionary <string, string> renames = new Dictionary <string, string>(); if (resolvedNameParamValue != null) { foreach (IFileSystemInfo entry in configFile.Parent.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)) { string tmpltRel = entry.PathRelativeTo(configFile.Parent); string outRel = tmpltRel.Replace(SourceName, (string)resolvedNameParamValue); renames[tmpltRel] = outRel; } } sources.Add(new FileSource { CopyOnly = copyOnlyPattern.ToArray(), Exclude = excludePattern.ToArray(), Include = includePattern.ToArray(), Source = source.Source ?? "./", Target = source.Target ?? "./", Rename = renames }); } if (Sources.Count == 0) { IReadOnlyList <string> includePattern = IncludePatternDefaults; IReadOnlyList <string> excludePattern = ExcludePatternDefaults; IReadOnlyList <string> copyOnlyPattern = CopyOnlyPatternDefaults; Dictionary <string, string> renames = new Dictionary <string, string>(); object resolvedValue; if (parameters.ResolvedValues.TryGetValue(NameParameter, out resolvedValue)) { foreach (IFileSystemInfo entry in configFile.Parent.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)) { string tmpltRel = entry.PathRelativeTo(configFile.Parent); string outRel = tmpltRel.Replace(SourceName, (string)resolvedValue); renames[tmpltRel] = outRel; } } sources.Add(new FileSource { CopyOnly = copyOnlyPattern, Exclude = excludePattern, Include = includePattern, Source = "./", Target = "./", Rename = renames }); } _sources = sources; }