Esempio n. 1
0
        public void Metadata()
        {
            using (CaptureConsole) {
                var swid = new SoftwareIdentity();

                swid.AddAttribute(XNamespace.Get("http://oneget.org/swidtag") + "test", "value");

                // add some data
                var meta1 = swid.AddMeta();
                meta1.AddAttribute("Key", "Value");
                meta1.AddAttribute("Key2", "Value");
                meta1.AddAttribute(XNamespace.Get("http://oneget.org/swidtag") + "other", "somevalue");

                var meta2 = swid.AddMeta();
                meta2.AddAttribute(XNamespace.Get("http://oneget.org/swidtag") + "other2", "somevalue2");

                // to xml
                var xml = XDocument.Parse(swid.SwidTagText);
                Console.WriteLine("SWID: {0} ", swid.SwidTagText);

                // assertions
                Assert.Equal(3, meta1.Attributes.Keys.Count());
                Assert.Equal(1, meta2.Attributes.Keys.Count());

                Assert.Equal("Value", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Meta[1]/@Key").Value);
                Assert.Equal("Value", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Meta[1]/@Key2").Value);
                Assert.Equal("somevalue", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Meta[1]/@oneget:other").Value);
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void Metadata()
        {
            using (CaptureConsole) {
                var swid = new SoftwareIdentity();

                swid.AddAttribute(XNamespace.Get("http://oneget.org/swidtag") + "test", "value");

                // add some data
                var meta1 = swid.AddMeta();
                meta1.AddAttribute("Key", "Value");
                meta1.AddAttribute("Key2", "Value");
                meta1.AddAttribute(XNamespace.Get("http://oneget.org/swidtag") + "other", "somevalue");

                var meta2 = swid.AddMeta();
                meta2.AddAttribute(XNamespace.Get("http://oneget.org/swidtag") + "other2", "somevalue2");

                // to xml
                var xml = XDocument.Parse(swid.SwidTagText);
                Console.WriteLine("SWID: {0} ", swid.SwidTagText);

                // assertions
                Assert.Equal(3, meta1.Attributes.Keys.Count());
                Assert.Equal(1, meta2.Attributes.Keys.Count());

                Assert.Equal("Value", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Meta[1]/@Key").Value);
                Assert.Equal("Value", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Meta[1]/@Key2").Value);
                Assert.Equal("somevalue", xml.XPathToAttribute("/swid:SoftwareIdentity/swid:Meta[1]/@oneget:other").Value);
            }
        }