Beispiel #1
0
        public override bool ProcessRecordAsync()
        {
            //Error out for the case where multiple provider names with any version specified
            if (((!Name.IsNullOrEmpty() && Name.Length > 1) || Name[0].ContainsWildcards()) &&
                ((RequiredVersion != null) || (MinimumVersion != null) || (MaximumVersion != null)))
            {
                Error(Constants.Errors.MultipleNamesWithVersionNotAllowed);
                return(false);
            }

            foreach (var path in Name)
            {
                var isRooted = false;

                var resolvedPath = path;

                if (!string.IsNullOrWhiteSpace(path))
                {
                    if (IsRooted(path))
                    {
                        if ((RequiredVersion != null) || (MaximumVersion != null) || (MinimumVersion != null))
                        {
                            Error(Constants.Errors.FullProviderFilePathVersionNotAllowed);
                        }

                        try {
                            ProviderInfo        provider      = null;
                            Collection <string> resolvedPaths = GetResolvedProviderPathFromPSPath(path, out provider);

                            // Ensure the path is a single path from the file system provider
                            if ((resolvedPaths.Count > 1) ||
                                (!String.Equals(provider.Name, "FileSystem", StringComparison.OrdinalIgnoreCase)))
                            {
                                Error(Constants.Errors.FilePathMustBeFileSystemPath, path);
                                return(false);
                            }
                            resolvedPath = resolvedPaths[0];

                            isRooted = true;
                        } catch (Exception ex) {
                            Error(Constants.Errors.FileNotFound, ex.Message);
                            return(true);
                        }
                    }

                    foreach (var p in PackageManagementService.ImportPackageProvider(this, resolvedPath, RequiredVersion.ToVersion(),
                                                                                     MinimumVersion.ToVersion(), MaximumVersion.ToVersion(), isRooted, Force.IsPresent))
                    {
                        WriteObject(p);
                    }
                }
            } //foreach name

            return(true);
        }
Beispiel #2
0
        private bool ImportProvider(SoftwareIdentity[] list)
        {
            Verbose("Importing the package provider {0}", Name.JoinWithComma());

            //after the provider gets installed, we are trying to load it
            var providers = list.SelectMany(each => PackageManagementService.ImportPackageProvider(this.SuppressErrorsAndWarnings(IsProcessing), each.Name, each.Version.ToVersion(), null, null, false, true)).ToArray();

            if (providers.Any())
            {
                Verbose(Resources.Messages.ProviderImported, providers.Select(e => e.ProviderPath).JoinWithComma());
                return(true);
            }
            else
            {
                Warning(Resources.Messages.ProviderNameDifferentFromPackageName, Name.JoinWithComma());
            }
            return(false);
        }