public bool YieldEntity(string parentFastPath, string name, string regid, string role, string thumbprint) { if (_currentSoftwareIdentity == null || parentFastPath != _currentSoftwareIdentity.FastPackageReference) { Console.WriteLine("TEMPORARY: SHOULD NOT GET HERE [YieldSoftwareMetadata] ================================================"); } if (_currentSoftwareIdentity != null) { _currentSoftwareIdentity.AddEntity(name, regid, role, thumbprint); } return(Continue); }
public void EntitiesTag() { using (CaptureConsole) { var swid = new SoftwareIdentity() { Name = "SamplePackage", FastPackageReference = "some-string", Source = "test-source", SearchKey = "search-key", Status = "test-status", TagId = "some-tag-id", Version = "1.0", VersionScheme = "multipart-numeric", TagVersion = "1", }; // add some data swid.AddEntity("garrett", "http://fearthecowboy.com/", "author"); var entity = swid.AddEntity("bob", "http://bob.com/", "contributor"); entity.AddRole("consultant"); // to xml var xml = XDocument.Parse(swid.SwidTagText); Console.WriteLine("SWID: {0} ", swid.SwidTagText); Assert.Equal("garrett", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Entity[1]/@name").Value); Assert.Equal("http://fearthecowboy.com/", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Entity[1]/@regId").Value); Assert.Equal("author", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Entity[1]/@role").Value); Assert.Equal(2, entity.Roles.Count()); Assert.Contains("contributor", entity.Roles); Assert.Contains("consultant", entity.Roles); Assert.Equal("contributor consultant", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Entity[2]/@role").Value); } }
private void saveTag_Click(object sender, RoutedEventArgs e) { string errorMsg = "Error: You have not entered enough information to create a proper SWID tag. Please review the following items \r\n\r\n"; Boolean error = false; if (tb_prdName.Text == "") { errorMsg = errorMsg + " - Product Name must be provided\r\n"; error = true; } if (tb_version.Text == "") { errorMsg = errorMsg + " - Product Version must be provided\r\n"; error = true; } if (tb_tagId.Text == "") { errorMsg = errorMsg + " - TagID must be provided\r\n"; error = true; } if (tb_entityName1.Text == "") { errorMsg = errorMsg + " - Entity name must be provided\r\n"; error = true; } if (tb_entityRegid1.Text == "") { errorMsg = errorMsg + " - Entity regid must be provided\r\n"; error = true; } if (error) { MessageBox.Show(errorMsg, "SWID Tag Generator", MessageBoxButton.OK, MessageBoxImage.Error); return; } var swidTag = new SoftwareIdentity(); swidTag.AddMeta().Generator = "TagVault.org Tag Creator"; swidTag.XmlLang = tb_defaultLang.Text; swidTag.Name = tb_prdName.Text; swidTag.Version = tb_version.Text; swidTag.VersionScheme = cb_versionScheme.Text; swidTag.TagId = tb_tagId.Text; if (tb_edition.Text != "") { swidTag.AddMeta().Edition = tb_edition.Text; } if (tb_Colloquial.Text != "") { swidTag.AddMeta().ColloquialVersion = tb_Colloquial.Text; } string tagToWrite = ""; // // Setup the roles that have been selected by the user for the first entity // string roles = ""; if ((bool)tbtn_tagCreator1.IsChecked) { roles = "tagCreator"; } if ((bool)tbtn_softwareCreator1.IsChecked) { roles = roles + " softwareCreator"; } if ((bool)tbtn_licensor1.IsChecked) { roles = roles + " licensor"; } swidTag.AddEntity(tb_entityName1.Text, tb_entityRegid1.Text, roles); // // Setup the roles that have been selected by the user for the first entity // if (tb_entityName2.Text != "") { roles = ""; if ((bool)tbtn_softwareCreator2.IsChecked) { roles = roles + " softwareCreator"; } if ((bool)tbtn_licensor2.IsChecked) { roles = roles + " licensor"; } swidTag.AddEntity(tb_entityName2.Text, tb_entityRegid2.Text, roles); } if (tb_entityName3.Text != "") { roles = ""; if ((bool)tbtn_softwareCreator3.IsChecked) { roles = roles + " softwareCreator"; } if ((bool)tbtn_licensor3.IsChecked) { roles = roles + " licensor"; } swidTag.AddEntity(tb_entityName3.Text, tb_entityRegid3.Text, roles); } // // Tmp fix for incorrect attribute name // //System.IO.File.WriteAllText("c:\\tmp\\test1.xml", swidTag.SwidTagXml.Replace("regId", "regid"); tagToWrite = swidTag.SwidTagXml.Replace("regId", "regid"); tagToWrite = tagToWrite.Replace("p2:role", "role"); tagToWrite = tagToWrite.Replace(" xmlns:p2=\"http://standards.iso.org/iso/19770/-2/2015/schema.xsd\" ", " "); tagToWrite = tagToWrite.Replace("standalone=\"yes\"", ""); tagToWrite = tagToWrite.Replace("utf-16", "utf-8"); tagToWrite = tagToWrite.Replace("lang", "xml:lang"); SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = "SWIDTag (*.swidtag)|*.swidtag" }; if (saveFileDialog.ShowDialog() == true) { System.IO.File.WriteAllText(saveFileDialog.FileName, tagToWrite); } //System.IO.File.WriteAllText(dialog.FileName, tagToWrite); // // End of Tmp fix // //System.IO.File.WriteAllText("c:\\tmp\\test1.xml", tagToWrite); }
public void EntitiesTag() { using (CaptureConsole) { var swid = new SoftwareIdentity() { Name = "SamplePackage", FastPackageReference = "some-string", Source = "test-source", SearchKey = "search-key", Status = "test-status", TagId = "some-tag-id", Version = "1.0", VersionScheme = "multipart-numeric", TagVersion = "1", }; // add some data swid.AddEntity("garrett", "http://fearthecowboy.com/", "author"); var entity = swid.AddEntity("bob", "http://bob.com/", "contributor"); entity.AddRole("consultant"); // to xml var xml = XDocument.Parse(swid.SwidTagText); Console.WriteLine("SWID: {0} ", swid.SwidTagText); Assert.Equal("garrett", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Entity[1]/@name").Value); Assert.Equal("http://fearthecowboy.com/", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Entity[1]/@regId").Value); Assert.Equal("author", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Entity[1]/@role").Value); Assert.Equal(2, entity.Roles.Count()); Assert.Contains("contributor", entity.Roles); Assert.Contains("consultant", entity.Roles); Assert.Equal("contributor consultant", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Entity[2]/@role").Value); } }