public void BomConversionTest_v1_2_to_v1_1_Test(string filename) { var resourceFilename = Path.Join("Resources", "v1.2", filename + "-1.2.xml"); var xmlBom = File.ReadAllText(resourceFilename); var bom = XmlBomDeserializer.Deserialize_v1_2(xmlBom); var actualBom = new Models.v1_1.Bom(bom); xmlBom = XmlBomSerializer.Serialize(actualBom); Snapshot.Match(xmlBom, SnapshotNameExtension.Create(filename)); }
public static string Serialize(Models.v1_1.Bom bom) { Contract.Requires(bom != null); var serializer = new XmlSerializer(typeof(Models.v1_1.Bom)); using (var writer = new Utf8StringWriter()) { serializer.Serialize(writer, bom); return(writer.ToString()); } }
public static void CleanupEmptyXmlArrays(Models.v1_1.Bom bom) { if (bom.Components?.Count == 0) { bom.Components = null; } if (bom.ExternalReferences?.Count == 0) { bom.ExternalReferences = null; } if (bom.Components != null) { foreach (var component in bom.Components) { CleanupEmptyXmlArrays(component); } } }
public static Models.v1_2.Bom Deserialize(Stream stream) { try { return(Deserialize_v1_2(stream)); } catch (InvalidOperationException) {} stream.Position = 0; try { return(new Models.v1_2.Bom(Deserialize_v1_1(stream))); } catch (InvalidOperationException) {} stream.Position = 0; var v1_0_sbom = Deserialize_v1_0(stream); var v1_1_sbom = new Models.v1_1.Bom(v1_0_sbom); return(new Models.v1_2.Bom(v1_1_sbom)); }