Exemple #1
0
        protected override void ProcessPackage(PackageProvider provider, string searchKey, SoftwareIdentity package)
        {
            base.ProcessPackage(provider, searchKey, package);

            var savePath = SaveFileName(package.PackageFilename);

            // if we have a valid path, make a local copy of the file.
            if (!string.IsNullOrEmpty(savePath))
            {
                provider.DownloadPackage(package, SaveFileName(savePath), this);
                if (File.Exists(savePath))
                {
                    package.FullPath = savePath;
                }
            }

            // return the object to the caller.
            WriteObject(package);

            if (IncludeDependencies)
            {
                foreach (var dep in provider.GetPackageDependencies(package, this))
                {
                    ProcessPackage(provider, searchKey, dep);
                }
            }
        }
Exemple #2
0
        protected override void ProcessPackage(PackageProvider provider, IEnumerable <string> searchKey, SoftwareIdentity package)
        {
            // if provider does not implement downloadpackage throw error saying that save-package is not implemented by provider
            if (!provider.IsMethodImplemented("DownloadPackage"))
            {
                Error(Constants.Errors.MethodNotImplemented, provider.ProviderName, "Save-Package");
            }

            base.ProcessPackage(provider, searchKey, package);

            // if we do save-package jquery -path C:\test then savepath would be C:\test
            var savePath = SaveFileName(package.PackageFilename);

            bool mainPackageDownloaded = false;

            if (!string.IsNullOrWhiteSpace(savePath))
            {
                // let the provider handles everything
                // message would be something like What if: Performing the operation "Save Package" on target "'jQuery' to location 'C:\test\test'".
                if (ShouldProcess(FormatMessageString(Resources.Messages.SavePackageWhatIfDescription, package.Name, savePath), FormatMessageString(Resources.Messages.SavePackage)).Result)
                {
                    foreach (var downloadedPkg in provider.DownloadPackage(package, savePath, this.ProviderSpecific(provider)).CancelWhen(CancellationEvent.Token))
                    {
                        if (IsCanceled)
                        {
                            Error(Constants.Errors.ProviderFailToDownloadFile, downloadedPkg.PackageFilename, provider.ProviderName);
                            return;
                        }

                        // check whether main package is downloaded;
                        if (downloadedPkg.Name.EqualsIgnoreCase(package.Name) && downloadedPkg.Version.EqualsIgnoreCase(package.Version))
                        {
                            mainPackageDownloaded = true;
                        }

                        WriteObject(AddPropertyToSoftwareIdentity(downloadedPkg));
                        LogEvent(EventTask.Download, EventId.Save, Resources.Messages.PackageSaved, downloadedPkg.Name, downloadedPkg.Version, downloadedPkg.ProviderName, downloadedPkg.Source ?? string.Empty, downloadedPkg.Status ?? string.Empty);
                        TraceMessage(Constants.SavePackageTrace, downloadedPkg);
                    }
                }
                else
                {
                    // What if scenario, don't error out
                    return;
                }
            }

            if (!mainPackageDownloaded)
            {
                Error(Constants.Errors.ProviderFailToDownloadFile, package.PackageFilename, provider.ProviderName);
                return;
            }
        }
Exemple #3
0
        protected override void ProcessPackage(PackageProvider provider, IEnumerable <string> searchKey, SoftwareIdentity package)
        {
            // if provider does not implement downloadpackage throw error saying that save-package is not implemented by provider
            if (!provider.IsMethodImplemented("DownloadPackage"))
            {
                Error(Constants.Errors.MethodNotImplemented, provider.ProviderName, "Save-Package");
            }

            base.ProcessPackage(provider, searchKey, package);

            // if we do save-package jquery -path C:\test then savepath would be C:\test
            var savePath = SaveFileName(package.PackageFilename);

            bool mainPackageDownloaded = false;

            if (!string.IsNullOrWhiteSpace(savePath))
            {
                // let the provider handles everything
                if (ShouldProcess(savePath, FormatMessageString(Resources.Messages.SavePackage)).Result)
                {
                    foreach (var downloadedPkg in provider.DownloadPackage(package, savePath, this.ProviderSpecific(provider)).CancelWhen(CancellationEvent.Token))
                    {
                        if (IsCanceled)
                        {
                            Error(Constants.Errors.ProviderFailToDownloadFile, downloadedPkg.PackageFilename, provider.ProviderName);
                            return;
                        }

                        // check whether main package is downloaded;
                        if (string.Equals(downloadedPkg.CanonicalId, package.CanonicalId, StringComparison.OrdinalIgnoreCase))
                        {
                            mainPackageDownloaded = true;
                        }

                        WriteObject(downloadedPkg);
                    }
                }
            }

            if (!mainPackageDownloaded)
            {
                Error(Constants.Errors.ProviderFailToDownloadFile, package.PackageFilename, provider.ProviderName);
                return;
            }
        }
