示例#1
0
        /// <summary>
        /// Take an enumeration of modules and only return those that match a specification
        /// in the given specification table, or have no corresponding entry in the specification table.
        /// </summary>
        /// <param name="modules">The modules to filter by specification match.</param>
        /// <param name="moduleSpecificationTable">The specification lookup table to filter the modules on.</param>
        /// <returns>The modules that match their corresponding table entry, or which have no table entry.</returns>
        private static IEnumerable <PSModuleInfo> FilterModulesForSpecificationMatch(
            IEnumerable <PSModuleInfo> modules,
            IDictionary <string, ModuleSpecification> moduleSpecificationTable)
        {
            Dbg.Assert(moduleSpecificationTable != null, $"Caller to verify that {nameof(moduleSpecificationTable)} is not null");
            Dbg.Assert(moduleSpecificationTable.Count != 0, $"Caller to verify that {nameof(moduleSpecificationTable)} is not empty");

            foreach (PSModuleInfo module in modules)
            {
                // TODO:
                // moduleSpecification.Name may be a path and will not match module.Name when they refer to the same module.
                // This actually causes the module to be returned always, so other specification checks are skipped erroneously.
                // Instead we need to be able to look up or match modules by path as well (e.g. a new comparer for PSModuleInfo).

                // No table entry means we return the module
                if (!moduleSpecificationTable.TryGetValue(module.Name, out ModuleSpecification moduleSpecification))
                {
                    yield return(module);

                    continue;
                }

                // Modules with table entries only get returned if they match them
                if (ModuleIntrinsics.IsModuleMatchingModuleSpec(module, moduleSpecification))
                {
                    yield return(module);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Take an enumeration of modules and only return those that match a specification
        /// in the given specification table, or have no corresponding entry in the specification table.
        /// </summary>
        /// <param name="modules">The modules to filter by specification match.</param>
        /// <param name="moduleSpecificationTable">The specification lookup table to filter the modules on.</param>
        /// <returns>The modules that match their corresponding table entry, or which have no table entry.</returns>
        private static IEnumerable <PSModuleInfo> FilterModulesForSpecificationMatch(
            IEnumerable <PSModuleInfo> modules,
            IDictionary <string, ModuleSpecification> moduleSpecificationTable)
        {
            Dbg.Assert(moduleSpecificationTable != null, $"Caller to verify that {nameof(moduleSpecificationTable)} is not null");
            Dbg.Assert(moduleSpecificationTable.Count != 0, $"Caller to verify that {nameof(moduleSpecificationTable)} is not empty");

            foreach (PSModuleInfo module in modules)
            {
                IEnumerable <ModuleSpecification> candidateModuleSpecs = GetCandidateModuleSpecs(moduleSpecificationTable, module);

                // Modules with table entries only get returned if they match them
                // We skip the name check since modules have already been prefiltered base on the moduleSpec path/name
                foreach (ModuleSpecification moduleSpec in candidateModuleSpecs)
                {
                    if (ModuleIntrinsics.IsModuleMatchingModuleSpec(module, moduleSpec, skipNameCheck: true))
                    {
                        yield return(module);
                    }
                }
            }
        }
        /// <summary>
        /// Take an enumeration of modules and only return those that match a specification
        /// in the given specification table, or have no corresponding entry in the specification table.
        /// </summary>
        /// <param name="modules">The modules to filter by specification match.</param>
        /// <param name="moduleSpecificationTable">The specification lookup table to filter the modules on.</param>
        /// <returns>The modules that match their corresponding table entry, or which have no table entry.</returns>
        private static IEnumerable <PSModuleInfo> FilterModulesForSpecificationMatch(
            IEnumerable <PSModuleInfo> modules,
            IDictionary <string, ModuleSpecification> moduleSpecificationTable)
        {
            Dbg.Assert(moduleSpecificationTable != null, $"Caller to verify that {nameof(moduleSpecificationTable)} is not null");
            Dbg.Assert(moduleSpecificationTable.Count != 0, $"Caller to verify that {nameof(moduleSpecificationTable)} is not empty");

            foreach (PSModuleInfo module in modules)
            {
                // No table entry means we return the module
                if (!moduleSpecificationTable.TryGetValue(module.Name, out ModuleSpecification moduleSpecification))
                {
                    yield return(module);

                    continue;
                }

                // Modules with table entries only get returned if they match them
                if (ModuleIntrinsics.IsModuleMatchingModuleSpec(module, moduleSpecification))
                {
                    yield return(module);
                }
            }
        }
 /// <summary>
 /// Determine whether a module info matches a given module specification table and specified PSEdition value.
 /// </summary>
 /// <param name="moduleInfo"></param>
 /// <param name="moduleSpecTable"></param>
 /// <param name="edition"></param>
 /// <returns></returns>
 private static bool ModuleMatch(PSModuleInfo moduleInfo, IDictionary<string, ModuleSpecification> moduleSpecTable, string edition)
 {
     ModuleSpecification moduleSpecification;
     return (String.IsNullOrEmpty(edition) || moduleInfo.CompatiblePSEditions.Contains(edition, StringComparer.OrdinalIgnoreCase)) &&
            (!moduleSpecTable.TryGetValue(moduleInfo.Name, out moduleSpecification) || ModuleIntrinsics.IsModuleMatchingModuleSpec(moduleInfo, moduleSpecification));
 }