Fetch() public method

public Fetch ( string source ) : FetchedPackage
source string
return FetchedPackage
Beispiel #1
0
        private bool install(string packageToken, string[] acceptedVersions)
        {
            var source = _packageFetcher.Fetch(packageToken);

            if (source == null || !File.Exists(source.Package))
            {
                _dispatch("error|could not find package " + packageToken);
                return(false);
            }

            if (isMetaPackage(source.Package))
            {
                installMetaPackage(source);
                return(true);
            }

            string activeProfile   = null;
            var    actionSucceeded = prepareForAction(
                source.Package,
                (package) => {
                var profiles = new ProfileLocator(_token);
                if (_useGlobal)
                {
                    activeProfile = profiles.GetActiveGlobalProfile();
                }
                else
                {
                    activeProfile = profiles.GetActiveLocalProfile();
                }
                var installPath = getInstallPath(package, profiles, activeProfile);
                if (installPath == null)
                {
                    return(null);
                }
                Logger.Write("Installing the package in " + installPath);
                return(installPath);
            },
                (args) => {
                if (args.Match != null)
                {
                    Logger.Write("found matching package " + args.Match);
                    var command = Path.GetFileNameWithoutExtension(args.Match);
                    var package = getPackage(command);
                    if (package != null)
                    {
                        Logger.Write("loaded package " + package.ID);
                        if (acceptedVersions != null)
                        {
                            if (acceptedVersions.Length > 0 && !acceptedVersions.Any(x => x == package.Version))
                            {
                                var versions = "";
                                foreach (var version in acceptedVersions)
                                {
                                    versions += version + ",";
                                }
                                versions = versions.Trim(new[] { ',' });
                                _dispatch(string.Format("error|dependency {0} ({1}) is installed. Accepted versions are {2}", args.Package.ID, package.Version, versions));
                                return(false);
                            }
                        }
                        Logger.Write(string.Format("skipping {0} ({1}) already installed", package.ID, package.Version));
                    }
                    else
                    {
                        _dispatch(string.Format("error|the package with the command {0} conflicts with the package you are trying to install", command));
                    }
                }
                 else if (acceptedVersions != null && !acceptedVersions.Any(x => x == args.Package.Version))
                {
                    var versions = "";
                    foreach (var version in acceptedVersions)
                    {
                        versions += version + ",";
                    }
                    versions = versions.Trim(new[] { ',' });
                    _dispatch(string.Format("error|dependency {0} of version {1} is not a valid. Accepted versions are {2}", args.Package.ID, args.Package.Version, versions));
                    return(false);
                }
                else
                {
                    installPackage(source.Package, args.Package, args.TempPath, args.InstallPath, activeProfile);
                }
                return(true);
            });

            if (source.IsTemporaryPackage)
            {
                File.Delete(source.Package);
            }
            return(actionSucceeded);
        }