Ejemplo n.º 1
0
        public void Add(PSModuleInfo module, ModuleImportScopes scope)
        {
            // it's either set at global or module level
            var targetScope = GetModuleImportScope(scope);

            targetScope.SetLocal(module, false);
        }
Ejemplo n.º 2
0
        internal void ImportMembers(PSModuleInfo module, ModuleImportScopes scope)
        {
            // we either export to
            var targetScope = GetModuleImportScope(scope);

            foreach (var fun in module.ExportedFunctions.Values)
            {
                fun.Module = fun.Module ?? module;
                targetScope.SessionState.Function.Set(fun);
            }
            foreach (var variable in module.ExportedVariables.Values)
            {
                variable.Module = variable.Module ?? module;
                targetScope.SessionState.PSVariable.Set(variable);
            }
            foreach (var alias in module.ExportedAliases.Values)
            {
                alias.Module = alias.Module ?? module;
                targetScope.SessionState.Alias.Set(alias, "local");
            }
            foreach (var cmdlet in module.ExportedCmdlets.Values)
            {
                cmdlet.Module = cmdlet.Module ?? module;
                targetScope.SessionState.Cmdlet.Set(cmdlet);
            }
        }
Ejemplo n.º 3
0
        private SessionStateScope <PSModuleInfo> GetModuleImportScope(ModuleImportScopes scope)
        {
            if (scope.Equals(ModuleImportScopes.Local))
            {
                return(Scope);
            }
            var moduleScope = scope.Equals(ModuleImportScopes.Module);

            foreach (var curScope in Scope.HierarchyIterator)
            {
                // check for global scope. Even if we want to get the module scope, this means it doesn't exist
                // or we would have returned it
                if (curScope.ParentScope == null)
                {
                    return(curScope);
                }
                // check for module scope
                if (moduleScope && curScope.SessionState.Module != null)
                {
                    return(curScope);
                }
            }
            // should never happen as we *must* reach the global scope
            return(null);
        }