Ejemplo n.º 1
0
        /// <summary>
        /// Send the specified warning record to client.
        /// </summary>
        /// <param name="record">Warning record.</param>
        internal void SendWarningRecordToClient(WarningRecord record)
        {
            record.SerializeExtendedInfo = (_streamSerializationOptions & RemoteStreamOptions.AddInvocationInfoToWarningRecord) != 0;

            SendDataAsync(RemotingEncoder.GeneratePowerShellInformational(
                              record, _clientRunspacePoolId, _clientPowerShellId, RemotingDataType.PowerShellWarning));
        }
Ejemplo n.º 2
0
 internal void AddWarning(WarningRecord item)
 {
     if (this.warning != null)
     {
         this.warning.InternalAdd(this.psInstanceId, item);
     }
 }
Ejemplo n.º 3
0
 internal void AddWarning(WarningRecord item)
 {
     if (this.warning != null)
     {
         this.warning.InternalAdd(this.psInstanceId, item);
     }
 }
 internal void SendWarningRecordToClient(WarningRecord record)
 {
     using (ServerPowerShellDataStructureHandler.tracer.TraceMethod())
     {
         record.SerializeExtendedInfo = (this.streamSerializationOptions & RemoteStreamOptions.AddInvocationInfoToWarningRecord) != (RemoteStreamOptions)0;
         this.SendDataAsync(RemotingEncoder.GeneratePowerShellInformational((object)record, this.clientRunspacePoolId, this.clientPowerShellId, RemotingDataType.PowerShellWarning));
     }
 }
Ejemplo n.º 5
0
        private void HandleWarningAdded(object sender, DataAddedEventArgs eventArgs)
        {
            int        index = eventArgs.Index;
            PowerShell pipelinePowerShell = this.GetPipelinePowerShell(this.remotePipeline, eventArgs.PowerShellInstanceId);

            if (pipelinePowerShell != null)
            {
                WarningRecord item = pipelinePowerShell.Streams.Warning[index];
                base.Warning.Add(item);
                base.Results.Add(new PSStreamObject(PSStreamObjectType.WarningRecord, item));
            }
        }
Ejemplo n.º 6
0
        private void HandleWarningAdded(object sender, DataAddedEventArgs eventArgs)
        {
            int index = eventArgs.Index;

            lock (this.syncObject)
            {
                int num2 = !this.extraPowerShellAlreadyScheduled ? 0 : 1;
                if ((num2 == 0) && !this.datasent[num2])
                {
                    WarningRecord record = this.localPowerShell.Streams.Warning[index];
                    this.localPowerShell.Streams.Warning.RemoveAt(index);
                    this.dsHandler.SendWarningRecordToClient(record);
                }
            }
        }
Ejemplo n.º 7
0
 private void HandleWarningAdded(object sender, DataAddedEventArgs eventArgs)
 {
     using (ServerPowerShellDriver.tracer.TraceEventHandlers())
     {
         int index = eventArgs.Index;
         lock (this.syncObject)
         {
             if (this.datasent)
             {
                 return;
             }
             WarningRecord record = this.localPowerShell.Streams.Warning[index];
             this.localPowerShell.Streams.Warning.RemoveAt(index);
             this.dsHandler.SendWarningRecordToClient(record);
         }
     }
 }
