Exemple #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());
        }
Exemple #2
0
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            ExTraceGlobals.IntegrationTracer.Information <CommandBehavior>((long)this.GetHashCode(), "-->MonadCommand.ExecuteReader({0})", behavior);
            MonadAsyncResult asyncResult = this.BeginExecute(null);
            MonadDataReader  result      = new MonadDataReader(this, behavior, asyncResult, this.preservedObjectProperty);

            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.ExecuteReader()");
            return(result);
        }
Exemple #3
0
        public object[] Execute(WorkUnit[] workUnits)
        {
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.Execute(workUnits)");
            MonadAsyncResult asyncResult = this.BeginExecute(workUnits);

            object[] result = this.EndExecute(asyncResult);
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.Execute()");
            return(result);
        }
        // Token: 0x0600105A RID: 4186 RVA: 0x00031C54 File Offset: 0x0002FE54
        internal MonadDataReader(MonadCommand command, CommandBehavior behavior, MonadAsyncResult asyncResult)
        {
            ExTraceGlobals.IntegrationTracer.Information <string, CommandBehavior>((long)this.GetHashCode(), "--> new MonadDataReader({0}, {1})", command.CommandText, behavior);
            this.command         = command;
            this.commandBehavior = behavior;
            this.connection      = command.Connection;
            this.isRemote        = command.Connection.IsRemote;
            this.asyncResult     = asyncResult;
            PSDataCollection <PSObject> output = asyncResult.Output;

            this.command.ActivePipeline.InvocationStateChanged += this.PipelineStateChanged;
            output.DataAdded += this.PipelineDataAdded;
            if (this.WaitOne(output))
            {
                ExTraceGlobals.VerboseTracer.Information((long)this.GetHashCode(), "\tFirst result ready.");
                PSObject          psobject          = output[0];
                PagedPositionInfo pagedPositionInfo = this.UnWrappPSObject(psobject) as PagedPositionInfo;
                if (pagedPositionInfo != null)
                {
                    ExTraceGlobals.VerboseTracer.Information((long)this.GetHashCode(), "\tPagedPositionInfo object found.");
                    output.RemoveAt(0);
                    this.positionInfo = pagedPositionInfo;
                    psobject          = null;
                    if (this.WaitOne(output))
                    {
                        psobject = output[0];
                    }
                }
                if (psobject != null)
                {
                    ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "\tFirst object returned, generating schema.");
                    this.GenerateSchema(psobject);
                    this.firstResult = this.UnWrappPSObject(psobject);
                }
            }
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<-- new MonadDataReader()");
        }
Exemple #5
0
        // Token: 0x060010C7 RID: 4295 RVA: 0x000337D4 File Offset: 0x000319D4
        private Collection <PSObject> ClosePipeline(MonadAsyncResult asyncResult)
        {
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.ClosePipeline()");
            if (base.PowerShell == null)
            {
                throw new InvalidOperationException("The command is not currently executing.");
            }
            Exception             ex     = null;
            Collection <PSObject> result = new Collection <PSObject>();

            ExTraceGlobals.VerboseTracer.Information((long)this.GetHashCode(), "\tWaiting for the pipeline to finish.");
            try
            {
                base.PowerShell.EndInvoke(asyncResult.PowerShellIAsyncResult);
            }
            catch (Exception)
            {
                ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "\tPipeline End Invoke Fired an Exception.");
                if (base.PowerShell.InvocationStateInfo.Reason == null)
                {
                    throw;
                }
            }
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "\tPipeline finished.");
            if (base.PowerShell.InvocationStateInfo.State == PSInvocationState.Completed && base.PowerShell.Streams.Error.Count == 0)
            {
                result = asyncResult.Output.ReadAll();
            }
            else if (base.PowerShell.InvocationStateInfo.State == PSInvocationState.Stopped || base.PowerShell.InvocationStateInfo.State == PSInvocationState.Failed || base.PowerShell.Streams.Error.Count > 0)
            {
                ex = MonadCommand.DeserializeException(base.PowerShell.InvocationStateInfo.Reason);
                if (ex != null && (this.IsHandledException(ex) || base.PowerShell.InvocationStateInfo.State == PSInvocationState.Stopped))
                {
                    ThrowTerminatingErrorException ex2 = ex as ThrowTerminatingErrorException;
                    ErrorRecord errorRecord;
                    if (ex2 != null)
                    {
                        errorRecord = ex2.ErrorRecord;
                    }
                    else
                    {
                        errorRecord = new ErrorRecord(ex, LocalizedException.GenerateErrorCode(ex).ToString("X"), ErrorCategory.InvalidOperation, null);
                    }
                    if (base.WorkUnits != null)
                    {
                        for (int i = 0; i < base.WorkUnits.Length; i++)
                        {
                            if (base.WorkUnits[i].CurrentStatus == 2)
                            {
                                if (base.PowerShell.InvocationStateInfo.State != PSInvocationState.Stopped)
                                {
                                    this.lastUnhandledError = errorRecord;
                                    break;
                                }
                            }
                            else
                            {
                                base.ReportError(errorRecord, i);
                                base.WorkUnits[i].CurrentStatus = 3;
                            }
                        }
                    }
                    else
                    {
                        base.ReportError(errorRecord, -1);
                    }
                    ex = null;
                }
                if (ex == null)
                {
                    result = asyncResult.Output.ReadAll();
                    base.DrainErrorStream(-1);
                }
                asyncResult.Output.Complete();
                base.PowerShell.Streams.Error.Complete();
            }
            this.pipelineStateAtClose = base.PowerShell.InvocationStateInfo.State;
            if (ex != null && !(ex is PipelineStoppedException))
            {
                ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), ex.ToString());
                if (!(ex is CmdletInvocationException))
                {
                    int innerErrorCode = LocalizedException.GenerateErrorCode(ex);
                    ex = new CommandExecutionException(innerErrorCode, this.Command.ToString(), ex);
                }
                this.InteractionHandler.ReportException(ex);
                throw ex;
            }
            if (this.LastUnhandledError != null)
            {
                throw new MonadDataAdapterInvocationException(this.LastUnhandledError, this.Command.ToString());
            }
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.ClosePipeline()");
            return(result);
        }
