Example #1
0
        private void OnAgentRemove(object obj)
        {
            var agent = Agents.FirstOrDefault(a => a.AgentId.Equals(SelectedAgent.AgentId));

            AgentAPI.RemoveAgent(agent.AgentId);
            Agents.Remove(agent);
        }
Example #2
0
 public void Detach(Agent agent)
 {
     if (Detached != null)
     {
         Detached(agent.gameObject);
     }
     Agents.Remove(agent);
 }
Example #3
0
        public void Match(Agent a1, Agent a2)
        {
            Solution.Add(a1, a2);
            Solution.Add(a2, a1);

            Agents.Remove(a1);
            Agents.Remove(a2);
        }
Example #4
0
        /// <summary>
        /// Processes the first available agent in a root node.
        /// </summary>
        /// <param name="r">Index of the root node to process.</param>
        /// <param name="state">State of the parallel loop.</param>
        /// <param name="doneTick">Whether or not the process cycle has been completed.</param>
        /// <returns>The doneTick variable.</returns>
        private long ProcessRootSingle(int r, ParallelLoopState state, long toProcess)
        {
            // Get root
            RootNode root = Roots[r];

            // If there is an agent leaving
            if (root.ExternalOut.Count > 0)
            {
                // Get agent from node
                Agent a = root.Leave();

                // Perform transaction between station and agent
                Dismissal(root.Port, a);

                // Remove agent from graph
                Agents.Remove(a);

                // If there are more agents, then the tick isn't done
                if (root.ExternalOut.Count > 0)
                {
                    toProcess++;
                }
            }

            // If there is an agent entering
            if (root.Out.Count > 0)
            {
                // Get agent from the node
                Agent a = root.Dequeue();

                // Perform transaction between station and agent
                InteractPort(root.Port, a);

                // Get node that agent will travel to next
                GraphNode exit = root.GetExit(a);

                // Move agent to node if avaialable, otherwise put back onto root
                if (exit != null)
                {
                    exit.Enqueue(a);
                }
                else
                {
                    root.Enqueue(a);
                }

                // If there are more agents, then the tick isn't done
                if (root.Out.Count > 0)
                {
                    toProcess++;
                }
            }

            return(toProcess);
        }
Example #5
0
        /// <summary>
        ///     Stops the execution of the agent identified by name and removes it from the environment. Use the Remove method
        ///     instead of Agent.Stop
        ///     when the decision to stop an agent does not belong to the agent itself, but to some other agent or to an external
        ///     factor.
        ///     Don't call it directly, use WhitePages.RemoveAgent
        /// </summary>
        /// <param name="agent">The agent to be removed</param>
        public void RemoveAgent(ReactiveAgent agent)
        {
            if (agent == null)
            {
                throw new ArgumentNullException(nameof(agent));
            }

            //MetaNetwork.RemoveActor(agent.AgentId);
            Agents.Remove(agent.AgentId);
            StoppedAgents.Add(agent);
        }
Example #6
0
    public void RemoveAgent(AgentEntity agent)
    {
        Console.WriteLine(String.Format("Town: {0}; Agent: {1}", Name, agent.Name));
        List <Market> agentMarkets = agent.Markets.Values.ToList();

        foreach (Market market in agentMarkets)
        {
            market.RemoveAgent(agent);
        }
        Guilds[agent.Type].RemoveMember(agent);
        Agents.Remove(agent);
    }
Example #7
0
 /// <summary>
 /// Stops the execution of the agent and removes it from the environment. Use the Remove method instead of Agent.Stop
 /// when the decision to stop an agent does not belong to the agent itself, but to some other agent or to an external factor.
 /// </summary>
 /// <param name="agent">The agent to be removed</param>
 public void Remove(TurnBasedAgent agent)
 {
     if (Agents.Contains(agent))
     {
         Agents.Remove(agent);
         AgentsDict.Remove(agent.Name);
     }
     else
     {
         throw new Exception("Agent " + agent.Name + " does not exist (TurnBasedAgent.Remove)");
     }
 }
