Ejemplo n.º 1
0
        private bool InstallAssemblyProvider(Package provider, Link link, string fastPath, BootstrapRequest request)
        {
            if (!Directory.Exists(request.DestinationPath))
            {
                request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.DestinationPathNotSet);
                return(false);
            }

            var targetFilename = link.Attributes[Iso19770_2.Discovery.TargetFilename];

            if (string.IsNullOrWhiteSpace(targetFilename))
            {
                request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.InvalidFilename);
                return(false);
            }

            targetFilename = Path.GetFileName(targetFilename);
            var targetFile = Path.Combine(request.DestinationPath, targetFilename);

            // download the file
            var file = request.DownloadAndValidateFile(provider.Name, provider._swidtag.Links.Where(each => each.Relationship == Iso19770_2.Relationship.InstallationMedia));

            if (file != null)
            {
                // looks good! let's keep it
                if (File.Exists(targetFile))
                {
                    request.Debug("Removing old file '{0}'", targetFile);
                    targetFile.TryHardToDelete();
                }

                // is that file still there?
                if (File.Exists(targetFile))
                {
                    request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.UnableToRemoveFile, targetFile);
                    return(false);
                }

                request.Debug("Copying file '{0}' to '{1}'", file, targetFile);
                File.Copy(file, targetFile);
                if (File.Exists(targetFile))
                {
                    // since we only installed a single assembly, we can just ask to load that specific assembly.
                    if (PackageManagementService.TryToLoadProviderAssembly(targetFile, request))
                    {
                        // looks good to me.
                        request.YieldFromSwidtag(provider, fastPath);
                        return(true);
                    }
                }
            }
            if (file != null)
            {
                file.TryHardToDelete();
            }
            return(false);
        }
Ejemplo n.º 2
0
 public void DownloadPackage(string fastPath, string location, BootstrapRequest request)
 {
     if (request == null) {
         throw new ArgumentNullException("request");
     }
     request.Debug("Calling 'Bootstrap::DownloadPackage'");
 }
Ejemplo n.º 3
0
 public void DownloadPackage(string fastPath, string location, BootstrapRequest request)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     request.Debug("Calling 'Bootstrap::DownloadPackage'");
 }
Ejemplo n.º 4
0
 public void InitializeProvider(BootstrapRequest request)
 {
     // we should go find out what's available once here just to make sure that
     // we have a list
     try {
         request.Debug("Initialize Bootstrapper");
         PackageManagementService.BootstrappableProviderNames = request.Providers.Select(provider => provider.Name).ToArray();
     } catch (Exception e) {
         e.Dump();
     }
 }
Ejemplo n.º 5
0
        public void GetFeatures(BootstrapRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            request.Debug("Calling 'Bootstrap::GetFeatures'");
            foreach (var feature in _features)
            {
                request.Yield(feature);
            }
        }
Ejemplo n.º 6
0
        public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, BootstrapRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            request.Debug("Calling '{0}::GetInstalledPackages' '{1}','{2}','{3}','{4}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion);
            // return all the dynamic package providers as packages

            foreach (var provider in PackageManagementService.DynamicProviders)
            {
                // for each package manager, match it's name and version with the swidtag from the remote feed
                var p = request.GetProvider(provider.Name, provider.Version);
                if (p == null)
                {
                    request.Debug("Dynamic provider '{0}' from '{1}' is not listed in a bootstrap feed.", provider.Name, provider.ProviderPath);
                    // we didn't find it. It's possible that the provider is listed elsewhere.
                    // well, we'll return as much info as we have.
                    continue;
                }
                request.YieldFromSwidtag(p, requiredVersion, minimumVersion, maximumVersion, name);
            }
        }
Ejemplo n.º 7
0
        public void GetDynamicOptions(string category, BootstrapRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            request.Debug("Calling 'Bootstrap::GetDynamicOptions ({0})'", category);

            switch ((category ?? string.Empty).ToLowerInvariant())
            {
            case "package":
                break;

            case "source":
                break;

            case "install":
                request.YieldDynamicOption("DestinationPath", "Folder", false);
                break;
            }
        }
Ejemplo n.º 8
0
        public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, BootstrapRequest request)
        {
            if (request == null) {
                throw new ArgumentNullException("request");
            }

            request.Debug("Calling 'Bootstrap::FindPackage'");

            if (name != null && name.EqualsIgnoreCase("PackageManagement")) {
                // they are looking for PackageManagement itself.
                // future todo: let PackageManagement update itself.
                return;
            }

            // are they are looking for a specific provider?
            if (string.IsNullOrWhiteSpace(name)) {
                // no, return all providers that match the range.
                if (request.GetOptionValue("AllVersions").IsTrue()) {
                    foreach (var p in request.Providers.Distinct(PackageEqualityComparer)) {
                        FindPackage(p.Name, null, "0.0", null, 0, request);
                    }
                    return;
                }

                if (request.Providers.Distinct(PackageEqualityComparer).Any(p => !request.YieldFromSwidtag(p, requiredVersion, minimumVersion, maximumVersion, name))) {
                    // if there is a problem, exit.
                    return;
                }
            } else {
                // return just the one they asked for.

                // asked for a specific version?
                if (!string.IsNullOrWhiteSpace(requiredVersion)) {
                    request.YieldFromSwidtag(request.GetProvider(name, requiredVersion), name);
                    return;
                }

                if (request.GetOptionValue("AllVersions").IsTrue() && string.IsNullOrWhiteSpace(minimumVersion)) {
                    minimumVersion = "0.0";
                }

                // asked for a version range?
                if (!string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrEmpty(maximumVersion)) {
                    if (request.GetProvider(name, minimumVersion, maximumVersion).Distinct(PackageEqualityComparer).Any(provider => !request.YieldFromSwidtag(provider, name))) {
                        // if there is a problem, exit.
                        return;
                    }
                    return;
                }

                // just return by name
                request.YieldFromSwidtag(request.GetProvider(name), name);
            }

            // return any matches in the name
        }
