internal MailEventNotificationInfo( MailMessage msg, WebBaseEventCollection events, DateTime lastNotificationUtc, int discardedSinceLastNotification, int eventsInBuffer, int notificationSequence, EventNotificationType notificationType, int eventsInNotification, int eventsRemaining, int messagesInNotification, int eventsLostDueToMessageLimit, int messageSequence) { _events = events; _lastNotificationUtc = lastNotificationUtc; _discardedSinceLastNotification = discardedSinceLastNotification; _eventsInBuffer = eventsInBuffer; _notificationSequence = notificationSequence; _notificationType = notificationType; _eventsInNotification = eventsInNotification; _eventsRemaining = eventsRemaining; _messagesInNotification = messagesInNotification; _eventsLostDueToMessageLimit = eventsLostDueToMessageLimit; _messageSequence = messageSequence; _msg = msg; }
private string GenerateBody(WebBaseEventCollection events, int begin, DateTime lastFlush, int discardedSinceLastFlush, int eventsInBuffer, int messageSequence, int eventsInNotification, int eventsLostDueToMessageLimit) { StringBuilder sb = new StringBuilder(); int count = events.Count; if (this._bodyHeader != null) { sb.Append(this._bodyHeader); } this.GenerateWarnings(sb, lastFlush, discardedSinceLastFlush, messageSequence, eventsLostDueToMessageLimit); this.GenerateSummary(sb, begin, (begin + count) - 1, eventsInNotification, eventsInBuffer); this.GenerateApplicationInformation(sb); for (int i = 0; i < count; i++) { string str = events[i].ToString(false, true); if ((this._maxEventLength != 0x7fffffff) && (str.Length > this._maxEventLength)) { str = str.Substring(0, this._maxEventLength); } if (i == 0) { sb.Append(s_header_events); sb.Append("\n"); sb.Append(this._separator); } sb.Append(str); sb.Append("\n"); sb.Append(this._separator); } if (this._bodyFooter != null) { sb.Append(this._bodyFooter); } return(sb.ToString()); }
private string GenerateBody(WebBaseEventCollection events, int begin, DateTime lastFlush, int discardedSinceLastFlush, int eventsInBuffer, int messageSequence, int eventsInNotification, int eventsLostDueToMessageLimit) { StringBuilder sb = new StringBuilder(); int count = events.Count; if (this._bodyHeader != null) { sb.Append(this._bodyHeader); } this.GenerateWarnings(sb, lastFlush, discardedSinceLastFlush, messageSequence, eventsLostDueToMessageLimit); this.GenerateSummary(sb, begin, (begin + count) - 1, eventsInNotification, eventsInBuffer); this.GenerateApplicationInformation(sb); for (int i = 0; i < count; i++) { string str = events[i].ToString(false, true); if ((this._maxEventLength != 0x7fffffff) && (str.Length > this._maxEventLength)) { str = str.Substring(0, this._maxEventLength); } if (i == 0) { sb.Append(s_header_events); sb.Append("\n"); sb.Append(this._separator); } sb.Append(str); sb.Append("\n"); sb.Append(this._separator); } if (this._bodyFooter != null) { sb.Append(this._bodyFooter); } return sb.ToString(); }
void SendMessageInternal(WebBaseEventCollection events, int notificationSequence, int begin, DateTime lastFlush, int discardedSinceLastFlush, int eventsInBuffer, int messageSequence, int messagesInNotification, int eventsInNotification, int eventsLostDueToMessageLimit) { using (MailMessage msg = GetMessage()) { // Don't report eventsLostDueToMessageLimit unless it's the last message in this notification if (messageSequence != messagesInNotification) { eventsLostDueToMessageLimit = 0; } msg.Body = GenerateBody(events, begin, lastFlush, discardedSinceLastFlush, eventsInBuffer, messageSequence, eventsInNotification, eventsLostDueToMessageLimit); msg.Subject = GenerateSubject(notificationSequence, messageSequence, events, events.Count); SendMail(msg); } }
internal override void SendMessage(WebBaseEvent eventRaised) { bool flag; WebBaseEventCollection events = new WebBaseEventCollection(eventRaised); this.SendMessageInternal(events, DateTime.MinValue, 0, 0, Interlocked.Increment(ref this._nonBufferNotificationSequence), EventNotificationType.Unbuffered, 1, 0, 1, 0, 1, out flag); }
void SendMessageInternal(WebBaseEventCollection events, DateTime lastNotificationUtc, int discardedSinceLastNotification, int eventsInBuffer, int notificationSequence, EventNotificationType notificationType, int eventsInNotification, int eventsRemaining, int messagesInNotification, int eventsLostDueToMessageLimit, int messageSequence, out bool fatalError) { using (MailMessage msg = GetMessage()) { msg.Subject = GenerateSubject(notificationSequence, messageSequence, events, events.Count); GenerateMessageBody( msg, events, lastNotificationUtc, discardedSinceLastNotification, eventsInBuffer, notificationSequence, notificationType, eventsInNotification, eventsRemaining, messagesInNotification, eventsLostDueToMessageLimit, messageSequence, out fatalError); SendMail(msg); } }
string GenerateBody(WebBaseEventCollection events, int begin, DateTime lastFlush, int discardedSinceLastFlush, int eventsInBuffer, int messageSequence, int eventsInNotification, int eventsLostDueToMessageLimit) { StringBuilder sb = new StringBuilder(); int totalEvents = events.Count; if (_bodyHeader != null) { sb.Append(_bodyHeader); } // Warnings GenerateWarnings(sb, lastFlush, discardedSinceLastFlush, messageSequence, eventsLostDueToMessageLimit); // Event Summary GenerateSummary(sb, begin, begin + totalEvents - 1, eventsInNotification, eventsInBuffer); // Application Info Debug.Assert(events.Count > 0, "events.Count > 0"); GenerateApplicationInformation(sb); // Please note that it's a text message, and thus we shouldn't need to HtmlEncode it. for (int i = 0; i < totalEvents; i++) { WebBaseEvent eventRaised = events[i]; string details = eventRaised.ToString(false, true); if (_maxEventLength != ProviderUtil.Infinite && details.Length > _maxEventLength) { details = details.Substring(0, _maxEventLength); } if (i == 0) { sb.Append(s_header_events); sb.Append("\n"); sb.Append(_separator); } sb.Append(details); sb.Append("\n"); sb.Append(_separator); } if (_bodyFooter != null) { sb.Append(_bodyFooter); } return(sb.ToString()); }
internal WebEventBufferFlushInfo(WebBaseEventCollection events, EventNotificationType notificationType, int notificationSequence, DateTime lastNotification, int eventsDiscardedSinceLastNotification, int eventsInBuffer) { this._events = events; this._notificationType = notificationType; this._notificationSequence = notificationSequence; this._lastNotification = lastNotification; this._eventsDiscardedSinceLastNotification = eventsDiscardedSinceLastNotification; this._eventsInBuffer = eventsInBuffer; }
private void SendMessageInternal(WebBaseEventCollection events, DateTime lastNotificationUtc, int discardedSinceLastNotification, int eventsInBuffer, int notificationSequence, EventNotificationType notificationType, int eventsInNotification, int eventsRemaining, int messagesInNotification, int eventsLostDueToMessageLimit, int messageSequence, out bool fatalError) { using (MailMessage message = base.GetMessage()) { message.Subject = base.GenerateSubject(notificationSequence, messageSequence, events, events.Count); this.GenerateMessageBody(message, events, lastNotificationUtc, discardedSinceLastNotification, eventsInBuffer, notificationSequence, notificationType, eventsInNotification, eventsRemaining, messagesInNotification, eventsLostDueToMessageLimit, messageSequence, out fatalError); base.SendMail(message); } }
private void WriteToSQL(WebBaseEventCollection events, int eventsDiscardedByBuffer, DateTime lastNotificationUtc) { if (this._retryDate <= DateTime.UtcNow) { try { SqlConnectionHolder connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true); SqlCommand sqlCommand = new SqlCommand("dbo.aspnet_WebEvent_LogEvent"); this.CheckSchemaVersion(connection.Connection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Connection = connection.Connection; if (this._commandTimeout > -1) { sqlCommand.CommandTimeout = this._commandTimeout; } this.PrepareParams(sqlCommand); try { connection.Open(null, true); Interlocked.Increment(ref this._connectionCount); if (eventsDiscardedByBuffer != 0) { WebBaseEvent eventRaised = new WebBaseEvent(System.Web.SR.GetString("Sql_webevent_provider_events_dropped", new object[] { eventsDiscardedByBuffer.ToString(CultureInfo.InstalledUICulture), lastNotificationUtc.ToString("r", CultureInfo.InstalledUICulture) }), null, 0x1771, 0xc47d); this.FillParams(sqlCommand, eventRaised); sqlCommand.ExecuteNonQuery(); } foreach (WebBaseEvent event3 in events) { this.FillParams(sqlCommand, event3); sqlCommand.ExecuteNonQuery(); } } finally { connection.Close(); Interlocked.Decrement(ref this._connectionCount); } try { this.EventProcessingComplete(events); } catch { } } catch { double num = 30.0; if (this._commandTimeout > -1) { num = this._commandTimeout; } this._retryDate = DateTime.UtcNow.AddSeconds(num); throw; } } }
internal abstract void SendMessage(WebBaseEventCollection events, WebEventBufferFlushInfo flushInfo, int eventsInNotification, int eventsRemaining, int messagesInNotification, int eventsLostDueToMessageLimit, int messageSequence, int eventsSent, out bool fatalError);
internal string GenerateSubject(int notificationSequence, int messageSequence, WebBaseEventCollection events, int count) { WebBaseEvent event2 = events[0]; if (count == 1) { return HttpUtility.HtmlEncode(System.Web.SR.GetString("WebEvent_event_email_subject", new string[] { notificationSequence.ToString(CultureInfo.InstalledUICulture), messageSequence.ToString(CultureInfo.InstalledUICulture), this._subjectPrefix, event2.GetType().ToString(), WebBaseEvent.ApplicationInformation.ApplicationVirtualPath })); } return HttpUtility.HtmlEncode(System.Web.SR.GetString("WebEvent_event_group_email_subject", new string[] { notificationSequence.ToString(CultureInfo.InstalledUICulture), messageSequence.ToString(CultureInfo.InstalledUICulture), this._subjectPrefix, count.ToString(CultureInfo.InstalledUICulture), WebBaseEvent.ApplicationInformation.ApplicationVirtualPath })); }
void GenerateMessageBody( MailMessage msg, WebBaseEventCollection events, DateTime lastNotificationUtc, int discardedSinceLastNotification, int eventsInBuffer, int notificationSequence, EventNotificationType notificationType, int eventsInNotification, int eventsRemaining, int messagesInNotification, int eventsLostDueToMessageLimit, int messageSequence, out bool fatalError) { StringWriter writer = new StringWriter(CultureInfo.InstalledUICulture); MailEventNotificationInfo info = new MailEventNotificationInfo( msg, events, lastNotificationUtc, discardedSinceLastNotification, eventsInBuffer, notificationSequence, notificationType, eventsInNotification, eventsRemaining, messagesInNotification, eventsLostDueToMessageLimit, messageSequence); CallContext.SetData(CurrentEventsName, info); try { TemplatedMailErrorFormatterGenerator gen = new TemplatedMailErrorFormatterGenerator(events.Count + eventsRemaining, _detailedTemplateErrors); HttpServerUtility.ExecuteLocalRequestAndCaptureResponse(_templateUrl, writer, gen); fatalError = gen.ErrorFormatterCalled; if (fatalError) { msg.Subject = HttpUtility.HtmlEncode(SR.GetString(SR.WebEvent_event_email_subject_template_error, notificationSequence.ToString(CultureInfo.InstalledUICulture), messageSequence.ToString(CultureInfo.InstalledUICulture), SubjectPrefix)); } msg.Body = writer.ToString(); msg.IsBodyHtml = true; } finally { CallContext.FreeNamedDataSlot(CurrentEventsName); } }
private void SendMessageInternal(WebBaseEventCollection events, int notificationSequence, int begin, DateTime lastFlush, int discardedSinceLastFlush, int eventsInBuffer, int messageSequence, int messagesInNotification, int eventsInNotification, int eventsLostDueToMessageLimit) { using (MailMessage message = base.GetMessage()) { if (messageSequence != messagesInNotification) { eventsLostDueToMessageLimit = 0; } message.Body = this.GenerateBody(events, begin, lastFlush, discardedSinceLastFlush, eventsInBuffer, messageSequence, eventsInNotification, eventsLostDueToMessageLimit); message.Subject = base.GenerateSubject(notificationSequence, messageSequence, events, events.Count); base.SendMail(message); } }
internal WebEventBufferFlushInfo( WebBaseEventCollection events, EventNotificationType notificationType, int notificationSequence, DateTime lastNotification, int eventsDiscardedSinceLastNotification, int eventsInBuffer) { _events = events; _notificationType = notificationType; _notificationSequence = notificationSequence; _lastNotification = lastNotification; _eventsDiscardedSinceLastNotification = eventsDiscardedSinceLastNotification; _eventsInBuffer = eventsInBuffer; }
internal override void SendMessage(WebBaseEvent eventRaised) { WebBaseEventCollection events = new WebBaseEventCollection(eventRaised); SendMessageInternal( events, // events Interlocked.Increment(ref _nonBufferNotificationSequence), // notificationSequence 0, // begin DateTime.MinValue, // lastFlush 0, // discardedSinceLastFlush 0, // eventsInBuffer MessageSequenceBase, // messageSequence 1, // messagesInNotification 1, // eventsInNotification 0); // eventsLostDueToMessageLimit }
internal override void SendMessage(WebBaseEvent eventRaised) { WebBaseEventCollection events = new WebBaseEventCollection(eventRaised); bool templateError; SendMessageInternal(events, // events DateTime.MinValue, // lastNotificationUtc 0, // discardedSinceLastNotification 0, // eventsInBuffer Interlocked.Increment(ref _nonBufferNotificationSequence), // notificationSequence EventNotificationType.Unbuffered, // notificationType 1, // eventsInNotification 0, // eventsRemaining 1, // messagesInNotification 0, // eventsLostDueToMessageLimit MessageSequenceBase, // messageSequence out templateError); // templateError }
private void GenerateMessageBody(MailMessage msg, WebBaseEventCollection events, DateTime lastNotificationUtc, int discardedSinceLastNotification, int eventsInBuffer, int notificationSequence, EventNotificationType notificationType, int eventsInNotification, int eventsRemaining, int messagesInNotification, int eventsLostDueToMessageLimit, int messageSequence, out bool fatalError) { StringWriter writer = new StringWriter(CultureInfo.InstalledUICulture); MailEventNotificationInfo data = new MailEventNotificationInfo(msg, events, lastNotificationUtc, discardedSinceLastNotification, eventsInBuffer, notificationSequence, notificationType, eventsInNotification, eventsRemaining, messagesInNotification, eventsLostDueToMessageLimit, messageSequence); CallContext.SetData("_TWCurEvt", data); try { TemplatedMailErrorFormatterGenerator errorFormatterGenerator = new TemplatedMailErrorFormatterGenerator(events.Count + eventsRemaining, this._detailedTemplateErrors); HttpServerUtility.ExecuteLocalRequestAndCaptureResponse(this._templateUrl, writer, errorFormatterGenerator); fatalError = errorFormatterGenerator.ErrorFormatterCalled; if (fatalError) { msg.Subject = HttpUtility.HtmlEncode(System.Web.SR.GetString("WebEvent_event_email_subject_template_error", new object[] { notificationSequence.ToString(CultureInfo.InstalledUICulture), messageSequence.ToString(CultureInfo.InstalledUICulture), base.SubjectPrefix })); } msg.Body = writer.ToString(); msg.IsBodyHtml = true; } finally { CallContext.FreeNamedDataSlot("_TWCurEvt"); } }
internal override void SendMessage(WebBaseEventCollection events, WebEventBufferFlushInfo flushInfo, int eventsInNotification, int eventsRemaining, int messagesInNotification, int eventsLostDueToMessageLimit, int messageSequence, int eventsSent, out bool fatalError) { SendMessageInternal(events, flushInfo.NotificationSequence, eventsSent, flushInfo.LastNotificationUtc, flushInfo.EventsDiscardedSinceLastNotification, flushInfo.EventsInBuffer, messageSequence, messagesInNotification, eventsInNotification, eventsLostDueToMessageLimit); fatalError = false; }
public override void ProcessEventFlush(WebEventBufferFlushInfo flushInfo) { int count = flushInfo.Events.Count; bool flag = false; int messageSequence = 1; int eventsLostDueToMessageLimit = 0; bool fatalError = false; if (count != 0) { int maxMessagesPerNotification; WebBaseEvent[] eventArray = null; if (count > this.MaxEventsPerMessage) { flag = true; maxMessagesPerNotification = count / this.MaxEventsPerMessage; if (count > (maxMessagesPerNotification * this.MaxEventsPerMessage)) { maxMessagesPerNotification++; } if (maxMessagesPerNotification > this.MaxMessagesPerNotification) { eventsLostDueToMessageLimit = count - (this.MaxMessagesPerNotification * this.MaxEventsPerMessage); maxMessagesPerNotification = this.MaxMessagesPerNotification; count -= eventsLostDueToMessageLimit; } } else { maxMessagesPerNotification = 1; } int eventsSent = 0; while (eventsSent < count) { WebBaseEventCollection events; if (flag) { int num6 = Math.Min(this.MaxEventsPerMessage, count - eventsSent); if ((eventArray == null) || (eventArray.Length != num6)) { eventArray = new WebBaseEvent[num6]; } for (int i = 0; i < num6; i++) { eventArray[i] = flushInfo.Events[i + eventsSent]; } events = new WebBaseEventCollection(eventArray); } else { events = flushInfo.Events; } this.SendMessage(events, flushInfo, count, count - (eventsSent + events.Count), maxMessagesPerNotification, eventsLostDueToMessageLimit, messageSequence, eventsSent, out fatalError); if (fatalError) { return; } eventsSent += events.Count; messageSequence++; } } }
internal override void SendMessage(WebBaseEvent eventRaised) { WebBaseEventCollection events = new WebBaseEventCollection(eventRaised); this.SendMessageInternal(events, Interlocked.Increment(ref this._nonBufferNotificationSequence), 0, DateTime.MinValue, 0, 0, 1, 1, 1, 0); }
string GenerateBody(WebBaseEventCollection events, int begin, DateTime lastFlush, int discardedSinceLastFlush, int eventsInBuffer, int messageSequence, int eventsInNotification, int eventsLostDueToMessageLimit) { StringBuilder sb = new StringBuilder(); int totalEvents = events.Count; if (_bodyHeader != null) { sb.Append(_bodyHeader); } // Warnings GenerateWarnings(sb, lastFlush, discardedSinceLastFlush, messageSequence, eventsLostDueToMessageLimit); // Event Summary GenerateSummary(sb, begin, begin + totalEvents - 1, eventsInNotification, eventsInBuffer); // Application Info Debug.Assert(events.Count > 0, "events.Count > 0"); GenerateApplicationInformation(sb); // Please note that it's a text message, and thus we shouldn't need to HtmlEncode it. for (int i = 0; i < totalEvents; i++) { WebBaseEvent eventRaised = events[i]; string details = eventRaised.ToString(false, true); if (_maxEventLength != ProviderUtil.Infinite && details.Length > _maxEventLength) { details = details.Substring(0, _maxEventLength); } if (i == 0) { sb.Append(s_header_events); sb.Append("\n"); sb.Append(_separator); } sb.Append(details); sb.Append("\n"); sb.Append(_separator); } if (_bodyFooter != null) { sb.Append(_bodyFooter); } return sb.ToString(); }
internal override void SendMessage(WebBaseEvent eventRaised) { WebBaseEventCollection events = new WebBaseEventCollection(eventRaised); SendMessageInternal( events, // events Interlocked.Increment(ref _nonBufferNotificationSequence), // notificationSequence 0, // begin DateTime.MinValue, // lastFlush 0, // discardedSinceLastFlush 0, // eventsInBuffer MessageSequenceBase,// messageSequence 1, // messagesInNotification 1, // eventsInNotification 0); // eventsLostDueToMessageLimit }
protected virtual new void EventProcessingComplete(WebBaseEventCollection raisedEvents) { }
internal MailEventNotificationInfo( MailMessage msg, WebBaseEventCollection events, DateTime lastNotificationUtc, int discardedSinceLastNotification, int eventsInBuffer, int notificationSequence, EventNotificationType notificationType, int eventsInNotification, int eventsRemaining, int messagesInNotification, int eventsLostDueToMessageLimit, int messageSequence) { _events = events; _lastNotificationUtc = lastNotificationUtc; _discardedSinceLastNotification = discardedSinceLastNotification; _eventsInBuffer = eventsInBuffer; _notificationSequence = notificationSequence; _notificationType = notificationType; _eventsInNotification = eventsInNotification; _eventsRemaining = eventsRemaining ; _messagesInNotification = messagesInNotification; _eventsLostDueToMessageLimit = eventsLostDueToMessageLimit; _messageSequence = messageSequence; _msg = msg; }
void WriteToSQL(WebBaseEventCollection events, int eventsDiscardedByBuffer, DateTime lastNotificationUtc) { // We don't want to send any more events until we've waited until the _retryDate (which defaults to minValue) if (_retryDate > DateTime.UtcNow) { return; } try { SqlConnectionHolder sqlConnHolder = SqlConnectionHelper.GetConnection(_sqlConnectionString, true); SqlCommand sqlCommand = new SqlCommand(SP_LOG_EVENT); CheckSchemaVersion(sqlConnHolder.Connection); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Connection = sqlConnHolder.Connection; if (_commandTimeout > -1) { sqlCommand.CommandTimeout = _commandTimeout; } PrepareParams(sqlCommand); try { sqlConnHolder.Open(null, true); Interlocked.Increment(ref _connectionCount); if (eventsDiscardedByBuffer != 0) { WebBaseEvent infoEvent = new WebBaseEvent( SR.GetString(SR.Sql_webevent_provider_events_dropped, eventsDiscardedByBuffer.ToString(CultureInfo.InstalledUICulture), lastNotificationUtc.ToString("r", CultureInfo.InstalledUICulture)), null, WebEventCodes.WebEventProviderInformation, WebEventCodes.SqlProviderEventsDropped); FillParams(sqlCommand, infoEvent); sqlCommand.ExecuteNonQuery(); } foreach (WebBaseEvent eventRaised in events) { FillParams(sqlCommand, eventRaised); sqlCommand.ExecuteNonQuery(); } } #if DBG catch (Exception e) { Debug.Trace("SqlWebEventProvider", "ExecuteNonQuery failed: " + e); throw; } #endif finally { sqlConnHolder.Close(); Interlocked.Decrement(ref _connectionCount); } #if (!DBG) try { #endif EventProcessingComplete(events); #if (!DBG) } catch { // Ignore all errors. } #endif } catch { // For any failure, we will wait at least 30 seconds or _commandTimeout before trying again double timeout = 30; if (_commandTimeout > -1) { timeout = (double)_commandTimeout; } _retryDate = DateTime.UtcNow.AddSeconds(timeout); throw; } }
internal string GenerateSubject(int notificationSequence, int messageSequence, WebBaseEventCollection events, int count) { WebBaseEvent event2 = events[0]; if (count == 1) { return(HttpUtility.HtmlEncode(System.Web.SR.GetString("WebEvent_event_email_subject", new string[] { notificationSequence.ToString(CultureInfo.InstalledUICulture), messageSequence.ToString(CultureInfo.InstalledUICulture), this._subjectPrefix, event2.GetType().ToString(), WebBaseEvent.ApplicationInformation.ApplicationVirtualPath }))); } return(HttpUtility.HtmlEncode(System.Web.SR.GetString("WebEvent_event_group_email_subject", new string[] { notificationSequence.ToString(CultureInfo.InstalledUICulture), messageSequence.ToString(CultureInfo.InstalledUICulture), this._subjectPrefix, count.ToString(CultureInfo.InstalledUICulture), WebBaseEvent.ApplicationInformation.ApplicationVirtualPath }))); }
public override void ProcessEventFlush(WebEventBufferFlushInfo flushInfo) { int eventsInNotification = flushInfo.Events.Count; int eventsRemaining = eventsInNotification; bool split = false; int messageSequence = MessageSequenceBase; int messagesInNotification; int eventsToBeDiscarded = 0; bool fatalError = false; if (eventsInNotification == 0) { return; } WebBaseEventCollection eventsToSend; WebBaseEvent[] eventsChunk = null; // We will split based on MaxEventsPerMessage if (eventsInNotification > MaxEventsPerMessage) { split = true; // I use the below clumsy calculation instead of (a+b-1)/b is to avoid // Int32 overflow. messagesInNotification = eventsInNotification/MaxEventsPerMessage; if (eventsInNotification > messagesInNotification*MaxEventsPerMessage) { messagesInNotification++; } // We will exceed the limit. if (messagesInNotification > MaxMessagesPerNotification) { eventsToBeDiscarded = eventsInNotification - MaxMessagesPerNotification * MaxEventsPerMessage; messagesInNotification = MaxMessagesPerNotification; eventsInNotification -= eventsToBeDiscarded; } } else { messagesInNotification = 1; } // In each email we only send a max of MaxEventsPerMessage events for(int eventsSent = 0; eventsSent < eventsInNotification; messageSequence++) { if (split) { int chunkSize = Math.Min(MaxEventsPerMessage, eventsInNotification - eventsSent); if (eventsChunk == null || eventsChunk.Length != chunkSize) { eventsChunk = new WebBaseEvent[chunkSize]; } for(int i = 0; i < chunkSize; i++) { eventsChunk[i] = flushInfo.Events[i + eventsSent]; } eventsToSend = new WebBaseEventCollection(eventsChunk); } else { eventsToSend = flushInfo.Events; } Debug.Trace("MailWebEventProvider", "Calling SendMessageInternal; # of events: " + eventsToSend.Count); SendMessage( eventsToSend, flushInfo, eventsInNotification, eventsInNotification - (eventsSent + eventsToSend.Count), // eventsRemaining messagesInNotification, eventsToBeDiscarded, messageSequence, eventsSent, out fatalError); if (fatalError) { Debug.Trace("MailWebEventProvider", "Stop sending because we hit a fatal error"); break; } eventsSent += eventsToSend.Count; } }
// </Snippet5> // <Snippet2> // Create an event collection. // Add to it the created simulatedEvents. public static void AddEvents() { events = new System.Web.Management.WebBaseEventCollection( simulatedEvents); }
public override void ProcessEventFlush(WebEventBufferFlushInfo flushInfo) { int eventsInNotification = flushInfo.Events.Count; int eventsRemaining = eventsInNotification; bool split = false; int messageSequence = MessageSequenceBase; int messagesInNotification; int eventsToBeDiscarded = 0; bool fatalError = false; if (eventsInNotification == 0) { return; } WebBaseEventCollection eventsToSend; WebBaseEvent[] eventsChunk = null; // We will split based on MaxEventsPerMessage if (eventsInNotification > MaxEventsPerMessage) { split = true; // I use the below clumsy calculation instead of (a+b-1)/b is to avoid // Int32 overflow. messagesInNotification = eventsInNotification / MaxEventsPerMessage; if (eventsInNotification > messagesInNotification * MaxEventsPerMessage) { messagesInNotification++; } // We will exceed the limit. if (messagesInNotification > MaxMessagesPerNotification) { eventsToBeDiscarded = eventsInNotification - MaxMessagesPerNotification * MaxEventsPerMessage; messagesInNotification = MaxMessagesPerNotification; eventsInNotification -= eventsToBeDiscarded; } } else { messagesInNotification = 1; } // In each email we only send a max of MaxEventsPerMessage events for (int eventsSent = 0; eventsSent < eventsInNotification; messageSequence++) { if (split) { int chunkSize = Math.Min(MaxEventsPerMessage, eventsInNotification - eventsSent); if (eventsChunk == null || eventsChunk.Length != chunkSize) { eventsChunk = new WebBaseEvent[chunkSize]; } for (int i = 0; i < chunkSize; i++) { eventsChunk[i] = flushInfo.Events[i + eventsSent]; } eventsToSend = new WebBaseEventCollection(eventsChunk); } else { eventsToSend = flushInfo.Events; } Debug.Trace("MailWebEventProvider", "Calling SendMessageInternal; # of events: " + eventsToSend.Count); SendMessage( eventsToSend, flushInfo, eventsInNotification, eventsInNotification - (eventsSent + eventsToSend.Count), // eventsRemaining messagesInNotification, eventsToBeDiscarded, messageSequence, eventsSent, out fatalError); if (fatalError) { Debug.Trace("MailWebEventProvider", "Stop sending because we hit a fatal error"); break; } eventsSent += eventsToSend.Count; } }