/// <summary>
 ///   Performs the actions needed to instrument a set of events.
 /// </summary>
 ///
 /// <param name="events">The events to instrument.</param>
 ///
 private void InstrumentMessages(IEnumerable <EventData> events)
 {
     foreach (EventData eventData in events)
     {
         EventDataInstrumentation.InstrumentEvent(eventData);
     }
 }
 /// <summary>
 ///   Performs the actions needed to instrument a set of events.
 /// </summary>
 ///
 /// <param name="events">The events to instrument.</param>
 ///
 private void InstrumentMessages(IEnumerable <EventData> events)
 {
     foreach (EventData eventData in events)
     {
         EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);
     }
 }
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        public bool TryAdd(EventData eventData)
        {
            bool instrumented = EventDataInstrumentation.InstrumentEvent(eventData);
            bool added        = InnerBatch.TryAdd(eventData);

            if (!added && instrumented)
            {
                EventDataInstrumentation.ResetEvent(eventData);
            }

            return(added);
        }
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        public bool TryAdd(EventData eventData)
        {
            bool instrumented = EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);
            bool added        = InnerBatch.TryAdd(eventData);

            if (!added && instrumented)
            {
                EventDataInstrumentation.ResetEvent(eventData);
            }

            return(added);
        }
Beispiel #5
0
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        /// <remarks>
        ///   When an event is accepted into the batch, its content and state are frozen; any
        ///   changes made to the event will not be reflected in the batch nor will any state
        ///   transitions be reflected to the original instance.
        /// </remarks>
        ///
        /// <exception cref="InvalidOperationException">
        ///   When a batch is published, it will be locked for the duration of that operation.  During this time,
        ///   no events may be added to the batch.  Calling <c>TryAdd</c> while the batch is being published will
        ///   result in an <see cref="InvalidOperationException" /> until publishing has completed.
        /// </exception>
        ///
        public bool TryAdd(EventData eventData)
        {
            lock (SyncGuard)
            {
                AssertNotLocked();

                eventData = eventData.Clone();
                EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);

                var added = InnerBatch.TryAdd(eventData);

                if ((added) && (EventDataInstrumentation.TryExtractDiagnosticId(eventData, out string diagnosticId)))
                {
                    EventDiagnosticIdentifiers.Add(diagnosticId);
                }

                return(added);
            }
        }
Beispiel #6
0
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        public bool TryAdd(EventData eventData)
        {
            bool instrumented = EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);
            bool added        = InnerBatch.TryAdd(eventData);

            if (added)
            {
                if (EventDataInstrumentation.TryExtractDiagnosticId(eventData, out string diagnosticId))
                {
                    EventDiagnosticIdentifiers.Add(diagnosticId);
                }
            }
            else if (instrumented)
            {
                EventDataInstrumentation.ResetEvent(eventData);
            }

            return(added);
        }
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        /// <remarks>
        ///   When an event is accepted into the batch, its content and state are frozen; any
        ///   changes made to the event will not be reflected in the batch nor will any state
        ///   transitions be reflected to the original instance.
        /// </remarks>
        ///
        /// <exception cref="InvalidOperationException">
        ///   When a batch is published, it will be locked for the duration of that operation.  During this time,
        ///   no events may be added to the batch.  Calling <c>TryAdd</c> while the batch is being published will
        ///   result in an <see cref="InvalidOperationException" /> until publishing has completed.
        /// </exception>
        ///
        public bool TryAdd(EventData eventData)
        {
            lock (SyncGuard)
            {
                AssertNotLocked();

                var messageScopeCreated = false;
                var identifier          = default(string);

                try
                {
                    (messageScopeCreated, identifier) = EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);

                    var added = InnerBatch.TryAdd(eventData);

                    if ((added) && (identifier != null))
                    {
                        EventDiagnosticIdentifiers.Add(identifier);
                    }

                    return(added);
                }
                finally
                {
                    // If a new message scope was added when instrumenting the instance, the identifier was
                    // added during this call.  If so, remove it so that the source event is not modified; the
                    // instrumentation will have been captured by the batch's copy of the event, if it was accepted
                    // into the batch.

                    if ((messageScopeCreated) && (identifier != null))
                    {
                        EventDataInstrumentation.ResetEvent(eventData);
                    }
                }
            }
        }
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        public bool TryAdd(EventData eventData)
        {
            if (_locked)
            {
                throw new InvalidOperationException(Resources.EventBatchIsLocked);
            }

            bool instrumented = EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);
            bool added        = InnerBatch.TryAdd(eventData);

            if (added)
            {
                if (EventDataInstrumentation.TryExtractDiagnosticId(eventData, out string diagnosticId))
                {
                    EventDiagnosticIdentifiers.Add(diagnosticId);
                }
            }
            else if (instrumented)
            {
                EventDataInstrumentation.ResetEvent(eventData);
            }

            return(added);
        }