Ejemplo n.º 8
0
 protected override void ProcessRecord()
 {
     MshCommandRuntime commandRuntime = base.CommandRuntime as MshCommandRuntime;
     if (commandRuntime != null)
     {
         WarningRecord record = new WarningRecord(this.Message);
         InvocationInfo variableValue = base.GetVariableValue("MyInvocation") as InvocationInfo;
         if (variableValue != null)
         {
             record.SetInvocationInfo(variableValue);
         }
         commandRuntime.WriteWarning(record, false);
     }
     else
     {
         base.WriteWarning(this.Message);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Handles DataAdded event from Warning of PowerShell
        /// </summary>
        /// <param name="sender">sender of this information, unused</param>
        /// <param name="eventArgs">arguments describing this event</param>
        private void HandleWarningAdded(object sender, DataAddedEventArgs eventArgs)
        {
            int index = eventArgs.Index;

            lock (_syncObject)
            {
                int indexIntoDataSent = (!_extraPowerShellAlreadyScheduled) ? 0 : 1;
                if ((indexIntoDataSent == 0) && (!_datasent[indexIntoDataSent]))
                {
                    WarningRecord data = LocalPowerShell.Streams.Warning[index];
                    // once the debug message is sent, it is removed so that
                    // the same is not sent again by SendRemainingData() method
                    LocalPowerShell.Streams.Warning.RemoveAt(index);

                    // send the output data to the client
                    DataStructureHandler.SendWarningRecordToClient(data);
                }
            } // lock ..
        }
Ejemplo n.º 10
0
        /// <summary>
        /// This method implements the ProcessRecord method for Write-Warning command
        /// </summary>
        protected override void ProcessRecord()
        {
            //
            // The write-warning command must use the script's InvocationInfo rather than its own,
            // so we create the WarningRecord here and fill it up with the appropriate InvocationInfo;
            // then, we call the command runtime directly and pass this record to WriteWarning().
            //
            MshCommandRuntime mshCommandRuntime = this.CommandRuntime as MshCommandRuntime;

            if (mshCommandRuntime != null)
            {
                WarningRecord record = new WarningRecord(Message);

                InvocationInfo invocationInfo = GetVariableValue(SpecialVariables.MyInvocation) as InvocationInfo;

                if (invocationInfo != null)
                {
                    record.SetInvocationInfo(invocationInfo);
                }

                mshCommandRuntime.WriteWarning(record);
            }
            else
            {
                WriteWarning(Message);
            }
        }//processrecord
Ejemplo n.º 11
0
 internal void WriteWarningInfoBuffers(WarningRecord record)
 {
     if (this.informationalBuffers != null)
     {
         this.informationalBuffers.AddWarning(record);
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Display warning information
        /// </summary>
        internal void WriteWarning(WarningRecord record, bool overrideInquire = false)
        {
            ActionPreference preference = WarningPreference;
            if (overrideInquire && preference == ActionPreference.Inquire)
                preference = ActionPreference.Continue;

            if (WriteHelper_ShouldWrite(preference, lastWarningContinueStatus))
            {
                if (record.InvocationInfo == null)
                {
                    record.SetInvocationInfo(MyInvocation);
                }

                if (WarningOutputPipe != null)
                {
                    if (CBhost != null && CBhost.InternalUI != null &&
                        WarningOutputPipe.NullPipe)
                    {
                        // If redirecting to a null pipe, still write to
                        // information buffers.
                        CBhost.InternalUI.WriteWarningInfoBuffers(record);
                    }

                    // Add note property so that the warning output is formatted correctly.
                    PSObject warningWrap = PSObject.AsPSObject(record);
                    if (warningWrap.Members["WriteWarningStream"] == null)
                    {
                        warningWrap.Properties.Add(new PSNoteProperty("WriteWarningStream", true));
                    }

                    WarningOutputPipe.AddWithoutAppendingOutVarList(warningWrap);
                }
                else
                {
                    //
                    // If no pipe, write directly to host.
                    //
                    if (null == Host || null == Host.UI)
                    {
                        Diagnostics.Assert(false, "No host in CommandBase.WriteWarning()");
                        throw PSTraceSource.NewInvalidOperationException();
                    }

                    CBhost.InternalUI.TranscribeResult(StringUtil.Format(InternalHostUserInterfaceStrings.WarningFormatString, record.Message));
                    CBhost.InternalUI.WriteWarningRecord(record);
                }
            }

            AppendWarningVarList(record);

            lastWarningContinueStatus = WriteHelper(
                null,
                null,
                preference,
                lastWarningContinueStatus,
                "WarningPreference",
                record.Message);
        }
        /// <summary>
        /// Binds the specified argument to the specified parameter using the appropriate
        /// parameter binder.
        /// </summary>
        /// 
        /// <param name="argument">
        /// The argument to be bound.
        /// </param>
        /// 
        /// <param name="parameter">
        /// The metadata for the parameter to bind the argument to.
        /// </param>
        /// 
        /// <param name="flags">
        /// Flags for type coercion and validation.
        /// </param>
        /// 
        /// <returns>
        /// True if the parameter was successfully bound. False if <paramref name="flags"/> 
        /// has the flag <see cref="ParameterBindingFlags.ShouldCoerceType"/> set and the type does not match the parameter type.
        /// </returns>
        /// 
        private bool BindParameter(
            CommandParameterInternal argument,
            MergedCompiledCommandParameter parameter,
            ParameterBindingFlags flags)
        {
            bool result = false;

            switch (parameter.BinderAssociation)
            {
                case ParameterBinderAssociation.DeclaredFormalParameters:
                    result =
                        DefaultParameterBinder.BindParameter(
                            argument,
                            parameter.Parameter,
                            flags);
                    break;

                case ParameterBinderAssociation.CommonParameters:
                    result =
                        CommonParametersBinder.BindParameter(
                            argument,
                            parameter.Parameter,
                            flags);
                    break;

                case ParameterBinderAssociation.ShouldProcessParameters:
                    Diagnostics.Assert(
                        _commandMetadata.SupportsShouldProcess,
                        "The metadata for the ShouldProcessParameters should only be available if the command supports ShouldProcess");

                    result =
                        ShouldProcessParametersBinder.BindParameter(
                            argument,
                            parameter.Parameter,
                            flags);
                    break;

                case ParameterBinderAssociation.PagingParameters:
                    Diagnostics.Assert(
                        _commandMetadata.SupportsPaging,
                        "The metadata for the PagingParameters should only be available if the command supports paging");

                    result =
                        PagingParametersBinder.BindParameter(
                            argument,
                            parameter.Parameter,
                            flags);
                    break;

                case ParameterBinderAssociation.TransactionParameters:
                    Diagnostics.Assert(
                        _commandMetadata.SupportsTransactions,
                        "The metadata for the TransactionsParameters should only be available if the command supports transactions");

                    result =
                        TransactionParametersBinder.BindParameter(
                            argument,
                            parameter.Parameter,
                            flags);
                    break;

                case ParameterBinderAssociation.DynamicParameters:
                    Diagnostics.Assert(
                        _commandMetadata.ImplementsDynamicParameters,
                        "The metadata for the dynamic parameters should only be available if the command supports IDynamicParameters");

                    if (_dynamicParameterBinder != null)
                    {
                        result =
                            _dynamicParameterBinder.BindParameter(
                                argument,
                                parameter.Parameter,
                                flags);
                    }
                    break;
            }

            if (result && ((flags & ParameterBindingFlags.IsDefaultValue) == 0))
            {
                // Update the current valid parameter set flags

                if (parameter.Parameter.ParameterSetFlags != 0)
                {
                    _currentParameterSetFlag &= parameter.Parameter.ParameterSetFlags;
                }

                UnboundParameters.Remove(parameter);

                if (!BoundParameters.ContainsKey(parameter.Parameter.Name))
                {
                    BoundParameters.Add(parameter.Parameter.Name, parameter);
                }

                if (!BoundArguments.ContainsKey(parameter.Parameter.Name))
                {
                    BoundArguments.Add(parameter.Parameter.Name, argument);
                }

                if (parameter.Parameter.ObsoleteAttribute != null &&
                    (flags & ParameterBindingFlags.IsDefaultValue) == 0 &&
                    !BoundObsoleteParameterNames.Contains(parameter.Parameter.Name))
                {
                    string obsoleteWarning = String.Format(
                        CultureInfo.InvariantCulture,
                        ParameterBinderStrings.UseOfDeprecatedParameterWarning,
                        parameter.Parameter.Name,
                        parameter.Parameter.ObsoleteAttribute.Message);
                    var warningRecord = new WarningRecord(ParameterBinderBase.FQIDParameterObsolete, obsoleteWarning);

                    BoundObsoleteParameterNames.Add(parameter.Parameter.Name);

                    if (ObsoleteParameterWarningList == null)
                        ObsoleteParameterWarningList = new List<WarningRecord>();

                    ObsoleteParameterWarningList.Add(warningRecord);
                }
            }

            return result;
        }
        void Warning_DataAdded(object sender, DataAddedEventArgs e)
        {
            PSDataCollection<WarningRecord> collection = sender as PSDataCollection<WarningRecord>;
            lastWarning = collection[e.Index];
            PSObject psObj = new PSObject(lastWarning);
            psObj.Properties.Add(new PSNoteProperty("TimeStamp", DateTime.Now));
            psObj.Properties.Add(new PSNoteProperty("Stream", "Warning"));
            timeStampedOutput.Add(psObj);
            if (Dispatcher != null)
            {
                RunOnUIThread(
                        new DispatcherOperationCallback(
                        delegate
                        {
                            NotifyWarningChanged();
                            return null;
                        }),
                        true);
            }
            else
            {
                NotifyWarningChanged();
            }


        }
 internal void SendWarningRecordToClient(WarningRecord record)
 {
     record.SerializeExtendedInfo = (this.streamSerializationOptions & RemoteStreamOptions.AddInvocationInfoToWarningRecord) != 0;
     this.SendDataAsync(RemotingEncoder.GeneratePowerShellInformational(record, this.clientRunspacePoolId, this.clientPowerShellId, RemotingDataType.PowerShellWarning));
 }
Ejemplo n.º 16
0
 internal RemotingWarningRecord(WarningRecord warningRecord, System.Management.Automation.Remoting.OriginInfo originInfo) : base(warningRecord.FullyQualifiedWarningId, warningRecord.Message)
 {
     this._originInfo = originInfo;
 }
Ejemplo n.º 17
0
 internal void WriteWarning(WarningRecord record, bool overrideInquire = false)
 {
     ActionPreference warningPreference = this.WarningPreference;
     if (overrideInquire && (warningPreference == ActionPreference.Inquire))
     {
         warningPreference = ActionPreference.Continue;
     }
     if (this.WriteHelper_ShouldWrite(warningPreference, this.lastWarningContinueStatus))
     {
         if (record.InvocationInfo == null)
         {
             record.SetInvocationInfo(this.MyInvocation);
         }
         if (this.WarningOutputPipe != null)
         {
             if (((this.CBhost != null) && (this.CBhost.InternalUI != null)) && this.WarningOutputPipe.NullPipe)
             {
                 this.CBhost.InternalUI.WriteWarningInfoBuffers(record);
             }
             PSObject obj2 = PSObject.AsPSObject(record);
             if (obj2.Members["WriteWarningStream"] == null)
             {
                 obj2.Properties.Add(new PSNoteProperty("WriteWarningStream", true));
             }
             this.WarningOutputPipe.AddWithoutAppendingOutVarList(obj2);
         }
         else
         {
             if ((this.Host == null) || (this.Host.UI == null))
             {
                 throw PSTraceSource.NewInvalidOperationException();
             }
             this.CBhost.InternalUI.WriteWarningRecord(record);
         }
     }
     this.AppendWarningVarList(record);
     this.lastWarningContinueStatus = this.WriteHelper(null, null, warningPreference, this.lastWarningContinueStatus, "WarningPreference", record.Message);
 }
Ejemplo n.º 18
0
 internal void WriteWarningRecord(WarningRecord record)
 {
     this.WriteWarningInfoBuffers(record);
     if (this.externalUI != null)
     {
         this.externalUI.WriteWarningLine(record.Message);
     }
 }
 private void WriteWarningRecord(RemoteComputer powershellComputer, WarningRecord record) {
     powershellComputer.AddLogEntry(new LogEntry(powershellComputer.Name, record.Message, LogEntryType.Warning));
 }
Ejemplo n.º 20
0
        private void HandleRobustConnectionNotification(object sender, ConnectionStatusEventArgs e)
        {
            PSConnectionRetryStatusEventArgs eventArgs = null;
            WarningRecord infoRecord = null;
            ErrorRecord record2 = null;
            int maxRetryConnectionTime = this.runspacePool.MaxRetryConnectionTime;
            int num2 = maxRetryConnectionTime / 0xea60;
            switch (e.Notification)
            {
                case ConnectionStatus.NetworkFailureDetected:
                    infoRecord = new WarningRecord("PowerShellNetworkFailureDetected", StringUtil.Format(RemotingErrorIdStrings.RCNetworkFailureDetected, this.computerName, num2));
                    eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.NetworkFailureDetected, this.computerName, maxRetryConnectionTime, infoRecord);
                    break;

                case ConnectionStatus.ConnectionRetryAttempt:
                    infoRecord = new WarningRecord("PowerShellConnectionRetryAttempt", StringUtil.Format(RemotingErrorIdStrings.RCConnectionRetryAttempt, this.computerName));
                    eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.ConnectionRetryAttempt, this.computerName, maxRetryConnectionTime, infoRecord);
                    break;

                case ConnectionStatus.ConnectionRetrySucceeded:
                    infoRecord = new WarningRecord("PowerShellConnectionRetrySucceeded", StringUtil.Format(RemotingErrorIdStrings.RCReconnectSucceeded, this.computerName));
                    eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.ConnectionRetrySucceeded, this.computerName, num2, infoRecord);
                    break;

                case ConnectionStatus.AutoDisconnectStarting:
                    infoRecord = new WarningRecord("PowerShellNetworkFailedStartDisconnect", StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnectingWarning, this.computerName));
                    eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.AutoDisconnectStarting, this.computerName, num2, infoRecord);
                    break;

                case ConnectionStatus.AutoDisconnectSucceeded:
                    infoRecord = new WarningRecord("PowerShellAutoDisconnectSucceeded", StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnected, this.computerName));
                    eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.AutoDisconnectSucceeded, this.computerName, num2, infoRecord);
                    break;

                case ConnectionStatus.InternalErrorAbort:
                {
                    RuntimeException exception = new RuntimeException(StringUtil.Format(RemotingErrorIdStrings.RCInternalError, this.computerName));
                    record2 = new ErrorRecord(exception, "PowerShellNetworkOrDisconnectFailed", ErrorCategory.InvalidOperation, this);
                    eventArgs = new PSConnectionRetryStatusEventArgs(PSConnectionRetryStatus.InternalErrorAbort, this.computerName, num2, record2);
                    break;
                }
            }
            if (eventArgs != null)
            {
                this.connectionRetryStatus = eventArgs.Notification;
                if (infoRecord != null)
                {
                    RemotingWarningRecord message = new RemotingWarningRecord(infoRecord, new OriginInfo(this.computerName, this.InstanceId));
                    this.HandleInformationalMessageReceived(this, new RemoteDataEventArgs<InformationalMessage>(new InformationalMessage(message, RemotingDataType.PowerShellWarning)));
                    RemoteHostCall data = new RemoteHostCall(-100L, RemoteHostMethodId.WriteWarningLine, new object[] { infoRecord.Message });
                    try
                    {
                        this.HandleHostCallReceived(this, new RemoteDataEventArgs<RemoteHostCall>(data));
                    }
                    catch (PSNotImplementedException)
                    {
                    }
                }
                if (record2 != null)
                {
                    RemotingErrorRecord record4 = new RemotingErrorRecord(record2, new OriginInfo(this.computerName, this.InstanceId));
                    this.HandleErrorReceived(this, new RemoteDataEventArgs<ErrorRecord>(record4));
                }
                this.RCConnectionNotification.SafeInvoke<PSConnectionRetryStatusEventArgs>(this, eventArgs);
            }
        }