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
        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.º 3
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.º 4
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);
            }
        }