//public SymbolDetails GetSymbolDetails() #endregion #region Private Fields /// <summary> /// Gets all aliases found in the runspace /// </summary> private async Task GetAliases() { if (!this.areAliasesLoaded) { RunspaceHandle runspaceHandle = await this.powerShellContext.GetRunspaceHandle(); CommandInvocationIntrinsics invokeCommand = runspaceHandle.Runspace.SessionStateProxy.InvokeCommand; IEnumerable <CommandInfo> aliases = invokeCommand.GetCommands("*", CommandTypes.Alias, true); runspaceHandle.Dispose(); foreach (AliasInfo aliasInfo in aliases) { if (!CmdletToAliasDictionary.ContainsKey(aliasInfo.Definition)) { CmdletToAliasDictionary.Add(aliasInfo.Definition, new List <String>() { aliasInfo.Name }); } else { CmdletToAliasDictionary[aliasInfo.Definition].Add(aliasInfo.Name); } AliasToCmdletDictionary.Add(aliasInfo.Name, aliasInfo.Definition); } this.areAliasesLoaded = true; } }
/// <summary> /// Gets all aliases found in the runspace /// </summary> private async Task GetAliases() { if (_areAliasesLoaded) { return; } try { RunspaceHandle runspaceHandle = await _powerShellContext.GetRunspaceHandle( new CancellationTokenSource(DefaultWaitTimeoutMilliseconds).Token); CommandInvocationIntrinsics invokeCommand = runspaceHandle.Runspace.SessionStateProxy.InvokeCommand; IEnumerable <CommandInfo> aliases = invokeCommand.GetCommands("*", CommandTypes.Alias, true); runspaceHandle.Dispose(); foreach (AliasInfo aliasInfo in aliases) { if (!_cmdletToAliasDictionary.ContainsKey(aliasInfo.Definition)) { _cmdletToAliasDictionary.Add(aliasInfo.Definition, new List <String> { aliasInfo.Name }); } else { _cmdletToAliasDictionary[aliasInfo.Definition].Add(aliasInfo.Name); } _aliasToCmdletDictionary.Add(aliasInfo.Name, aliasInfo.Definition); } _areAliasesLoaded = true; } catch (PSNotSupportedException e) { _logger.Write( LogLevel.Warning, $"Caught PSNotSupportedException while attempting to get aliases from remote session:\n\n{e.ToString()}"); // Prevent the aliases from being fetched again - no point if the remote doesn't support InvokeCommand. _areAliasesLoaded = true; } catch (TaskCanceledException) { // The wait for a RunspaceHandle has timed out, skip aliases for now } }
/// <summary> /// Gets all aliases found in the runspace /// </summary> private async Task GetAliases() { if (!this.areAliasesLoaded) { try { RunspaceHandle runspaceHandle = await this.powerShellContext.GetRunspaceHandle( new CancellationTokenSource(DefaultWaitTimeoutMilliseconds).Token); CommandInvocationIntrinsics invokeCommand = runspaceHandle.Runspace.SessionStateProxy.InvokeCommand; IEnumerable <CommandInfo> aliases = invokeCommand.GetCommands("*", CommandTypes.Alias, true); runspaceHandle.Dispose(); foreach (AliasInfo aliasInfo in aliases) { if (!CmdletToAliasDictionary.ContainsKey(aliasInfo.Definition)) { CmdletToAliasDictionary.Add(aliasInfo.Definition, new List <String>() { aliasInfo.Name }); } else { CmdletToAliasDictionary[aliasInfo.Definition].Add(aliasInfo.Name); } AliasToCmdletDictionary.Add(aliasInfo.Name, aliasInfo.Definition); } this.areAliasesLoaded = true; } catch (TaskCanceledException) { // The wait for a RunspaceHandle has timed out, skip aliases for now } } }