Пример #1
0
        public static IEnumerable<string> GetPackageFolders(RemoteInstall remote, string projectPath, string systemRepositoryPath, params string[] packageNamesToLoad)
        {
            var regex = new Regex(string.Format(@"^(?<name>{0})-(?<version>\d+(\.\d+(\.\d+(\.\d+)?)?)?)$", string.Join("|", packageNamesToLoad.ToArray())), RegexOptions.IgnoreCase);

            IEnumerable<string> bootstrapPackagePaths = Enumerable.Empty<string>();
            if (projectPath != null)
            {
                EnsurePackagesUnzippedInRepository(projectPath);

                bootstrapPackagePaths = GetLatestPackagesForProjectRepository(packageNamesToLoad, projectPath);
                if (bootstrapPackagePaths.Count() >= packageNamesToLoad.Length) return bootstrapPackagePaths;
            }
            FileNotFoundException fileNotFound = null;
            try
            {
                bootstrapPackagePaths = GetLatestPackagesForSystemRepository(systemRepositoryPath, packageNamesToLoad);
            }
            catch (FileNotFoundException e)
            {
                fileNotFound = e;
            }
            if ((fileNotFound != null || bootstrapPackagePaths.Count() < packageNamesToLoad.Length) && remote.Enabled)
                return TryDownloadPackages(systemRepositoryPath, packageNamesToLoad, remote);
            if (bootstrapPackagePaths.Count() >= packageNamesToLoad.Length)
                return bootstrapPackagePaths;
            throw new ArgumentException("No package present.", fileNotFound);
        }
Пример #2
0
        public static IEnumerable <string> GetPackageFolders(RemoteInstall remote, string currentDirectory, string systemRepositoryPath, params string[] packageNamesToLoad)
        {
            var regex = new Regex(string.Format(@"^(?<name>{0})-(?<version>\d+(\.\d+(\.\d+(\.\d+)?)?)?)$", string.Join("|", packageNamesToLoad.ToArray())), RegexOptions.IgnoreCase);

            EnsurePackagesUnzippedInRepository(Environment.CurrentDirectory);

            var bootstrapPackagePaths = currentDirectory != null
                ? GetLatestPackagesForProjectRepository(packageNamesToLoad, currentDirectory)
                : new string[0];

            if (bootstrapPackagePaths.Count() >= packageNamesToLoad.Length)
            {
                return(bootstrapPackagePaths);
            }

            FileNotFoundException fileNotFound = null;

            try
            {
                bootstrapPackagePaths = GetLatestPackagesForSystemRepository(systemRepositoryPath, packageNamesToLoad);
            }
            catch (FileNotFoundException e)
            {
                fileNotFound = e;
            }
            if ((fileNotFound != null || bootstrapPackagePaths.Count() < packageNamesToLoad.Length) && remote.Enabled)
            {
                return(TryDownloadPackages(systemRepositoryPath, packageNamesToLoad, remote));
            }
            if (bootstrapPackagePaths.Count() >= packageNamesToLoad.Length)
            {
                return(bootstrapPackagePaths);
            }
            throw new ArgumentException("No package present.", fileNotFound);
        }
Пример #3
0
        public static IEnumerable<string> GetPackageFolders(RemoteInstall remote, string currentDirectory, string systemRepositoryPath, params string[] packageNamesToLoad)
        {
            var regex = new Regex(string.Format(@"^(?<name>{0})-(?<version>\d+(\.\d+(\.\d+(\.\d+)?)?)?)$", string.Join("|", packageNamesToLoad.ToArray())), RegexOptions.IgnoreCase);
            EnsurePackagesUnzippedInProjectRepository(Environment.CurrentDirectory);

            var bootstrapAssemblies = currentDirectory != null ? GetLatestPackagesForProjectRepository(regex, currentDirectory) : new string[0];
            return bootstrapAssemblies.Count() != packageNamesToLoad.Length
                           ? ((bootstrapAssemblies = GetLatestPackagesForSystemRepository(systemRepositoryPath, regex)).Count() != packageNamesToLoad.Length && remote.Enabled
                                      ? TryDownloadPackages(systemRepositoryPath, packageNamesToLoad, regex, remote)
                                      : bootstrapAssemblies)
                           : bootstrapAssemblies;
        }
