Ejemplo n.º 1
0
        public async Task<Stream> OpenNuspecStreamAsync(PackageInfo package)
        {
            using (var nupkgStream = await OpenNupkgStreamAsync(package))
            {
#if NET45
                if (PlatformHelper.IsMono)
                {
                    // Don't close the stream
                    var archive = Package.Open(nupkgStream, FileMode.Open, FileAccess.Read);
                    var partUri = PackUriHelper.CreatePartUri(new Uri(package.Id + ".nuspec", UriKind.Relative));
                    var entry = archive.GetPart(partUri);

                    using (var entryStream = entry.GetStream())
                    {
                        var nuspecStream = new MemoryStream((int)entryStream.Length);
                        await entryStream.CopyToAsync(nuspecStream);
                        nuspecStream.Seek(0, SeekOrigin.Begin);
                        return nuspecStream;
                    }
                }
#endif

                using (var archive = new ZipArchive(nupkgStream, ZipArchiveMode.Read, leaveOpen: true))
                {
                    var entry = archive.GetEntryOrdinalIgnoreCase(package.Id + ".nuspec");
                    using (var entryStream = entry.Open())
                    {
                        var nuspecStream = new MemoryStream((int)entry.Length);
                        await entryStream.CopyToAsync(nuspecStream);
                        nuspecStream.Seek(0, SeekOrigin.Begin);
                        return nuspecStream;
                    }
                }
            }
        }
    public SettingsViewModel(PackageInfo packageInfo)
    {
      _package = packageInfo.Package;
      PackageSource = GetPackageSource(packageInfo.PackagePath);
      Question = string.Format("Are you sure you want to remove package [{0}, {1}] from source?", _package.Id, _package.Version);

      Execute = new Command(ExecuteCommandExecute, CanExecuteCommandExecute);
      Cancel = new Command<Window>(CancelCommandExecute);
    }
