コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        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));
                    }
                }
            }
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
            /// <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);
                }

            }
コード例 #9
0
            /// <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);
                }               

            }
コード例 #10
0
 public void RemoveTarget(IRecieveMessageEntity entity)
 {
     _targets.Remove(entity);
 }
コード例 #11
0
 public void AddTarget(IRecieveMessageEntity entity)
 {
     _targets.Add(entity);
 }