Example #1
0
        public static string Serialize(Models.v1_2.Bom bom)
        {
            Contract.Requires(bom != null);

            var jsonBom = JsonSerializer.Serialize(bom, Utils.GetJsonSerializerOptions_v1_2());

            return(jsonBom);
        }
Example #2
0
        public void BomConversionTest_v1_1_to_v1_2_Test(string filename)
        {
            var resourceFilename = Path.Join("Resources", "v1.1", filename + "-1.1.xml");
            var xmlBom           = File.ReadAllText(resourceFilename);

            var bom       = XmlBomDeserializer.Deserialize_v1_1(xmlBom);
            var actualBom = new Models.v1_2.Bom(bom);

            xmlBom = XmlBomSerializer.Serialize(actualBom);

            Snapshot.Match(xmlBom, SnapshotNameExtension.Create(filename));
        }
Example #3
0
        public static string Serialize(Models.v1_2.Bom bom)
        {
            Contract.Requires(bom != null);

            var serializer = new XmlSerializer(typeof(Models.v1_2.Bom));

            using (var writer = new Utf8StringWriter())
            {
                serializer.Serialize(writer, bom);
                return(writer.ToString());
            }
        }
        public static void CleanupEmptyXmlArrays(Models.v1_2.Bom bom)
        {
            if (bom.Metadata?.Authors?.Count == 0)
            {
                bom.Metadata.Authors = null;
            }
            if (bom.Metadata?.Tools?.Count == 0)
            {
                bom.Metadata.Tools = null;
            }
            if (bom.Components?.Count == 0)
            {
                bom.Components = null;
            }
            if (bom.Services?.Count == 0)
            {
                bom.Services = null;
            }
            if (bom.ExternalReferences?.Count == 0)
            {
                bom.ExternalReferences = null;
            }
            if (bom.Dependencies?.Count == 0)
            {
                bom.Dependencies = null;
            }

            if (bom.Components != null)
            {
                foreach (var component in bom.Components)
                {
                    CleanupEmptyXmlArrays(component);
                }
            }

            if (bom.Dependencies != null)
            {
                foreach (var dependency in bom.Dependencies)
                {
                    if (dependency.Dependencies?.Count == 0)
                    {
                        dependency.Dependencies = null;
                    }
                }
            }

            if (bom.Dependencies?.Count == 0)
            {
                bom.Dependencies = null;
            }
        }