Ejemplo n.º 3
0
        private IEnumerable<LibraryDependency> GetDependencies(PackageInfo packageInfo, FrameworkName targetFramework)
        {
            var package = packageInfo.Package;

            IEnumerable<PackageDependencySet> dependencySet;
            if (VersionUtility.GetNearest(targetFramework, package.DependencySets, out dependencySet))
            {
                foreach (var set in dependencySet)
                {
                    foreach (var d in set.Dependencies)
                    {
                        yield return new LibraryDependency
                        {
                            LibraryRange = new LibraryRange(d.Id, frameworkReference: false)
                            {
                                VersionRange = d.VersionSpec == null ? null : new SemanticVersionRange(d.VersionSpec)
                            },
                        };
                    }
                }
            }

            // TODO: Remove this when we do #596
            // ASP.NET Core isn't compatible with generic PCL profiles
            if (string.Equals(targetFramework.Identifier, VersionUtility.AspNetCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) ||
                string.Equals(targetFramework.Identifier, VersionUtility.DnxCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
            {
                yield break;
            }

            IEnumerable<FrameworkAssemblyReference> frameworkAssemblies;
            if (VersionUtility.GetNearest(targetFramework, package.FrameworkAssemblies, out frameworkAssemblies))
            {
                foreach (var assemblyReference in frameworkAssemblies)
                {
                    if (!assemblyReference.SupportedFrameworks.Any() &&
                        !VersionUtility.IsDesktop(targetFramework))
                    {
                        // REVIEW: This isn't 100% correct since none *can* mean
                        // any in theory, but in practice it means .NET full reference assembly
                        // If there's no supported target frameworks and we're not targeting
                        // the desktop framework then skip it.

                        // To do this properly we'll need all reference assemblies supported
                        // by each supported target framework which isn't always available.
                        continue;
                    }

                    yield return new LibraryDependency
                    {
                        LibraryRange = new LibraryRange(assemblyReference.AssemblyName, frameworkReference: true)
                    };
                }
            }
        }
Ejemplo n.º 4
0
 public Task<Stream> OpenRuntimeStreamAsync(PackageInfo package)
 {
     var nuspecPath = _pathResolver.GetManifestFilePath(package.Id, package.Version);
     var runtimePath = Path.Combine(Path.GetDirectoryName(nuspecPath), "runtime.json");
     if (File.Exists(runtimePath))
     {
         _reports.Quiet.WriteLine(string.Format("  OPEN {0}", _fileSystem.GetFullPath(runtimePath)));
         return Task.FromResult<Stream>(File.OpenRead(runtimePath));
     }
     return Task.FromResult<Stream>(null);
 }
        public void Load()
        {
            _commands = new Dictionary <string, NuGet.PackageInfo>();

            var pathFilter = RuntimeEnvironmentHelper.IsWindows ? "*.cmd" : "*.*";

            var allCommandFiles = _commandsFolder
                                  .GetFiles(".", pathFilter, recursive: false)
                                  .Select(relativePath => _commandsFolder.GetFullPath(relativePath));

            foreach (string commandFile in allCommandFiles)
            {
                var lines = File.ReadAllLines(commandFile);

                if (lines.Length != 1)
                {
                    // The run scripts are just one line so this is not an installed app script
                    continue;
                }

                var pathParts = lines[0].Split(new char[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

                // ~dp0\packages\<packageId>\<packageVersion>\app\<commandName>[.cmd]
                if (pathParts.Length != 6)
                {
                    continue;
                }

                var             packageId = pathParts[2];
                SemanticVersion packageVersion;
                if (!SemanticVersion.TryParse(pathParts[3], out packageVersion))
                {
                    continue;
                }

                // version dir = {packagesFolderName}\{packageId}\{version}
                var versionDir = Path.Combine(
                    PackagesRoot.Root,
                    packageId,
                    packageVersion.ToString());

                var appPackage = new NuGet.PackageInfo(
                    PackagesRoot,
                    packageId,
                    packageVersion,
                    versionDir);

                _commands.Add(
                    Path.GetFileNameWithoutExtension(commandFile),
                    appPackage);
            }
        }
Ejemplo n.º 6
0
 public PackageDescription(
     LibraryRange requestedRange, 
     PackageInfo package, 
     LockFileTargetLibrary lockFileLibrary, 
     IEnumerable<LibraryDependency> dependencies, 
     bool resolved, 
     bool compatible)
     : base(requestedRange,
           new LibraryIdentity(package.Id, package.Version, isGacOrFrameworkReference: false),
           path: null,
           type: LibraryTypes.Package,
           dependencies: dependencies,
           assemblies: Enumerable.Empty<string>(),
           framework: null)
 {
     Package = package;
     LockFileLibrary = lockFileLibrary;
     Resolved = resolved;
     Compatible = compatible;
 }
        public PackageInfoViewModel(
            PackageInfo info, 
            bool showPrereleasePackages,
            IPackageRepository repository,
            PackageChooserViewModel parentViewModel)
        {
            Debug.Assert(info != null);
            Debug.Assert(repository != null);

            LatestPackageInfo = info;
            ShowPrerelease = showPrereleasePackages;
            _repository = repository;
            _parentViewModel = parentViewModel;
            AllPackages = new ObservableCollection<PackageInfo>();

            ToggleAllVersionsCommand = new RelayCommand(OnToggleAllVersions, CanToggleAllVersions);
            OpenCommand = new RelayCommand(OnOpenPackage);
            DownloadCommand = new RelayCommand(OnDownloadPackage);
            CancelCommand = new RelayCommand(OnCancelDownload, CanCancelDownload);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Set the solution to use, when resolving the package containing the remote commands.
        /// </summary>
        /// <param name="solutionPath">The full path to the solution file.</param>
        /// <param name="domain">The AppDomain to set the solution on, or null the current AppDomain.</param>
        public static void InitialzeFromSolution(string solutionPath, AppDomain domain = null)
        {
            if (domain == null)
            {
                lock (computedParadoxPackageInfoLock)
                {
                    // Set the new solution and clear the package info, so it will be recomputed
                    solution = solutionPath;
                    computedParadoxPackageInfo = new PackageInfo();
                }

                lock (paradoxCommandProxyLock)
                {
                    solutionChanged = true;
                }
            }
            else
            {
                var initializationHelper = (InitializationHelper)domain.CreateInstanceFromAndUnwrap(typeof(InitializationHelper).Assembly.Location, typeof(InitializationHelper).FullName);
                initializationHelper.Initialze(solutionPath);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the paradox SDK dir.
        /// </summary>
        /// <returns></returns>
        private static PackageInfo FindParadoxSdkDir()
        {
            // Resolve the sdk version to load from the solution's package
            var packageInfo = new PackageInfo { ExpectedVersion = PackageSessionHelper.GetPackageVersion(solution) };

            // TODO: Maybe move it in some common class somewhere? (in this case it would be included with "Add as link" in VSPackage)
            var paradoxSdkDir = Environment.GetEnvironmentVariable("SiliconStudioParadoxDir");

            // Failed to locate paradox
            if (paradoxSdkDir == null)
                return packageInfo;

            // If we are in a dev directory, assume we have the right version
            if (File.Exists(Path.Combine(paradoxSdkDir, "build\\Paradox.sln")))
            {
                packageInfo.SdkPath = paradoxSdkDir;
                packageInfo.LoadedVersion = packageInfo.ExpectedVersion;
                return packageInfo;
            }

            // Check if we are in a root directory with store/packages facilities
            if (NugetStore.IsStoreDirectory(paradoxSdkDir))
            {
                var store = new NugetStore(paradoxSdkDir);
                IPackage paradoxPackage = null;

                // Try to find the package with the expected version
                if (packageInfo.ExpectedVersion != null && packageInfo.ExpectedVersion >= MinimumVersion)
                    paradoxPackage = store.GetPackagesInstalled(store.MainPackageId).FirstOrDefault(package => GetVersion(package) == packageInfo.ExpectedVersion);

                // If the expected version is not found, get the latest package
                if (paradoxPackage == null)
                    paradoxPackage = store.GetLatestPackageInstalled(store.MainPackageId);

                // If no package was found, return no sdk path
                if (paradoxPackage == null)
                    return packageInfo;

                // Return the loaded version and the sdk path
                var packageDirectory = store.PathResolver.GetPackageDirectory(paradoxPackage);
                packageInfo.LoadedVersion = GetVersion(paradoxPackage);
                packageInfo.SdkPath = Path.Combine(paradoxSdkDir, store.RepositoryPath, packageDirectory);
            }

            return packageInfo;
        }
Ejemplo n.º 10
0
 public bool Equals(PackageInfo other)
 {
     return !object.ReferenceEquals(null, other) &&
            string.Equals(Id, other.Id) &&
            Version.Equals(other.Version);
 }
Ejemplo n.º 11
0
        public async Task<Stream> OpenNupkgStreamAsync(PackageInfo package)
        {
            Task<NupkgEntry> task;
            lock (_cache2)
            {
                if (!_cache2.TryGetValue(package.ContentUri, out task))
                {
                    task = _cache2[package.ContentUri] = _OpenNupkgStreamAsync(package);
                }
            }
            var result = await task;
            if (result == null)
            {
                return null;
            }

            // Acquire the lock on a file before we open it to prevent this process
            // from opening a file deleted by the logic in HttpSource.GetAsync() in another process
            return await ConcurrencyUtilities.ExecuteWithFileLocked(result.TempFileName, _ =>
            {
                return Task.FromResult(
                    new FileStream(result.TempFileName, FileMode.Open, FileAccess.Read,
                    FileShare.ReadWrite | FileShare.Delete));
            });
        }
Ejemplo n.º 12
0
 public async Task<Stream> OpenRuntimeStreamAsync(PackageInfo package)
 {
     return await PackageUtilities.OpenRuntimeStreamFromNupkgAsync(package, OpenNupkgStreamAsync, _reports.Information);
 }
Ejemplo n.º 13
0
        public bool IsPackageServiceable(PackageInfo package)
        {
            if (!_isEnabled)
            {
                return false;
            }

            return package.LockFileLibrary.IsServiceable;
        }
Ejemplo n.º 14
0
 public Task<Stream> OpenNupkgStreamAsync(PackageInfo package)
 {
     return Task.FromResult(_repository.FindPackage(package.Id, package.Version).GetStream());
 }
Ejemplo n.º 15
0
 public async Task<Stream> OpenNuspecStreamAsync(PackageInfo package)
 {
     return await PackageUtilities.OpenNuspecStreamFromNupkgAsync(package, OpenNupkgStreamAsync, _reports.Quiet);
 }
Ejemplo n.º 16
0
        private string ResolvePackagePath(IPackagePathResolver defaultResolver,
                                          IEnumerable<IPackagePathResolver> cacheResolvers,
                                          PackageInfo packageInfo)
        {
            string expectedHash = packageInfo.LockFileLibrary.Sha;

            foreach (var resolver in cacheResolvers)
            {
                var cacheHashFile = resolver.GetHashPath(packageInfo.Id, packageInfo.Version);

                // REVIEW: More efficient compare?
                if (File.Exists(cacheHashFile) &&
                    File.ReadAllText(cacheHashFile) == expectedHash)
                {
                    return resolver.GetInstallPath(packageInfo.Id, packageInfo.Version);
                }
            }

            return defaultResolver.GetInstallPath(packageInfo.Id, packageInfo.Version);
        }
Ejemplo n.º 17
0
        public void RemovePackage(PackageInfo package)
        {
            string packageName = package.Id;
            string packageVersion = package.Version.ToString();

            string folderToDelete;
            if (RepositoryRoot.GetDirectories(packageName).Count() > 1)
            {
                // There is more than one version of this package so we can only
                // remove the version folder without risking to break something else
                folderToDelete = Path.Combine(packageName, packageVersion);
            }
            else
            {
                folderToDelete = packageName;
            }

            RepositoryRoot.DeleteDirectory(folderToDelete, recursive: true);
        }
Ejemplo n.º 18
0
        private void PurgeOrphanPackages()
        {
            _reports.Verbose.WriteLine("Removing orphaned packages...");

            // Find the packages still used by the command scripts
            var applicationPackagesStillUsed = _commandsRepo.Commands
                .Select(cmd => _commandsRepo.FindCommandOwner(cmd))
                .Distinct();

            // Get all the installed packages
            var packagesRepo = new PackageRepository(
                _commandsRepo.PackagesRoot,
                caseSensitivePackagesName: false);

            // Key = package<id, version>, Value = bool (true if used, false otherwise)
            var usedPackages = packagesRepo
                    .GetAllPackages()
                    .SelectMany(pack => pack.Value)
                    .ToDictionary(
                        pack => pack,
                        _ => false);

            var lockFileFormat = new LockFileFormat();

            // Mark all the packages still in used by using the dependencies in the lock file
            foreach(var applicationPackage in applicationPackagesStillUsed)
            {
                var appLockFileFullPath = Path.Combine(
                    _commandsRepo.PackagesRoot.Root,
                    _commandsRepo.PathResolver.GetPackageDirectory(applicationPackage.Id, applicationPackage.Version),
                    InstallBuilder.CommandsFolderName,
                    LockFileFormat.LockFileName);

                if (!File.Exists(appLockFileFullPath))
                {
                    _reports.Verbose.WriteLine("Lock file {0} not found. This package will be removed if it is not used by another application", appLockFileFullPath);
                    // The lock file is missing, probably the app is not installed correctly
                    // unless someone else is using it, we'll remove it
                    continue;
                }

                var lockFile = lockFileFormat.Read(appLockFileFullPath);
                foreach(var dependency in lockFile.PackageLibraries)
                {
                    var dependencyPackage = new NuGet.PackageInfo(
                        _commandsRepo.PackagesRoot,
                        dependency.Name,
                        dependency.Version,
                        null,
                        null);

                    if (usedPackages.ContainsKey(dependencyPackage))
                    {
                        // Mark the dependency as used
                        usedPackages[dependencyPackage] = true;
                    }
                }
            }

            // Now it's time to remove those unused packages
            var unusedPackages = usedPackages
                .Where(pack => !pack.Value)
                .Select(pack => pack.Key);

            foreach (var package in unusedPackages)
            {
                packagesRepo.RemovePackage(package);
                _reports.Verbose.WriteLine("Removed orphaned package: {0} {1}", package.Id, package.Version);
            }
        }
Ejemplo n.º 19
0
        private void PurgeOrphanPackages()
        {
            _reports.Verbose.WriteLine("Removing orphaned packages...");

            // Find the packages still used by the command scripts
            var applicationPackagesStillUsed = _commandsRepo.Commands
                                               .Select(cmd => _commandsRepo.FindCommandOwner(cmd))
                                               .Distinct();

            // Get all the installed packages
            var packagesRepo = new PackageRepository(
                _commandsRepo.PackagesRoot,
                caseSensitivePackagesName: false);

            // Key = package<id, version>, Value = bool (true if used, false otherwise)
            var usedPackages = packagesRepo
                               .GetAllPackages()
                               .SelectMany(pack => pack.Value)
                               .ToDictionary(
                pack => pack,
                _ => false);

            var lockFileFormat = new LockFileFormat();

            // Mark all the packages still in used by using the dependencies in the lock file
            foreach (var applicationPackage in applicationPackagesStillUsed)
            {
                var appLockFileFullPath = Path.Combine(
                    _commandsRepo.PackagesRoot.Root,
                    _commandsRepo.PathResolver.GetPackageDirectory(applicationPackage.Id, applicationPackage.Version),
                    InstallBuilder.CommandsFolderName,
                    LockFileFormat.LockFileName);

                if (!File.Exists(appLockFileFullPath))
                {
                    _reports.Verbose.WriteLine("Lock file {0} not found. This package will be removed if it is not used by another application", appLockFileFullPath);
                    // The lock file is missing, probably the app is not installed correctly
                    // unless someone else is using it, we'll remove it
                    continue;
                }

                var lockFile = lockFileFormat.Read(appLockFileFullPath);
                foreach (var dependency in lockFile.Libraries)
                {
                    var dependencyPackage = new NuGet.PackageInfo(
                        _commandsRepo.PackagesRoot,
                        dependency.Name,
                        dependency.Version,
                        null,
                        null);

                    if (usedPackages.ContainsKey(dependencyPackage))
                    {
                        // Mark the dependency as used
                        usedPackages[dependencyPackage] = true;
                    }
                }
            }

            // Now it's time to remove those unused packages
            var unusedPackages = usedPackages
                                 .Where(pack => !pack.Value)
                                 .Select(pack => pack.Key);

            foreach (var package in unusedPackages)
            {
                packagesRepo.RemovePackage(package);
                _reports.Verbose.WriteLine("Removed orphaned package: {0} {1}", package.Id, package.Version);
            }
        }
Ejemplo n.º 20
0
        public void Load()
        {
            _commands = new Dictionary<string, NuGet.PackageInfo>();

            var pathFilter = RuntimeEnvironmentHelper.IsWindows ? "*.cmd" : "*.*";

            var allCommandFiles = _commandsFolder
                    .GetFiles(".", pathFilter, recursive: false)
                    .Select(relativePath => _commandsFolder.GetFullPath(relativePath));

            foreach (string commandFile in allCommandFiles)
            {
                var lines = File.ReadAllLines(commandFile);

                if (lines.Length != 1)
                {
                    // The run scripts are just one line so this is not an installed app script
                    continue;
                }

                var pathParts = lines[0].Split(new char[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

                // ~dp0\packages\<packageId>\<packageVersion>\app\<commandName>[.cmd]
                if (pathParts.Length != 6)
                {
                    continue;
                }

                var packageId = pathParts[2];
                SemanticVersion packageVersion;
                if (!SemanticVersion.TryParse(pathParts[3], out packageVersion))
                {
                    continue;
                }

                // version dir = {packagesFolderName}\{packageId}\{version}
                var versionDir = Path.Combine(
                    PackagesRoot.Root,
                    packageId,
                    packageVersion.ToString());

                var appPackage = new NuGet.PackageInfo(
                    PackagesRoot,
                    packageId,
                    packageVersion,
                    versionDir);

                _commands.Add(
                    Path.GetFileNameWithoutExtension(commandFile),
                    appPackage);
            }
        }
 public PackageDownloadRequestedEventArgs(PackageInfo packageInfo)
 {
     PackageInfo = packageInfo;
 }
Ejemplo n.º 22
0
        public async Task<Stream> OpenNuspecStreamAsync(PackageInfo package)
        {
            using (var nupkgStream = await OpenNupkgStreamAsync(package))
            {
#if NET45
                if (PlatformHelper.IsMono)
                {
                    // Don't close the stream
                    var archive = Package.Open(nupkgStream, FileMode.Open, FileAccess.Read);
                    var partUri = PackUriHelper.CreatePartUri(new Uri(package.Id + ".nuspec", UriKind.Relative));
                    var entry = archive.GetPart(partUri);
                    using (var entryStream = entry.GetStream())
                    {
                        var nuspecStream = new MemoryStream((int)entryStream.Length);
                        await entryStream.CopyToAsync(nuspecStream);
                        nuspecStream.Seek(0, SeekOrigin.Begin);
                        return nuspecStream;
                    }
                }
#endif
                using (var archive = new ZipArchive(nupkgStream, ZipArchiveMode.Read, leaveOpen: true))
                {
                    var entry = archive.GetEntryOrdinalIgnoreCase(package.Id + ".nuspec");
                    using (var entryStream = entry.Open())
                    {
                        var nuspecStream = new MemoryStream((int)entry.Length);
#if NET45
                        await entryStream.CopyToAsync(nuspecStream);
#else
                        // System.IO.Compression.DeflateStream throws exception when multiple
                        // async readers/writers are working on a single instance of it
                        entryStream.CopyTo(nuspecStream);
#endif
                        nuspecStream.Seek(0, SeekOrigin.Begin);
                        return nuspecStream;
                    }
                }
            }
        }
Ejemplo n.º 23
0
 public Task<Stream> OpenNuspecStreamAsync(PackageInfo package)
 {
     var nuspecPath = _pathResolver.GetManifestFilePath(package.Id, package.Version);
     _reports.Quiet.WriteLine(string.Format("  OPEN {0}", _fileSystem.GetFullPath(nuspecPath)));
     return Task.FromResult<Stream>(File.OpenRead(nuspecPath));
 }
Ejemplo n.º 24
0
 private async Task<NupkgEntry> _OpenNupkgStreamAsync(PackageInfo package)
 {
     for (int retry = 0; retry != 3; ++retry)
     {
         try
         {
             using (var data = await _httpSource.GetAsync(
                 package.ContentUri,
                 "nupkg_" + package.Id + "." + package.Version,
                 retry == 0 ? _cacheAgeLimitNupkg : TimeSpan.Zero))
             {
                 return new NupkgEntry
                 {
                     TempFileName = data.CacheFileName
                 };
             }
         }
         catch (Exception ex)
         {
             if (retry == 2)
             {
                 _report.WriteLine(string.Format("Error: DownloadPackageAsync: {1}\r\n  {0}", ex.Message, package.ContentUri.Red().Bold()));
             }
             else
             {
                 _report.WriteLine(string.Format("Warning: DownloadPackageAsync: {1}\r\n  {0}".Yellow().Bold(), ex.Message, package.ContentUri.Yellow().Bold()));
             }
         }
     }
     return null;
 }
Ejemplo n.º 25
0
        public Task<Stream> OpenNupkgStreamAsync(PackageInfo package)
        {
            var nuspecPath = _pathResolver.GetManifestFilePath(package.Id, package.Version);
            var unzippedPackage = new UnzippedPackage(_fileSystem, nuspecPath);

            var nupkgPath = _pathResolver.GetPackageFilePath(package.Id, package.Version);
            _reports.Quiet.WriteLine(string.Format("  OPEN {0}", _fileSystem.GetFullPath(nupkgPath)));

            return Task.FromResult(unzippedPackage.GetStream());
        }