Exemple #6
0
        // Token: 0x060010C6 RID: 4294 RVA: 0x0003361C File Offset: 0x0003181C
        protected override Collection <PSObject> InternalEndInvoke(IAsyncResult results)
        {
            MonadAsyncResult monadAsyncResult = results as MonadAsyncResult;

            if (monadAsyncResult == null)
            {
                throw new ArgumentException("results");
            }
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.EndExecute()");
            if (monadAsyncResult.RunningCommand != this.Command)
            {
                throw new ArgumentException("Parameter does not correspond to this command.", "asyncResult");
            }
            Collection <PSObject> result      = null;
            ErrorRecord           errorRecord = null;

            try
            {
                result = this.ClosePipeline(monadAsyncResult);
                if (this.pipelineStateAtClose == PSInvocationState.Stopped)
                {
                    errorRecord = new ErrorRecord(new PipelineStoppedException(), string.Empty, ErrorCategory.OperationStopped, null);
                }
            }
            catch (CmdletInvocationException ex)
            {
                errorRecord = ex.ErrorRecord;
                throw;
            }
            catch (CommandExecutionException ex2)
            {
                errorRecord = new ErrorRecord(ex2.InnerException, string.Empty, ErrorCategory.InvalidOperation, null);
                throw;
            }
            catch (Exception exception)
            {
                errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidOperation, null);
                throw;
            }
            finally
            {
                if (base.WorkUnits != null)
                {
                    foreach (WorkUnit workUnit in base.WorkUnits)
                    {
                        workUnit.ExecutedCommandText = this.Command.ToString();
                        if (workUnit.CurrentStatus == 1)
                        {
                            if (errorRecord != null)
                            {
                                workUnit.Errors.Add(errorRecord);
                                workUnit.CurrentStatus = 3;
                            }
                            else if (workUnit.Errors.Count > 0)
                            {
                                workUnit.CurrentStatus = 3;
                            }
                            else
                            {
                                workUnit.CurrentStatus = 2;
                            }
                        }
                        if (workUnit.CurrentStatus == null && workUnit.Errors.Count > 0)
                        {
                            workUnit.CurrentStatus = 3;
                        }
                    }
                }
            }
            ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.EndExecute()");
            return(result);
        }
 // Token: 0x06001059 RID: 4185 RVA: 0x00031C3F File Offset: 0x0002FE3F
 internal MonadDataReader(MonadCommand command, CommandBehavior behavior, MonadAsyncResult asyncResult, string preservedObjectProperty) : this(command, behavior, asyncResult)
 {
     this.preservedObjectProperty = preservedObjectProperty;
 }