Example #8
0
 /// <summary>
 /// Stops the execution of the agent identified by name and removes it from the environment. Use the Remove method instead of Agent.Stop
 /// when the decision to stop an agent does not belong to the agent itself, but to some other agent or to an external factor.
 /// </summary>
 /// <param name="agentName">The name of the agent to be removed</param>
 override public void Remove(string agentName)
 {
     if (AgentsDict.ContainsKey(agentName))
     {
         TurnBasedAgent ag = AgentsDict[agentName];
         Agents.Remove(ag);
         AgentsDict.Remove(agentName);
     }
     else
     {
         throw new Exception("Agent " + agentName + " does not exist (TurnBasedAgent.Remove)");
     }
 }
        public AgentsViewModel(IAgentRepository agentRepo, IViewModelFactory vmFactory,
                               IUserInteraction ui)
        {
            _agentRepo = agentRepo;
            _vmFactory = vmFactory;

            var agentVms = agentRepo.GetAll().Select(x => CreateAgentViewModel(x));

            Agents.ReplaceItems(agentVms);

            AddAgentCommand = new ActionCommand(o =>
            {
                Agents.Add(CreateAgentViewModel(null));
                IsDirty = true;
            });

            DeleteAgentCommand = new ActionCommand(_ =>
            {
                var selectedAgent = Agents.FirstOrDefault(x => x.IsSelected);
                if (selectedAgent == null)
                {
                    ui.ShowWarning("No agent selected.");
                    return;
                }
                if (!ui.AskForConfirmation($"Are you sure you want to delete the selected '{selectedAgent.Id}' agent?", "Delete agent"))
                {
                    return;
                }

                Agents.Remove(selectedAgent);
                if (!string.IsNullOrEmpty(selectedAgent.Id))
                {
                    agentRepo.Delete(selectedAgent.Id);
                }
            });

            CommitAgentsCommand = new ActionCommand(_ => CommitAgents(),
                                                    _ => IsDirty && !HasErrors);

            ResetChangesCommand = new ActionCommand(_ => {
                foreach (var agent in Agents)
                {
                    agent.ResetForm();
                }
                IsDirty = false;
            }, _ => IsDirty);

            PropertiesAreInitialized = true;
        }
Example #10
0
        public void RemoveClientOrAgent(ulong clientId)
        {
            var client = JoiningAgents.Where(q => q.ID == clientId).FirstOrDefault();

            if (client != null)
            {
                JoiningAgents.Remove(client);
            }
            var agent = Agents.Where(q => q.Client.ID == clientId).FirstOrDefault();

            if (agent != null)
            {
                Agents.Remove(agent);
                var message = new PlayerDisconnectedMessage(agent.PlayerId);
                SendMessageToGameMaster(message.Serialize());
            }
        }
Example #11
0
    public void Remove(Agent agent, bool queueFree = true)
    {
        Agents.Remove(agent);

        try
        {
            RemoveChild(agent);
        }
        catch (System.ObjectDisposedException)
        {
        }

        if (queueFree)
        {
            agent.QueueFree();
        }
    }
Example #12
0
        void MonitoringChannelAgentsChanged(object sender, AgentsChangedEventArgs e)
        {
            foreach (string uri in e.AgentsRemoved)
            {
                Agents.Remove(new MonitoredAgentViewModel(_monitoringChannel)
                {
                    Uri = uri
                });
            }

            foreach (agentType agent in e.AgentsUpdated)
            {
                MonitoredAgentViewModel avm = CreateAgentViewModel(agent);

                int index;

                if ((index = _agents.IndexOf(avm)) != -1)
                {
                    _agents[index].DisplayName = avm.DisplayName;

                    _agents[index].StartTime = avm.StartTime;
                    _agents[index].Status    = avm.Status;

                    _agents[index].MediaTypes.Clear();

                    if (avm.MediaTypes != null)
                    {
                        foreach (string m in avm.MediaTypes)
                        {
                            _agents[index].MediaTypes.Add(m);
                        }
                    }
                }
                else
                {
                    Agents.Add(avm);
                }
            }

            if (!IsMonitoringReady &&
                (Agents.Count > 0 || Customers.Count > 0 || Participants.Count > 0))
            {
                IsMonitoringReady = true;
            }
        }
Example #13
0
    // Placeholder for agent death
    public void DeleteAgent(Agent deletedAgent)
    {
        Agents.Remove(deletedAgent);

        foreach (Agent a in Agents)
        {
            if (a.seenOtherAgents.ContainsKey(deletedAgent.name))
            {
                a.seenOtherAgents.Remove(deletedAgent.name);
            }

            if (a.TargetAgent != null && a.TargetAgent.Enemy.Name == deletedAgent.name)
            {
                a.TargetAgent = null;
            }
        }

        Destroy(deletedAgent.gameObject);
    }
Example #14
0
        private void ModelAgentsChanged(object sender, AgentsChangedEventArgs e)
        {
            foreach (string uri in e.AgentsRemoved)
            {
                Agents.Remove(new SupervisedAgentViewModel(Model)
                {
                    Uri = uri
                });
            }

            foreach (agentType agent in e.AgentsUpdated)
            {
                SupervisedAgentViewModel avm = CreateAgentViewModel(agent);

                int index;

                if ((index = _agents.IndexOf(avm)) != -1)
                {
                    _agents[index].DisplayName = avm.DisplayName;

                    _agents[index].StartTime = avm.StartTime;
                    _agents[index].Status    = avm.Status;

                    _agents[index].MediaTypes.Clear();

                    if (avm.MediaTypes != null)
                    {
                        foreach (string m in avm.MediaTypes)
                        {
                            _agents[index].MediaTypes.Add(m);
                        }
                    }
                }
                else
                {
                    avm.PropertyChanged += AvmPropertyChanged;
                    avm.Monitored       += AvmMonitored;

                    Agents.Add(avm);
                }
            }
        }
 public virtual void DeleteSelectedAgent()
 {
     if (SelectedAgent != null)
     {
         if (MessageBoxService.ShowMessage("您确定要删除选中的商业代理吗?", "提示信息", MessageButton.OKCancel, MessageIcon.Question) == MessageResult.OK)
         {
             string sqlStr = $"UPDATE tb_Agent SET IsOpen=0 WHERE int_AGid={SelectedAgent.int_AGid}";
             if (SQLHelper.UpDateSQL(sqlStr))
             {
                 Agents.Remove(SelectedAgent);
             }
             else
             {
                 MessageBoxService.ShowMessage("删除失败!", "提示信息", MessageButton.OK, MessageIcon.Information);
             }
         }
     }
     else
     {
         MessageBoxService.ShowMessage("请选中要删除的行?", "提示信息", MessageButton.OK, MessageIcon.Information);
     }
 }
