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 void onMascotAudioComplete(EventNotificationType type, string eventName, object info, GameObject gameObject) { if (eventName == AudioEventName.Value && type == EventNotificationType.OnFinished) { Service.Get <EventDispatcher>().DispatchEvent(default(QuestEvents.MascotAudioComplete)); } }
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); } }
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); } }
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); } }
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; }
public void OnEventNotify(EventNotificationType type, string eventName, object info, GameObject gameObject) { if (_stopping) { currentIndex = 0; return; } EventNotificationType eventNotificationType = (currentIndex != 0) ? events[currentIndex - 1].notificationType : notificationType; if (type == eventNotificationType) { PostEvent(GetNextEventName()); } }
public void dialogAudioCallback(EventNotificationType type, string eventName, object info, GameObject gameObject) { if (autoStopDialogAnim && eventName == currentAudioEvent && type == EventNotificationType.OnFinished) { Service.Get <EventDispatcher>().DispatchEvent(default(QuestEvents.MascotAudioComplete)); if (string.IsNullOrEmpty(overrideStopAnimationName)) { PlayIdleAnimation(); } else { playDialogAnimation(Animator.StringToHash(overrideStopAnimationName)); } } }
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"); } }
/// <summary> /// Processes the events. /// </summary> private void ProcessEvents() { while (true) { EventAction action = null; lock (eventLock) { if (eventQueue.Count > 0) { PriorityQueueItem <EventAction, EventPriority> eventItem = eventQueue.Dequeue(); action = eventItem.Value; if (action == null) { return; } } } if (action != null) { log.Info(string.Format("Processing events {0} from {1}", action.Notification, action.Computer)); // Start processing events EventNotificationType notificationType = (EventNotificationType)StringEnum.Parse(typeof(EventNotificationType), action.Notification); if (notificationType == EventNotificationType.NewMessage) { log.Info("New messages arrived"); RefreshMessageView(ViewAction.RefreshInbox); } } else { eventTrigger.WaitOne(); // wait for events } } }
// This method can be called by the timer, or by AddEvent. // // Basic design: // - We have one timer, and one buffer. // - We flush periodically every _regularFlushIntervalMs ms // - But if # of items in buffer has reached _urgentFlushThreshold, we will flush more frequently, // but at most once every _urgentFlushIntervalMs ms. However, these urgent flushes will not // prevent the regular flush from happening. // - We never flush synchronously, meaning if we're called by AddEvent and decide to flush // because we've reached the _urgentFlushThreshold, we will still use the timer thread // to flush the buffer. // - At any point only a maximum of _maxBufferThreads threads can be flushing. If exceeded, // we will delay a flush. // // // For example, let's say we have this setting: // "1 minute urgentFlushInterval and 5 minute regularFlushInterval" // // Assume regular flush timer starts at 10:00am. It means regular // flush will happen at 10:05am, 10:10am, 10:15am, and so on, // regardless of when urgent flush happens. // // An "urgent flush" happens whenever urgentFlushThreshold is reached. // However, when we schedule an "urgent flush", we ensure that the time // between an urgent flush and the last flush (no matter it's urgent or // regular) will be at least urgentFlushInterval. // // One interesting case here. Assume at 10:49:30 we had an urgent // flush, but the # of events left is still above urgentFlushThreshold. // You may think we'll schedule the next urgent flush at 10:50:30 // (urgentFlushInterval == 1 min). However, because we know we will // have a regular flush at 10:50:00, we won't schedule the next urgent // flush. Instead, during the regular flush at 10:50:00 happens, we'll // check if there're still too many events; and if so, we will schedule // the next urgent flush at 10:51:00. // internal void Flush(int max, FlushCallReason reason) { WebBaseEvent[] events = null; DateTime nowUtc = DateTime.UtcNow; long waitTime = 0; DateTime lastFlushTime = DateTime.MaxValue; int discardedSinceLastFlush = -1; int eventsInBuffer = -1; int toFlush = 0; EventNotificationType notificationType = EventNotificationType.Regular; // By default, this call will flush, but will not schedule the next flush. bool flushThisTime = true; bool scheduleNextFlush = false; bool nextFlushIsUrgent = false; lock (_buffer) { Debug.Assert(max > 0, "max > 0"); if (_buffer.Count == 0) { // We have nothing in the buffer. Don't flush this time. Debug.Trace("WebEventBufferExtended", "Flush: buffer is empty, don't flush"); flushThisTime = false; } switch (reason) { case FlushCallReason.StaticFlush: // It means somebody calls provider.Flush() break; case FlushCallReason.Timer: // It's a callback from a timer. We will schedule the next regular flush if needed. if (_regularFlushIntervalMs != Infinite) { scheduleNextFlush = true; waitTime = GetNextRegularFlushDueTimeInMs(); } break; case FlushCallReason.UrgentFlushThresholdExceeded: // It means this method is called by AddEvent because the urgent flush threshold is reached. // If an urgent flush has already been scheduled by someone else, we don't need to duplicate the // effort. Just return. if (_urgentFlushScheduled) { return; } // Flush triggered by AddEvent isn't synchronous, so we won't flush this time, but will // schedule an urgent flush instead. flushThisTime = false; scheduleNextFlush = true; nextFlushIsUrgent = true; // Calculate how long we have to wait when scheduling the flush if (AnticipateBurst(nowUtc)) { Debug.Trace("WebEventBuffer", "Flush: Called by AddEvent. Waiting for burst"); waitTime = _burstWaitTimeMs; } else { Debug.Trace("WebEventBuffer", "Flush: Called by AddEvent. Schedule an immediate flush"); waitTime = 0; } // Have to wait longer because of _urgentFlushIntervalMs long msSinceLastScheduledFlush = (long)(nowUtc - _lastScheduledFlushTime).TotalMilliseconds; if (msSinceLastScheduledFlush + waitTime < _urgentFlushIntervalMs) { Debug.Trace("WebEventBuffer", "Flush: Called by AddEvent. Have to wait longer because of _urgentFlushIntervalMs."); waitTime = _urgentFlushIntervalMs - msSinceLastScheduledFlush; } Debug.Trace("WebEventBuffer", "Wait time=" + waitTime + "; nowUtc=" + PrintTime(nowUtc) + "; _lastScheduledFlushTime=" + PrintTime(_lastScheduledFlushTime) + "; _urgentFlushIntervalMs=" + _urgentFlushIntervalMs); break; } Debug.Trace("WebEventBuffer", "Flush called: max=" + max + "; reason=" + reason); if (flushThisTime) { // Check if we've exceeded the # of flushing threads. If so, // don't flush this time. if (_threadsInFlush >= _maxBufferThreads) { // Won't set flushThisTime to false because we depend on // the logic inside the next "if" block to schedule the // next urgent flush as needed. toFlush = 0; } else { toFlush = Math.Min(_buffer.Count, max); } } #if DBG DebugUpdateStats(flushThisTime, nowUtc, toFlush, reason); #endif if (flushThisTime) { Debug.Assert(reason != FlushCallReason.UrgentFlushThresholdExceeded, "reason != FlushCallReason.UrgentFlushThresholdExceeded"); if (toFlush > 0) { // Move the to-be-flushed events to an array events = new WebBaseEvent[toFlush]; for (int i = 0; i < toFlush; i++) { events[i] = (WebBaseEvent)_buffer.Dequeue(); } lastFlushTime = _lastFlushTime; // Update _lastFlushTime and _lastScheduledFlushTime. // These information are used when Flush is called the next time. _lastFlushTime = nowUtc; if (reason == FlushCallReason.Timer) { _lastScheduledFlushTime = nowUtc; } discardedSinceLastFlush = _discardedSinceLastFlush; _discardedSinceLastFlush = 0; if (reason == FlushCallReason.StaticFlush) { notificationType = EventNotificationType.Flush; } else { Debug.Assert(!(!_regularTimeoutUsed && !_urgentFlushScheduled), "It's impossible to have a non-regular flush and yet the flush isn't urgent"); notificationType = _regularTimeoutUsed ? EventNotificationType.Regular : EventNotificationType.Urgent; } } eventsInBuffer = _buffer.Count; // If we still have at least _urgentFlushThreshold left, set timer // to flush asap. if (eventsInBuffer >= _urgentFlushThreshold) { Debug.Trace("WebEventBuffer", "Flush: going to flush " + toFlush + " events, but still have at least _urgentFlushThreshold left. Schedule a flush"); scheduleNextFlush = true; nextFlushIsUrgent = true; waitTime = _urgentFlushIntervalMs; } else { Debug.Trace("WebEventBuffer", "Flush: going to flush " + toFlush + " events"); } } // We are done moving the flushed events to the 'events' array. // Now schedule the next flush if needed. _urgentFlushScheduled = false; if (scheduleNextFlush) { if (nextFlushIsUrgent) { long nextRegular = GetNextRegularFlushDueTimeInMs(); // If next regular flush is closer than next urgent flush, // use regular flush instead. if (nextRegular < waitTime) { Debug.Trace("WebEventBuffer", "Switch to use regular timeout"); waitTime = nextRegular; _regularTimeoutUsed = true; } else { _regularTimeoutUsed = false; } } else { _regularTimeoutUsed = true; } SetTimer(waitTime); _urgentFlushScheduled = nextFlushIsUrgent; #if DBG Debug.Trace("WebEventBuffer", "Flush: Registered for a flush. Waittime = " + waitTime + "ms" + "; _nextFlush=" + PrintTime(_nextFlush) + "; _urgentFlushScheduled=" + _urgentFlushScheduled); #endif } // Cleanup. If we are called by a timer callback, but we haven't scheduled for the next // one (can only happen if _regularFlushIntervalMs == Infinite), we should dispose the timer if (reason == FlushCallReason.Timer && !scheduleNextFlush) { Debug.Trace("WebEventBuffer", "Flush: Disposing the timer"); Debug.Assert(_regularFlushIntervalMs == Infinite, "We can dispose the timer only if _regularFlushIntervalMs == Infinite"); ((IDisposable)_timer).Dispose(); _timer = null; _urgentFlushScheduled = false; } // We want to increment the thread count within the lock to ensure we don't let too many threads in if (events != null) { Interlocked.Increment(ref _threadsInFlush); } } // Release lock // Now call the providers to flush the events if (events != null) { Debug.Assert(lastFlushTime != DateTime.MaxValue, "lastFlushTime != DateTime.MaxValue"); Debug.Assert(discardedSinceLastFlush != -1, "discardedSinceLastFlush != -1"); Debug.Assert(eventsInBuffer != -1, "eventsInBuffer != -1"); Debug.Trace("WebEventBufferSummary", "_threadsInFlush=" + _threadsInFlush); using (new ApplicationImpersonationContext()) { try { WebEventBufferFlushInfo flushInfo = new WebEventBufferFlushInfo( new WebBaseEventCollection(events), notificationType, Interlocked.Increment(ref _notificationSequence), lastFlushTime, discardedSinceLastFlush, eventsInBuffer); _flushCallback(flushInfo); } catch (Exception e) { try { _provider.LogException(e); } catch { // Ignore all errors } } #pragma warning disable 1058 catch { // non compliant exceptions are caught and logged as Unknown try { _provider.LogException(new Exception(SR.GetString(SR.Provider_Error))); } catch { // Ignore all errors } } #pragma warning restore 1058 } Interlocked.Decrement(ref _threadsInFlush); } }
internal void Flush(int max, FlushCallReason reason) { WebBaseEvent[] events = null; DateTime utcNow = DateTime.UtcNow; long waitTimeMs = 0L; DateTime maxValue = DateTime.MaxValue; int eventsDiscardedSinceLastNotification = -1; int eventsInBuffer = -1; int num4 = 0; EventNotificationType regular = EventNotificationType.Regular; bool flag = true; bool flag2 = false; bool flag3 = false; lock (this._buffer) { if (this._buffer.Count == 0) { flag = false; } switch (reason) { case FlushCallReason.UrgentFlushThresholdExceeded: if (!this._urgentFlushScheduled) { break; } return; case FlushCallReason.Timer: if (this._regularFlushIntervalMs != Infinite) { flag2 = true; waitTimeMs = this.GetNextRegularFlushDueTimeInMs(); } goto Label_00D3; default: goto Label_00D3; } flag = false; flag2 = true; flag3 = true; if (this.AnticipateBurst(utcNow)) { waitTimeMs = this._burstWaitTimeMs; } else { waitTimeMs = 0L; } TimeSpan span = (TimeSpan)(utcNow - this._lastScheduledFlushTime); long totalMilliseconds = (long)span.TotalMilliseconds; if ((totalMilliseconds + waitTimeMs) < this._urgentFlushIntervalMs) { waitTimeMs = this._urgentFlushIntervalMs - totalMilliseconds; } Label_00D3: if (flag) { if (this._threadsInFlush >= this._maxBufferThreads) { num4 = 0; } else { num4 = Math.Min(this._buffer.Count, max); } } if (flag) { if (num4 > 0) { events = new WebBaseEvent[num4]; for (int i = 0; i < num4; i++) { events[i] = (WebBaseEvent)this._buffer.Dequeue(); } maxValue = this._lastFlushTime; this._lastFlushTime = utcNow; if (reason == FlushCallReason.Timer) { this._lastScheduledFlushTime = utcNow; } eventsDiscardedSinceLastNotification = this._discardedSinceLastFlush; this._discardedSinceLastFlush = 0; if (reason == FlushCallReason.StaticFlush) { regular = EventNotificationType.Flush; } else { regular = this._regularTimeoutUsed ? EventNotificationType.Regular : EventNotificationType.Urgent; } } eventsInBuffer = this._buffer.Count; if (eventsInBuffer >= this._urgentFlushThreshold) { flag2 = true; flag3 = true; waitTimeMs = this._urgentFlushIntervalMs; } } this._urgentFlushScheduled = false; if (flag2) { if (flag3) { long nextRegularFlushDueTimeInMs = this.GetNextRegularFlushDueTimeInMs(); if (nextRegularFlushDueTimeInMs < waitTimeMs) { waitTimeMs = nextRegularFlushDueTimeInMs; this._regularTimeoutUsed = true; } else { this._regularTimeoutUsed = false; } } else { this._regularTimeoutUsed = true; } this.SetTimer(waitTimeMs); this._urgentFlushScheduled = flag3; } if ((reason == FlushCallReason.Timer) && !flag2) { this._timer.Dispose(); this._timer = null; this._urgentFlushScheduled = false; } if (events != null) { Interlocked.Increment(ref this._threadsInFlush); } } if (events != null) { ApplicationImpersonationContext context = new ApplicationImpersonationContext(); try { WebEventBufferFlushInfo flushInfo = new WebEventBufferFlushInfo(new WebBaseEventCollection(events), regular, Interlocked.Increment(ref this._notificationSequence), maxValue, eventsDiscardedSinceLastNotification, eventsInBuffer); this._flushCallback(flushInfo); } catch (Exception exception) { try { this._provider.LogException(exception); } catch { } } catch { try { this._provider.LogException(new Exception(System.Web.SR.GetString("Provider_Error"))); } catch { } } finally { if (context != null) { ((IDisposable)context).Dispose(); } } Interlocked.Decrement(ref this._threadsInFlush); } }
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; }
public NexoEvent() { Request.MessageHeader.MessageType = MessageTypeEnumeration.Notification.ToString(); RequestItem = new EventNotificationType(); ReplyItem = null; }