private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord) { if (serializedErrorRecord == null) { throw PSTraceSource.NewArgumentNullException("serializedErrorRecord"); } PSObject propertyValue = RemotingDecoder.GetPropertyValue <PSObject>(serializedErrorRecord, "Exception"); object targetObject = RemotingDecoder.GetPropertyValue <object>(serializedErrorRecord, "TargetObject"); PSObject serializedRemoteInvocationInfo = RemotingDecoder.GetPropertyValue <PSObject>(serializedErrorRecord, "InvocationInfo"); string str = null; if (propertyValue != null) { PSPropertyInfo info = propertyValue.Properties["Message"]; if (info != null) { str = info.Value as string; } } string fullyQualifiedErrorId = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "FullyQualifiedErrorId"); if (fullyQualifiedErrorId == null) { fullyQualifiedErrorId = "fullyQualifiedErrorId"; } ErrorCategory errorCategory = RemotingDecoder.GetPropertyValue <ErrorCategory>(serializedErrorRecord, "errorCategory_Category"); string str3 = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_Activity"); string str4 = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_Reason"); string str5 = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_TargetName"); string str6 = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_TargetType"); string str7 = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_Message"); string noteValue = GetNoteValue(serializedErrorRecord, "ErrorDetails_Message") as string; string str9 = GetNoteValue(serializedErrorRecord, "ErrorDetails_RecommendedAction") as string; RemoteException exception = new RemoteException((str != null) ? str : str7, propertyValue, serializedRemoteInvocationInfo); this.PopulateProperties(exception, targetObject, fullyQualifiedErrorId, errorCategory, str3, str4, str5, str6, str7, noteValue, str9); exception.SetRemoteErrorRecord(this); this.serializeExtendedInfo = RemotingDecoder.GetPropertyValue <bool>(serializedErrorRecord, "SerializeExtendedInfo"); if (this.serializeExtendedInfo) { this._invocationInfo = new System.Management.Automation.InvocationInfo(serializedErrorRecord); ArrayList list = RemotingDecoder.GetPropertyValue <ArrayList>(serializedErrorRecord, "PipelineIterationInfo"); if (list != null) { this.pipelineIterationInfo = new ReadOnlyCollection <int>((int[])list.ToArray(typeof(int))); } } else { this._invocationInfo = null; } }
internal static RemoteCommandInfo FromPSObjectForRemoting(PSObject psObject) { RemoteCommandInfo remoteCommandInfo = (RemoteCommandInfo)null; if (SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "CommandInfo_CommandType") != null) { CommandTypes propertyValue = RemotingDecoder.GetPropertyValue <CommandTypes>(psObject, "CommandInfo_CommandType"); remoteCommandInfo = new RemoteCommandInfo(RemotingDecoder.GetPropertyValue <string>(psObject, "CommandInfo_Name"), propertyValue); remoteCommandInfo.definition = RemotingDecoder.GetPropertyValue <string>(psObject, "CommandInfo_Definition"); remoteCommandInfo.Visibility = RemotingDecoder.GetPropertyValue <SessionStateEntryVisibility>(psObject, "CommandInfo_Visibility"); } return(remoteCommandInfo); }
internal static RemoteSessionCapability GetSessionCapability(object data) { RemoteSessionCapability sessionCapability = data is PSObject psObject ? new RemoteSessionCapability(RemotingDestination.InvalidDestination, RemotingDecoder.GetPropertyValue <Version>(psObject, "protocolversion"), RemotingDecoder.GetPropertyValue <Version>(psObject, "PSVersion"), RemotingDecoder.GetPropertyValue <Version>(psObject, "SerializationVersion")) : throw new PSRemotingDataStructureException(PSRemotingErrorId.CantCastRemotingDataToPSObject, new object[1] { (object)data.GetType().FullName }); if (psObject.Properties["TimeZone"] != null) { byte[] propertyValue = RemotingDecoder.GetPropertyValue <byte[]>(psObject, "TimeZone"); sessionCapability.TimeZone = RemoteSessionCapability.ConvertFromByteToTimeZone(propertyValue); } return(sessionCapability); }
internal static ProgressRecord FromPSObjectForRemoting(PSObject progressAsPSObject) { if (progressAsPSObject == null) { throw PSTraceSource.NewArgumentNullException("progressAsPSObject"); } string propertyValue = RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, "Activity"); int activityId = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, "ActivityId"); return(new ProgressRecord(activityId, propertyValue, RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, "StatusDescription")) { CurrentOperation = RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, "CurrentOperation"), ParentActivityId = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, "ParentActivityId"), PercentComplete = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, "PercentComplete"), RecordType = RemotingDecoder.GetPropertyValue <ProgressRecordType>(progressAsPSObject, "Type"), SecondsRemaining = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, "SecondsRemaining") }); }
public static RemoteRunspace FromPSObjectForRemoting(PSObject obj) { int id = RemotingDecoder.GetPropertyValue <int> (obj, "Id"); string name = RemotingDecoder.GetPropertyValue <string> (obj, "Name"); PSPrimitiveDictionary appArgs = RemotingDecoder.GetPropertyValue <PSPrimitiveDictionary> (obj, "ApplicationArguments"); string connectionInfoType = RemotingDecoder.GetPropertyValue <string> (obj, "ConnectionInfoType"); PSObject connectionObj = RemotingDecoder.GetPropertyValue <PSObject> (obj, "ConnectionInfo"); RunspaceConnectionInfo connectionInfo = null; if (connectionInfoType == "WSManConnectionInfo") { connectionInfo = WSManConnectionInfo.FromPSObjectForRemoting(connectionObj); } else { var securePassord = new System.Security.SecureString(); securePassord.AppendChar('z'); connectionInfo = new NewProcessConnectionInfo(new PSCredential("Anonymous", securePassord)); } var runspace = new RemoteRunspace(new TypeTable(), connectionInfo, null, appArgs, name, id); runspace._version = RemotingDecoder.GetPropertyValue <Version>(obj, "Version"); runspace.ApartmentState = RemotingDecoder.GetPropertyValue <ApartmentState>(obj, "ApartmentState"); runspace.InstanceId = RemotingDecoder.GetPropertyValue <Guid>(obj, "InstanceId"); runspace._shouldCloseOnPop = RemotingDecoder.GetPropertyValue <bool>(obj, "ShouldCloseOnPop"); runspace._runspaceStateInfo = new System.Management.Automation.Runspaces.RunspaceStateInfo(RemotingDecoder.GetPropertyValue <RunspaceState>(obj, "RunspaceStateInfo")); runspace._runspaceAvailability = RemotingDecoder.GetPropertyValue <RunspaceAvailability>(obj, "RunspaceAvailability"); runspace.ThreadOptions = RemotingDecoder.GetPropertyValue <PSThreadOptions>(obj, "ThreadOptions"); runspace.EngineActivityId = RemotingDecoder.GetPropertyValue <Guid>(obj, "EngineActivityId"); runspace._bSessionStateProxyCallInProgress = RemotingDecoder.GetPropertyValue <bool>(obj, "SessionStateProxyCallInProgress"); runspace._bypassRunspaceStateCheck = RemotingDecoder.GetPropertyValue <bool>(obj, "ByPassRunspaceStateCheck"); PSEtwLog.SetActivityIdForCurrentThread(runspace.InstanceId); string originalConnectionInfoType = RemotingDecoder.GetPropertyValue <string> (obj, "OriginalConnectionInfoType"); PSObject originalConnectionObj = RemotingDecoder.GetPropertyValue <PSObject> (obj, "OriginalConnectionInfo"); RunspaceConnectionInfo originalConnectionInfo = null; if (originalConnectionInfoType == "WSManConnectionInfo") { originalConnectionInfo = WSManConnectionInfo.FromPSObjectForRemoting(originalConnectionObj); } else { var securePassord = new System.Security.SecureString(); securePassord.AppendChar('z'); originalConnectionInfo = new NewProcessConnectionInfo(new PSCredential("Anonymous", securePassord)); } runspace._originalConnectionInfo = originalConnectionInfo; runspace.RunspacePool.RemoteRunspacePoolInternal.SetStateInfo(new RunspacePoolStateInfo(RunspacePoolState.Opened, null)); return(runspace); }
internal static ProgressRecord FromPSObjectForRemoting(PSObject progressAsPSObject) { string activity = progressAsPSObject != null?RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, "Activity") : throw ProgressRecord.tracer.NewArgumentNullException(nameof(progressAsPSObject)); int propertyValue1 = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, "ActivityId"); string propertyValue2 = RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, "StatusDescription"); return(new ProgressRecord(propertyValue1, activity, propertyValue2) { CurrentOperation = RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, "CurrentOperation"), ParentActivityId = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, "ParentActivityId"), PercentComplete = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, "PercentComplete"), RecordType = RemotingDecoder.GetPropertyValue <ProgressRecordType>(progressAsPSObject, "Type"), SecondsRemaining = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, "SecondsRemaining") }); }
/// <summary> /// Creates a RemoteCommandInfo from an instance serialized as a PSObject by ToPSObjectForRemoting. /// </summary> internal static RemoteCommandInfo FromPSObjectForRemoting(PSObject psObject) { RemoteCommandInfo commandInfo = null; object ctype = SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "CommandInfo_CommandType"); if (ctype != null) { CommandTypes type = RemotingDecoder.GetPropertyValue <CommandTypes>(psObject, "CommandInfo_CommandType"); string name = RemotingDecoder.GetPropertyValue <string>(psObject, "CommandInfo_Name"); commandInfo = new RemoteCommandInfo(name, type); commandInfo._definition = RemotingDecoder.GetPropertyValue <string>(psObject, "CommandInfo_Definition"); commandInfo.Visibility = RemotingDecoder.GetPropertyValue <SessionStateEntryVisibility>(psObject, "CommandInfo_Visibility"); } return(commandInfo); }
internal static PowerShell GetCommandDiscoveryPipeline(object data) { using (RemotingDecoder._trace.TraceMethod()) { PSObject psObject = PSObject.AsPSObject(data); CommandTypes commandTypes = psObject != null?RemotingDecoder.GetPropertyValue <CommandTypes>(psObject, "CommandType") : throw new PSRemotingDataStructureException(PSRemotingErrorId.CantCastRemotingDataToPSObject, new object[1] { (object)data.GetType().FullName }); string[] strArray1; if (RemotingDecoder.GetPropertyValue <PSObject>(psObject, "Name") != null) { strArray1 = new List <string>(RemotingDecoder.EnumerateListProperty <string>(psObject, "Name")).ToArray(); } else { strArray1 = new string[1] { "*" } }; string[] strArray2; if (RemotingDecoder.GetPropertyValue <PSObject>(psObject, "Namespace") != null) { strArray2 = new List <string>(RemotingDecoder.EnumerateListProperty <string>(psObject, "Namespace")).ToArray(); } else { strArray2 = new string[1] { "" } }; object[] objArray = RemotingDecoder.GetPropertyValue <PSObject>(psObject, "ArgumentList") == null ? (object[])null : new List <object>(RemotingDecoder.EnumerateListProperty <object>(psObject, "ArgumentList")).ToArray(); PowerShell powerShell = PowerShell.Create(); powerShell.AddCommand("Get-Command"); powerShell.AddParameter("Name", (object)strArray1); powerShell.AddParameter("CommandType", (object)commandTypes); powerShell.AddParameter("Module", (object)strArray2); powerShell.AddParameter("ArgumentList", (object)objArray); return(powerShell); } }
internal static IEnumerable <T> EnumerateListProperty <T>( PSObject psObject, string propertyName) { using (RemotingDecoder._trace.TraceMethod()) { if (psObject == null) { throw RemotingDecoder._trace.NewArgumentNullException(nameof(psObject)); } IEnumerable e = propertyName != null?RemotingDecoder.GetPropertyValue <IEnumerable>(psObject, propertyName) : throw RemotingDecoder._trace.NewArgumentNullException(nameof(propertyName)); if (e != null) { foreach (object propertyValue in e) { yield return(RemotingDecoder.ConvertPropertyValueTo <T>(propertyName, propertyValue)); } } } }
/// <summary> /// Creates a ProgressRecord object from a PSObject property bag. /// PSObject has to be in the format returned by ToPSObjectForRemoting method. /// </summary> /// <param name="progressAsPSObject">PSObject to rehydrate.</param> /// <returns> /// ProgressRecord 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 ProgressRecord FromPSObjectForRemoting(PSObject progressAsPSObject) { if (progressAsPSObject == null) { throw PSTraceSource.NewArgumentNullException(nameof(progressAsPSObject)); } string activity = RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_Activity); int activityId = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_ActivityId); string statusDescription = RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_StatusDescription); ProgressRecord result = new ProgressRecord(activityId, activity, statusDescription); result.CurrentOperation = RemotingDecoder.GetPropertyValue <string>(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_CurrentOperation); result.ParentActivityId = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_ParentActivityId); result.PercentComplete = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_PercentComplete); result.RecordType = RemotingDecoder.GetPropertyValue <ProgressRecordType>(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_Type); result.SecondsRemaining = RemotingDecoder.GetPropertyValue <int>(progressAsPSObject, RemoteDataNameStrings.ProgressRecord_SecondsRemaining); return(result); }
internal static PSEventArgs GetPSEventArgs(PSObject dataAsPSObject) { using (RemotingDecoder._trace.TraceMethod()) { int eventIdentifier = dataAsPSObject != null?RemotingDecoder.GetPropertyValue <int>(dataAsPSObject, "PSEventArgs.EventIdentifier") : throw RemotingDecoder._trace.NewArgumentNullException(nameof(dataAsPSObject)); string propertyValue1 = RemotingDecoder.GetPropertyValue <string>(dataAsPSObject, "PSEventArgs.SourceIdentifier"); object propertyValue2 = RemotingDecoder.GetPropertyValue <object>(dataAsPSObject, "PSEventArgs.Sender"); object propertyValue3 = RemotingDecoder.GetPropertyValue <object>(dataAsPSObject, "PSEventArgs.MessageData"); string propertyValue4 = RemotingDecoder.GetPropertyValue <string>(dataAsPSObject, "PSEventArgs.ComputerName"); Guid propertyValue5 = RemotingDecoder.GetPropertyValue <Guid>(dataAsPSObject, "PSEventArgs.RunspaceId"); ArrayList arrayList = new ArrayList(); foreach (object obj in RemotingDecoder.EnumerateListProperty <object>(dataAsPSObject, "PSEventArgs.SourceArgs")) { arrayList.Add(obj); } return(new PSEventArgs(propertyValue4, propertyValue5, eventIdentifier, propertyValue1, propertyValue2, arrayList.ToArray(), propertyValue3 == null ? (PSObject)null : PSObject.AsPSObject(propertyValue3)) { TimeGenerated = RemotingDecoder.GetPropertyValue <DateTime>(dataAsPSObject, "PSEventArgs.TimeGenerated") }); } }
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 IEnumerable <KeyValuePair <KeyType, ValueType> > EnumerateHashtableProperty <KeyType, ValueType>( PSObject psObject, string propertyName) { using (RemotingDecoder._trace.TraceMethod()) { if (psObject == null) { throw RemotingDecoder._trace.NewArgumentNullException(nameof(psObject)); } Hashtable h = propertyName != null?RemotingDecoder.GetPropertyValue <Hashtable>(psObject, propertyName) : throw RemotingDecoder._trace.NewArgumentNullException(nameof(propertyName)); if (h != null) { foreach (DictionaryEntry dictionaryEntry in h) { KeyType key = RemotingDecoder.ConvertPropertyValueTo <KeyType>(propertyName, dictionaryEntry.Key); ValueType value = RemotingDecoder.ConvertPropertyValueTo <ValueType>(propertyName, dictionaryEntry.Value); yield return(new KeyValuePair <KeyType, ValueType>(key, value)); } } } }
internal static ApartmentState GetApartmentState(object data) { using (RemotingDecoder._trace.TraceMethod()) return(RemotingDecoder.GetPropertyValue <ApartmentState>(PSObject.AsPSObject(data), "ApartmentState")); }
internal static RunspacePoolStateInfo GetRunspacePoolStateInfo( PSObject dataAsPSObject) { using (RemotingDecoder._trace.TraceMethod()) return(dataAsPSObject != null ? new RunspacePoolStateInfo(RemotingDecoder.GetPropertyValue <RunspacePoolState>(dataAsPSObject, "RunspaceState"), RemotingDecoder.GetExceptionFromStateInfoObject(dataAsPSObject)) : throw RemotingDecoder._trace.NewArgumentNullException(nameof(dataAsPSObject))); }
internal static string GetEncryptedSessionKey(PSObject dataAsPSObject) => dataAsPSObject != null?RemotingDecoder.GetPropertyValue <string>(dataAsPSObject, "EncryptedSessionKey") : throw RemotingDecoder._trace.NewArgumentNullException(nameof(dataAsPSObject));
internal static int GetMaxRunspaces(PSObject dataAsPSObject) { using (RemotingDecoder._trace.TraceMethod()) return(dataAsPSObject != null?RemotingDecoder.GetPropertyValue <int>(dataAsPSObject, "MaxRunspaces") : throw RemotingDecoder._trace.NewArgumentNullException(nameof(dataAsPSObject))); }
internal static PSPrimitiveDictionary GetApplicationArguments( PSObject dataAsPSObject) { using (RemotingDecoder._trace.TraceMethod()) return(dataAsPSObject != null?RemotingDecoder.GetPropertyValue <PSPrimitiveDictionary>(dataAsPSObject, "ApplicationArguments") : throw RemotingDecoder._trace.NewArgumentNullException(nameof(dataAsPSObject))); }
internal static PSThreadOptions GetThreadOptions(PSObject dataAsPSObject) { using (RemotingDecoder._trace.TraceMethod()) return(dataAsPSObject != null?RemotingDecoder.GetPropertyValue <PSThreadOptions>(dataAsPSObject, "PSThreadOptions") : throw RemotingDecoder._trace.NewArgumentNullException(nameof(dataAsPSObject))); }
internal static RemoteStreamOptions GetRemoteStreamOptions(object data) { using (RemotingDecoder._trace.TraceMethod()) return(RemotingDecoder.GetPropertyValue <RemoteStreamOptions>(PSObject.AsPSObject(data), "RemoteStreamOptions")); }
internal static HostInfo GetHostInfo(PSObject dataAsPSObject) { using (RemotingDecoder._trace.TraceMethod()) return(dataAsPSObject != null?RemoteHostEncoder.DecodeObject((object)RemotingDecoder.GetPropertyValue <PSObject>(dataAsPSObject, "HostInfo"), typeof(HostInfo)) as HostInfo : throw RemotingDecoder._trace.NewArgumentNullException(nameof(dataAsPSObject))); }
internal static PSInvocationStateInfo GetPowerShellStateInfo(object data) { using (RemotingDecoder._trace.TraceMethod()) return(data is PSObject psObject ? new PSInvocationStateInfo(RemotingDecoder.GetPropertyValue <PSInvocationState>(psObject, "PipelineState"), RemotingDecoder.GetExceptionFromStateInfoObject(psObject)) : throw new PSRemotingDataStructureException(PSRemotingErrorId.DecodingErrorForPowerShellStateInfo, new object[0])); }