Ejemplo n.º 9
0
        private bool InstallAssemblyProvider(Package provider, Link link, string fastPath, BootstrapRequest request)
        {
            if (!Directory.Exists(request.DestinationPath)) {
                request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.DestinationPathNotSet);
                return false;
            }

            var targetFilename = link.Attributes[Iso19770_2.Discovery.TargetFilename];

            if (string.IsNullOrWhiteSpace(targetFilename)) {
                request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.InvalidFilename);
                return false;
            }

            targetFilename = Path.GetFileName(targetFilename);
            var targetFile = Path.Combine(request.DestinationPath, targetFilename);

            // download the file
            var file = request.DownloadAndValidateFile(provider.Name, provider._swidtag.Links.Where(each => each.Relationship == Iso19770_2.Relationship.InstallationMedia));
            if (file != null) {
                // looks good! let's keep it
                if (File.Exists(targetFile)) {
                    request.Debug("Removing old file '{0}'", targetFile);
                    targetFile.TryHardToDelete();
                }

                // is that file still there?
                if (File.Exists(targetFile)) {
                    request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.UnableToRemoveFile, targetFile);
                    return false;
                }

                request.Debug("Copying file '{0}' to '{1}'", file, targetFile);
                File.Copy(file, targetFile);
                if (File.Exists(targetFile)) {
                    // since we only installed a single assembly, we can just ask to load that specific assembly.
                    if (PackageManagementService.TryToLoadProviderAssembly(targetFile, request)) {
                        // looks good to me.
                        request.YieldFromSwidtag(provider, fastPath);
                        return true;
                    }
                }
            }
            if (file != null) {
                file.TryHardToDelete();
            }
            return false;
        }
Ejemplo n.º 10
0
        public void InstallPackage(string fastPath, BootstrapRequest request)
        {
            if (request == null) {
                throw new ArgumentNullException("request");
            }
            // ensure that mandatory parameters are present.
            request.Debug("Calling 'Bootstrap::InstallPackage'");
            var triedAndFailed = false;

            // verify the package integrity (ie, check if it's digitally signed before installing)

            var provider = request.GetProvider(new Uri(fastPath));
            if (provider == null || !provider.IsValid) {
                request.Error(ErrorCategory.InvalidData, fastPath, Constants.Messages.UnableToResolvePackage, fastPath);
                return;
            }

            // group the links along 'artifact' lines
            var artifacts = provider._swidtag.Links.Where(link => link.Relationship == Iso19770_2.Relationship.InstallationMedia).GroupBy(link => link.Artifact);

            // try one artifact set at a time.
            foreach (var artifact in artifacts) {
                // first time we succeed, we're good to go.
                foreach (var link in artifact) {
                    switch (link.Attributes[Iso19770_2.Discovery.Type]) {
                        case "assembly":
                            if (InstallAssemblyProvider(provider, link, fastPath, request)) {
                                return;
                            }
                            triedAndFailed = true;
                            continue;

                        default:
                            if (InstallProviderFromInstaller(provider, link, fastPath, request)) {
                                return;
                            }
                            triedAndFailed = true;
                            continue;
                    }
                }
            }

            if (triedAndFailed) {
                // we tried installing something and it didn't go well.
                request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.FailedProviderBootstrap, fastPath);
            } else {
                // we didn't even find a link to bootstrap.
                request.Error(ErrorCategory.InvalidOperation, fastPath, "Provider {0} missing installationmedia to install.", fastPath);
            }
        }
Ejemplo n.º 11
0
 public void InitializeProvider(BootstrapRequest request)
 {
     // we should go find out what's available once here just to make sure that
     // we have a list
     try {
         request.Debug("Initialize Bootstrapper");
         PackageManagementService.BootstrappableProviderNames = request.Providers.Select(provider => provider.Name).ToArray();
     } catch (Exception e) {
         e.Dump();
     }
 }
