Пример #1
0
        internal static IEnumerable <string> GetDefaultAvailableModuleFiles(bool isForAutoDiscovery, ExecutionContext context)
        {
            HashSet <string> uniqueModuleFiles = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (string directory in ModuleIntrinsics.GetModulePath(isForAutoDiscovery, context))
            {
                var            needWriteProgressCompleted = false;
                ProgressRecord analysisProgress           = null;

                // Write a progress message for UNC paths, so that users know what is happening
                try
                {
                    if ((context.CurrentCommandProcessor != null) && Utils.PathIsUnc(directory))
                    {
                        analysisProgress = new ProgressRecord(0,
                                                              Modules.DeterminingAvailableModules,
                                                              string.Format(CultureInfo.InvariantCulture, Modules.SearchingUncShare, directory))
                        {
                            RecordType = ProgressRecordType.Processing
                        };

                        context.CurrentCommandProcessor.CommandRuntime.WriteProgress(analysisProgress);
                        needWriteProgressCompleted = true;
                    }
                }
                catch (InvalidOperationException)
                {
                    // This may be called when we are not allowed to write progress,
                    // So eat the invalid operation
                }

                try
                {
                    foreach (string moduleFile in ModuleUtils.GetDefaultAvailableModuleFiles(directory))
                    {
                        if (uniqueModuleFiles.Add(moduleFile))
                        {
                            yield return(moduleFile);
                        }
                    }
                }
                finally
                {
                    if (needWriteProgressCompleted)
                    {
                        analysisProgress.RecordType = ProgressRecordType.Completed;
                        context.CurrentCommandProcessor.CommandRuntime.WriteProgress(analysisProgress);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Check if the CompatiblePSEditions field of a given module
        /// declares compatibility with the running PowerShell edition.
        /// </summary>
        /// <param name="moduleManifestPath">The path to the module manifest being checked.</param>
        /// <param name="compatiblePSEditions">The value of the CompatiblePSEditions field of the module manifest.</param>
        /// <returns>True if the module is compatible with the running PowerShell edition, false otherwise.</returns>
        internal static bool IsPSEditionCompatible(
            string moduleManifestPath,
            IEnumerable <string> compatiblePSEditions)
        {
#if UNIX
            return(true);
#else
            if (!ModuleUtils.IsOnSystem32ModulePath(moduleManifestPath))
            {
                return(true);
            }

            return(Utils.IsPSEditionSupported(compatiblePSEditions));
#endif
        }
Пример #3
0
            public bool MoveNext()
            {
                try
                {
                    int num = this.__1__state;
                    if (num != 0)
                    {
                        if (num == 3)
                        {
                            this.__1__state = 2;
                            this.__m__Finally1e();
                        }
                        if (num == 7)
                        {
                            this.__1__state = 5;
                            this.__m__Finally22();
                        }
                    }
                    else
                    {
                        this.__1__state           = -1;
                        this._commandPattern_5__b = new WildcardPattern(this.pattern, WildcardOptions.IgnoreCase);
                        this._cmdletInfo_5__c     = this.context.SessionState.InvokeCommand.GetCmdlet(@"Microsoft.PowerShell.Core\Get-Module");
                        aa__ = CommandDiscovery.GetCommandDiscoveryPreference(this.context, SpecialVariables.PSModuleAutoLoadingPreferenceVarPath, "PSModuleAutoLoadingPreference");
                        if ((aa__ != PSModuleAutoLoadingPreference.None) && ((this.commandOrigin == CommandOrigin.Internal) || ((this._cmdletInfo_5__c != null) && (this._cmdletInfo_5__c.Visibility == SessionStateEntryVisibility.Public))))
                        {
                            this.__7__wrap1b = ModuleUtils.GetDefaultAvailableModuleFiles(true, false, this.context).GetEnumerator();
                            this.__1__state  = 1;
                            while (this.__7__wrap1b.MoveNext())
                            {
                                this._modulePath_5__e      = this.__7__wrap1b.Current;
                                this._moduleName_5__f      = Path.GetFileNameWithoutExtension(this._modulePath_5__e);
                                this._modules_5__10        = this.context.Modules.GetExactMatchModules(this._moduleName_5__f, false, true);
                                this._tempModuleInfo_5__11 = null;
                                if (this._modules_5__10.Count != 0)
                                {
                                    if (!this.rediscoverImportedModules)
                                    {
                                        continue;
                                    }
                                    if (this._modules_5__10.Exists(new Predicate <PSModuleInfo>(ModuleUtils.GetMatchingCommands_b__8)))
                                    {
                                        continue;
                                    }
                                    if (this._modules_5__10.Count == 1)
                                    {
                                        this._psModule_5__12       = this._modules_5__10[0];
                                        this._tempModuleInfo_5__11 = new PSModuleInfo(this._psModule_5__12.Name, this._psModule_5__12.Path, null, null);
                                        this._tempModuleInfo_5__11.SetModuleBase(this._psModule_5__12.ModuleBase);
                                        this.__7__wrap1d = this._psModule_5__12.ExportedCommands.GetEnumerator();
                                        this.__1__state  = 2;
                                        while (this.__7__wrap1d.MoveNext())
                                        {
                                            this._entry_5__13 = this.__7__wrap1d.Current;
                                            if (!this._commandPattern_5__b.IsMatch(this._entry_5__13.Value.Name))
                                            {
                                                continue;
                                            }
                                            this._current_5__14 = null;
                                            switch (this._entry_5__13.Value.CommandType)
                                            {
                                            case CommandTypes.Alias:
                                                this._current_5__14 = new AliasInfo(this._entry_5__13.Value.Name, null, this.context);
                                                break;

                                            case CommandTypes.Function:
                                                this._current_5__14 = new FunctionInfo(this._entry_5__13.Value.Name, ScriptBlock.Create(""), this.context);
                                                break;

                                            case CommandTypes.Filter:
                                                this._current_5__14 = new FilterInfo(this._entry_5__13.Value.Name, ScriptBlock.Create(""), this.context);
                                                break;

                                            case CommandTypes.Cmdlet:
                                                this._current_5__14 = new CmdletInfo(this._entry_5__13.Value.Name, null, null, null, this.context);
                                                break;

                                            case CommandTypes.Workflow:
                                                this._current_5__14 = new WorkflowInfo(this._entry_5__13.Value.Name, ScriptBlock.Create(""), this.context);
                                                break;
                                            }
                                            this._current_5__14.SetModule(this._tempModuleInfo_5__11);
                                            this.__2__current = this._current_5__14;
                                            this.__1__state   = 3;
                                            return(true);

                                            this.__1__state = 2;
                                        }
                                        this.__m__Finally1e();
                                        continue;
                                    }
                                }
                                this._moduleShortName_5__15  = Path.GetFileNameWithoutExtension(this._modulePath_5__e);
                                this._exportedCommands_5__16 = AnalysisCache.GetExportedCommands(this._modulePath_5__e, false, this.context);
                                if (this._exportedCommands_5__16 != null)
                                {
                                    this._tempModuleInfo_5__11 = new PSModuleInfo(this._moduleShortName_5__15, this._modulePath_5__e, null, null);
                                    if (InitialSessionState.IsEngineModule(this._moduleShortName_5__15))
                                    {
                                        this._tempModuleInfo_5__11.SetModuleBase(Utils.GetApplicationBase(Utils.DefaultPowerShellShellID));
                                    }
                                    this.__7__wrap1f = this._exportedCommands_5__16.Keys.GetEnumerator();
                                    this.__1__state  = 4;
                                    while (this.__7__wrap1f.MoveNext())
                                    {
                                        this._exportedCommand_5__17 = this.__7__wrap1f.Current;
                                        if (this._commandPattern_5__b.IsMatch(this._exportedCommand_5__17))
                                        {
                                            this.__7__wrap21 = this._exportedCommands_5__16[this._exportedCommand_5__17].GetEnumerator();
                                            this.__1__state  = 5;
                                            while (this.__7__wrap21.MoveNext())
                                            {
                                                this._commandType_5__18         = this.__7__wrap21.Current;
                                                this._shouldExportCommand_5__19 = true;
                                                if ((this.context.InitialSessionState != null) && (this.commandOrigin == CommandOrigin.Runspace))
                                                {
                                                    foreach (SessionStateCommandEntry entry in this.context.InitialSessionState.Commands[this._exportedCommand_5__17])
                                                    {
                                                        string b = null;
                                                        if (entry.Module != null)
                                                        {
                                                            b = entry.Module.Name;
                                                        }
                                                        else if (entry.PSSnapIn != null)
                                                        {
                                                            b = entry.PSSnapIn.Name;
                                                        }
                                                        if (string.Equals(this._moduleShortName_5__15, b, StringComparison.OrdinalIgnoreCase) && (entry.Visibility == SessionStateEntryVisibility.Private))
                                                        {
                                                            this._shouldExportCommand_5__19 = false;
                                                        }
                                                    }
                                                }
                                                if (!this._shouldExportCommand_5__19)
                                                {
                                                    continue;
                                                }
                                                this._current_5__1a = null;
                                                switch (this._commandType_5__18)
                                                {
                                                case CommandTypes.Alias:
                                                    this._current_5__1a = new AliasInfo(this._exportedCommand_5__17, null, this.context);
                                                    break;

                                                case CommandTypes.Function:
                                                    this._current_5__1a = new FunctionInfo(this._exportedCommand_5__17, ScriptBlock.Create(""), this.context);
                                                    break;

                                                case CommandTypes.Cmdlet:
                                                    this._current_5__1a = new CmdletInfo(this._exportedCommand_5__17, null, null, null, this.context);
                                                    break;

                                                case CommandTypes.Workflow:
                                                    this._current_5__1a = new WorkflowInfo(this._exportedCommand_5__17, ScriptBlock.Create(""), this.context);
                                                    break;
                                                }
                                                if (this._current_5__1a != null)
                                                {
                                                    this._current_5__1a.SetModule(this._tempModuleInfo_5__11);
                                                }
                                                this.__2__current = this._current_5__1a;
                                                this.__1__state   = 7;
                                                return(true);

Label_060F:
                                                this.__1__state = 5;
                                            }
                                            this.__m__Finally22();
                                        }
                                    }
                                    this.__m__Finally20();
                                }
                            }
                            this.__m__Finally1c();
                        }
                    }
                    return(false);
                }
                finally
                {
                    (this as IDisposable).Dispose();
                }
            }