Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        /// <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(int));
            }
            else
            {
                PipelineIterationInfo = Array.Empty <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);
            }
        }