/// \brief Constructor that accepts a Component, a RoutePointer<R, T1, T2, T3> and a RoutingEvent. /// \warning Do not pass null as any parameters.\n /// \warning Router will discard any Routes with null attributes. public Route(Component RouteSubscriber /**< Reference to the subscribing Component.\n Can be of any type derived from Component. */, RoutePointer <R, T1, T2, T3> RoutingAddress /**< Reference to a function that this route calls.\n R is return type while T1, T2 and T3 are parameter types. */, RoutingEvent Event /**< Value stating which event calls this Route. */) : this() { Subscriber = RouteSubscriber; Address = (RoutingAddress != null)? (RoutePointer <R, T1, T2, T3>)(RoutingAddress.GetInvocationList()[0]) : null; RouteEvent = Event; IsValid = ((this.Subscriber != null) && (this.Address != null) && (this.RouteEvent != RoutingEvent.Null)); }
private void ProcessRoutingEvent(RoutingEvent objRoutingEvent) { try { switch (objRoutingEvent.Code) { case enRoutingEventCodes.RoutingEventCode_Enqueued: var objRoutingEventEnqueuedEvent = objRoutingEvent as EnqueuedEvent; if (objRoutingEventEnqueuedEvent != null) { _logger.Info("RoutingEvent Enqueued ## CallID: " + objRoutingEventEnqueuedEvent.CallID + " Description: " + objRoutingEventEnqueuedEvent.Description + " Priority: " + objRoutingEventEnqueuedEvent.Priority); string[] row = { objRoutingEventEnqueuedEvent.CallID, "Not Assigned", "Wait" }; callDetailGridEvent?.Invoke(row, objRoutingEventEnqueuedEvent.CallID); lock (activeCallsDict) activeCallsDict.Add(objRoutingEventEnqueuedEvent.CallID, "Enqued"); } break; case enRoutingEventCodes.RoutingEventCode_Dequeued: var objRoutingEventDequeuedEvent = objRoutingEvent as DequeuedEvent; _logger.Info("RoutingEvent Dequeued ## ContactId: " + objRoutingEventDequeuedEvent.CallID + " Description: " + objRoutingEventDequeuedEvent.Description + " Priority: " + objRoutingEventDequeuedEvent.Priority + " DequeueReason: " + objRoutingEventDequeuedEvent.DequeueReason); break; case enRoutingEventCodes.RoutingEventCode_Assigned: var objRoutingEventAssignedEvent = objRoutingEvent as AssignedEvent; // processRingingEvent(objRoutingEventAssignedEvent); break; } } catch (Exception ex) { _logger.Error("Exception in ProcessRoutingEvent " + ex); } }
/// \brief Broadcasts a message to this and all children of this GameObject. /// \note This function is recursive. public void BroadcastDownwards(RoutingEvent EventType) { if (TablesExist && KeyHasAddress(EventType)) { PointerTable[EventType](); } else { PrintWarning("[" + this + "] Cannot broadcast messages as no routes are registered under event " + EventType + ".", this); } for (int i = 0; i < this.transform.childCount; i++) { Transform Child = this.transform.GetChild(i); Hub ChildHub = Hub.GetHub(Child); if (ChildHub != null) { ChildHub.BroadcastDownwards(EventType); } /* else * { * UseTempHub(Child, EventType); * } */ } }
/** \brief Constructor that constructs a new AreaMessage from a RoutingEvent and another AreaMessage. */ public AreaMessage(RoutingEvent Event, AreaMessage AM) : this() { Origin = AM.Origin; Radius = AM.Radius; EventType = Event; DoRayCheck = AM.DoRayCheck; UseInverse = AM.UseInverse; }
/** \brief Constructor that constructs a new AreaMessage from a Vector3 and another AreaMessage. */ public AreaMessage(Vector3 OriginCoord, AreaMessage AM) : this() { Origin = OriginCoord; Radius = AM.Radius; EventType = AM.EventType; DoRayCheck = AM.DoRayCheck; UseInverse = AM.UseInverse; }
private void UseTempHub(Transform TR, RoutingEvent EventType) { if (TR != null) { Hub TempHub = Hub.GetOrAddHub(TR); TempHub.BroadcastDownwards(EventType); Component.Destroy(TempHub, 0f); } }
/// \internal Janitorial Functions private static void CleanDeadRoutes(RoutingEvent EventType) { if (TablesExist && EventIsPopulated(EventType) && TableIsPolluted(EventType)) { Route <R>[] DeadRoutes = Array.FindAll(RouteTable[EventType].ToArray(), x => x.IsDead); Array.ForEach(DeadRoutes, x => { DeregisterRoute(x); DetachAddress(x); }); TablesExist = (TablesExist? DeconstructTables() : TablesExist); } }
/** \brief Routes a message to inactive subscribers. */ public void RouteMessageInactiveObjects(RoutingEvent EventType /**< Type of event to send. */) { CleanDeadRoutes(EventType); if (TableExists && EventIsPopulated(EventType)) { RouteTable[EventType].ForEach(SendInactive); } }
private void CleanDeadRoutes(RoutingEvent EventType) { if (TableExists && EventIsPopulated(EventType)) { RouteTable[EventType].ForEach(PruneDead); } DeleteEmptyTable(); }
/** \brief Routes a message of the specified event to all subscribers. */ public void RouteMessage(RoutingEvent EventType /**< Type of event to send. */) { CleanDeadRoutes(EventType); if (TableExists && EventIsPopulated(EventType)) { RouteTable[EventType].ForEach(x => x.Address()); } }
/** \brief Standard constructor for new AreaMessages. */ public AreaMessage(Vector3 OriginCoord, float AreaRadius, RoutingEvent Event) : this() { float AbsR = Mathf.Abs(AreaRadius); Origin = OriginCoord; Radius = (AbsR < 0.5f)? 0.5f : AbsR; EventType = Event; DoRayCheck = false; UseInverse = false; }
/** \brief Routes a message to active subscribers. */ /// \returns Enqueues all returned data from subscribers of this event type in the specified queue.\n /// \returns Enqueues nothing if the message cannot be sent. public static void RouteMessageActiveObjects(RoutingEvent EventType /**< Type of event to send. */, Queue <R> OutputQueue /**< Queue to output returned values into. */) { CleanDeadRoutes(EventType); if (TablesExist && EventIsPopulated(EventType)) { List <Route <R> > RPL = RouteTable[EventType].FindAll(x => x.Subscriber.gameObject.activeInHierarchy); RPL.ForEach(x => OutputQueue.Enqueue(x.Address())); } }
/// \internal Janitorial Functions private static void CleanDeadRoutes(RoutingEvent EventType) { if (!RouteTable[EventType].TrueForAll(x => x.Subscriber != null)) { Route <R, T1, T2, T3>[] DeadRoutes = RouteTable[EventType].ToArray(); DeadRoutes = Array.FindAll(DeadRoutes, x => x.Subscriber == null); Array.ForEach(DeadRoutes, x => { DeregisterRoute(x); DetachAddress(x); }); TablesExist = (TablesExist? DeconstructTables() : TablesExist); } }
/** \brief Constructor that constructs a new AreaMessage from a float and another AreaMessage. */ public AreaMessage(float AreaRadius, AreaMessage AM) : this() { float AbsR = Mathf.Abs(AreaRadius); Origin = AM.Origin; Radius = (AbsR < 0.5f)? 0.5f : AbsR; EventType = AM.EventType; DoRayCheck = AM.DoRayCheck; UseInverse = AM.UseInverse; }
/// \brief Broadcasts a message to all registered components on this GameObject. public void Broadcast(RoutingEvent EventType) { if (TablesExist && KeyHasAddress(EventType)) { PointerTable[EventType](); } else { PrintWarning("[" + this + "] Cannot broadcast messages as no routes are registered under event " + EventType + ".", this); } }
/// \brief Constructor that accepts a Component, a RoutePointer and a RoutingEvent. /// \warning Do not pass null as any parameters.\n /// \warning Router will discard any Routes with null attributes. public Route(Component RouteSubscriber /**< Reference to the subscribing Component.\n Can be of any type derived from Component. */, RoutePointer RoutingAddress /**< Reference to a function that this route calls.\n Must return void and accept no parameters. */, RoutingEvent Event /**< Value stating which event calls this Route. */) : this() { Subscriber = RouteSubscriber; RouteEvent = Event; Address = (RoutingAddress != null)? (RoutePointer)(RoutingAddress.GetInvocationList()[0]) : null; IsValid = (this.Subscriber != null) && (this.Address != null) && (((Component)this.Address.Target) == this.Subscriber) && (this.RouteEvent != RoutingEvent.Null); }
/// \brief Routes a message of the specified event to all subscribers and adds their values to the specified queue. /// \returns Enqueues all returned data from subscribers of this event type in the specified queue.\n /// \returns Enqueues nothing if the message cannot be sent. public static void RouteMessage(RoutingEvent EventType /**< Type of event to send. */, Queue <R> OutputQueue /**< Queue to output returned values into. */) { CleanDeadRoutes(EventType); if (TablesExist && KeyHasAddress(EventType) && EventIsRegistered(EventType)) { Delegate[] RPL = PointerTable[EventType].GetInvocationList(); for (int i = 0; i < RPL.Length; i++) { OutputQueue.Enqueue((RPL[i] as RoutePointer <R>)()); } } }
/** \brief Routes a message to active subscribers. */ /// \returns Adds all returned data from subscribers of this event type to the specified list.\n /// \returns Assigns null to OutputList if the message cannot be sent. public static void RouteMessageActiveObjects(RoutingEvent EventType /**< Type of event to send. */, out List <R> OutputList /**< List to output returned values into. */) { CleanDeadRoutes(EventType); OutputList = null; if (TablesExist && EventIsPopulated(EventType)) { List <Route <R> > RPL = RouteTable[EventType].FindAll(x => x.Subscriber.gameObject.activeInHierarchy); OutputList = new List <R>(RPL.Count); for (int i = 0; i < RPL.Count; i++) { OutputList.Add(RPL[i].Address()); } OutputList.TrimExcess(); } }
/// \brief Routes a message of the specified event to all subscribers and returns their values in the specified list. /// \returns Adds all returned data from subscribers of this event type to the specified list.\n /// \returns Assigns null to OutputList if the message cannot be sent. public static void RouteMessage(RoutingEvent EventType /**< Type of event to send. */, out List <R> OutputList /**< List to output returned values into. */) { CleanDeadRoutes(EventType); OutputList = null; if (TablesExist && KeyHasAddress(EventType) && EventIsRegistered(EventType)) { Delegate[] RPL = PointerTable[EventType].GetInvocationList(); OutputList = new List <R>(RPL.Length); for (int i = 0; i < RPL.Length; i++) { OutputList.Add((RPL[i] as RoutePointer <R>)()); } OutputList.TrimExcess(); } }
/// \brief Broadcasts a message to this and all parents of this GameObject. /// \note This function is recursive. public void BroadcastUpwards(RoutingEvent EventType) { if (TablesExist && KeyHasAddress(EventType)) { PointerTable[EventType](); } else { PrintWarning("[" + this + "] Cannot broadcast messages as no routes are registered under event " + EventType + ".", this); } Hub ParentHub = Hub.GetHub(this.transform.parent); if (ParentHub != null) { ParentHub.BroadcastUpwards(EventType); } }
/** \brief Returns the amount of Routes registered with the Router under the specified event. */ /// \returns Returns the quantity of routes registered under the passed event type. /// \returns If Null is passed as event type then the total quantity for all events is returned. public int RouteCount(RoutingEvent EventType) { int EventRoutes = 0; if (TableExists && (EventType != RoutingEvent.Null) && EventIsPopulated(EventType)) { EventRoutes = RouteTable[EventType].Count; } if (TableExists && (EventType == RoutingEvent.Null)) { List <Route>[] Lists = new List <Route> [RouteTable.Values.Count]; RouteTable.Values.CopyTo(Lists, 0); Array.ForEach(Lists, x => EventRoutes += x.Count); } return(EventRoutes); }
/** \brief Routes a message to active subscribers. */ /// \returns Returns a List<R> containing all returned data from subscribers of this event type.\n /// \returns Otherwise returns null if the message cannot be sent. public static List <R> RouteMessageActiveObjects(RoutingEvent EventType /**< Type of event to send. */) { CleanDeadRoutes(EventType); List <R> Results = null; if (TablesExist && EventIsPopulated(EventType)) { List <Route <R> > RPL = RouteTable[EventType].FindAll(x => x.Subscriber.gameObject.activeInHierarchy); Results = new List <R>(RPL.Count); for (int i = 0; i < RPL.Count; i++) { Results.Add(RPL[i].Address()); } Results.TrimExcess(); } return(Results); }
/// \brief Routes a message of the specified event to all subscribers and returns their values. /// \returns Returns a List<R> containing all returned data from subscribers of this event type.\n /// \returns Otherwise returns null if the message cannot be sent. public static List <R> RouteMessage(RoutingEvent EventType /**< Type of event to send. */) { CleanDeadRoutes(EventType); List <R> Results = null; if (TablesExist && KeyHasAddress(EventType) && EventIsRegistered(EventType)) { Delegate[] RPL = PointerTable[EventType].GetInvocationList(); Results = new List <R>(RPL.Length); for (int i = 0; i < RPL.Length; i++) { Results.Add((RPL[i] as RoutePointer <R>)()); } Results.TrimExcess(); } return(Results); }
/** \brief Routes a message of the specified event to all subscribers and returns their values. */ /// \returns Returns a List<R> containing all return data from subscribers of this event type.\n /// \returns Otherwise returns null if the message cannot be sent. public static List <R> RouteMessage(RoutingEvent EventType /**< Type of event to send. */, T Parameter) { if (TablesExist && KeyHasValue(EventType) && EventIsRegistered(EventType)) { CleanDeadRoutes(EventType); Delegate[] RPL = PointerTable[EventType].GetInvocationList(); R[] Results = new R[RPL.Length]; for (int i = 0; i < RPL.Length; i++) { Results[i] = (RPL[i] as RoutePointer <R, T>)(Parameter); } return(new List <R>(Results)); } else { return(null); } }
/** \brief Routes a message of the specified event to all subscribers and returns their values. */ /// \returns Returns a List<R> containing all return data from subscribers of this event type.\n /// \returns Otherwise returns null if the message cannot be sent. public static List <R> RouteMessage(RoutingEvent EventType /**< Type of event to send. */, RouteParameters <T1, T2, T3> Parameters /**< Struct containing parameters to pass to recipients. */) { if (TablesExist && KeyHasValue(EventType) && EventIsRegistered(EventType)) { CleanDeadRoutes(EventType); Delegate[] RPL = PointerTable[EventType].GetInvocationList(); R[] Results = new R[RPL.Length]; for (int i = 0; i < RPL.Length; i++) { Results[i] = (RPL[i] as RoutePointer <R, T1, T2, T3>)(Parameters.FirstParameter, Parameters.SecondParameter, Parameters.ThirdParameter); } return(new List <R>(Results)); } else { return(null); } }
private bool KeyHasAddress(RoutingEvent EventType) { return(PointerTable.ContainsKey(EventType) && (PointerTable[EventType] != null)); }
/// \internal Misc Functions private static bool KeyHasValue(RoutingEvent EventType) { return(PointerTable.ContainsKey(EventType) && (PointerTable[EventType] != null)); }
public void Update() { Event = (RoutingEvent)Enum.Parse(typeof(RoutingEvent), RNG.Next(1, 17).ToString()); RTR.RouteMessage(Event); }
/** \brief Routes a message of the specified event to the specified GameObject and its children. */ /// Both direct and indirect children of the specified GameObject receive the event.\n /// \returns Returns a List<R> containing all return data from subscribers of this event type.\n /// \returns Otherwise returns null if the message cannot be sent. /// \note Only works for subscribed GameObjects. Children must be subscribed as-well in order to receive the event. public static List <R> RouteMessageDescendants(GameObject Scope /**< GameObject specifying the scope of the message. */, RoutingEvent EventType /**< Type of event to send. */, RouteParameters <T1, T2, T3> Parameters /**< Struct containing parameters to pass to recipients. */) { if (TablesExist && ScopeIsValid(Scope) && EventIsRegistered(EventType)) { CleanDeadRoutes(EventType); List <Route <R, T1, T2, T3> > RT = RouteTable[EventType].FindAll(x => x.Subscriber.transform.IsChildOf(Scope.transform)); R[] Results = new R[RT.Count]; for (int i = 0; i < RT.Count; i++) { Results[i] = RT[i].Address(Parameters.FirstParameter, Parameters.SecondParameter, Parameters.ThirdParameter); } return(new List <R>(Results)); } else { return(null); } }
private static bool EventIsRegistered(RoutingEvent EventType) { return(RouteTable.ContainsKey(EventType) && (RouteTable[EventType] != null) && (RouteTable[EventType].Count >= 1)); }