Ejemplo n.º 1
0
        /// <summary>
        /// If we cannot use psget to get swidtag information, we will try to fill in some of the information
        /// </summary>
        /// <param name="packageProvider"></param>
        /// <param name="psModuleInfo"></param>
        private void ProvideSwidTagInformation(PackageProvider packageProvider, PSModuleInfo psModuleInfo)
        {
            if (packageProvider == null || psModuleInfo == null)
            {
                return;
            }

            packageProvider.VersionScheme = "MultiPartNumeric";

            Microsoft.PackageManagement.Internal.Packaging.SoftwareMetadata softwareMetadata = new Microsoft.PackageManagement.Internal.Packaging.SoftwareMetadata();
            bool changed = false;

            var type = psModuleInfo.GetType();

            // introduced in ps 2.0
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Description))
            {
                softwareMetadata.Description = psModuleInfo.Description;
                changed = true;
            }

            // introduced in ps 3.0
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Copyright))
            {
                softwareMetadata.AddAttribute("copyright", psModuleInfo.Copyright);
                changed = true;
            }

            // tags is introduced in ps 5.0
            var tagsProperty = type.GetProperty("Tags");
            bool isV5 = tagsProperty != null;

            if (isV5)
            {
                // introduced in ps 5.0
                var tags = tagsProperty.GetValue(psModuleInfo);

                // check that we have something in tags
                if (tags is IEnumerable<string> && (tags as IEnumerable<string>).Any())
                {
                    softwareMetadata.AddAttribute("tags", string.Join(" ", (tags as IEnumerable<string>).Distinct()));
                    changed = true;
                }

                var releaseNotes = type.GetProperty("ReleaseNotes").GetValue(psModuleInfo);

                // check that we have something in releasenotes
                if (releaseNotes is string && !string.IsNullOrWhiteSpace(type.GetProperty("ReleaseNotes").GetValue(psModuleInfo) as string))
                {
                    softwareMetadata.AddAttribute("tags", string.Join(" ", (tags as IEnumerable<string>).Distinct()));
                    changed = true;
                }
            }

            if (changed)
            {
                packageProvider.AddElement(softwareMetadata);
            }

            if (isV5)
            {
                var iconUri = type.GetProperty("IconUri").GetValue(psModuleInfo);

                // introduced in ps 5.0
                if (iconUri is Uri)
                {
                    packageProvider.AddLink(iconUri as Uri, "icon");
                }

                var licenseUri = type.GetProperty("LicenseUri").GetValue(psModuleInfo);

                // introduced in ps 5.0
                if (licenseUri is Uri)
                {
                    packageProvider.AddLink(licenseUri as Uri, "license");
                }

                var projectUri = type.GetProperty("ProjectUri").GetValue(psModuleInfo);

                // introduced in ps 5.0
                if (projectUri is Uri)
                {
                    packageProvider.AddLink(projectUri as Uri, "project");
                }

            }

            // introduced in ps 3.0
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Author))
            {
                packageProvider.AddEntity(psModuleInfo.Author, null, "author");
            }

            // introduced in ps 3.0
            if (!string.IsNullOrWhiteSpace(psModuleInfo.CompanyName))
            {
                packageProvider.AddEntity(psModuleInfo.CompanyName, null, "owner");
            }        
        }
Ejemplo n.º 2
0
        /// <summary>
        /// If we cannot use psget to get swidtag information, we will try to fill in some of the information
        /// </summary>
        /// <param name="packageProvider"></param>
        /// <param name="psModuleInfo"></param>
        private void ProvideSwidTagInformation(PackageProvider packageProvider, PSModuleInfo psModuleInfo)
        {
            if (packageProvider == null || psModuleInfo == null)
            {
                return;
            }

            packageProvider.VersionScheme = "MultiPartNumeric";

            Microsoft.PackageManagement.Internal.Packaging.SoftwareMetadata softwareMetadata = new Microsoft.PackageManagement.Internal.Packaging.SoftwareMetadata();
            bool changed = false;

            var type = psModuleInfo.GetType();

            // introduced in ps 2.0
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Description))
            {
                softwareMetadata.Description = psModuleInfo.Description;
                changed = true;
            }

            // introduced in ps 3.0
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Copyright))
            {
                softwareMetadata.AddAttribute("copyright", psModuleInfo.Copyright);
                changed = true;
            }

            // tags is introduced in ps 5.0
            var  tagsProperty = type.GetProperty("Tags");
            bool isV5         = tagsProperty != null;

            if (isV5)
            {
                // introduced in ps 5.0
                var tags = tagsProperty.GetValue(psModuleInfo);

                // check that we have something in tags
                if (tags is IEnumerable <string> && (tags as IEnumerable <string>).Any())
                {
                    softwareMetadata.AddAttribute("tags", string.Join(" ", (tags as IEnumerable <string>).Distinct()));
                    changed = true;
                }

                var releaseNotes = type.GetProperty("ReleaseNotes").GetValue(psModuleInfo);

                // check that we have something in releasenotes
                if (releaseNotes is string && !string.IsNullOrWhiteSpace(type.GetProperty("ReleaseNotes").GetValue(psModuleInfo) as string))
                {
                    softwareMetadata.AddAttribute("tags", string.Join(" ", (tags as IEnumerable <string>).Distinct()));
                    changed = true;
                }
            }

            if (changed)
            {
                packageProvider.AddElement(softwareMetadata);
            }

            if (isV5)
            {
                var iconUri = type.GetProperty("IconUri").GetValue(psModuleInfo);

                // introduced in ps 5.0
                if (iconUri is Uri)
                {
                    packageProvider.AddLink(iconUri as Uri, "icon");
                }

                var licenseUri = type.GetProperty("LicenseUri").GetValue(psModuleInfo);

                // introduced in ps 5.0
                if (licenseUri is Uri)
                {
                    packageProvider.AddLink(licenseUri as Uri, "license");
                }

                var projectUri = type.GetProperty("ProjectUri").GetValue(psModuleInfo);

                // introduced in ps 5.0
                if (projectUri is Uri)
                {
                    packageProvider.AddLink(projectUri as Uri, "project");
                }
            }

            // introduced in ps 3.0
            if (!string.IsNullOrWhiteSpace(psModuleInfo.Author))
            {
                packageProvider.AddEntity(psModuleInfo.Author, null, "author");
            }

            // introduced in ps 3.0
            if (!string.IsNullOrWhiteSpace(psModuleInfo.CompanyName))
            {
                packageProvider.AddEntity(psModuleInfo.CompanyName, null, "owner");
            }
        }