Пример #4
0
        public static IEnumerable <string> GetPackageFolders(RemoteInstall remote, string projectPath, string systemPath, params string[] packageNamesToLoad)
        {
            DirectoryInfo systemDirectory = systemPath == null ? null : new DirectoryInfo(systemPath);

            var bootstrapPackagePaths = Enumerable.Empty <string>();
            var fileNotFound          = new List <PackageMissingException>();


            if (projectPath != null)
            {
                try
                {
                    bootstrapPackagePaths = GetLatestPackagesForProjectDirectory(packageNamesToLoad, projectPath);
                    if (bootstrapPackagePaths.Count() >= packageNamesToLoad.Length)
                    {
                        return(bootstrapPackagePaths);
                    }
                }
                catch (PackageMissingException e)
                {
                    fileNotFound.Add(e);
                }
            }

            if (systemDirectory != null)
            {
                try
                {
                    bootstrapPackagePaths = GetLatestPackagesForSystemRepository(GetRepositoryDirectoryFromProjectDirectory(systemDirectory), packageNamesToLoad);
                }
                catch (PackageMissingException e)
                {
                    fileNotFound.Add(e);
                }
            }

            if ((fileNotFound.Any() || bootstrapPackagePaths.Count() < packageNamesToLoad.Length) && systemDirectory != null && remote.Enabled)
            {
                return(TryDownloadPackagesToRepository(GetRepositoryDirectoryFromProjectDirectory(systemDirectory), packageNamesToLoad, remote));
            }

            if (bootstrapPackagePaths.Count() >= packageNamesToLoad.Length)
            {
                return(bootstrapPackagePaths);
            }

            throw new PackageMissingException(fileNotFound.SelectMany(_ => _.Paths).ToList());
        }
Пример #5
0
        public static IEnumerable<string> GetPackageFolders(RemoteInstall remote, string projectPath, string systemPath, params string[] packageNamesToLoad)
        {
            DirectoryInfo systemDirectory = systemPath == null ? null : new DirectoryInfo(systemPath);

            var bootstrapPackagePaths = Enumerable.Empty<string>();
            var fileNotFound = new List<PackageMissingException>();


            if (projectPath != null)
            {
                try
                {
                    bootstrapPackagePaths = GetLatestPackagesForProjectDirectory(packageNamesToLoad, projectPath);
                    if (bootstrapPackagePaths.Count() >= packageNamesToLoad.Length) return bootstrapPackagePaths;
                }
                catch (PackageMissingException e)
                {
                    fileNotFound.Add(e);
                }
            }

            if (systemDirectory != null)
            {
                
                try
                {
                    bootstrapPackagePaths = GetLatestPackagesForSystemRepository(GetRepositoryDirectoryFromProjectDirectory(systemDirectory), packageNamesToLoad);
                    fileNotFound.Clear();
                }
                catch (PackageMissingException e)
                {
                    fileNotFound.Add(e);
                }
            }

            if ((fileNotFound.Any() || bootstrapPackagePaths.Count() < packageNamesToLoad.Length) && systemDirectory != null && remote.Enabled)
                return TryDownloadPackagesToRepository(GetRepositoryDirectoryFromProjectDirectory(systemDirectory), packageNamesToLoad, remote);

            if (bootstrapPackagePaths.Count() >= packageNamesToLoad.Length)
                return bootstrapPackagePaths;

            throw new PackageMissingException(fileNotFound.SelectMany(_ => _.Paths).ToList());
        }
