Beispiel #1
0
        private void onInfectMessage(Message message)
        {
            int agentId = Int32.Parse(message.data);
            var agent   = GlobalAgentDescriptorTable.GetAgentById(agentId);

            agent.EventMessage(new CoreAMS.MessageTransportSystem.AgentMessage(Enums.MessageType.Infected.ToString(), -1, -1));
        }
        public void SendGoto()
        {
            lock (gotoAgents)
            {
                if (gotoAgents.Count != gotoContainers.Count)
                {
                    Trace.TraceWarning("!!! Agent and container count doesn't match");
                }
                //return;

                //if (gotoAgents.Count == 0)
                //    return;

                List <AddAgentMessage> ams = new List <AddAgentMessage>();
                foreach (AbstractPerson a in this.gotoAgents)
                {
                    ams.Add(new AddAgentMessage(
                                this.transportSystem.Id,
                                a.GetType().Name,
                                a.GetId(),
                                a.GetHealthState(),
                                1
                                ));
                }

                GoToContainerMessage msg = new GoToContainerMessage(
                    this.transportSystem.Id,
                    ams.ToArray(),
                    this.gotoContainers.ToArray(),
                    this.infectedAgents.ToArray(),
                    GlobalAgentDescriptorTable.Count
                    );

                if (this.moveContainerMessage != null)
                {
                    msg.containerToMove = this.moveContainerMessage;
                }

                msg.currentResult = this.intermediateResult;

                this.transportSystem.SendMessage(msg);
                foreach (AbstractPerson a in this.gotoAgents)
                {
                    GlobalAgentDescriptorTable.DeleteOneAgent(a);
                }

                if (this.moveContainerMessage != null)
                {
                    foreach (var am in this.moveContainerMessage.agentData)
                    {
                        IAgent a = GlobalAgentDescriptorTable.GetAgentById(am.agentId);
                        if (a != null)
                        {
                            GlobalAgentDescriptorTable.DeleteOneAgent(a);
                        }
                    }
                    Containers.Instance.Remove(this.moveContainerMessage.containerId);
                }

                gotoAgents.Clear();
                gotoContainers.Clear();
                infectedAgents.Clear();
                this.moveContainerMessage = null;
                this.intermediateResult   = null;
            }
        }