internal static void ProcessCliXmlTestabilityHook(PSStreamObject streamObject)
            {
                if (!s_isCliXmlTestabilityHookActive)
                {
                    return;
                }

                if (streamObject.ObjectType != PSStreamObjectType.Output)
                {
                    return;
                }

                if (streamObject.Value == null)
                {
                    return;
                }

                if (!(PSObject.AsPSObject(streamObject.Value).BaseObject.GetType().Name.Equals("CimInstance")))
                {
                    return;
                }

                string serializedForm     = PSSerializer.Serialize(streamObject.Value, depth: 1);
                object deserializedObject = PSSerializer.Deserialize(serializedForm);

                streamObject.Value = PSObject.AsPSObject(deserializedObject).BaseObject;
            }
Ejemplo n.º 2
0
        internal void WriteStreamObject(PSStreamObject psstreamObject)
        {
            switch (psstreamObject.objectType)
            {
            case PSStreamObjectType.Output:
                this.WriteObject(psstreamObject.value);
                break;

            case PSStreamObjectType.Error:
                ErrorRecord errorRecord = (ErrorRecord)psstreamObject.value;
                errorRecord.PreserveInvocationInfoOnce = true;
                this.WriteError(errorRecord);
                break;

            case PSStreamObjectType.Verbose:
                this.WriteVerbose((string)psstreamObject.value);
                break;

            case PSStreamObjectType.Debug:
                this.WriteDebug((string)psstreamObject.value);
                break;

            case PSStreamObjectType.MethodExecutor:
                ((ClientMethodExecutor)psstreamObject.value).Execute((Cmdlet)this);
                break;

            case PSStreamObjectType.Warning:
                this.WriteWarning((string)psstreamObject.value);
                break;
            }
        }
Ejemplo n.º 3
0
 private void HandleResultsDataAdding(object sender, DataAddingEventArgs dataAddingArgs)
 {
     if (_debugCollection.IsOpen)
     {
         PSStreamObject streamObject = dataAddingArgs.ItemAdded as PSStreamObject;
         if (streamObject != null)
         {
             try
             {
                 _debugCollection.Add(streamObject);
             }
             catch (PSInvalidOperationException) { }
         }
     }
 }
Ejemplo n.º 4
0
        private void AddToDebugBlockingCollection(PSStreamObject streamItem)
        {
            if (!_debugBlockingCollection.IsOpen)
            {
                return;
            }

            if (streamItem != null)
            {
                try
                {
                    _debugBlockingCollection.Add(streamItem);
                }
                catch (PSInvalidOperationException) { }
            }
        }
Ejemplo n.º 5
0
        private void ResultsAdded(object sender, DataAddedEventArgs e)
        {
            lock (this._syncObject)
            {
                if (this._isDisposed)
                {
                    return;
                }
            }
            this._writeExistingData.WaitOne();
            PSDataCollection <PSStreamObject> collection = sender as PSDataCollection <PSStreamObject>;
            PSStreamObject data = this.GetData <PSStreamObject>(collection, e.Index);

            if (data != null)
            {
                data.Id = collection.SourceId;
                this._results.Add(data);
            }
        }
Ejemplo n.º 6
0
        private void HandlePowerShellPStreamItem(PSStreamObject streamItem)
        {
            if (!_debugger.InBreakpoint)
            {
                // First write any accumulated items.
                foreach (var item in _debugAccumulateCollection.ReadAll())
                {
                    AddToDebugBlockingCollection(item);
                }

                // Handle new item.
                if ((_debugBlockingCollection != null) && (_debugBlockingCollection.IsOpen))
                {
                    AddToDebugBlockingCollection(streamItem);
                }
            }
            else if (_debugAccumulateCollection.IsOpen)
            {
                // Add to accumulator if debugger is stopped in breakpoint.
                _debugAccumulateCollection.Add(streamItem);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Process the stream object before writing it in the specified collection.
        /// </summary>
        /// <param name="streamObject">stream object to process</param>
        private void PreProcessStreamObject(PSStreamObject streamObject)
        {
            ErrorRecord errorRecord = streamObject.Value as ErrorRecord;

            //
            // In case of PSDirectException, we should output the precise error message
            // in inner exception instead of the generic one in outer exception.
            //
            if ((errorRecord != null) &&
                (errorRecord.Exception != null) &&
                (errorRecord.Exception.InnerException != null))
            {
                PSDirectException ex = errorRecord.Exception.InnerException as PSDirectException;
                if (ex != null)
                {
                    streamObject.Value = new ErrorRecord(errorRecord.Exception.InnerException,
                                                         errorRecord.FullyQualifiedErrorId,
                                                         errorRecord.CategoryInfo.Category,
                                                         errorRecord.TargetObject);
                }
            }
        }
Ejemplo n.º 8
0
            internal static void ProcessCliXmlTestabilityHook(PSStreamObject streamObject)
            {
                if (!s_isCliXmlTestabilityHookActive)
                {
                    return;
                }

                if (streamObject.ObjectType != PSStreamObjectType.Output)
                {
                    return;
                }

                if (streamObject.Value == null)
                {
                    return;
                }

                if (!(PSObject.AsPSObject(streamObject.Value).BaseObject.GetType().Name.Equals("CimInstance")))
                {
                    return;
                }

                string serializedForm = PSSerializer.Serialize(streamObject.Value, depth: 1);
                object deserializedObject = PSSerializer.Deserialize(serializedForm);
                streamObject.Value = PSObject.AsPSObject(deserializedObject).BaseObject;
            }