Пример #6
0
        static IEnumerable <string> TryDownloadPackages(string systemRepositoryPath, IEnumerable <string> packageNames, RemoteInstall remote)
        {
            var systemRepositoryCacheDirectory = GetCacheDirectoryFromRepositoryDirectory(new DirectoryInfo(systemRepositoryPath));

            if (!systemRepositoryCacheDirectory.Exists)
            {
                systemRepositoryCacheDirectory.Create();
            }

            XDocument document;

            try
            {
                var indexUri = new Uri(new Uri(remote.ServerUri, UriKind.Absolute), "index.wraplist");

                var content = remote.Client.DownloadData(indexUri);
                document = XDocument.Load(new XmlTextReader(new MemoryStream(content)));

                var packageNamesToDownload = ResolvePackageNames(document, packageNames);
                var packagesToDownload     = from packageElement in document.Descendants("wrap")
                                             let nameAttribute = packageElement.Attribute("name")
                                                                 let versionAttribute = packageElement.Attribute("version")
                                                                                        let packageSource = (from link in packageElement.Descendants("link")
                                                                                                             let rel = link.Attribute("rel")
                                                                                                                       let href = link.Attribute("href")
                                                                                                                                  where rel != null && rel.Value.Equals("package", StringComparison.OrdinalIgnoreCase)
                                                                                                                                  select href.Value).FirstOrDefault()
                                                                                                            where nameAttribute != null &&
                                                                                                            versionAttribute != null &&
                                                                                                            packageSource != null &&
                                                                                                            packageNamesToDownload.Contains(nameAttribute.Value, StringComparer.OrdinalIgnoreCase)
                                                                                                            group new { Name = nameAttribute.Value, Version = versionAttribute.Value, Href = packageSource } by nameAttribute.Value
                into byNameGroup
                select byNameGroup.OrderByDescending(x => x.Version)
                .Select(x => new { x.Name, Href = new Uri(x.Href, UriKind.RelativeOrAbsolute) })
                .FirstOrDefault();

                foreach (var foundPackage in packagesToDownload)
                {
                    var fullPackageUri = foundPackage.Href;
                    if (!fullPackageUri.IsAbsoluteUri)
                    {
                        fullPackageUri = new Uri(new Uri(remote.ServerUri, UriKind.Absolute), fullPackageUri);
                    }

                    var    fileName     = fullPackageUri.Segments.Last();
                    string wrapFilePath = Path.Combine(systemRepositoryPath, fileName);


                    if (File.Exists(wrapFilePath))
                    {
                        File.Delete(wrapFilePath);
                    }

                    remote.Client.DownloadFile(fullPackageUri, wrapFilePath);

                    var extractFolder = Path.Combine(systemRepositoryCacheDirectory.FullName, Path.GetFileNameWithoutExtension(fileName));

                    if (Directory.Exists(extractFolder))
                    {
                        Directory.Delete(extractFolder, true);
                    }

                    Directory.CreateDirectory(extractFolder);

                    using (var wrapFileStream = File.OpenRead(wrapFilePath))
                        Extractor(wrapFileStream, extractFolder);
                }
                return(GetLatestPackagesForSystemRepository(systemRepositoryPath, packageNames));
            }
            catch
            {
                return(new string[0]);
            }
        }
Пример #7
0
        static IEnumerable<string> TryDownloadPackages(string systemRepositoryPath, IEnumerable<string> packageNames, RemoteInstall remote)
        {
            var systemRepositoryCacheDirectory = GetCacheDirectoryFromRepositoryDirectory(new DirectoryInfo(systemRepositoryPath));

            XDocument document;
            try
            {
                var indexUri = new Uri(new Uri(remote.ServerUri, UriKind.Absolute), "index.wraplist");

                var content = remote.Client.DownloadData(indexUri);
                document = XDocument.Load(new XmlTextReader(new MemoryStream(content)));

                var packageNamesToDownload = ResolvePackageNames(document, packageNames);
                var packagesToDownload = from packageElement in document.Descendants("wrap")
                                         let nameAttribute = packageElement.Attribute("name")
                                         let semanticVersionAttribute = packageElement.Attribute("semantic-version")
                                                                        ?? packageElement.Attribute("version")
                                         let nukedAttribute = packageElement.Attribute("nuked")
                                         let packageSource = (from link in packageElement.Descendants("link")
                                                              let rel = link.Attribute("rel")
                                                              let href = link.Attribute("href")
                                                              where rel != null && rel.Value.Equals("package", StringComparison.OrdinalIgnoreCase)
                                                              select href.Value).FirstOrDefault()
                                         where nameAttribute != null &&
                                               semanticVersionAttribute != null &&
                                               packageSource != null &&
                                               (nukedAttribute == null || !nukedAttribute.Value.Equals("true", StringComparison.OrdinalIgnoreCase)) &&
                                               packageNamesToDownload.Contains(nameAttribute.Value, StringComparer.OrdinalIgnoreCase)
                                         group new { Name = nameAttribute.Value, Version = semanticVersionAttribute.Value, Href = packageSource } by nameAttribute.Value.ToLowerInvariant()
                                             into byNameGroup
                                             select byNameGroup.OrderByDescending(x => x.Version)
                                                 .Select(x => new { x.Name, Href = new Uri(x.Href, UriKind.RelativeOrAbsolute) })
                                                 .FirstOrDefault();

                foreach (var foundPackage in packagesToDownload)
                {
                    var fullPackageUri = foundPackage.Href;
                    if (!fullPackageUri.IsAbsoluteUri)
                        fullPackageUri = new Uri(new Uri(remote.ServerUri, UriKind.Absolute), fullPackageUri);

                    var fileName = fullPackageUri.Segments.Last();
                    string wrapFilePath = Path.Combine(systemRepositoryPath, fileName);

                    if (File.Exists(wrapFilePath))
                        File.Delete(wrapFilePath);

                    remote.Client.DownloadFile(fullPackageUri, wrapFilePath);

                    var extractFolder = Path.Combine(systemRepositoryCacheDirectory.FullName, Path.GetFileNameWithoutExtension(fileName));

                    if (Directory.Exists(extractFolder))
                        Directory.Delete(extractFolder, true);

                    Directory.CreateDirectory(extractFolder);

                    using (var wrapFileStream = File.OpenRead(wrapFilePath))
                        Extractor(wrapFileStream, extractFolder);
                }

                return GetLatestPackagesForSystemRepository(systemRepositoryPath, packageNames);
            }
            catch
            {
                return new string[0];
            }
        }
