private void HandleResponseReceived(object sender, RemoteDataEventArgs <PSObject> eventArgs) { PSObject data = eventArgs.Data; object propertyValue = RemotingDecoder.GetPropertyValue <object>(data, "SetMinMaxRunspacesResponse"); this.dispatchTable.SetResponse(RemotingDecoder.GetPropertyValue <long>(data, "ci"), propertyValue); }
internal static RemoteHostResponse Decode(PSObject data) { long propertyValue = RemotingDecoder.GetPropertyValue <long>(data, "ci"); RemoteHostMethodId methodId = RemotingDecoder.GetPropertyValue <RemoteHostMethodId>(data, "mi"); RemoteHostMethodInfo info = RemoteHostMethodInfo.LookUp(methodId); object returnValue = DecodeReturnValue(data, info.ReturnType); return(new RemoteHostResponse(propertyValue, methodId, returnValue, DecodeException(data))); }
internal static RemoteHostResponse Decode(PSObject data) { long propertyValue1 = RemotingDecoder.GetPropertyValue <long>(data, "ci"); RemoteHostMethodId propertyValue2 = RemotingDecoder.GetPropertyValue <RemoteHostMethodId>(data, "mi"); RemoteHostMethodInfo remoteHostMethodInfo = RemoteHostMethodInfo.LookUp(propertyValue2); object returnValue = RemoteHostResponse.DecodeReturnValue(data, remoteHostMethodInfo.ReturnType); Exception exception = RemoteHostResponse.DecodeException(data); return(new RemoteHostResponse(propertyValue1, propertyValue2, returnValue, exception)); }
internal static RemoteHostCall Decode(PSObject data) { long propertyValue1 = RemotingDecoder.GetPropertyValue <long>(data, "ci"); PSObject propertyValue2 = RemotingDecoder.GetPropertyValue <PSObject>(data, "mp"); RemoteHostMethodId propertyValue3 = RemotingDecoder.GetPropertyValue <RemoteHostMethodId>(data, "mi"); RemoteHostMethodInfo remoteHostMethodInfo = RemoteHostMethodInfo.LookUp(propertyValue3); object[] parameters = RemoteHostCall.DecodeParameters(propertyValue2, remoteHostMethodInfo.ParameterTypes); return(new RemoteHostCall(propertyValue1, propertyValue3, parameters)); }
internal static RemoteHostCall Decode(PSObject data) { long propertyValue = RemotingDecoder.GetPropertyValue <long>(data, "ci"); PSObject parametersPSObject = RemotingDecoder.GetPropertyValue <PSObject>(data, "mp"); RemoteHostMethodId methodId = RemotingDecoder.GetPropertyValue <RemoteHostMethodId>(data, "mi"); RemoteHostMethodInfo info = RemoteHostMethodInfo.LookUp(methodId); object[] objects = DecodeParameters(parametersPSObject, info.ParameterTypes); return(new RemoteHostCall(propertyValue, methodId, objects)); }
internal static CommandParameter FromPSObjectForRemoting(PSObject parameterAsPSObject) { if (parameterAsPSObject == null) { throw PSTraceSource.NewArgumentNullException("parameterAsPSObject"); } string propertyValue = RemotingDecoder.GetPropertyValue <string>(parameterAsPSObject, "N"); return(new CommandParameter(propertyValue, RemotingDecoder.GetPropertyValue <object>(parameterAsPSObject, "V"))); }
/// <summary> /// Creates a Command object from a PSObject property bag. /// PSObject has to be in the format returned by ToPSObjectForRemoting method. /// </summary> /// <param name="commandAsPSObject">PSObject to rehydrate.</param> /// <returns> /// Command rehydrated from a PSObject property bag /// </returns> /// <exception cref="ArgumentNullException"> /// Thrown if the PSObject is null. /// </exception> /// <exception cref="System.Management.Automation.Remoting.PSRemotingDataStructureException"> /// Thrown when the PSObject is not in the expected format /// </exception> internal static Command FromPSObjectForRemoting(PSObject commandAsPSObject) { if (commandAsPSObject == null) { throw PSTraceSource.NewArgumentNullException("commandAsPSObject"); } string commandText = RemotingDecoder.GetPropertyValue <string>(commandAsPSObject, RemoteDataNameStrings.CommandText); bool isScript = RemotingDecoder.GetPropertyValue <bool>(commandAsPSObject, RemoteDataNameStrings.IsScript); bool? useLocalScopeNullable = RemotingDecoder.GetPropertyValue <bool?>(commandAsPSObject, RemoteDataNameStrings.UseLocalScopeNullable); Command command = new Command(commandText, isScript, useLocalScopeNullable); // For V2 backwards compatibility. PipelineResultTypes mergeMyResult = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, RemoteDataNameStrings.MergeMyResult); PipelineResultTypes mergeToResult = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, RemoteDataNameStrings.MergeToResult); command.MergeMyResults(mergeMyResult, mergeToResult); command.MergeUnclaimedPreviousCommandResults = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, RemoteDataNameStrings.MergeUnclaimedPreviousCommandResults); // V3 merge instructions will not be returned by V2 server and this is expected. if (commandAsPSObject.Properties[RemoteDataNameStrings.MergeError] != null) { command.MergeInstructions[(int)MergeType.Error] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, RemoteDataNameStrings.MergeError); } if (commandAsPSObject.Properties[RemoteDataNameStrings.MergeWarning] != null) { command.MergeInstructions[(int)MergeType.Warning] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, RemoteDataNameStrings.MergeWarning); } if (commandAsPSObject.Properties[RemoteDataNameStrings.MergeVerbose] != null) { command.MergeInstructions[(int)MergeType.Verbose] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, RemoteDataNameStrings.MergeVerbose); } if (commandAsPSObject.Properties[RemoteDataNameStrings.MergeDebug] != null) { command.MergeInstructions[(int)MergeType.Debug] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, RemoteDataNameStrings.MergeDebug); } if (commandAsPSObject.Properties[RemoteDataNameStrings.MergeInformation] != null) { command.MergeInstructions[(int)MergeType.Information] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, RemoteDataNameStrings.MergeInformation); } foreach (PSObject parameterAsPSObject in RemotingDecoder.EnumerateListProperty <PSObject>(commandAsPSObject, RemoteDataNameStrings.Parameters)) { command.Parameters.Add(CommandParameter.FromPSObjectForRemoting(parameterAsPSObject)); } return(command); }
/// <summary> /// Creates a CommandParameter object from a PSObject property bag. /// PSObject has to be in the format returned by ToPSObjectForRemoting method. /// </summary> /// <param name="parameterAsPSObject">PSObject to rehydrate.</param> /// <returns> /// CommandParameter rehydrated from a PSObject property bag /// </returns> /// <exception cref="ArgumentNullException"> /// Thrown if the PSObject is null. /// </exception> /// <exception cref="System.Management.Automation.Remoting.PSRemotingDataStructureException"> /// Thrown when the PSObject is not in the expected format /// </exception> internal static CommandParameter FromPSObjectForRemoting(PSObject parameterAsPSObject) { if (parameterAsPSObject == null) { throw PSTraceSource.NewArgumentNullException(nameof(parameterAsPSObject)); } string name = RemotingDecoder.GetPropertyValue <string>(parameterAsPSObject, RemoteDataNameStrings.ParameterName); object value = RemotingDecoder.GetPropertyValue <object>(parameterAsPSObject, RemoteDataNameStrings.ParameterValue); return(new CommandParameter(name, value)); }
private void PopulateFromSerializedInfo(PSObject serializedScriptExtent) { string propertyValue = RemotingDecoder.GetPropertyValue <string>(serializedScriptExtent, "ScriptExtent_File"); int scriptLineNumber = RemotingDecoder.GetPropertyValue <int>(serializedScriptExtent, "ScriptExtent_StartLineNumber"); int offsetInLine = RemotingDecoder.GetPropertyValue <int>(serializedScriptExtent, "ScriptExtent_StartColumnNumber"); int num3 = RemotingDecoder.GetPropertyValue <int>(serializedScriptExtent, "ScriptExtent_EndLineNumber"); int num4 = RemotingDecoder.GetPropertyValue <int>(serializedScriptExtent, "ScriptExtent_EndColumnNumber"); ScriptPosition position = new ScriptPosition(propertyValue, scriptLineNumber, offsetInLine, null); ScriptPosition position2 = new ScriptPosition(propertyValue, num3, num4, null); this._startPosition = position; this._endPosition = position2; }
private void PopulateFromSerializedInfo(PSObject serializedScriptExtent) { string file = RemotingDecoder.GetPropertyValue <string>(serializedScriptExtent, "ScriptExtent_File"); int startLineNumber = RemotingDecoder.GetPropertyValue <int>(serializedScriptExtent, "ScriptExtent_StartLineNumber"); int startColumnNumber = RemotingDecoder.GetPropertyValue <int>(serializedScriptExtent, "ScriptExtent_StartColumnNumber"); int endLineNumber = RemotingDecoder.GetPropertyValue <int>(serializedScriptExtent, "ScriptExtent_EndLineNumber"); int endColumnNumber = RemotingDecoder.GetPropertyValue <int>(serializedScriptExtent, "ScriptExtent_EndColumnNumber"); ScriptPosition startPosition = new ScriptPosition(file, startLineNumber, startColumnNumber, null); ScriptPosition endPosition = new ScriptPosition(file, endLineNumber, endColumnNumber, null); _startPosition = startPosition; _endPosition = endPosition; }
/// <summary> /// Decode. /// </summary> internal static RemoteHostResponse Decode(PSObject data) { Dbg.Assert(data != null, "Expected data != null"); // Extract all the fields from data. long callId = RemotingDecoder.GetPropertyValue <long>(data, RemoteDataNameStrings.CallId); RemoteHostMethodId methodId = RemotingDecoder.GetPropertyValue <RemoteHostMethodId>(data, RemoteDataNameStrings.MethodId); // Decode the return value and the exception. RemoteHostMethodInfo methodInfo = RemoteHostMethodInfo.LookUp(methodId); object returnValue = DecodeReturnValue(data, methodInfo.ReturnType); Exception exception = DecodeException(data); // Use these values to create a RemoteHostResponse and return it. return(new RemoteHostResponse(callId, methodId, returnValue, exception)); }
/// <summary> /// Decode. /// </summary> internal static RemoteHostCall Decode(PSObject data) { Dbg.Assert(data != null, "Expected data != null"); // Extract all the fields from data. long callId = RemotingDecoder.GetPropertyValue <long>(data, RemoteDataNameStrings.CallId); PSObject parametersPSObject = RemotingDecoder.GetPropertyValue <PSObject>(data, RemoteDataNameStrings.MethodParameters); RemoteHostMethodId methodId = RemotingDecoder.GetPropertyValue <RemoteHostMethodId>(data, RemoteDataNameStrings.MethodId); // Look up all the info related to the method. RemoteHostMethodInfo methodInfo = RemoteHostMethodInfo.LookUp(methodId); // Decode the parameters. object[] parameters = DecodeParameters(parametersPSObject, methodInfo.ParameterTypes); // Create and return the RemoteHostCall. return(new RemoteHostCall(callId, methodId, parameters)); }
public static RunspaceConnectionInfo FromPSObjectForRemoting(PSObject obj) { var connection = new WSManConnectionInfo(PSSessionType.DefaultRemoteShell); connection._allowImplicitCredForNegotiate = RemotingDecoder.GetPropertyValue <bool>(obj, "AllowImplicitCredForNegotiate"); connection._appName = RemotingDecoder.GetPropertyValue <string>(obj, "ApplicationName"); connection._authMechanism = RemotingDecoder.GetPropertyValue <WSManNativeApi.WSManAuthenticationMechanism>(obj, "AuthenticationMechanism"); connection._computerName = RemotingDecoder.GetPropertyValue <string>(obj, "ComputerName"); connection._connectionUri = RemotingDecoder.GetPropertyValue <Uri>(obj, "ConnectionUri"); connection._credential = RemotingDecoder.GetPropertyValue <PSCredential>(obj, "Credential"); connection._maxRecvdDataSizePerCommand = RemotingDecoder.GetPropertyValue <int?>(obj, "MaxRecvdDataSizePerCommand"); connection._enableNetworkAccess = RemotingDecoder.GetPropertyValue <bool>(obj, "EnableNetworkAccess"); connection._includePortInSPN = RemotingDecoder.GetPropertyValue <bool>(obj, "IncludePortInSPN"); connection._maxRecvdObjectSize = RemotingDecoder.GetPropertyValue <int?>(obj, "MaxRecvdObjectSize"); connection._maxUriRedirectionCount = RemotingDecoder.GetPropertyValue <int>(obj, "MaxUriRedirectionCount"); connection._noEncryption = RemotingDecoder.GetPropertyValue <bool>(obj, "NoEncryption"); connection._noMachineProfile = RemotingDecoder.GetPropertyValue <bool>(obj, "NoMachineProfile"); connection._outputBufferingMode = RemotingDecoder.GetPropertyValue <OutputBufferingMode>(obj, "OutputBufferingMode"); connection._port = RemotingDecoder.GetPropertyValue <int>(obj, "Port"); connection._proxyAcessType = RemotingDecoder.GetPropertyValue <ProxyAccessType>(obj, "ProxyAccessType"); connection._proxyAuthentication = RemotingDecoder.GetPropertyValue <AuthenticationMechanism>(obj, "ProxyAuthenticationMechanism"); connection._proxyCredential = RemotingDecoder.GetPropertyValue <PSCredential>(obj, "ProxyCredential"); connection._thumbPrint = RemotingDecoder.GetPropertyValue <string>(obj, "ThumbPrint"); connection._scheme = RemotingDecoder.GetPropertyValue <string>(obj, "Scheme"); connection._shellUri = RemotingDecoder.GetPropertyValue <string>(obj, "ShellUri"); connection._skipCaCheck = RemotingDecoder.GetPropertyValue <bool>(obj, "SkipCaCheck"); connection._skipCnCheck = RemotingDecoder.GetPropertyValue <bool>(obj, "SkipCnCheck"); connection._skipRevocationCheck = RemotingDecoder.GetPropertyValue <bool>(obj, "SkipRevocationCheck"); connection._useCompression = RemotingDecoder.GetPropertyValue <bool>(obj, "UseCompression"); connection._useDefaultWSManPort = RemotingDecoder.GetPropertyValue <bool>(obj, "UseDefaultWSManPort"); connection._useUtf16 = RemotingDecoder.GetPropertyValue <bool>(obj, "UseUtf16"); connection.IdleTimeout = RemotingDecoder.GetPropertyValue <int>(obj, "IdleTimeout"); connection.MaxIdleTimeout = RemotingDecoder.GetPropertyValue <int>(obj, "MaxIdleTimeout"); connection.CancelTimeout = RemotingDecoder.GetPropertyValue <int>(obj, "CancelTimeout"); connection.OpenTimeout = RemotingDecoder.GetPropertyValue <int>(obj, "OpenTimeout"); connection.OperationTimeout = RemotingDecoder.GetPropertyValue <int>(obj, "OperationTimeout"); connection.Culture = new System.Globalization.CultureInfo(RemotingDecoder.GetPropertyValue <string>(obj, "Culture")); connection.UICulture = new System.Globalization.CultureInfo(RemotingDecoder.GetPropertyValue <string>(obj, "UICulture")); return(connection); }
internal static InformationRecord FromPSObjectForRemoting(PSObject inputObject) { InformationRecord informationRecord = new InformationRecord(); informationRecord.MessageData = RemotingDecoder.GetPropertyValue <object>(inputObject, "MessageData"); informationRecord.Source = RemotingDecoder.GetPropertyValue <string>(inputObject, "Source"); informationRecord.TimeGenerated = RemotingDecoder.GetPropertyValue <DateTime>(inputObject, "TimeGenerated"); informationRecord.Tags = new List <string>(); System.Collections.ArrayList tagsArrayList = RemotingDecoder.GetPropertyValue <System.Collections.ArrayList>(inputObject, "Tags"); foreach (string tag in tagsArrayList) { informationRecord.Tags.Add(tag); } informationRecord.User = RemotingDecoder.GetPropertyValue <string>(inputObject, "User"); informationRecord.Computer = RemotingDecoder.GetPropertyValue <string>(inputObject, "Computer"); informationRecord.ProcessId = RemotingDecoder.GetPropertyValue <uint>(inputObject, "ProcessId"); informationRecord.NativeThreadId = RemotingDecoder.GetPropertyValue <uint>(inputObject, "NativeThreadId"); informationRecord.ManagedThreadId = RemotingDecoder.GetPropertyValue <uint>(inputObject, "ManagedThreadId"); return(informationRecord); }
internal static Command FromPSObjectForRemoting(PSObject commandAsPSObject) { if (commandAsPSObject == null) { throw PSTraceSource.NewArgumentNullException("commandAsPSObject"); } string propertyValue = RemotingDecoder.GetPropertyValue <string>(commandAsPSObject, "Cmd"); bool isScript = RemotingDecoder.GetPropertyValue <bool>(commandAsPSObject, "IsScript"); bool? useLocalScope = RemotingDecoder.GetPropertyValue <bool?>(commandAsPSObject, "UseLocalScope"); Command command = new Command(propertyValue, isScript, useLocalScope); PipelineResultTypes myResult = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, "MergeMyResult"); PipelineResultTypes toResult = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, "MergeToResult"); command.MergeMyResults(myResult, toResult); command.MergeUnclaimedPreviousCommandResults = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, "MergePreviousResults"); if (commandAsPSObject.Properties["MergeError"] != null) { command.MergeInstructions[0] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, "MergeError"); } if (commandAsPSObject.Properties["MergeWarning"] != null) { command.MergeInstructions[1] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, "MergeWarning"); } if (commandAsPSObject.Properties["MergeVerbose"] != null) { command.MergeInstructions[2] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, "MergeVerbose"); } if (commandAsPSObject.Properties["MergeDebug"] != null) { command.MergeInstructions[3] = RemotingDecoder.GetPropertyValue <PipelineResultTypes>(commandAsPSObject, "MergeDebug"); } foreach (PSObject obj2 in RemotingDecoder.EnumerateListProperty <PSObject>(commandAsPSObject, "Args")) { command.Parameters.Add(CommandParameter.FromPSObjectForRemoting(obj2)); } return(command); }
internal static CommandParameter FromPSObjectForRemoting( PSObject parameterAsPSObject) { return(parameterAsPSObject != null ? new CommandParameter(RemotingDecoder.GetPropertyValue <string>(parameterAsPSObject, "N"), RemotingDecoder.GetPropertyValue <object>(parameterAsPSObject, "V")) : throw CommandParameter._trace.NewArgumentNullException(nameof(parameterAsPSObject))); }
internal List <CommandMetadata> GetRemoteCommandMetadata(out Dictionary <string, string> alias2resolvedCommandName) { bool flag = this.Session.Runspace.GetRemoteProtocolVersion() == RemotingConstants.ProtocolVersionWin7RC; alias2resolvedCommandName = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (((this.CommandName == null) || (this.CommandName.Length == 0)) || (!this.commandParameterSpecified && this.formatTypeNamesSpecified)) { return(new List <CommandMetadata>()); } this.WriteProgress(StringUtil.Format(ImplicitRemotingStrings.ProgressStatusGetCommandStart, new object[0]), null, null); using (PowerShell shell = this.BuildPowerShellForGetCommand()) { shell.AddCommand("Select-Object"); shell.AddParameter("Property", new string[] { "Name", "CommandType", "ResolvedCommandName", "DefaultParameterSet", "CmdletBinding", "Parameters" }); shell.IsGetCommandMetadataSpecialPipeline = !flag; IAsyncResult asyncResult = null; try { int expectedCount = -1; if (flag) { using (PowerShell shell2 = this.BuildPowerShellForGetCommand()) { expectedCount = this.CountRemoteObjects(shell2); } } Dictionary <string, CommandMetadata> dictionary = new Dictionary <string, CommandMetadata>(StringComparer.OrdinalIgnoreCase); using (new PowerShellStopper(base.Context, shell)) { DateTime utcNow = DateTime.UtcNow; PSDataCollection <PSObject> output = new PSDataCollection <PSObject>(); asyncResult = shell.BeginInvoke <PSObject, PSObject>(null, output); int num2 = 0; foreach (PSObject obj2 in output) { if (!flag && (expectedCount == -1)) { expectedCount = RemotingDecoder.GetPropertyValue <int>(obj2, "Count"); } else { this.AddRemoteCommandMetadata(dictionary, alias2resolvedCommandName, obj2); this.DuplicatePowerShellStreams(shell); this.WriteProgress(utcNow, ++num2, expectedCount, ImplicitRemotingStrings.ProgressStatusGetCommandProgress); } } this.DuplicatePowerShellStreams(shell); shell.EndInvoke(asyncResult); if ((num2 == 0) && this.commandParameterSpecified) { base.ThrowTerminatingError(this.GetErrorNoResultsFromRemoteEnd("Get-Command")); } return(new List <CommandMetadata>(dictionary.Values)); } } catch (RuntimeException exception) { base.ThrowTerminatingError(this.GetErrorFromRemoteCommand("Get-Command", exception)); } } return(null); }