예제 #1
0
        private async Task <List <string> > GetLicenseUrls(FileInfo[] nupkgFiles)
        {
            var retVal = new List <string>();

            foreach (var nupkgFile in nupkgFiles)
            {
                var tempPath    = Path.GetTempPath();
                var archivePath = Path.Combine(tempPath, Guid.NewGuid().ToString());
                System.IO.Compression.ZipFile.ExtractToDirectory(nupkgFile.FullName, archivePath);

                var directory = new DirectoryInfo(archivePath);

                var nuspecs = directory.GetFiles("*.nuspec");

                if (nuspecs?.Any() == true)
                {
                    foreach (var nuspec in nuspecs)
                    {
                        var xml = await _fileUtilities.ReadXmlDocument(nuspec);

                        var licenseElements = xml.GetElementsByTagName("licenseUrl");

                        if (licenseElements.Count > 0)
                        {
                            foreach (XmlNode licenseElement in licenseElements)
                            {
                                if (licenseElement != null)
                                {
                                    retVal.Add(licenseElement.InnerText);
                                }
                            }
                        }
                    }
                }

                _fileUtilities.DeleteDirectory(directory);
            }

            return(retVal);
        }