public static string BomSerializer(CycloneDX.Models.v1_2.Bom bom, BomFormat format) { if (format == BomFormat.Json || format == BomFormat.Json_v1_2) { return(JsonBomSerializer.Serialize(bom)); } else if (format == BomFormat.Xml || format == BomFormat.Xml_v1_2) { return(XmlBomSerializer.Serialize(bom)); } else if (format == BomFormat.Xml_v1_1) { return(XmlBomSerializer.Serialize(new CycloneDX.Models.v1_1.Bom(bom))); } else if (format == BomFormat.Xml_v1_0) { var v1_1_bom = new CycloneDX.Models.v1_1.Bom(bom); return(XmlBomSerializer.Serialize(new CycloneDX.Models.v1_0.Bom(v1_1_bom))); } else if (format == BomFormat.SpdxTag || format == BomFormat.SpdxTag_v2_2) { return(SpdxTagSerializer.Serialize(bom, SpdxVersion.v2_2)); } else if (format == BomFormat.SpdxTag_v2_1) { return(SpdxTagSerializer.Serialize(bom, SpdxVersion.v2_1)); } else if (format == BomFormat.Csv) { return(CsvSerializer.Serialize(bom)); } throw new UnsupportedFormatException("Unsupported SBOM file format"); }
public void Process() { if (!_productNumber.validateProductNumber()) { MessageBox.Show("Invalid Product number.", "Invalid Entry", MessageBoxButton.OK, MessageBoxImage.Error); return; } else if (!BomSelectionModel.HasSelectedItem()) { MessageBox.Show("No BOM is selected.", "Invalid Entry", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { ConfigurationManager.RefreshSection("applicationConfiguration"); BomFormat bomFormat = new BomFormat(_container.GetInstance <IFormatterConfiguration>(), BomSelectionModel.SelectedItem.Key, _productNumber); bomFormat.FormatBom(); ProductNumber = ""; } catch (Exception e) { MessageBox.Show("Error:\n\n" + ErrorFormating.FormatException(e), "Error Occured", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static async Task <int> Convert(string inputFile, string outputFile, InputFormat inputFormat, ConvertOutputFormat outputFormat) { var inputBomFormat = InputFormatHelper(inputFile, inputFormat); if (inputBomFormat == BomFormat.Unsupported) { return((int)ExitCode.ParameterValidationError); } BomFormat outputBomFormat = BomFormat.Unsupported; string inputBomString; CycloneDX.Models.v1_2.Bom inputBom; string outputBomString; if (outputFormat == ConvertOutputFormat.autodetect) { if (string.IsNullOrEmpty(outputFile)) { Console.Error.WriteLine("You must specify a value for --output-format when standard output is used"); return((int)ExitCode.ParameterValidationError); } outputBomFormat = Utils.DetectFileFormat(outputFile); if (outputBomFormat == BomFormat.Unsupported) { Console.Error.WriteLine("Unable to auto-detect output format from output filename"); return((int)ExitCode.ParameterValidationError); } } else { outputBomFormat = (BomFormat)outputFormat; } inputBomString = InputFileHelper(inputFile); if (inputBomString == null) { return((int)ExitCode.ParameterValidationError); } inputBom = Utils.BomDeserializer(inputBomString, inputBomFormat); outputBomString = Utils.BomSerializer(inputBom, outputBomFormat); if (string.IsNullOrEmpty(outputFile)) { Console.Write(outputBomString); } else { Console.WriteLine("Writing output file..."); await File.WriteAllTextAsync(outputFile, outputBomString); } return((int)ExitCode.Ok); }
public static CycloneDX.Models.v1_3.Bom BomDeserializer(string bom, BomFormat format) { if (format == BomFormat.Json) { return(Json.Deserializer.Deserialize(bom)); } else if (format == BomFormat.Xml) { return(Xml.Deserializer.Deserialize(bom)); } else if (format == BomFormat.Csv) { return(CsvSerializer.Deserialize(bom)); } throw new UnsupportedFormatException("Unsupported SBOM file format"); }