Example #16
0
        /// <summary>
        ///     Adds an agent to the environment. The agent should already have a name and its name should be unique.
        /// </summary>
        /// <param name="agent">The concurrent agent that will be added</param>
        public void AddAgent(ReactiveAgent agent)
        {
            if (agent == null || agent.IsNull)
            {
                throw new ArgumentNullException(nameof(agent));
            }

            if (Agents.Exists(agent.AgentId))
            {
                // todo => throw new ArgumentException("Trying to add an agent " + agent.AgentId.ClassId + " with an existing key: " + agent.AgentId);

                //todo should be done only in reference
                Agents.Remove(agent.AgentId);
            }

            Agents.Add(agent);
            //todo should be done only in reference
            if (!_agentsReference.Exists(x => x.AgentId.Equals(agent.AgentId)))
            {
                _agentsReference.Add(agent);
            }
        }
Example #17
0
        public void LeaveChat(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }
            // was it an agent
            var agent = Agents.ContainsKey(id) ? Agents[id] : null;

            if (agent != null)
            {
                Agents.Remove(id);

                var sessions = ChatSessions.Where(x => x.Value == agent.Id);
                if (sessions != null)
                {
                    foreach (var session in sessions)
                    {
                        Clients.Client(session.Key).addMessage("", UiStringTheAgentWasDisconnectedFromChat);
                    }
                }

                Clients.All.updateStatus(Agents.Values.Count(x => x.IsOnline) > 0);
            }

            // was it a visitor
            if (ChatSessions.ContainsKey(id))
            {
                var agentId = ChatSessions[id];
                Clients.Client(agentId).addMessage(id, UiStringSystem, UiStringTheVisitorCloseTheConnection);
                ChatClient client = GetChatClient(id);
                SaveChat(id, client);
                string buffer = "";
                ChatSessions.TryRemove(id, out buffer);
                ChatClients.Remove(id);
            }
        }
Example #18
0
        /// <summary>
        /// Processes all agents in a root node.
        /// </summary>
        /// <param name="r">Index of root node to processes.</param>
        private void ProcessRootAll(RootNode root)
        {
            // Exit graph through portal
            while (root.ExternalOut.Count > 0)
            {
                // Get agent from node
                Agent a = root.Leave();

                // Perform transaction between station and agent
                Dismissal(root.Port, a);

                // Remove agent from graph
                Agents.Remove(a);
            }
            // Enter the graph
            while (root.Out.Count > 0)
            {
                // Get agent from node
                Agent a = root.Dequeue();

                // Perform transaction between station and agent
                InteractPort(root.Port, a);

                // Get node that agent will travel to next
                GraphNode exit = root.GetExit(a);

                // Move agent to node if available, otherwise put back onto root
                if (exit != null)
                {
                    exit.Enqueue(a);
                }
                else
                {
                    root.Enqueue(a);
                }
            }
        }
Example #19
0
 public bool turnView()
 {
     ticks++;
     for (int j = 0; j < Robots.Count; j++)
     {
         Robots[j].clearSensors();
         foreach (RoboAgent a in agents)
         {
             if (Utilities.Distance(Robots[j], a) <= 10)
             {
                 Agents.Remove(a);
                 return(true);
             }
             else
             {
                 Robots[j].ProcessAgent(a);
             }
         }
         SizeF pt = Robots[j].determineBiasedMove();
         //SizeF pt = Robots[j].determineMove();
         if (isValidMove(Robots[j], pt))
         {
             Robots[j].Move(pt);
         }
         else
         {
             Robots[j].InvalidMoves = Robots[j].InvalidMoves + 1;
             if (Robots[j].InvalidMoves >= 10)
             {
                 ticks = 1000;
                 return(true);
             }
         }
     }
     return(false);
 }
Example #20
0
 public void RemoveAgent(GameObject owner)
 {
     Agents.Remove((Character)owner);
     owner.Dispose();
 }
Example #21
0
 public Gateway RemoveServer(string host)
 {
     Agents.Remove(host);
     Routes.RemoveServer(host);
     return(this);
 }
 public void RemoveAgent(AgentEntity agent)
 {
     agent.RemoveMarket(Resource.Type);
     Agents.Remove(agent);
 }