public override InitialSessionStateEntry Clone() { SessionStateAliasEntry entry = new SessionStateAliasEntry(base.Name, this._definition, this._description, this._options, base.Visibility); entry.SetModule(base.Module); return(entry); }
/// <summary> /// Add a new alias entry to this session state object... /// </summary> /// <param name="entry">The entry to add</param> /// <param name="scopeID"> /// A scope identifier that is either one of the "special" scopes like /// "global", "script", "local", or "private, or a numeric ID of a relative scope /// to the current scope. /// </param> internal void AddSessionStateEntry(SessionStateAliasEntry entry, string scopeID) { AliasInfo alias = new AliasInfo(entry.Name, entry.Definition, this.ExecutionContext, entry.Options) { Visibility = entry.Visibility, Module = entry.Module, Description = entry.Description }; // Create alias in the global scope... this.SetAliasItemAtScope(alias, scopeID, true, CommandOrigin.Internal); }
public override InitialSessionStateEntry Clone() { SessionStateAliasEntry entry = new SessionStateAliasEntry(base.Name, this._definition, this._description, this._options, base.Visibility); entry.SetModule(base.Module); return entry; }
public static InitialSessionState GetSessionStateForCommands(CommandInfo[] commands) { InitialSessionState iss = InitialSessionState.CreateDefault(); Dictionary<string, SessionStateCommandEntry> commandCache = new Dictionary<string, SessionStateCommandEntry>(); foreach (SessionStateCommandEntry ssce in iss.Commands) { commandCache[ssce.Name] = ssce; } iss.ApartmentState = ApartmentState.STA; iss.ThreadOptions = PSThreadOptions.ReuseThread; if (commands.Length == 0) { return iss; } foreach (CommandInfo cmd in commands) { if (cmd.Module != null) { if (cmd.ModuleName == "WPK") { if (cmd is AliasInfo) { SessionStateAliasEntry alias = new SessionStateAliasEntry(cmd.Name, cmd.Definition); iss.Commands.Add(alias); continue; } if (cmd is FunctionInfo) { SessionStateFunctionEntry func = new SessionStateFunctionEntry(cmd.Name, cmd.Definition); iss.Commands.Add(func); continue; } if (cmd is CmdletInfo) { CmdletInfo cmdletData = cmd as CmdletInfo; SessionStateCmdletEntry cmdlet = new SessionStateCmdletEntry(cmd.Name, cmdletData.ImplementingType, cmdletData.HelpFile); iss.Commands.Add(cmdlet); } } else { string manifestPath = cmd.Module.Path.Replace(".psm1",".psd1").Replace(".dll", ".psd1"); if (System.IO.File.Exists(manifestPath)) { iss.ImportPSModule(new string[] { manifestPath }); } else { iss.ImportPSModule(new string[] { cmd.Module.Path }); } continue; } } if (cmd is AliasInfo) { CommandInfo loopCommand = cmd; while (loopCommand is AliasInfo) { SessionStateAliasEntry alias = new SessionStateAliasEntry(loopCommand.Name, loopCommand.Definition); iss.Commands.Add(alias); loopCommand = (loopCommand as AliasInfo).ReferencedCommand; } if (loopCommand is FunctionInfo) { SessionStateFunctionEntry func = new SessionStateFunctionEntry(loopCommand.Name, loopCommand.Definition); iss.Commands.Add(func); } if (loopCommand is CmdletInfo) { CmdletInfo cmdletData = loopCommand as CmdletInfo; SessionStateCmdletEntry cmdlet = new SessionStateCmdletEntry(cmd.Name, cmdletData.ImplementingType, cmdletData.HelpFile); iss.Commands.Add(cmdlet); } } if (cmd is FunctionInfo) { SessionStateFunctionEntry func = new SessionStateFunctionEntry(cmd.Name, cmd.Definition); iss.Commands.Add(func); } if (cmd is CmdletInfo) { CmdletInfo cmdletData = cmd as CmdletInfo; SessionStateCmdletEntry cmdlet = new SessionStateCmdletEntry(cmd.Name, cmdletData.ImplementingType, cmdletData.HelpFile); iss.Commands.Add(cmdlet); } } return iss; }
internal void AddSessionStateEntry(SessionStateAliasEntry entry) { AliasInfo alias = new AliasInfo(entry.Name, entry.Definition, this.ExecutionContext, entry.Options) { Visibility = entry.Visibility }; alias.SetModule(entry.Module); if (!string.IsNullOrEmpty(entry.Description)) { alias.Description = entry.Description; } this.SetAliasItemAtScope(alias, "global", true, CommandOrigin.Internal); }