Example #1
0
        private static bool TryLoadXmlTag(string text, out SoftwareIdentity tag)
        {
            try
            {
                tag = SoftwareIdentity.LoadXml(text);
            }
            catch (Exception)
            {
                tag = null;
            }

            return(tag != null);
        }
Example #2
0
        private void btnFileOpen_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = "*.swidtag";
            dlg.Filter     = "SWID Tag Files (*.swidtag)|*.swidtag";

            // Display OpenFileDialog by calling ShowDialog method
            Nullable <bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;

                // Read text into string
                string XMLData = System.IO.File.ReadAllText(filename);

                //Note - this change is required to deal with an error in the element name in the SWID handling library
                XMLData = XMLData.Replace("regid", "regId");

                // Parse the Text into a SWID Tag
                var openTag = SoftwareIdentity.LoadXml(XMLData);

                // Clear out and reset the form before starting to populate values

                tb_prdName.Text    = "";
                tb_edition.Text    = "";
                tb_Colloquial.Text = "";
                tb_version.Text    = "";
                tb_tagId.Text      = "";

                tb_entityName1.Text             = "";
                tb_entityRegid1.Text            = "";
                tbtn_softwareCreator1.IsChecked = false;
                tbtn_licensor1.IsChecked        = false;

                tb_entityName2.Text             = "";
                tb_entityRegid2.Text            = "";
                tbtn_softwareCreator2.IsChecked = false;
                tbtn_licensor2.IsChecked        = false;
                Entity2.IsExpanded = false;


                tb_entityName3.Text             = "";
                tb_entityRegid3.Text            = "";
                tbtn_softwareCreator3.IsChecked = false;
                tbtn_licensor3.IsChecked        = false;
                Entity3.IsExpanded = false;

                tb_prdName.Text = openTag.Name;
                var meta = openTag.Meta.FirstOrDefault(each => each["edition"] != null);
                if (meta != null)
                {
                    // you can access metdata as a dictionary
                    var str1 = meta["edition"];
                    tb_edition.Text = str1;
                    // or use known properties directly
                    //var str = meta.edition;
                }
                tb_version.Text       = openTag.Version;
                cb_versionScheme.Text = openTag.VersionScheme;
                tb_tagId.Text         = openTag.TagId;
                tb_defaultLang.Text   = openTag.XmlLang;

                //tb_defaultLang.Text = openTag.XmlLang;  //XmlLang attribute is not working from the SWID Tag Library


                if (XMLData.Contains("lang"))
                {
                    int langAttributeStart = XMLData.IndexOf("lang");
                    int langValueStart     = XMLData.IndexOf("\"", langAttributeStart) + 1;
                    int langValueEnd       = XMLData.IndexOf("\"", langValueStart) - 1;
                    int langLen            = langValueEnd - langValueStart + 1;

                    tb_defaultLang.Text = XMLData.Substring(langValueStart, langLen);
                }

                meta = openTag.Meta.FirstOrDefault(each => each["colloquialVersion"] != null);
                if (meta != null)
                {
                    // you can access metdata as a dictionary
                    var str1 = meta["colloquialVersion"];
                    tb_Colloquial.Text = str1;
                    // or use known properties directly
                    //var str = meta.edition;
                }



                System.Windows.Controls.TextBox  entName, entRegid;
                System.Windows.Controls.CheckBox swCreator, tagCreator, licensor;

                bool   tagCreatorDefined = false, softwareCreatorDefined = false, licensorDefined = false, tooManyEntities = false, noEntities = true;
                int    entityOptionNumber = 2;
                string warningMessage     = "";


                foreach (Entity ent in openTag.Entities)
                {
                    if (openTag.Entities.Count() > 3)
                    {
                        tooManyEntities = true;
                    }
                    if (openTag.Entities.Count() > 0)
                    {
                        noEntities = false;
                    }
                    if (ent.Roles.Contains("tagCreator"))
                    {
                        entName    = tb_entityName1;
                        entRegid   = tb_entityRegid1;
                        swCreator  = tbtn_softwareCreator1;
                        licensor   = tbtn_licensor1;
                        tagCreator = tbtn_tagCreator1;

                        if (tagCreatorDefined)
                        {
                            MessageBox.Show("Error - SWID Tag contains multiple Entity values with the role of tagCreator", "SWID Tag Generator", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        tagCreatorDefined = true;  // Note - this will be used to identify if tagCreator has already been identified in a subsequent Entity
                    }
                    else
                    {
                        if (entityOptionNumber == 2)
                        {
                            entName            = tb_entityName2;
                            entRegid           = tb_entityRegid2;
                            swCreator          = tbtn_softwareCreator2;
                            licensor           = tbtn_licensor2;
                            Entity2.IsExpanded = true;
                            entityOptionNumber++;
                        }
                        else
                        {
                            entName            = tb_entityName3;
                            entRegid           = tb_entityRegid3;
                            swCreator          = tbtn_softwareCreator3;
                            licensor           = tbtn_licensor3;
                            Entity3.IsExpanded = true;
                            entityOptionNumber++;
                        }
                    }


                    entName.Text  = ent.Name;
                    entRegid.Text = ent.RegId;

                    if (ent.Roles.Contains("softwareCreator"))
                    {
                        if (softwareCreatorDefined)
                        {
                            MessageBox.Show("Error - SWID Tag contains multiple Entity values with the role of softwareCreator", "SWID Tag Generator", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        else
                        {
                            swCreator.IsChecked    = true;
                            softwareCreatorDefined = true;
                        }
                    }
                    if (ent.Roles.Contains("licensor"))
                    {
                        if (licensorDefined)
                        {
                            MessageBox.Show("Error - SWID Tag contains multiple Entity values with the role of licensor", "SWID Tag Generator", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        else
                        {
                            licensor.IsChecked = true;
                            licensorDefined    = true;
                        }
                    }
                }
                if (tooManyEntities)
                {
                    warningMessage = "    - There are more than 3 Entities defined in the SWID Tag\r\n";
                }
                if (noEntities)
                {
                    warningMessage = warningMessage + "    - There were no Entities defined in the SWID Tag\r\n";
                }
                if (!tagCreatorDefined)
                {
                    warningMessage = warningMessage + "    - This SWID tag has no tagCreator entity defined\r\n";
                }
                if (warningMessage != "")
                {
                    warningMessage = "There are some issues with how this application will display data from this tag including: \r\n\r\n" + warningMessage;
                    MessageBox.Show(warningMessage, "SWID Tag Generator", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Example #3
0
        private async Task <SoftwareIdentity> GetIndexSoftwareIdentity(CloudBlobDirectory sourcesDirectory, string contentType)
        {
            var extension = (contentType == FearTheCowboy.Iso19770.Schema.MediaType.SwidTagJsonLd) ? "json" : "xml";

            var indexBlob = sourcesDirectory.GetBlockBlobReference(String.Format("index.{0}.SoftwareIdentity", extension));

            if (indexBlob.Exists())
            {
                var text = await indexBlob.DownloadTextAsync();

                return((contentType == FearTheCowboy.Iso19770.Schema.MediaType.SwidTagJsonLd) ? SoftwareIdentity.LoadJson(text) : SoftwareIdentity.LoadXml(text));
            }

            return(new SoftwareIdentity()
            {
                Name = "AppSyndication Index", TagId = indexBlob.Uri.AbsoluteUri
            });
        }