/// <summary> /// Adds the information about this informational record to a PSObject as note properties. /// The PSObject is used to serialize the record during remote operations. /// </summary> /// <remarks> /// InvocationInfos are usually serialized as part of another object, so we add "InvocationInfo_" to /// the note properties to prevent collisions with any properties set by the containing object. /// </remarks> internal void ToPSObjectForRemoting(PSObject psObject) { RemotingEncoder.AddNoteProperty <object>(psObject, "InvocationInfo_BoundParameters", () => this.BoundParameters); RemotingEncoder.AddNoteProperty <CommandOrigin>(psObject, "InvocationInfo_CommandOrigin", () => this.CommandOrigin); RemotingEncoder.AddNoteProperty <bool>(psObject, "InvocationInfo_ExpectingInput", () => this.ExpectingInput); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_InvocationName", () => this.InvocationName); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_Line", () => this.Line); RemotingEncoder.AddNoteProperty <int>(psObject, "InvocationInfo_OffsetInLine", () => this.OffsetInLine); RemotingEncoder.AddNoteProperty <long>(psObject, "InvocationInfo_HistoryId", () => this.HistoryId); RemotingEncoder.AddNoteProperty <int[]>(psObject, "InvocationInfo_PipelineIterationInfo", () => this.PipelineIterationInfo); RemotingEncoder.AddNoteProperty <int>(psObject, "InvocationInfo_PipelineLength", () => this.PipelineLength); RemotingEncoder.AddNoteProperty <int>(psObject, "InvocationInfo_PipelinePosition", () => this.PipelinePosition); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_PSScriptRoot", () => this.PSScriptRoot); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_PSCommandPath", () => this.PSCommandPath); // PositionMessage is ignored when deserializing because it is synthesized from the other position related fields, but // it is serialized for backwards compatibility. RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_PositionMessage", () => this.PositionMessage); RemotingEncoder.AddNoteProperty <int>(psObject, "InvocationInfo_ScriptLineNumber", () => this.ScriptLineNumber); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_ScriptName", () => this.ScriptName); RemotingEncoder.AddNoteProperty <object>(psObject, "InvocationInfo_UnboundArguments", () => this.UnboundArguments); ScriptExtent extent = DisplayScriptPosition as ScriptExtent; if (extent != null) { extent.ToPSObjectForRemoting(psObject); RemotingEncoder.AddNoteProperty(psObject, "SerializeExtent", () => true); } else { RemotingEncoder.AddNoteProperty(psObject, "SerializeExtent", () => false); } RemoteCommandInfo.ToPSObjectForRemoting(this.MyCommand, psObject); }
internal void ToPSObjectForRemoting(PSObject psObject) { RemotingEncoder.AddNoteProperty <object>(psObject, "InvocationInfo_BoundParameters", () => this.BoundParameters); RemotingEncoder.AddNoteProperty <System.Management.Automation.CommandOrigin>(psObject, "InvocationInfo_CommandOrigin", () => this.CommandOrigin); RemotingEncoder.AddNoteProperty <bool>(psObject, "InvocationInfo_ExpectingInput", () => this.ExpectingInput); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_InvocationName", () => this.InvocationName); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_Line", () => this.Line); RemotingEncoder.AddNoteProperty <int>(psObject, "InvocationInfo_OffsetInLine", () => this.OffsetInLine); RemotingEncoder.AddNoteProperty <long>(psObject, "InvocationInfo_HistoryId", () => this.HistoryId); RemotingEncoder.AddNoteProperty <int[]>(psObject, "InvocationInfo_PipelineIterationInfo", () => this.PipelineIterationInfo); RemotingEncoder.AddNoteProperty <int>(psObject, "InvocationInfo_PipelineLength", () => this.PipelineLength); RemotingEncoder.AddNoteProperty <int>(psObject, "InvocationInfo_PipelinePosition", () => this.PipelinePosition); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_PSScriptRoot", () => this.PSScriptRoot); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_PSCommandPath", () => this.PSCommandPath); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_PositionMessage", () => this.PositionMessage); RemotingEncoder.AddNoteProperty <int>(psObject, "InvocationInfo_ScriptLineNumber", () => this.ScriptLineNumber); RemotingEncoder.AddNoteProperty <string>(psObject, "InvocationInfo_ScriptName", () => this.ScriptName); RemotingEncoder.AddNoteProperty <object>(psObject, "InvocationInfo_UnboundArguments", () => this.UnboundArguments); ScriptExtent displayScriptPosition = this.DisplayScriptPosition as ScriptExtent; if (displayScriptPosition != null) { displayScriptPosition.ToPSObjectForRemoting(psObject); RemotingEncoder.AddNoteProperty <bool>(psObject, "SerializeExtent", () => true); } else { RemotingEncoder.AddNoteProperty <bool>(psObject, "SerializeExtent", () => false); } RemoteCommandInfo.ToPSObjectForRemoting(this.MyCommand, psObject); }
internal static RemoteCommandInfo FromPSObjectForRemoting(PSObject psObject) { RemoteCommandInfo info = null; if (SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "CommandInfo_CommandType") != null) { CommandTypes propertyValue = RemotingDecoder.GetPropertyValue<CommandTypes>(psObject, "CommandInfo_CommandType"); info = new RemoteCommandInfo(RemotingDecoder.GetPropertyValue<string>(psObject, "CommandInfo_Name"), propertyValue) { definition = RemotingDecoder.GetPropertyValue<string>(psObject, "CommandInfo_Definition"), Visibility = RemotingDecoder.GetPropertyValue<SessionStateEntryVisibility>(psObject, "CommandInfo_Visibility") }; } return info; }
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); }
/// <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); }
/// <summary> /// Creates an InformationalRecord from an instance serialized as a PSObject by ToPSObjectForRemoting. /// </summary> internal InvocationInfo(PSObject psObject) { CommandOrigin = (CommandOrigin)SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "InvocationInfo_CommandOrigin"); ExpectingInput = (bool)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_ExpectingInput"); _invocationName = (string)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_InvocationName"); HistoryId = (long)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_HistoryId"); PipelineLength = (int)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_PipelineLength"); PipelinePosition = (int)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_PipelinePosition"); string scriptName = (string)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_ScriptName"); int scriptLineNumber = (int)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_ScriptLineNumber"); int offsetInLine = (int)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_OffsetInLine"); string line = (string)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_Line"); var scriptPosition = new ScriptPosition(scriptName, scriptLineNumber, offsetInLine, line); ScriptPosition scriptEndPosition; if (!string.IsNullOrEmpty(line)) { int endColumn = line.Length + 1; scriptEndPosition = new ScriptPosition(scriptName, scriptLineNumber, endColumn, line); } else { scriptEndPosition = scriptPosition; } _scriptPosition = new ScriptExtent(scriptPosition, scriptEndPosition); MyCommand = RemoteCommandInfo.FromPSObjectForRemoting(psObject); // // Arrays are de-serialized as ArrayList so we need to convert the deserialized // object into an int[] before assigning to pipelineIterationInfo. // var list = (ArrayList)SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "InvocationInfo_PipelineIterationInfo"); if (list != null) { PipelineIterationInfo = (int[])list.ToArray(typeof(Int32)); } else { PipelineIterationInfo = Utils.EmptyArray <int>(); } // // Dictionaries are de-serialized as Hashtables so we need to convert the deserialized object into a dictionary // before assigning to CommandLineParameters. // Hashtable hashtable = (Hashtable)SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "InvocationInfo_BoundParameters"); Dictionary <string, object> dictionary = new Dictionary <string, object>(); if (hashtable != null) { foreach (DictionaryEntry entry in hashtable) { dictionary.Add((string)entry.Key, entry.Value); } } _boundParameters = dictionary; // // The unbound parameters are de-serialized as an ArrayList, which we need to convert to a List // var unboundArguments = (ArrayList)SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "InvocationInfo_UnboundArguments"); _unboundArguments = new List <object>(); if (unboundArguments != null) { foreach (object o in unboundArguments) { _unboundArguments.Add(o); } } object value = SerializationUtilities.GetPropertyValue(psObject, "SerializeExtent"); bool serializeExtent = false; if (value != null) { serializeExtent = (bool)value; } if (serializeExtent) { DisplayScriptPosition = ScriptExtent.FromPSObjectForRemoting(psObject); } }
/// <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 InvocationInfo(PSObject psObject) { this._historyId = -1L; this._pipelineIterationInfo = new int[0]; this._commandOrigin = (System.Management.Automation.CommandOrigin)SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "InvocationInfo_CommandOrigin"); this._expectingInput = (bool)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_ExpectingInput"); this._invocationName = (string)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_InvocationName"); this._historyId = (long)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_HistoryId"); this._pipelineLength = (int)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_PipelineLength"); this._pipelinePosition = (int)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_PipelinePosition"); string propertyValue = (string)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_ScriptName"); int scriptLineNumber = (int)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_ScriptLineNumber"); int offsetInLine = (int)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_OffsetInLine"); string line = (string)SerializationUtilities.GetPropertyValue(psObject, "InvocationInfo_Line"); System.Management.Automation.Language.ScriptPosition startPosition = new System.Management.Automation.Language.ScriptPosition(propertyValue, scriptLineNumber, offsetInLine, line); this._scriptPosition = new ScriptExtent(startPosition, startPosition); this._commandInfo = RemoteCommandInfo.FromPSObjectForRemoting(psObject); ArrayList psObjectPropertyBaseObject = (ArrayList)SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "InvocationInfo_PipelineIterationInfo"); if (psObjectPropertyBaseObject != null) { this._pipelineIterationInfo = (int[])psObjectPropertyBaseObject.ToArray(Type.GetType("System.Int32")); } else { this._pipelineIterationInfo = new int[0]; } Hashtable hashtable = (Hashtable)SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "InvocationInfo_BoundParameters"); Dictionary <string, object> dictionary = new Dictionary <string, object>(); if (hashtable != null) { foreach (DictionaryEntry entry in hashtable) { dictionary.Add((string)entry.Key, entry.Value); } } this._boundParameters = dictionary; ArrayList list2 = (ArrayList)SerializationUtilities.GetPsObjectPropertyBaseObject(psObject, "InvocationInfo_UnboundArguments"); this._unboundArguments = new List <object>(); if (list2 != null) { foreach (object obj2 in list2) { this._unboundArguments.Add(obj2); } } object obj3 = SerializationUtilities.GetPropertyValue(psObject, "SerializeExtent"); bool flag = false; if (obj3 != null) { flag = (bool)obj3; } if (flag) { this._displayScriptPosition = ScriptExtent.FromPSObjectForRemoting(psObject); } }