Esempio n. 1
0
 public ActionResult Index()
 {
     ViewModels.EventViewModel eventViewModel = new ViewModels.EventViewModel();
     eventViewModel.Events = EventCache.GetEventBag();
     return(View(eventViewModel));
 }
Esempio n. 2
0
        /// <summary>
        ///   Helper method of <see cref = "HandleRaiseEventOperation" />.
        ///   Stores an event for new actors.
        /// </summary>
        /// <param name = "actor">
        ///   The actor.
        /// </param>
        /// <param name = "raiseEventRequest">
        ///   The raise event request.
        /// </param>
        /// <param name = "eventCode">
        ///   The event code.
        /// </param>
        /// <returns>
        ///   True if <see cref = "RaiseEventRequest.Cache" /> is valid.
        /// </returns>
        protected bool UpdateEventCache(Actor actor, RaiseEventRequest raiseEventRequest, byte eventCode)
        {
            switch (raiseEventRequest.Cache)
            {
                case (byte) CacheOperation.MergeCache:
                    {
                        EventCache eventCache;
                        if (!this.cachedEvents.TryGetValue(actor.ActorNr, out eventCache))
                        {
                            eventCache = new EventCache();
                            this.cachedEvents.Add(actor.ActorNr, eventCache);
                        }

                        Hashtable @event;
                        if (eventCache.TryGetValue(eventCode, out @event))
                        {
                            // null events are removed
                            if (raiseEventRequest.Data == null)
                            {
                                eventCache.Remove(eventCode);
                            }
                            else
                            {
                                // merge or delete
                                foreach (DictionaryEntry pair in raiseEventRequest.Data)
                                {
                                    // null values are removed
                                    if (pair.Value == null)
                                    {
                                        @event.Remove(pair.Key);
                                    }
                                    else
                                    {
                                        @event[pair.Key] = pair.Value;
                                    }
                                }
                            }
                        }
                        else if (raiseEventRequest.Data != null)
                        {
                            // new
                            @event = raiseEventRequest.Data;
                            eventCache.Add(eventCode, @event);
                        }

                        return true;
                    }

                case (byte) CacheOperation.RemoveCache:
                    {
                        EventCache eventCache;
                        if (!this.cachedEvents.TryGetValue(actor.ActorNr, out eventCache))
                        {
                            return true;
                        }

                        eventCache.Remove(eventCode);
                        return true;
                    }

                case (byte) CacheOperation.ReplaceCache:
                    {
                        EventCache eventCache;
                        if (!this.cachedEvents.TryGetValue(actor.ActorNr, out eventCache))
                        {
                            eventCache = new EventCache();
                            this.cachedEvents.Add(actor.ActorNr, eventCache);
                        }

                        eventCache.Remove(eventCode);
                        if (raiseEventRequest.Data != null)
                        {
                            Hashtable @event = raiseEventRequest.Data;
                            eventCache.Add(eventCode, @event);
                        }

                        return true;
                    }

                default:
                    {
                        return false;
                    }
            }
        }
Esempio n. 3
0
 public static void TraceEvent(TraceEventType eventType, int id, string format, params object[] args)
 {
     if (UseGlobalLock)
     {
         lock (critSec) {
             if (args == null)
             {
                 foreach (TraceListener listener in Listeners)
                 {
                     listener.TraceEvent(EventCache, AppName, eventType, id, format);
                     if (AutoFlush)
                     {
                         listener.Flush();
                     }
                 }
             }
             else
             {
                 foreach (TraceListener listener in Listeners)
                 {
                     listener.TraceEvent(EventCache, AppName, eventType, id, format, args);
                     if (AutoFlush)
                     {
                         listener.Flush();
                     }
                 }
             }
         }
     }
     else
     {
         if (args == null)
         {
             foreach (TraceListener listener in Listeners)
             {
                 if (!listener.IsThreadSafe)
                 {
                     lock (listener) {
                         listener.TraceEvent(EventCache, AppName, eventType, id, format);
                         if (AutoFlush)
                         {
                             listener.Flush();
                         }
                     }
                 }
                 else
                 {
                     listener.TraceEvent(EventCache, AppName, eventType, id, format);
                     if (AutoFlush)
                     {
                         listener.Flush();
                     }
                 }
             }
         }
         else
         {
             foreach (TraceListener listener in Listeners)
             {
                 if (!listener.IsThreadSafe)
                 {
                     lock (listener) {
                         listener.TraceEvent(EventCache, AppName, eventType, id, format, args);
                         if (AutoFlush)
                         {
                             listener.Flush();
                         }
                     }
                 }
                 else
                 {
                     listener.TraceEvent(EventCache, AppName, eventType, id, format, args);
                     if (AutoFlush)
                     {
                         listener.Flush();
                     }
                 }
             }
         }
     }
     EventCache.Clear();
 }