/// <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> /// <returns> /// True if <see cref = "RaiseEventRequest.Cache" /> is valid. /// </returns> protected bool UpdateEventCache(Actor actor, RaiseEventRequest raiseEventRequest) { CustomEvent customEvent; switch (raiseEventRequest.Cache) { case (byte)CacheOperation.AddToRoomCache: customEvent = new CustomEvent(actor.ActorNr, raiseEventRequest.EvCode, raiseEventRequest.Data) { Cache = raiseEventRequest.Cache }; this.eventCache.AddEvent(customEvent); return true; case (byte)CacheOperation.AddToRoomCacheGlobal: customEvent = new CustomEvent(0, raiseEventRequest.EvCode, raiseEventRequest.Data) { Cache = raiseEventRequest.Cache }; this.eventCache.AddEvent(customEvent); return true; case (byte)CacheOperation.MergeCache: { EventCache eventCache; if (!this.eventCacheOld.TryGetValue(actor.ActorNr, out eventCache)) { eventCache = new EventCache(); this.eventCacheOld.Add(actor.ActorNr, eventCache); } Hashtable @event; if (eventCache.TryGetValue(raiseEventRequest.EvCode, out @event)) { // null events are removed if (raiseEventRequest.Data == null) { eventCache.Remove(raiseEventRequest.EvCode); } 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(raiseEventRequest.EvCode, @event); } return true; } case (byte)CacheOperation.RemoveCache: { EventCache eventCache; if (!this.eventCacheOld.TryGetValue(actor.ActorNr, out eventCache)) { return true; } eventCache.Remove(raiseEventRequest.EvCode); return true; } case (byte)CacheOperation.ReplaceCache: { EventCache eventCache; if (!this.eventCacheOld.TryGetValue(actor.ActorNr, out eventCache)) { eventCache = new EventCache(); this.eventCacheOld.Add(actor.ActorNr, eventCache); } eventCache.Remove(raiseEventRequest.EvCode); if (raiseEventRequest.Data != null) { Hashtable @event = raiseEventRequest.Data; eventCache.Add(raiseEventRequest.EvCode, @event); } return true; } default: { return false; } } }
/// <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> /// <returns> /// True if <see cref = "RaiseEventRequest.Cache" /> is valid. /// </returns> protected bool UpdateEventCache(Actor actor, RaiseEventRequest raiseEventRequest) { CustomEvent customEvent; switch (raiseEventRequest.Cache) { case (byte)CacheOperation.AddToRoomCache: customEvent = new CustomEvent(actor.ActorNr, raiseEventRequest.EvCode, raiseEventRequest.Data) { Cache = raiseEventRequest.Cache }; this.eventCache.AddEvent(customEvent); return(true); case (byte)CacheOperation.AddToRoomCacheGlobal: customEvent = new CustomEvent(0, raiseEventRequest.EvCode, raiseEventRequest.Data) { Cache = raiseEventRequest.Cache }; this.eventCache.AddEvent(customEvent); return(true); case (byte)CacheOperation.MergeCache: { EventCache eventCache; if (!this.eventCacheOld.TryGetValue(actor.ActorNr, out eventCache)) { eventCache = new EventCache(); this.eventCacheOld.Add(actor.ActorNr, eventCache); } Hashtable @event; if (eventCache.TryGetValue(raiseEventRequest.EvCode, out @event)) { // null events are removed if (raiseEventRequest.Data == null) { eventCache.Remove(raiseEventRequest.EvCode); } 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(raiseEventRequest.EvCode, @event); } return(true); } case (byte)CacheOperation.RemoveCache: { EventCache eventCache; if (!this.eventCacheOld.TryGetValue(actor.ActorNr, out eventCache)) { return(true); } eventCache.Remove(raiseEventRequest.EvCode); return(true); } case (byte)CacheOperation.ReplaceCache: { EventCache eventCache; if (!this.eventCacheOld.TryGetValue(actor.ActorNr, out eventCache)) { eventCache = new EventCache(); this.eventCacheOld.Add(actor.ActorNr, eventCache); } eventCache.Remove(raiseEventRequest.EvCode); if (raiseEventRequest.Data != null) { Hashtable @event = raiseEventRequest.Data; eventCache.Add(raiseEventRequest.EvCode, @event); } return(true); } default: { return(false); } } }