public static ConfigModel FromJObject(JObject source) { ConfigModel temp = new ConfigModel(); temp.Author = source.ToString(nameof(Author)); List <string> classifications = new List <string>(); temp.Classifications = classifications; foreach (JToken item in source.Get <JArray>(nameof(Classifications))) { classifications.Add(item.ToString()); } temp.Config = new Dictionary <string, JObject>(); foreach (JProperty prop in source.PropertiesOf(nameof(Config))) { temp.Config[prop.Name] = (JObject)prop.Value; } temp.DefaultName = source.ToString(nameof(DefaultName)); temp.GroupIdentity = source.ToString(nameof(GroupIdentity)); temp.Identity = source.ToString(nameof(Identity)); temp.Macros = new Dictionary <string, string>(); foreach (JProperty prop in source.PropertiesOf(nameof(Macros))) { temp.Macros[prop.Name] = prop.Value.ToString(); } temp.Name = source.ToString(nameof(Name)); temp.ShortName = source.ToString(nameof(ShortName)); temp.Special = new Dictionary <string, Dictionary <string, JObject> >(); foreach (JProperty prop in source.PropertiesOf(nameof(Special))) { Dictionary <string, JObject> current = temp.Special[prop.Name] = new Dictionary <string, JObject>(); foreach (JProperty child in ((JObject)prop.Value).Properties()) { current[child.Name] = (JObject)child.Value; } } temp.Sources = new List <FileSource>(); foreach (JToken item in source.Get <JArray>(nameof(Sources))) { FileSource src = new FileSource(); src.Source = item.ToString(nameof(src.Source)); src.Target = item.ToString(nameof(src.Target)); src.Include = item.Get <JArray>(nameof(src.Include)).ArrayAsStrings(); src.Exclude = item.Get <JArray>(nameof(src.Exclude)).ArrayAsStrings(); src.CopyOnly = item.Get <JArray>(nameof(src.CopyOnly)).ArrayAsStrings(); src.Rename = item.ToStringDictionary(StringComparer.OrdinalIgnoreCase, nameof(src.Rename)); temp.Sources.Add(src); } temp.Parameters = new Dictionary <string, Parameter>(); foreach (JToken item in source.Get <JArray>(nameof(Parameters))) { Parameter p = new Parameter(); p.DefaultValue = item.ToString(nameof(p.DefaultValue)); p.Description = item.ToString(nameof(p.Description)); p.IsName = item.ToBool(nameof(p.IsName)); p.IsVariable = item.ToBool(nameof(p.IsVariable)); p.Name = item.ToString(nameof(p.Name)); p.Requirement = item.ToEnum <TemplateParameterPriority>(nameof(p.Requirement)); p.Type = item.ToString(nameof(p.Type)); temp.Parameters[p.Name] = p; } Dictionary <string, string> tags = new Dictionary <string, string>(); temp.Tags = tags; foreach (JProperty item in source.PropertiesOf(nameof(Tags))) { tags[item.Name] = item.Value.ToString(); } return(temp); }
public GlobalRunSpec(FileSource source, ITemplateSourceFolder templateRoot, IParameterSet parameters, IReadOnlyDictionary <string, JObject> operations, IReadOnlyDictionary <string, Dictionary <string, JObject> > special) { int expect = source.Include?.Length ?? 0; List <IPathMatcher> includes = new List <IPathMatcher>(expect); if (source.Include != null && expect > 0) { foreach (string include in source.Include) { includes.Add(new GlobbingPatternMatcher(include)); } } Include = includes; expect = source.CopyOnly?.Length ?? 0; List <IPathMatcher> copyOnlys = new List <IPathMatcher>(expect); if (source.CopyOnly != null && expect > 0) { foreach (string copyOnly in source.CopyOnly) { copyOnlys.Add(new GlobbingPatternMatcher(copyOnly)); } } CopyOnly = copyOnlys; expect = source.Exclude?.Length ?? 0; List <IPathMatcher> excludes = new List <IPathMatcher>(expect); if (source.Exclude != null && expect > 0) { foreach (string exclude in source.Exclude) { excludes.Add(new GlobbingPatternMatcher(exclude)); } } Exclude = excludes; Rename = source.Rename != null ? new Dictionary <string, string>(source.Rename, StringComparer.OrdinalIgnoreCase) : new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); VariableCollection variables; Operations = ProcessOperations(parameters, templateRoot, operations, out variables); RootVariableCollection = variables; Dictionary <IPathMatcher, IRunSpec> specials = new Dictionary <IPathMatcher, IRunSpec>(); if (special != null) { foreach (KeyValuePair <string, Dictionary <string, JObject> > specialEntry in special) { IReadOnlyList <IOperationProvider> specialOps = null; VariableCollection specialVariables = variables; if (specialEntry.Value != null) { specialOps = ProcessOperations(parameters, templateRoot, specialEntry.Value, out specialVariables); } RunSpec spec = new RunSpec(specialOps, specialVariables ?? variables); specials[new GlobbingPatternMatcher(specialEntry.Key)] = spec; } } Special = specials; }