Пример #8
0
        static IEnumerable<string> TryDownloadPackages(string systemRepositoryPath, IEnumerable<string> packageNames, Regex regex, RemoteInstall remote)
        {
            var systemRepositoryCacheDirectory = GetCacheDirectoryFromRepositoryDirectory(new DirectoryInfo(systemRepositoryPath));
            if (!systemRepositoryCacheDirectory.Exists)
                systemRepositoryCacheDirectory.Create();

            var indexUri = new Uri(new Uri(remote.ServerUri, UriKind.Absolute), "index.wraplist");

            var content = remote.Client.DownloadData(indexUri);
            XDocument document = XDocument.Load(new XmlTextReader(new MemoryStream(content)));

            var packagesToDownload = from packageElement in document.Descendants("wrap")
                                     let nameAttribute = packageElement.Attribute("name")
                                     let versionAttribute = packageElement.Attribute("version")
                                     let packageSource = (from link in packageElement.Descendants("link")
                                                          let rel = link.Attribute("rel")
                                                          let href = link.Attribute("href")
                                                          where rel != null && rel.Value.EqualsNoCase("package")
                                                          select href.Value).FirstOrDefault()
                                     where nameAttribute != null &&
                                           versionAttribute != null &&
                                           packageSource != null &&
                                           packageNames.Contains(nameAttribute.Value, StringComparer.OrdinalIgnoreCase)
                                     group new { Name = nameAttribute.Value, Version = versionAttribute.Value, Href = packageSource } by nameAttribute.Value
                                     into byNameGroup
                                     select byNameGroup.OrderByDescending(x => x.Version)
                                             .Select(x => new { x.Name, Href = new Uri(x.Href, UriKind.RelativeOrAbsolute) })
                                             .FirstOrDefault();

            foreach (var packageName in packageNames)
            {
                var foundPackage = packagesToDownload.FirstOrDefault(x => x.Name.EqualsNoCase(packageName));
                if (foundPackage == null)
                    throw new FileNotFoundException(string.Format("Package '{0}' not found in repository.", packageName));
                var fullPackageUri = foundPackage.Href;
                if (!fullPackageUri.IsAbsoluteUri)
                    fullPackageUri = new Uri(new Uri(remote.ServerUri, UriKind.Absolute), fullPackageUri);

                var fileName = fullPackageUri.Segments.Last();
                string wrapFilePath = Path.Combine(systemRepositoryPath, fileName);

                if (File.Exists(wrapFilePath))
                    File.Delete(wrapFilePath);

                remote.Client.DownloadFile(fullPackageUri, wrapFilePath);

                var extractFolder = Path.Combine(systemRepositoryCacheDirectory.FullName, Path.GetFileNameWithoutExtension(fileName));

                if (Directory.Exists(extractFolder))
                    Directory.Delete(extractFolder, true);

                Directory.CreateDirectory(extractFolder);

                using (var wrapFileStream = File.OpenRead(wrapFilePath))
                    ZipArchive.Extract(wrapFileStream, extractFolder);
            }
            return GetLatestPackagesForSystemRepository(systemRepositoryPath, regex);
        }