Example #1
0
        public object[] EndExecute(MonadAsyncResult asyncResult)
        {
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.EndExecute()");
            if (asyncResult.RunningCommand != this)
            {
                throw new ArgumentException("Parameter does not correspond to this command.", "asyncResult");
            }
            List <object> list = null;

            try
            {
                Collection <PSObject> collection = this.pipelineProxy.EndInvoke(asyncResult);
                bool flag = false;
                if (this.Connection.IsRemote && collection.Count > 0 && collection[0] != null && collection[0].BaseObject != null && collection[0].BaseObject is PSCustomObject)
                {
                    flag = MonadCommand.CanDeserialize(collection[0]);
                }
                list = new List <object>(collection.Count);
                ExTraceGlobals.IntegrationTracer.Information <int>((long)this.GetHashCode(), "\tPipeline contains {0} results", collection.Count);
                for (int i = 0; i < collection.Count; i++)
                {
                    if (collection[i] == null)
                    {
                        ExTraceGlobals.VerboseTracer.Information <int>((long)this.GetHashCode(), "\tPipeline contains a null result at position {0}", i);
                    }
                    else
                    {
                        if (collection[i].BaseObject == null)
                        {
                            throw new InvalidOperationException("Pure PSObjects are not supported.");
                        }
                        if (!this.Connection.IsRemote)
                        {
                            list.Add(collection[i].BaseObject);
                        }
                        else if (flag)
                        {
                            list.Add(MonadCommand.Deserialize(collection[i]));
                        }
                        else
                        {
                            list.Add(collection[i]);
                        }
                    }
                }
            }
            finally
            {
                this.Connection.NotifyExecutionFinished();
                if (this.EndExecution != null)
                {
                    this.EndExecution(this, new RunGuidEventArgs(this.guid));
                }
                this.Connection.CurrentCommand = null;
                this.pipelineProxy             = null;
            }
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.EndExecute()");
            return(list.ToArray());
        }
Example #2
0
        internal static Exception DeserializeException(Exception ex)
        {
            RemoteException ex2 = ex as RemoteException;

            if (ex2 != null && MonadCommand.CanDeserialize(ex2.SerializedRemoteException))
            {
                return((MonadCommand.Deserialize(ex2.SerializedRemoteException) as Exception) ?? ex);
            }
            return(ex);
        }
 // Token: 0x06001087 RID: 4231 RVA: 0x00032A73 File Offset: 0x00030C73
 private object UnWrappPSObject(PSObject element)
 {
     if (this.isRemote && element.BaseObject != null && element.BaseObject is PSCustomObject && MonadCommand.CanDeserialize(element))
     {
         return(MonadCommand.Deserialize(element));
     }
     return(element.BaseObject);
 }