/// <summary> /// Creates a list of PropertyEditorManifest from the file contents of each manifest file /// </summary> /// <param name="manifestFileContents"></param> /// <returns></returns> /// <remarks> /// This ensures that comments are removed (but they have to be /* */ style comments /// and ensures that virtual paths are replaced with real ones /// </remarks> internal static IEnumerable<PackageManifest> CreateManifests(params string[] manifestFileContents) { var result = new List<PackageManifest>(); foreach (var m in manifestFileContents) { if (m.IsNullOrWhiteSpace()) continue; //remove any comments first Comments.Replace(m, match => ""); var deserialized = JsonConvert.DeserializeObject<JObject>(m); //validate the config var config = deserialized.Properties().Where(x => x.Name == "config").ToArray(); if (config.Length > 1) { throw new FormatException("The manifest is not formatted correctly contains more than one 'config' element"); } //validate the init var init = deserialized.Properties().Where(x => x.Name == "init").ToArray(); if (init.Length > 1) { throw new FormatException("The manifest is not formatted correctly contains more than one 'init' element"); } //validate the property editors section var propEditors = deserialized.Properties().Where(x => x.Name == "propertyEditors").ToArray(); if (propEditors.Length > 1) { throw new FormatException("The manifest is not formatted correctly contains more than one 'propertyEditors' element"); } var jConfig = config.Any() ? (JObject) deserialized["config"] : new JObject(); ReplaceVirtualPaths(jConfig); //replace virtual paths for each property editor if (deserialized["propertyEditors"] != null) { foreach (JObject p in deserialized["propertyEditors"]) { if (p["editor"] != null) { ReplaceVirtualPaths((JObject) p["editor"]); } if (p["preValues"] != null) { ReplaceVirtualPaths((JObject)p["preValues"]); } } } var manifest = new PackageManifest() { JavaScriptConfig = jConfig, JavaScriptInitialize = init.Any() ? (JArray)deserialized["init"] : new JArray(), PropertyEditors = propEditors.Any() ? (JArray)deserialized["propertyEditors"] : new JArray(), }; result.Add(manifest); } return result; }
/// <summary> /// Creates a list of PropertyEditorManifest from the file contents of each manifest file /// </summary> /// <param name="manifestFileContents"></param> /// <returns></returns> /// <remarks> /// This ensures that comments are removed (but they have to be /* */ style comments /// and ensures that virtual paths are replaced with real ones /// </remarks> internal static IEnumerable <PackageManifest> CreateManifests(params string[] manifestFileContents) { var result = new List <PackageManifest>(); foreach (var m in manifestFileContents) { if (m.IsNullOrWhiteSpace()) { continue; } //remove any comments first Comments.Replace(m, match => ""); var deserialized = JsonConvert.DeserializeObject <JObject>(m); //validate the config var config = deserialized.Properties().Where(x => x.Name == "config").ToArray(); if (config.Length > 1) { throw new FormatException("The manifest is not formatted correctly contains more than one 'config' element"); } //validate the init var init = deserialized.Properties().Where(x => x.Name == "init").ToArray(); if (init.Length > 1) { throw new FormatException("The manifest is not formatted correctly contains more than one 'init' element"); } //validate the property editors section var propEditors = deserialized.Properties().Where(x => x.Name == "propertyEditors").ToArray(); if (propEditors.Length > 1) { throw new FormatException("The manifest is not formatted correctly contains more than one 'propertyEditors' element"); } var jConfig = config.Any() ? (JObject)deserialized["config"] : new JObject(); ReplaceVirtualPaths(jConfig); //replace virtual paths for each property editor if (deserialized["propertyEditors"] != null) { foreach (JObject p in deserialized["propertyEditors"]) { if (p["editor"] != null) { ReplaceVirtualPaths((JObject)p["editor"]); } if (p["preValues"] != null) { ReplaceVirtualPaths((JObject)p["preValues"]); } } } var manifest = new PackageManifest() { JavaScriptConfig = jConfig, JavaScriptInitialize = init.Any() ? (JArray)deserialized["init"] : new JArray(), PropertyEditors = propEditors.Any() ? (JArray)deserialized["propertyEditors"] : new JArray(), }; result.Add(manifest); } return(result); }