Exemple #1
0
        /// <summary>
        /// The OnNext is used to publish events using Rx
        /// </summary>
        /// <param name="wspEvent">The WspEvent being published</param>
        public void OnNext(WspEvent wspEvent)
        {
            ThreadPriority threadPriority;

            WspEvent[] wspEvents = null;
            long       beginTick = DateTime.Now.Ticks;
            long       interceptorTicks;
            long       totalTicks;

            threadPriority = Thread.CurrentThread.Priority;
            Thread.CurrentThread.Priority = ThreadPriority.Lowest;

            if (Interceptor.publishInterceptor != null)
            {
                try
                {
                    if (Interceptor.publishInterceptor(wspEvent, null, out wspEvents) == false)
                    {
                        return;
                    }
                }
                catch
                {
                }
            }

            interceptorTicks = DateTime.Now.Ticks - beginTick;

            if (wspEvents == null || wspEvents.Length == 0)
            {
                pubMgr.Publish(wspEvent.SerializedEvent);
            }
            else
            {
                for (int i = 0; i < wspEvents.Length; i++)
                {
                    pubMgr.Publish(wspEvents[i].SerializedEvent);
                }
            }

            totalTicks = DateTime.Now.Ticks - beginTick;

            if (totalTicks > expectedMaxLatency)
            {
                StackTrace    st = new StackTrace(true);
                StringBuilder sb = new StringBuilder();
                sb.Append("\nEventType = ");
                sb.Append(wspEvent.EventType.ToString());
                sb.Append("\nProcessID = ");
                sb.Append(Process.GetCurrentProcess().Id.ToString());
                sb.Append("\nManagedThreadID = ");
                sb.Append(Thread.CurrentThread.ManagedThreadId.ToString());
                sb.Append("\nAppDomain = ");
                sb.Append(AppDomain.CurrentDomain.ApplicationIdentity.FullName);
                sb.Append("\nStackTrace = ");
                sb.Append(st.ToString());

                EventLog.WriteEntry("WspEventRouter", "Event publish threshold exceeded for: " + sb.ToString(), EventLogEntryType.Warning);
            }

            Thread.CurrentThread.Priority = threadPriority;
        }
Exemple #2
0
        private void ObservableThread()
        {
            WspEvent wspEvent;

            WspEvent[] wspEvents = null;

            try
            {
                while (true)
                {
                    try
                    {
                        wspEvent = this.queue.Dequeue();

                        if (wspEvent == null)
                        {
                            continue;
                        }

                        if (this.filterMethod != null)
                        {
                            if (this.filterMethod(wspEvent) == false)
                            {
                                continue;
                            }
                        }

                        if (Interceptor.subscribeInterceptor != null)
                        {
                            wspEvents = null;

                            try
                            {
                                if (Interceptor.subscribeInterceptor(wspEvent, this, out wspEvents) == false)
                                {
                                    continue;
                                }
                            }
                            catch (Exception e)
                            {
                                EventLog.WriteEntry("WspEventRouter", "Interceptor threw unhandled exception:  " + e.ToString(), EventLogEntryType.Warning);
                            }
                        }

                        List <SubscriptionObserver> observers;

                        if (wspEvents == null)
                        {
                            lock (lockObj)
                            {
                                if (observables.TryGetValue(this.id, out observers) == true)
                                {
                                    for (int i = 0; i < observers.Count; i++)
                                    {
                                        observers[i].queue.Enqueue(wspEvent, wspEvent.SerializedEvent.Length);
                                    }
                                }
                            }
                        }
                        else
                        {
                            lock (lockObj)
                            {
                                for (int x = 0; x < wspEvents.Length; x++)
                                {
                                    if (observables.TryGetValue(this.id, out observers) == true)
                                    {
                                        for (int i = 0; i < observers.Count; i++)
                                        {
                                            observers[i].queue.Enqueue(wspEvents[x], wspEvents[x].SerializedEvent.Length);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        wspEvent = null;
                    }
                    catch (Exception e)
                    {
                        EventLog.WriteEntry("WspEventRouter", "Exception processing event:  " + e.ToString(), EventLogEntryType.Warning);

                        continue;
                    }
                }
            }
            catch
            {
                // intentionally left blank
            }
        }