/// <summary> /// Execute method. /// </summary> internal T ExecuteMethod <T>(RemoteHostMethodId methodId, object[] parameters) { Dbg.Assert(parameters != null, "Expected parameters != null"); // Create the method call object. long callId = _serverDispatchTable.CreateNewCallId(); RemoteHostCall remoteHostCall = new RemoteHostCall(callId, methodId, parameters); RemoteDataObject <PSObject> dataToBeSent = RemoteDataObject <PSObject> .CreateFrom(RemotingDestination.Client, _remoteHostCallDataType, _clientRunspacePoolId, _clientPowerShellId, remoteHostCall.Encode()); // report that execution is pending host response _transportManager.SendDataToClient(dataToBeSent, false, true); // Wait for response. RemoteHostResponse remoteHostResponse = _serverDispatchTable.GetResponse(callId, null); // Null means that the response PSObject was not received and there was an error. if (remoteHostResponse == null) { throw RemoteHostExceptions.NewRemoteHostCallFailedException(methodId); } // Process the response. object returnValue = remoteHostResponse.SimulateExecution(); Dbg.Assert(returnValue is T, "Expected returnValue is T"); return((T)remoteHostResponse.SimulateExecution()); }
internal RemoteHostResponse(long callId, RemoteHostMethodId methodId, object returnValue, Exception exception) { this._callId = callId; this._methodId = methodId; this._returnValue = returnValue; this._exception = exception; }
internal void ExecuteVoidMethod(RemoteHostMethodId methodId, object[] parameters) { long callId = -100L; RemoteDataObject <PSObject> data = RemoteDataObject <PSObject> .CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Client, this._remoteHostCallDataType, this._clientRunspacePoolId, this._clientPowerShellId, new RemoteHostCall(callId, methodId, parameters).Encode()); this._transportManager.SendDataToClient <PSObject>(data, false, false); }
/// <summary> /// Constructor for RemoteHostResponse. /// </summary> internal RemoteHostResponse(long callId, RemoteHostMethodId methodId, object returnValue, Exception exception) { _callId = callId; _methodId = methodId; _returnValue = returnValue; _exception = exception; }
internal RemoteHostCall(long callId, RemoteHostMethodId methodId, object[] parameters) { this._callId = callId; this._methodId = methodId; this._parameters = parameters; this._methodInfo = RemoteHostMethodInfo.LookUp(methodId); }
internal RemoteHostCall(long callId, RemoteHostMethodId methodId, object[] parameters) { this._callId = callId; this._methodId = methodId; this._parameters = parameters; this._methodInfo = RemoteHostMethodInfo.LookUp(methodId); }
/// <summary> /// Constructor for RemoteHostCall. /// </summary> internal RemoteHostCall(long callId, RemoteHostMethodId methodId, object[] parameters) { Dbg.Assert(parameters != null, "Expected parameters != null"); _callId = callId; MethodId = methodId; Parameters = parameters; _methodInfo = RemoteHostMethodInfo.LookUp(methodId); }
/// <summary> /// New remote host call failed exception. /// </summary> internal static Exception NewRemoteHostCallFailedException(RemoteHostMethodId methodId) { RemoteHostMethodInfo methodInfo = RemoteHostMethodInfo.LookUp(methodId); string resourceString = PSRemotingErrorInvariants.FormatResourceString( RemotingErrorIdStrings.RemoteHostCallFailed, methodInfo.Name); return(new PSRemotingDataStructureException(resourceString)); }
/// <summary> /// Constructor for RemoteHostCall. /// </summary> internal RemoteHostCall(long callId, RemoteHostMethodId methodId, object[] parameters) { Dbg.Assert(parameters != null, "Expected parameters != null"); _callId = callId; MethodId = methodId; Parameters = parameters; _methodInfo = RemoteHostMethodInfo.LookUp(methodId); }
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 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 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 T ExecuteMethod <T>(RemoteHostMethodId methodId, object[] parameters) { long newCallId = this._serverDispatchTable.CreateNewCallId(); this._transportManager.SendDataToClient <PSObject>(RemoteDataObject <PSObject> .CreateFrom(RemotingDestination.Client, this._remoteHostCallDataType, this._clientRunspacePoolId, this._clientPowerShellId, new RemoteHostCall(newCallId, methodId, parameters).Encode()), false); RemoteHostResponse response = this._serverDispatchTable.GetResponse(newCallId, (RemoteHostResponse)null); if (response == null) { throw RemoteHostExceptions.NewRemoteHostCallFailedException(methodId); } response.SimulateExecution(); return((T)response.SimulateExecution()); }
/// <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)); }
/// <summary> /// Execute void method. /// </summary> internal void ExecuteVoidMethod(RemoteHostMethodId methodId, object[] parameters) { Dbg.Assert(parameters != null, "Expected parameters != null"); // Use void call ID so that the call is known to not have a return value. long callId = ServerDispatchTable.VoidCallId; RemoteHostCall remoteHostCall = new RemoteHostCall(callId, methodId, parameters); // Dispatch the call but don't wait for response since the return value is void. // TODO: remove redundant data from the RemoteHostCallPacket. RemoteDataObject<PSObject> dataToBeSent = RemoteDataObject<PSObject>.CreateFrom(RemotingDestination.Client, _remoteHostCallDataType, _clientRunspacePoolId, _clientPowerShellId, remoteHostCall.Encode()); // flush is not used here..since this is a void method and server host // does not expect anything from client..so let the transport manager buffer // and send as much data as possible. _transportManager.SendDataToClient(dataToBeSent, false); }
internal void ExecuteVoidMethod(RemoteHostMethodId methodId, object[] parameters) => this._transportManager.SendDataToClient <PSObject>(RemoteDataObject <PSObject> .CreateFrom(RemotingDestination.Client, this._remoteHostCallDataType, this._clientRunspacePoolId, this._clientPowerShellId, new RemoteHostCall(-100L, methodId, parameters).Encode()), false);
internal static Exception NewRemoteHostCallFailedException(RemoteHostMethodId methodId) { RemoteHostMethodInfo info = RemoteHostMethodInfo.LookUp(methodId); return(new PSRemotingDataStructureException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.RemoteHostCallFailed, new object[] { info.Name }))); }
internal static Exception NewRemoteHostCallFailedException(RemoteHostMethodId methodId) => (Exception) new PSRemotingDataStructureException(PSRemotingErrorInvariants.FormatResourceString(PSRemotingErrorId.RemoteHostCallFailed, (object)RemoteHostMethodInfo.LookUp(methodId).Name));
internal T ExecuteMethod <T>(RemoteHostMethodId methodId) => this.ExecuteMethod <T>(methodId, new object[0]);
internal T ExecuteMethod <T>(RemoteHostMethodId methodId) { return(this.ExecuteMethod <T>(methodId, new object[0])); }
internal static RemoteHostMethodInfo LookUp(RemoteHostMethodId methodId) { switch (methodId) { case RemoteHostMethodId.GetName: return(new RemoteHostMethodInfo(typeof(PSHost), "get_Name", typeof(string), new Type[0])); case RemoteHostMethodId.GetVersion: return(new RemoteHostMethodInfo(typeof(PSHost), "get_Version", typeof(Version), new Type[0])); case RemoteHostMethodId.GetInstanceId: return(new RemoteHostMethodInfo(typeof(PSHost), "get_InstanceId", typeof(Guid), new Type[0])); case RemoteHostMethodId.GetCurrentCulture: return(new RemoteHostMethodInfo(typeof(PSHost), "get_CurrentCulture", typeof(CultureInfo), new Type[0])); case RemoteHostMethodId.GetCurrentUICulture: return(new RemoteHostMethodInfo(typeof(PSHost), "get_CurrentUICulture", typeof(CultureInfo), new Type[0])); case RemoteHostMethodId.SetShouldExit: return(new RemoteHostMethodInfo(typeof(PSHost), "SetShouldExit", typeof(void), new Type[] { typeof(int) })); case RemoteHostMethodId.EnterNestedPrompt: return(new RemoteHostMethodInfo(typeof(PSHost), "EnterNestedPrompt", typeof(void), new Type[0])); case RemoteHostMethodId.ExitNestedPrompt: return(new RemoteHostMethodInfo(typeof(PSHost), "ExitNestedPrompt", typeof(void), new Type[0])); case RemoteHostMethodId.NotifyBeginApplication: return(new RemoteHostMethodInfo(typeof(PSHost), "NotifyBeginApplication", typeof(void), new Type[0])); case RemoteHostMethodId.NotifyEndApplication: return(new RemoteHostMethodInfo(typeof(PSHost), "NotifyEndApplication", typeof(void), new Type[0])); case RemoteHostMethodId.ReadLine: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "ReadLine", typeof(string), new Type[0])); case RemoteHostMethodId.ReadLineAsSecureString: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "ReadLineAsSecureString", typeof(SecureString), new Type[0])); case RemoteHostMethodId.Write1: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "Write", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.Write2: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "Write", typeof(void), new Type[] { typeof(ConsoleColor), typeof(ConsoleColor), typeof(string) })); case RemoteHostMethodId.WriteLine1: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteLine", typeof(void), new Type[0])); case RemoteHostMethodId.WriteLine2: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.WriteLine3: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteLine", typeof(void), new Type[] { typeof(ConsoleColor), typeof(ConsoleColor), typeof(string) })); case RemoteHostMethodId.WriteErrorLine: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteErrorLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.WriteDebugLine: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteDebugLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.WriteProgress: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteProgress", typeof(void), new Type[] { typeof(long), typeof(ProgressRecord) })); case RemoteHostMethodId.WriteVerboseLine: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteVerboseLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.WriteWarningLine: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteWarningLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.Prompt: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "Prompt", typeof(Dictionary <string, PSObject>), new Type[] { typeof(string), typeof(string), typeof(Collection <FieldDescription>) })); case RemoteHostMethodId.PromptForCredential1: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "PromptForCredential", typeof(PSCredential), new Type[] { typeof(string), typeof(string), typeof(string), typeof(string) })); case RemoteHostMethodId.PromptForCredential2: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "PromptForCredential", typeof(PSCredential), new Type[] { typeof(string), typeof(string), typeof(string), typeof(string), typeof(PSCredentialTypes), typeof(PSCredentialUIOptions) })); case RemoteHostMethodId.PromptForChoice: return(new RemoteHostMethodInfo(typeof(PSHostUserInterface), "PromptForChoice", typeof(int), new Type[] { typeof(string), typeof(string), typeof(Collection <ChoiceDescription>), typeof(int) })); case RemoteHostMethodId.GetForegroundColor: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_ForegroundColor", typeof(ConsoleColor), new Type[0])); case RemoteHostMethodId.SetForegroundColor: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_ForegroundColor", typeof(void), new Type[] { typeof(ConsoleColor) })); case RemoteHostMethodId.GetBackgroundColor: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_BackgroundColor", typeof(ConsoleColor), new Type[0])); case RemoteHostMethodId.SetBackgroundColor: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_BackgroundColor", typeof(void), new Type[] { typeof(ConsoleColor) })); case RemoteHostMethodId.GetCursorPosition: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_CursorPosition", typeof(Coordinates), new Type[0])); case RemoteHostMethodId.SetCursorPosition: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_CursorPosition", typeof(void), new Type[] { typeof(Coordinates) })); case RemoteHostMethodId.GetWindowPosition: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_WindowPosition", typeof(Coordinates), new Type[0])); case RemoteHostMethodId.SetWindowPosition: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_WindowPosition", typeof(void), new Type[] { typeof(Coordinates) })); case RemoteHostMethodId.GetCursorSize: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_CursorSize", typeof(int), new Type[0])); case RemoteHostMethodId.SetCursorSize: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_CursorSize", typeof(void), new Type[] { typeof(int) })); case RemoteHostMethodId.GetBufferSize: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_BufferSize", typeof(Size), new Type[0])); case RemoteHostMethodId.SetBufferSize: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_BufferSize", typeof(void), new Type[] { typeof(Size) })); case RemoteHostMethodId.GetWindowSize: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_WindowSize", typeof(Size), new Type[0])); case RemoteHostMethodId.SetWindowSize: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_WindowSize", typeof(void), new Type[] { typeof(Size) })); case RemoteHostMethodId.GetWindowTitle: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_WindowTitle", typeof(string), new Type[0])); case RemoteHostMethodId.SetWindowTitle: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_WindowTitle", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.GetMaxWindowSize: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_MaxWindowSize", typeof(Size), new Type[0])); case RemoteHostMethodId.GetMaxPhysicalWindowSize: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_MaxPhysicalWindowSize", typeof(Size), new Type[0])); case RemoteHostMethodId.GetKeyAvailable: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_KeyAvailable", typeof(bool), new Type[0])); case RemoteHostMethodId.ReadKey: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "ReadKey", typeof(KeyInfo), new Type[] { typeof(ReadKeyOptions) })); case RemoteHostMethodId.FlushInputBuffer: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "FlushInputBuffer", typeof(void), new Type[0])); case RemoteHostMethodId.SetBufferContents1: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "SetBufferContents", typeof(void), new Type[] { typeof(Rectangle), typeof(BufferCell) })); case RemoteHostMethodId.SetBufferContents2: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "SetBufferContents", typeof(void), new Type[] { typeof(Coordinates), typeof(BufferCell[, ]) })); case RemoteHostMethodId.GetBufferContents: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "GetBufferContents", typeof(BufferCell[, ]), new Type[] { typeof(Rectangle) })); case RemoteHostMethodId.ScrollBufferContents: return(new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "ScrollBufferContents", typeof(void), new Type[] { typeof(Rectangle), typeof(Coordinates), typeof(Rectangle), typeof(BufferCell) })); case RemoteHostMethodId.PushRunspace: return(new RemoteHostMethodInfo(typeof(IHostSupportsInteractiveSession), "PushRunspace", typeof(void), new Type[] { typeof(Runspace) })); case RemoteHostMethodId.PopRunspace: return(new RemoteHostMethodInfo(typeof(IHostSupportsInteractiveSession), "PopRunspace", typeof(void), new Type[0])); case RemoteHostMethodId.GetIsRunspacePushed: return(new RemoteHostMethodInfo(typeof(IHostSupportsInteractiveSession), "get_IsRunspacePushed", typeof(bool), new Type[0])); case RemoteHostMethodId.GetRunspace: return(new RemoteHostMethodInfo(typeof(IHostSupportsInteractiveSession), "get_Runspace", typeof(Runspace), new Type[0])); case RemoteHostMethodId.PromptForChoiceMultipleSelection: return(new RemoteHostMethodInfo(typeof(IHostUISupportsMultipleChoiceSelection), "PromptForChoice", typeof(Collection <int>), new Type[] { typeof(string), typeof(string), typeof(Collection <ChoiceDescription>), typeof(IEnumerable <int>) })); } return(null); }
internal void ExecuteVoidMethod(RemoteHostMethodId methodId) { this.ExecuteVoidMethod(methodId, new object[0]); }
/// <summary> /// Execute void method. /// </summary> internal void ExecuteVoidMethod(RemoteHostMethodId methodId) { ExecuteVoidMethod(methodId, Array.Empty <object>()); }
/// <summary> /// Look up. /// </summary> internal static RemoteHostMethodInfo LookUp(RemoteHostMethodId methodId) { switch (methodId) { // Host read-only properties. case RemoteHostMethodId.GetName: return(new RemoteHostMethodInfo( typeof(PSHost), "get_Name", typeof(string), Array.Empty <Type>())); case RemoteHostMethodId.GetVersion: return(new RemoteHostMethodInfo( typeof(PSHost), "get_Version", typeof(Version), Array.Empty <Type>())); case RemoteHostMethodId.GetInstanceId: return(new RemoteHostMethodInfo( typeof(PSHost), "get_InstanceId", typeof(Guid), Array.Empty <Type>())); case RemoteHostMethodId.GetCurrentCulture: return(new RemoteHostMethodInfo( typeof(PSHost), "get_CurrentCulture", typeof(System.Globalization.CultureInfo), Array.Empty <Type>())); case RemoteHostMethodId.GetCurrentUICulture: return(new RemoteHostMethodInfo( typeof(PSHost), "get_CurrentUICulture", typeof(System.Globalization.CultureInfo), Array.Empty <Type>())); // Host methods. case RemoteHostMethodId.SetShouldExit: return(new RemoteHostMethodInfo( typeof(PSHost), "SetShouldExit", typeof(void), new Type[] { typeof(int) })); case RemoteHostMethodId.EnterNestedPrompt: return(new RemoteHostMethodInfo( typeof(PSHost), "EnterNestedPrompt", typeof(void), Array.Empty <Type>())); case RemoteHostMethodId.ExitNestedPrompt: return(new RemoteHostMethodInfo( typeof(PSHost), "ExitNestedPrompt", typeof(void), Array.Empty <Type>())); case RemoteHostMethodId.NotifyBeginApplication: return(new RemoteHostMethodInfo( typeof(PSHost), "NotifyBeginApplication", typeof(void), Array.Empty <Type>())); case RemoteHostMethodId.NotifyEndApplication: return(new RemoteHostMethodInfo( typeof(PSHost), "NotifyEndApplication", typeof(void), Array.Empty <Type>())); // Host UI methods. case RemoteHostMethodId.ReadLine: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "ReadLine", typeof(string), Array.Empty <Type>())); case RemoteHostMethodId.ReadLineAsSecureString: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "ReadLineAsSecureString", typeof(System.Security.SecureString), Array.Empty <Type>())); case RemoteHostMethodId.Write1: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "Write", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.Write2: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "Write", typeof(void), new Type[] { typeof(ConsoleColor), typeof(ConsoleColor), typeof(string) })); case RemoteHostMethodId.WriteLine1: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "WriteLine", typeof(void), Array.Empty <Type>())); case RemoteHostMethodId.WriteLine2: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "WriteLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.WriteLine3: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "WriteLine", typeof(void), new Type[] { typeof(ConsoleColor), typeof(ConsoleColor), typeof(string) })); case RemoteHostMethodId.WriteErrorLine: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "WriteErrorLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.WriteDebugLine: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "WriteDebugLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.WriteProgress: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "WriteProgress", typeof(void), new Type[] { typeof(long), typeof(ProgressRecord) })); case RemoteHostMethodId.WriteVerboseLine: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "WriteVerboseLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.WriteWarningLine: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "WriteWarningLine", typeof(void), new Type[] { typeof(string) })); case RemoteHostMethodId.Prompt: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "Prompt", typeof(Dictionary <string, PSObject>), new Type[] { typeof(string), typeof(string), typeof(System.Collections.ObjectModel.Collection <FieldDescription>) })); case RemoteHostMethodId.PromptForCredential1: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "PromptForCredential", typeof(PSCredential), new Type[] { typeof(string), typeof(string), typeof(string), typeof(string) })); case RemoteHostMethodId.PromptForCredential2: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "PromptForCredential", typeof(PSCredential), new Type[] { typeof(string), typeof(string), typeof(string), typeof(string), typeof(PSCredentialTypes), typeof(PSCredentialUIOptions) })); case RemoteHostMethodId.PromptForChoice: return(new RemoteHostMethodInfo( typeof(PSHostUserInterface), "PromptForChoice", typeof(int), new Type[] { typeof(string), typeof(string), typeof(System.Collections.ObjectModel.Collection <ChoiceDescription>), typeof(int) })); case RemoteHostMethodId.PromptForChoiceMultipleSelection: return(new RemoteHostMethodInfo( typeof(IHostUISupportsMultipleChoiceSelection), "PromptForChoice", typeof(Collection <int>), new Type[] { typeof(string), typeof(string), typeof(Collection <ChoiceDescription>), typeof(IEnumerable <int>) })); // Host raw UI read-write properties. case RemoteHostMethodId.GetForegroundColor: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_ForegroundColor", typeof(ConsoleColor), Array.Empty <Type>())); case RemoteHostMethodId.SetForegroundColor: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "set_ForegroundColor", typeof(void), new Type[] { typeof(ConsoleColor) })); case RemoteHostMethodId.GetBackgroundColor: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_BackgroundColor", typeof(ConsoleColor), Array.Empty <Type>())); case RemoteHostMethodId.SetBackgroundColor: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "set_BackgroundColor", typeof(void), new Type[] { typeof(ConsoleColor) })); case RemoteHostMethodId.GetCursorPosition: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_CursorPosition", typeof(Coordinates), Array.Empty <Type>())); case RemoteHostMethodId.SetCursorPosition: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "set_CursorPosition", typeof(void), new Type[] { typeof(Coordinates) })); case RemoteHostMethodId.GetWindowPosition: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_WindowPosition", typeof(Coordinates), Array.Empty <Type>())); case RemoteHostMethodId.SetWindowPosition: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "set_WindowPosition", typeof(void), new Type[] { typeof(Coordinates) })); case RemoteHostMethodId.GetCursorSize: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_CursorSize", typeof(int), Array.Empty <Type>())); case RemoteHostMethodId.SetCursorSize: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "set_CursorSize", typeof(void), new Type[] { typeof(int) })); case RemoteHostMethodId.GetBufferSize: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_BufferSize", typeof(Size), Array.Empty <Type>())); case RemoteHostMethodId.SetBufferSize: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "set_BufferSize", typeof(void), new Type[] { typeof(Size) })); case RemoteHostMethodId.GetWindowSize: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_WindowSize", typeof(Size), Array.Empty <Type>())); case RemoteHostMethodId.SetWindowSize: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "set_WindowSize", typeof(void), new Type[] { typeof(Size) })); case RemoteHostMethodId.GetWindowTitle: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_WindowTitle", typeof(string), Array.Empty <Type>())); case RemoteHostMethodId.SetWindowTitle: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "set_WindowTitle", typeof(void), new Type[] { typeof(string) })); // Host raw UI read-only properties. case RemoteHostMethodId.GetMaxWindowSize: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_MaxWindowSize", typeof(Size), Array.Empty <Type>())); case RemoteHostMethodId.GetMaxPhysicalWindowSize: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_MaxPhysicalWindowSize", typeof(Size), Array.Empty <Type>())); case RemoteHostMethodId.GetKeyAvailable: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "get_KeyAvailable", typeof(bool), Array.Empty <Type>())); // Host raw UI methods. case RemoteHostMethodId.ReadKey: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "ReadKey", typeof(KeyInfo), new Type[] { typeof(ReadKeyOptions) })); case RemoteHostMethodId.FlushInputBuffer: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "FlushInputBuffer", typeof(void), Array.Empty <Type>())); case RemoteHostMethodId.SetBufferContents1: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "SetBufferContents", typeof(void), new Type[] { typeof(Rectangle), typeof(BufferCell) })); case RemoteHostMethodId.SetBufferContents2: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "SetBufferContents", typeof(void), new Type[] { typeof(Coordinates), typeof(BufferCell[, ]) })); case RemoteHostMethodId.GetBufferContents: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "GetBufferContents", typeof(BufferCell[, ]), new Type[] { typeof(Rectangle) })); case RemoteHostMethodId.ScrollBufferContents: return(new RemoteHostMethodInfo( typeof(PSHostRawUserInterface), "ScrollBufferContents", typeof(void), new Type[] { typeof(Rectangle), typeof(Coordinates), typeof(Rectangle), typeof(BufferCell) })); // IHostSupportsInteractiveSession methods. case RemoteHostMethodId.PushRunspace: return(new RemoteHostMethodInfo( typeof(IHostSupportsInteractiveSession), "PushRunspace", typeof(void), new Type[] { typeof(System.Management.Automation.Runspaces.Runspace) })); case RemoteHostMethodId.PopRunspace: return(new RemoteHostMethodInfo( typeof(IHostSupportsInteractiveSession), "PopRunspace", typeof(void), Array.Empty <Type>())); // IHostSupportsInteractiveSession properties. case RemoteHostMethodId.GetIsRunspacePushed: return(new RemoteHostMethodInfo( typeof(IHostSupportsInteractiveSession), "get_IsRunspacePushed", typeof(bool), Array.Empty <Type>())); case RemoteHostMethodId.GetRunspace: return(new RemoteHostMethodInfo( typeof(IHostSupportsInteractiveSession), "get_Runspace", typeof(System.Management.Automation.Runspaces.Runspace), Array.Empty <Type>())); default: Dbg.Assert(false, "All RemoteHostMethodId's should be handled. This code should not be reached."); return(null); } }
/// <summary> /// Execute method. /// </summary> internal T ExecuteMethod <T>(RemoteHostMethodId methodId) { return(ExecuteMethod <T>(methodId, Array.Empty <object>())); }
internal static Exception NewRemoteHostCallFailedException(RemoteHostMethodId methodId) { RemoteHostMethodInfo info = RemoteHostMethodInfo.LookUp(methodId); return new PSRemotingDataStructureException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.RemoteHostCallFailed, new object[] { info.Name })); }
internal static RemoteHostMethodInfo LookUp(RemoteHostMethodId methodId) { switch (methodId) { case RemoteHostMethodId.GetName: return new RemoteHostMethodInfo(typeof(PSHost), "get_Name", typeof(string), new Type[0]); case RemoteHostMethodId.GetVersion: return new RemoteHostMethodInfo(typeof(PSHost), "get_Version", typeof(Version), new Type[0]); case RemoteHostMethodId.GetInstanceId: return new RemoteHostMethodInfo(typeof(PSHost), "get_InstanceId", typeof(Guid), new Type[0]); case RemoteHostMethodId.GetCurrentCulture: return new RemoteHostMethodInfo(typeof(PSHost), "get_CurrentCulture", typeof(CultureInfo), new Type[0]); case RemoteHostMethodId.GetCurrentUICulture: return new RemoteHostMethodInfo(typeof(PSHost), "get_CurrentUICulture", typeof(CultureInfo), new Type[0]); case RemoteHostMethodId.SetShouldExit: return new RemoteHostMethodInfo(typeof(PSHost), "SetShouldExit", typeof(void), new Type[] { typeof(int) }); case RemoteHostMethodId.EnterNestedPrompt: return new RemoteHostMethodInfo(typeof(PSHost), "EnterNestedPrompt", typeof(void), new Type[0]); case RemoteHostMethodId.ExitNestedPrompt: return new RemoteHostMethodInfo(typeof(PSHost), "ExitNestedPrompt", typeof(void), new Type[0]); case RemoteHostMethodId.NotifyBeginApplication: return new RemoteHostMethodInfo(typeof(PSHost), "NotifyBeginApplication", typeof(void), new Type[0]); case RemoteHostMethodId.NotifyEndApplication: return new RemoteHostMethodInfo(typeof(PSHost), "NotifyEndApplication", typeof(void), new Type[0]); case RemoteHostMethodId.ReadLine: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "ReadLine", typeof(string), new Type[0]); case RemoteHostMethodId.ReadLineAsSecureString: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "ReadLineAsSecureString", typeof(SecureString), new Type[0]); case RemoteHostMethodId.Write1: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "Write", typeof(void), new Type[] { typeof(string) }); case RemoteHostMethodId.Write2: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "Write", typeof(void), new Type[] { typeof(ConsoleColor), typeof(ConsoleColor), typeof(string) }); case RemoteHostMethodId.WriteLine1: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteLine", typeof(void), new Type[0]); case RemoteHostMethodId.WriteLine2: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteLine", typeof(void), new Type[] { typeof(string) }); case RemoteHostMethodId.WriteLine3: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteLine", typeof(void), new Type[] { typeof(ConsoleColor), typeof(ConsoleColor), typeof(string) }); case RemoteHostMethodId.WriteErrorLine: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteErrorLine", typeof(void), new Type[] { typeof(string) }); case RemoteHostMethodId.WriteDebugLine: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteDebugLine", typeof(void), new Type[] { typeof(string) }); case RemoteHostMethodId.WriteProgress: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteProgress", typeof(void), new Type[] { typeof(long), typeof(ProgressRecord) }); case RemoteHostMethodId.WriteVerboseLine: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteVerboseLine", typeof(void), new Type[] { typeof(string) }); case RemoteHostMethodId.WriteWarningLine: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "WriteWarningLine", typeof(void), new Type[] { typeof(string) }); case RemoteHostMethodId.Prompt: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "Prompt", typeof(Dictionary<string, PSObject>), new Type[] { typeof(string), typeof(string), typeof(Collection<FieldDescription>) }); case RemoteHostMethodId.PromptForCredential1: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "PromptForCredential", typeof(PSCredential), new Type[] { typeof(string), typeof(string), typeof(string), typeof(string) }); case RemoteHostMethodId.PromptForCredential2: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "PromptForCredential", typeof(PSCredential), new Type[] { typeof(string), typeof(string), typeof(string), typeof(string), typeof(PSCredentialTypes), typeof(PSCredentialUIOptions) }); case RemoteHostMethodId.PromptForChoice: return new RemoteHostMethodInfo(typeof(PSHostUserInterface), "PromptForChoice", typeof(int), new Type[] { typeof(string), typeof(string), typeof(Collection<ChoiceDescription>), typeof(int) }); case RemoteHostMethodId.GetForegroundColor: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_ForegroundColor", typeof(ConsoleColor), new Type[0]); case RemoteHostMethodId.SetForegroundColor: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_ForegroundColor", typeof(void), new Type[] { typeof(ConsoleColor) }); case RemoteHostMethodId.GetBackgroundColor: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_BackgroundColor", typeof(ConsoleColor), new Type[0]); case RemoteHostMethodId.SetBackgroundColor: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_BackgroundColor", typeof(void), new Type[] { typeof(ConsoleColor) }); case RemoteHostMethodId.GetCursorPosition: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_CursorPosition", typeof(Coordinates), new Type[0]); case RemoteHostMethodId.SetCursorPosition: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_CursorPosition", typeof(void), new Type[] { typeof(Coordinates) }); case RemoteHostMethodId.GetWindowPosition: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_WindowPosition", typeof(Coordinates), new Type[0]); case RemoteHostMethodId.SetWindowPosition: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_WindowPosition", typeof(void), new Type[] { typeof(Coordinates) }); case RemoteHostMethodId.GetCursorSize: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_CursorSize", typeof(int), new Type[0]); case RemoteHostMethodId.SetCursorSize: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_CursorSize", typeof(void), new Type[] { typeof(int) }); case RemoteHostMethodId.GetBufferSize: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_BufferSize", typeof(Size), new Type[0]); case RemoteHostMethodId.SetBufferSize: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_BufferSize", typeof(void), new Type[] { typeof(Size) }); case RemoteHostMethodId.GetWindowSize: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_WindowSize", typeof(Size), new Type[0]); case RemoteHostMethodId.SetWindowSize: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_WindowSize", typeof(void), new Type[] { typeof(Size) }); case RemoteHostMethodId.GetWindowTitle: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_WindowTitle", typeof(string), new Type[0]); case RemoteHostMethodId.SetWindowTitle: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "set_WindowTitle", typeof(void), new Type[] { typeof(string) }); case RemoteHostMethodId.GetMaxWindowSize: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_MaxWindowSize", typeof(Size), new Type[0]); case RemoteHostMethodId.GetMaxPhysicalWindowSize: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_MaxPhysicalWindowSize", typeof(Size), new Type[0]); case RemoteHostMethodId.GetKeyAvailable: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "get_KeyAvailable", typeof(bool), new Type[0]); case RemoteHostMethodId.ReadKey: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "ReadKey", typeof(KeyInfo), new Type[] { typeof(ReadKeyOptions) }); case RemoteHostMethodId.FlushInputBuffer: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "FlushInputBuffer", typeof(void), new Type[0]); case RemoteHostMethodId.SetBufferContents1: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "SetBufferContents", typeof(void), new Type[] { typeof(Rectangle), typeof(BufferCell) }); case RemoteHostMethodId.SetBufferContents2: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "SetBufferContents", typeof(void), new Type[] { typeof(Coordinates), typeof(BufferCell[,]) }); case RemoteHostMethodId.GetBufferContents: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "GetBufferContents", typeof(BufferCell[,]), new Type[] { typeof(Rectangle) }); case RemoteHostMethodId.ScrollBufferContents: return new RemoteHostMethodInfo(typeof(PSHostRawUserInterface), "ScrollBufferContents", typeof(void), new Type[] { typeof(Rectangle), typeof(Coordinates), typeof(Rectangle), typeof(BufferCell) }); case RemoteHostMethodId.PushRunspace: return new RemoteHostMethodInfo(typeof(IHostSupportsInteractiveSession), "PushRunspace", typeof(void), new Type[] { typeof(Runspace) }); case RemoteHostMethodId.PopRunspace: return new RemoteHostMethodInfo(typeof(IHostSupportsInteractiveSession), "PopRunspace", typeof(void), new Type[0]); case RemoteHostMethodId.GetIsRunspacePushed: return new RemoteHostMethodInfo(typeof(IHostSupportsInteractiveSession), "get_IsRunspacePushed", typeof(bool), new Type[0]); case RemoteHostMethodId.GetRunspace: return new RemoteHostMethodInfo(typeof(IHostSupportsInteractiveSession), "get_Runspace", typeof(Runspace), new Type[0]); case RemoteHostMethodId.PromptForChoiceMultipleSelection: return new RemoteHostMethodInfo(typeof(IHostUISupportsMultipleChoiceSelection), "PromptForChoice", typeof(Collection<int>), new Type[] { typeof(string), typeof(string), typeof(Collection<ChoiceDescription>), typeof(IEnumerable<int>) }); } return null; }
/// <summary> /// New remote host call failed exception. /// </summary> internal static Exception NewRemoteHostCallFailedException(RemoteHostMethodId methodId) { RemoteHostMethodInfo methodInfo = RemoteHostMethodInfo.LookUp(methodId); string resourceString = PSRemotingErrorInvariants.FormatResourceString( RemotingErrorIdStrings.RemoteHostCallFailed, methodInfo.Name); return new PSRemotingDataStructureException(resourceString); }