Exemple #4
0
        protected override void ProcessPackage(PackageProvider provider, IEnumerable <string> searchKey, SoftwareIdentity package)
        {
            base.ProcessPackage(provider, searchKey, package);

            var savePath = SaveFileName(package.PackageFilename);

            if (savePath.FileExists())
            {
                if (Force)
                {
                    savePath.TryHardToDelete();
                    if (savePath.FileExists())
                    {
                        Error(Constants.Errors.UnableToOverwrite, savePath);
                        return;
                    }
                }
                else
                {
                    Error(Constants.Errors.PackageFileExists, savePath);
                    return;
                }
            }

            // if we have a valid path, make a local copy of the file.
            if (!string.IsNullOrWhiteSpace(savePath))
            {
                if (ShouldProcess(savePath, Constants.Messages.SavePackage).Result)
                {
                    provider.DownloadPackage(package, SaveFileName(savePath), this.ProviderSpecific(provider)).Wait();

                    if (File.Exists(savePath))
                    {
                        package.FullPath = savePath;
                    }
                }
                // return the object to the caller.
                WriteObject(package);
            }
        }
Exemple #5
0
        protected override void ProcessPackage(PackageProvider provider, IEnumerable<string> searchKey, SoftwareIdentity package)
        {
            base.ProcessPackage(provider, searchKey, package);

            var savePath = SaveFileName(package.PackageFilename);

            if (savePath.FileExists()) {
                if (Force) {
                    savePath.TryHardToDelete();
                    if (savePath.FileExists()) {
                        Error(Constants.Errors.UnableToOverwrite, savePath);
                        return;
                    }
                } else {
                    Error(Constants.Errors.PackageFileExists, savePath);
                    return;
                }
            }

            // if we have a valid path, make a local copy of the file.
            if (!string.IsNullOrWhiteSpace(savePath)) {
                if (ShouldProcess(savePath, Constants.Messages.SavePackage).Result) {
                    provider.DownloadPackage(package, SaveFileName(savePath), this.ProviderSpecific(provider)).Wait();

                    if (File.Exists(savePath)) {
                        package.FullPath = savePath;
                    }
                }
                // return the object to the caller.
                WriteObject(package);
            }
        }
Exemple #6
0
        protected override void ProcessPackage(PackageProvider provider, IEnumerable<string> searchKey, SoftwareIdentity package) {
            // if provider does not implement downloadpackage throw error saying that save-package is not implemented by provider
            if (!provider.IsMethodImplemented("DownloadPackage"))
            {
                Error(Constants.Errors.MethodNotImplemented, provider.ProviderName, "Save-Package");
            }

            base.ProcessPackage(provider, searchKey, package);

            // if we do save-package jquery -path C:\test then savepath would be C:\test
            var savePath = SaveFileName(package.PackageFilename);

            bool mainPackageDownloaded = false;

            if (!string.IsNullOrWhiteSpace(savePath)) {                
                // let the provider handles everything
                if (ShouldProcess(savePath, FormatMessageString(Resources.Messages.SavePackage)).Result)
                {
                    foreach (var downloadedPkg in provider.DownloadPackage(package, savePath, this.ProviderSpecific(provider)).CancelWhen(CancellationEvent.Token))
                    {
                        if (IsCanceled)
                        {
                            Error(Constants.Errors.ProviderFailToDownloadFile, downloadedPkg.PackageFilename, provider.ProviderName);
                            return;
                        }

                        // check whether main package is downloaded;
                        if (string.Equals(downloadedPkg.CanonicalId, package.CanonicalId, StringComparison.OrdinalIgnoreCase))
                        {
                            mainPackageDownloaded = true;
                        }

                        WriteObject(downloadedPkg);
                    }
                }
            }

            if (!mainPackageDownloaded)
            {
                Error(Constants.Errors.ProviderFailToDownloadFile, package.PackageFilename, provider.ProviderName);
                return;
            }
        }