protected override void ProcessRecord()
        {
            bool flag = false;

            lock (base.Events.ReceivedEvents.SyncRoot)
            {
                PSEventArgsCollection receivedEvents = base.Events.ReceivedEvents;
                for (int i = receivedEvents.Count; i > 0; i--)
                {
                    PSEventArgs args = receivedEvents[i - 1];
                    if (((this.sourceIdentifier == null) || this.matchPattern.IsMatch(args.SourceIdentifier)) && ((this.eventIdentifier < 0) || (args.EventIdentifier == this.eventIdentifier)))
                    {
                        flag = true;
                        if (base.ShouldProcess(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.EventResource, new object[] { args.SourceIdentifier }), EventingStrings.Remove))
                        {
                            receivedEvents.RemoveAt(i - 1);
                        }
                    }
                }
            }
            if (((this.sourceIdentifier != null) && !WildcardPattern.ContainsWildcardCharacters(this.sourceIdentifier)) && !flag)
            {
                ErrorRecord errorRecord = new ErrorRecord(new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.SourceIdentifierNotFound, new object[] { this.sourceIdentifier })), "INVALID_SOURCE_IDENTIFIER", ErrorCategory.InvalidArgument, null);
                base.WriteError(errorRecord);
            }
            else if ((this.eventIdentifier >= 0) && !flag)
            {
                ErrorRecord record2 = new ErrorRecord(new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.EventIdentifierNotFound, new object[] { this.eventIdentifier })), "INVALID_EVENT_IDENTIFIER", ErrorCategory.InvalidArgument, null);
                base.WriteError(record2);
            }
        }
Exemple #2
0
        /// <summary>
        /// Remove the event from the queue
        /// </summary>
        protected override void ProcessRecord()
        {
            // Go through all the received events and write them to the output
            // pipeline
            bool foundMatch = false;

            lock (Events.ReceivedEvents.SyncRoot)
            {
                PSEventArgsCollection currentEvents = Events.ReceivedEvents;

                for (int eventCounter = currentEvents.Count; eventCounter > 0; eventCounter--)
                {
                    PSEventArgs currentEvent = currentEvents[eventCounter - 1];

                    // If they specified a event identifier and we don't match, continue
                    if ((_sourceIdentifier != null) &&
                        (!_matchPattern.IsMatch(currentEvent.SourceIdentifier)))
                    {
                        continue;
                    }

                    // If they specified a TimeGenerated and we don't match, continue
                    if ((_eventIdentifier >= 0) &&
                        (currentEvent.EventIdentifier != _eventIdentifier))
                    {
                        continue;
                    }

                    foundMatch = true;
                    if (ShouldProcess(
                            String.Format(
                                System.Globalization.CultureInfo.CurrentCulture,
                                EventingStrings.EventResource,
                                currentEvent.SourceIdentifier),
                            EventingStrings.Remove))
                    {
                        currentEvents.RemoveAt(eventCounter - 1);
                    }
                }
            }

            // Generate an error if we couldn't find the subscription identifier,
            // and no globbing was done.
            if ((_sourceIdentifier != null) &&
                (!WildcardPattern.ContainsWildcardCharacters(_sourceIdentifier)) &&
                (!foundMatch))
            {
                ErrorRecord errorRecord = new ErrorRecord(
                    new ArgumentException(
                        String.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            EventingStrings.SourceIdentifierNotFound, _sourceIdentifier)),
                    "INVALID_SOURCE_IDENTIFIER",
                    ErrorCategory.InvalidArgument,
                    null);

                WriteError(errorRecord);
            }
            else if ((_eventIdentifier >= 0) && (!foundMatch))
            {
                ErrorRecord errorRecord = new ErrorRecord(
                    new ArgumentException(
                        String.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            EventingStrings.EventIdentifierNotFound, _eventIdentifier)),
                    "INVALID_EVENT_IDENTIFIER",
                    ErrorCategory.InvalidArgument,
                    null);

                WriteError(errorRecord);
            }
        }