Ejemplo n.º 12
0
        public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, BootstrapRequest request)
        {
            if (request == null) {
                throw new ArgumentNullException("request");
            }

            request.Debug("Calling '{0}::GetInstalledPackages' '{1}','{2}','{3}','{4}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion);
            // return all the dynamic package providers as packages

            foreach (var provider in PackageManagementService.DynamicProviders) {
                // for each package manager, match it's name and version with the swidtag from the remote feed
                var p = request.GetProvider(provider.Name, provider.Version);
                if (p == null) {
                    request.Debug("Dynamic provider '{0}' from '{1}' is not listed in a bootstrap feed.", provider.Name, provider.ProviderPath);
                    // we didn't find it. It's possible that the provider is listed elsewhere.
                    // well, we'll return as much info as we have.
                    continue;
                }
                request.YieldFromSwidtag(p, requiredVersion, minimumVersion, maximumVersion, name);
            }
        }
Ejemplo n.º 13
0
        public void GetFeatures(BootstrapRequest request)
        {
            if (request == null) {
                throw new ArgumentNullException("request");
            }

            request.Debug("Calling 'Bootstrap::GetFeatures'");
            foreach (var feature in _features) {
                request.Yield(feature);
            }
        }
Ejemplo n.º 14
0
        public void GetDynamicOptions(string category, BootstrapRequest request)
        {
            if (request == null) {
                throw new ArgumentNullException("request");
            }

            request.Debug("Calling 'Bootstrap::GetDynamicOptions ({0})'", category);

            switch ((category ?? string.Empty).ToLowerInvariant()) {
                case "package":
                    break;

                case "source":
                    break;

                case "install":
                    request.YieldDynamicOption("DestinationPath", "Folder", false);
                    break;
            }
        }
Ejemplo n.º 15
0
        public void InstallPackage(string fastPath, BootstrapRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            // ensure that mandatory parameters are present.
            request.Debug("Calling 'Bootstrap::InstallPackage'");
            var triedAndFailed = false;

            // verify the package integrity (ie, check if it's digitally signed before installing)

            var provider = request.GetProvider(new Uri(fastPath));

            if (provider == null || !provider.IsValid)
            {
                request.Error(ErrorCategory.InvalidData, fastPath, Constants.Messages.UnableToResolvePackage, fastPath);
                return;
            }

            // group the links along 'artifact' lines
            var artifacts = provider._swidtag.Links.Where(link => link.Relationship == Iso19770_2.Relationship.InstallationMedia).GroupBy(link => link.Artifact);

            // try one artifact set at a time.
            foreach (var artifact in artifacts)
            {
                // first time we succeed, we're good to go.
                foreach (var link in artifact)
                {
                    switch (link.Attributes[Iso19770_2.Discovery.Type])
                    {
                    case "assembly":
                        if (InstallAssemblyProvider(provider, link, fastPath, request))
                        {
                            return;
                        }
                        triedAndFailed = true;
                        continue;

                    default:
                        if (InstallProviderFromInstaller(provider, link, fastPath, request))
                        {
                            return;
                        }
                        triedAndFailed = true;
                        continue;
                    }
                }
            }

            if (triedAndFailed)
            {
                // we tried installing something and it didn't go well.
                request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.FailedProviderBootstrap, fastPath);
            }
            else
            {
                // we didn't even find a link to bootstrap.
                request.Error(ErrorCategory.InvalidOperation, fastPath, "Provider {0} missing installationmedia to install.", fastPath);
            }
        }
Ejemplo n.º 16
0
        public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, BootstrapRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            request.Debug("Calling 'Bootstrap::FindPackage'");

            if (name != null && name.EqualsIgnoreCase("PackageManagement"))
            {
                // they are looking for PackageManagement itself.
                // future todo: let PackageManagement update itself.
                return;
            }

            // are they are looking for a specific provider?
            if (string.IsNullOrWhiteSpace(name))
            {
                // no, return all providers that match the range.
                if (request.GetOptionValue("AllVersions").IsTrue())
                {
                    foreach (var p in request.Providers.Distinct(PackageEqualityComparer))
                    {
                        FindPackage(p.Name, null, "0.0", null, 0, request);
                    }
                    return;
                }

                if (request.Providers.Distinct(PackageEqualityComparer).Any(p => !request.YieldFromSwidtag(p, requiredVersion, minimumVersion, maximumVersion, name)))
                {
                    // if there is a problem, exit.
                    return;
                }
            }
            else
            {
                // return just the one they asked for.

                // asked for a specific version?
                if (!string.IsNullOrWhiteSpace(requiredVersion))
                {
                    request.YieldFromSwidtag(request.GetProvider(name, requiredVersion), name);
                    return;
                }

                if (request.GetOptionValue("AllVersions").IsTrue() && string.IsNullOrWhiteSpace(minimumVersion))
                {
                    minimumVersion = "0.0";
                }

                // asked for a version range?
                if (!string.IsNullOrWhiteSpace(minimumVersion) || !string.IsNullOrEmpty(maximumVersion))
                {
                    if (request.GetProvider(name, minimumVersion, maximumVersion).Distinct(PackageEqualityComparer).Any(provider => !request.YieldFromSwidtag(provider, name)))
                    {
                        // if there is a problem, exit.
                        return;
                    }
                    return;
                }

                // just return by name
                request.YieldFromSwidtag(request.GetProvider(name), name);
            }

            // return any matches in the name
        }