/// <summary> /// Add the IrecieveMessageEntity in a tag (create the tag if doesnt exists) /// </summary> /// <param name="tag"></param> /// <param name="Agente"></param> public void AddgrouptagRecieveEntity(string tag, IRecieveMessageEntity Agente) { System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(tag)); System.Diagnostics.Debug.Assert(Agente != null); if (!IdEntity.ContainsKey(Agente.GetId())) { throw new Exception("The following instance is not in the mapper, add it beforing calling this: " + Agente.ToString()); } if (tagRecieveEntity.ContainsKey(tag)) { tagRecieveEntity[tag].Add(Agente); } else { WeakList <IRecieveMessageEntity> l = new WeakList <IRecieveMessageEntity>(); l.Add(Agente); tagRecieveEntity.Add(tag, l); } if (recieveEntityTag.ContainsKey(Agente.GetId())) { recieveEntityTag[Agente.GetId()].Add(tag); } else { recieveEntityTag[Agente.GetId()] = new List <string>(); recieveEntityTag[Agente.GetId()].Add(tag); } }
/// <summary> /// Remove the entity /// THE ID USED BY THIS ENTITY WILL NOT USED AGAIN (EVEN AFTER THE REMOVE) /// </summary> /// <param name="cod">id</param> /// <returns></returns> public bool RemoveEntity(long cod) { if (IdEntity.ContainsKey(cod)) { IdEntity.Remove(cod); if (IdRecieveEntity.ContainsKey(cod)) { IRecieveMessageEntity irent = IdRecieveEntity[cod].Target; if (irent == null) { IdRecieveEntity.Remove(cod); return(false); } IList <String> tags = null; bool found = recieveEntityTag.TryGetValue(irent.GetId(), out tags); if (found) { foreach (String var in tags) { tagRecieveEntity[var].Remove(irent); } recieveEntityTag.Remove(irent.GetId()); } IdRecieveEntity.Remove(cod); } } else { return(false); } return(true); }
/// <summary> /// Remove one IRecieveMessageEntity from a tag /// </summary> /// <param name="tag"></param> /// <param name="Agente"></param> public void RemovegrouptagRecieveEntity(string tag, IRecieveMessageEntity Agente) { System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(tag)); System.Diagnostics.Debug.Assert(Agente != null); if (tagRecieveEntity.ContainsKey(tag)) { tagRecieveEntity[tag].Remove(Agente); } }
/// <summary> /// return a RecieverMessageEntity by ID /// </summary> /// <param name="id">id</param> /// <returns></returns> public IRecieveMessageEntity getRecieveEntity(long id) { if (IdRecieveEntity.ContainsKey(id)) { IRecieveMessageEntity IRecieveMessageEntity = IdRecieveEntity[id].Target; if (IRecieveMessageEntity != null) { return(IRecieveMessageEntity); } } throw new Exception("Reference not found for ID" + id); }
/// <summary> /// return all IRecieveMessageEntity entities /// </summary> /// <returns></returns> public ICollection <IRecieveMessageEntity> GetAllRecieveEntities() { List <IRecieveMessageEntity> IRecieveMessageEntity = new List <IRecieveMessageEntity>(); foreach (var item in IdRecieveEntity.Values) { IRecieveMessageEntity i = item.Target; if (i != null) { IRecieveMessageEntity.Add(i); } } return(IRecieveMessageEntity); }
private static void deliver(Message m) { if (m.Tag != null) { if (m.Tag == SendToALLTag) { foreach (IRecieveMessageEntity var in EntityMapper.getInstance().GetAllRecieveEntities()) { if (var.HandleThisMessageType(m.SenderType) != false) { var.HandleMessage(m); } } return; } IList <IRecieveMessageEntity> list = EntityMapper.getInstance().GetTagRecieveEntity(m.Tag); foreach (IRecieveMessageEntity var in list) { if (var != null) { if (var.HandleThisMessageType(m.SenderType) != false) { var.HandleMessage(m); } } } } else { if (EntityMapper.getInstance().CheckEntity(m.Receiver)) { IRecieveMessageEntity ag = EntityMapper.getInstance().getRecieveEntity(m.Receiver); if (ag.HandleThisMessageType(m.SenderType) != false) { ag.HandleMessage(m); } } else { if (m.Check == Checks.CHECK_DELIVERY) { SendMessageWithChecking(SystemMessageFactory.NotFoundReciever(m.Sender, m.Receiver)); } } } }
/// <summary> /// REMOVE AN ENTITY /// </summary> /// <param name="ent"></param> public bool RemoveEntity(IEntity ent) { System.Diagnostics.Debug.Assert(ent != null); long cod = ent.GetId(); if (IdEntity.ContainsKey(cod)) { IdEntity.Remove(cod); if (IdRecieveEntity.ContainsKey(cod)) { //iam sure it is not collected cause one reference is passed as a parameter .... IRecieveMessageEntity irent = IdRecieveEntity[cod].Target; IList <String> tags = null; bool found = recieveEntityTag.TryGetValue(irent.GetId(), out tags); if (found) { foreach (String var in tags) { tagRecieveEntity[var].Remove(irent); } recieveEntityTag.Remove(irent.GetId()); } IdRecieveEntity.Remove(cod); } } else { return(false); } return(true); }
/// <summary> /// Add the IrecieveMessageEntity in a tag (create the tag if doesnt exists) /// </summary> /// <param name="tag"></param> /// <param name="Agente"></param> public void AddgrouptagRecieveEntity(string tag, IRecieveMessageEntity Agente) { System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(tag)); System.Diagnostics.Debug.Assert(Agente != null); if (!IdEntity.ContainsKey(Agente.GetId())) { throw new Exception("The following instance is not in the mapper, add it beforing calling this: " + Agente.ToString()); } if (tagRecieveEntity.ContainsKey(tag)) { tagRecieveEntity[tag].Add(Agente); } else { WeakList<IRecieveMessageEntity> l = new WeakList<IRecieveMessageEntity>(); l.Add(Agente); tagRecieveEntity.Add(tag, l); } if (recieveEntityTag.ContainsKey(Agente.GetId())) { recieveEntityTag[Agente.GetId()].Add(tag); } else { recieveEntityTag[Agente.GetId()] = new List<string>(); recieveEntityTag[Agente.GetId()].Add(tag); } }
/// <summary> /// Remove one IRecieveMessageEntity from a tag /// </summary> /// <param name="tag"></param> /// <param name="Agente"></param> public void RemovegrouptagRecieveEntity(string tag, IRecieveMessageEntity Agente) { System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(tag)); System.Diagnostics.Debug.Assert(Agente!=null); if (tagRecieveEntity.ContainsKey(tag)) { tagRecieveEntity[tag].Remove(Agente); } }
public void RemoveTarget(IRecieveMessageEntity entity) { _targets.Remove(entity); }
public void AddTarget(IRecieveMessageEntity entity) { _targets.Add(entity); }