public override void HandleSignal(Signal signal) { var cytokine = signal as Cytokine; if (cytokine != null && (cytokine.Type == CytokineType.IL2 || cytokine.Type == CytokineType.IL4)) { var sender = Agents.FirstOrDefault(a => a.Address == signal.Sender); if (sender == null) { throw new Exception("Sender of the signal is not one of my child cells!"); } if (sender is HelperTCell) { var helper = (HelperTCell)sender; foreach (var activator in helper.Activators) { //var apc = (APC)Agents.FirstOrDefault(a => a.Address == activator); //Log("Attack detected in node " + apc.ActivatedIn + //" with costimulation " + cytokine.Concentration, LogLevel.Major); /*// report the detection results to the parent * // TODO: the signal dispatch delay is dummy * Scheduler.Schedule(Parent.HandleSignal, 0.0001, new Signal(apc.ActivatedIn, * SignalType.Cytokine, signal.Concentration, null));*/ } } } base.HandleSignal(signal); // to forward the signal even if it is a cytokine in order to stimulate proliferation and differentiation }
public void AllocateToEngine(string link) { if (Agents.Count == 0) { throw new ArgumentException("No agents defined"); } var item = Agents.FirstOrDefault(x => !x.InUse); while (item == null) { // if non free, wait until existing task finishes var active = GetActiveTasks(); var offset = Task.WaitAny(active, WaitTimeOut); if (offset >= 0 && offset != WaitHandle.WaitTimeout) { foreach (var done in Agents.Where(x => x.InUse && x.Task != null && x.Task.IsCompleted)) { done.ReleaseTask(); } item = Agents.First(x => !x.InUse); } } // launch task item.SetTask(link, Task.Run(() => item.Process.Get(link))); }
private void OnAgentRemove(object obj) { var agent = Agents.FirstOrDefault(a => a.AgentId.Equals(SelectedAgent.AgentId)); AgentAPI.RemoveAgent(agent.AgentId); Agents.Remove(agent); }
private async void GetAgentData() { var agentData = await AgentAPI.GetAgentData(); if (agentData != null) { foreach (var agent in agentData) { if (!Agents.Any(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase))) { Agents.Add(new Agent { AgentId = agent.Metadata.AgentID, Hostname = agent.Metadata.Hostname, IpAddress = agent.Metadata.IPAddress, Identity = agent.Metadata.Identity, ProcessName = agent.Metadata.ProcessName, ProcessId = agent.Metadata.ProcessID, Arch = agent.Metadata.Arch.ToString(), CLR = agent.Metadata.CLR, Integrity = agent.Metadata.Integrity.ToString(), AgentModules = agent.LoadModules, LastSeen = Helpers.CalculateTimeDiff(agent.LastSeen) }); } else { Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .Hostname = agent.Metadata.Hostname; Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .IpAddress = agent.Metadata.IPAddress; Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .Identity = agent.Metadata.Identity; Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .ProcessName = agent.Metadata.ProcessName; Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .ProcessId = agent.Metadata.ProcessID; Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .Arch = agent.Metadata.Arch.ToString(); Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .CLR = agent.Metadata.CLR; Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .Integrity = agent.Metadata.Integrity.ToString(); Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .AgentModules = agent.LoadModules; Agents.FirstOrDefault(a => a.AgentId.Equals(agent.Metadata.AgentID, StringComparison.OrdinalIgnoreCase)) .LastSeen = Helpers.CalculateTimeDiff(agent.LastSeen); } } } }
public void AddOrUpdateAgent(Agent agent) { var existingAgent = Agents.FirstOrDefault(r => r.Id == agent.Id); if (existingAgent != null) { existingAgent.Status = agent.Status; } else { Agents.Add(agent); } }
public Tuple <Agent, bool> GetAgent(List <Guid> contactResponsibles) { var result = Agents.FirstOrDefault(r => r.Status == AgentStatus.Online && contactResponsibles.Contains(r.Id)) ?? Agents.FirstOrDefault(r => r.Status == AgentStatus.Online); var isAnyNotOffline = Agents.Any(); if (result != null) { result.Status = AgentStatus.Paused; } return(new Tuple <Agent, bool>(result, isAnyNotOffline)); }
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; }
private void ClientOnSessionCompleted(object sender, VoIPEventArgs <ISession> e) { ISession session; _activeSessions.TryRemove(e.Item.SessionID, out session); var agentFinished = Agents.FirstOrDefault(a => a.AgentInfo.Extensions.Contains(session.Callee)); if (agentFinished != null && !_activeSessions.Any(s => agentFinished.AgentInfo.Extensions.Contains(s.Value.Callee))) { CallEnded(agentFinished, Customers.FirstOrDefault(customer => customer.State.HandlingAgent == agentFinished && customer.State.ProgressState == ProgressState.InProgress), ProgressState.Completed); } Debug.WriteLine("Session completed " + e.Item.Caller + " -> " + e.Item.Callee); }
private void ApiCallStateChanged(object sender, VoIPEventArgs <CallState> e) { lock (_sync) { var call = (ICall)sender; if (e.Item == CallState.InCall) { var handlingAgent = DialerBehaviour == AgentDialerBehaviour.ChooseByOccupation ? Agents.FirstOrDefault(agent => agent.State == AgentState.Free) : Agents.Where(agent => agent.State == AgentState.Free) .OrderBy(agent => agent.NumberOfCalls) .FirstOrDefault(); if (handlingAgent != null) { handlingAgent.State = AgentState.Occupied; handlingAgent.CurrentCallId = call.CallId; handlingAgent.NumberOfCalls++; var target = handlingAgent.AgentInfo.PhoneNumber; call.BlindTransfer(target); var handledCustomer = Customers.FirstOrDefault(customer => customer.CallId == call.CallId); if (handledCustomer != null) { handledCustomer.State = new CustomerState(ProgressState.InProgress, handlingAgent); } } } else if (e.Item.IsCallEnded()) { var customer = Customers.FirstOrDefault(c => c.CallId == call.CallId); if (customer != null) { var agent = Agents.FirstOrDefault(a => customer.State.HandlingAgent == a); if (agent == null) { CallEnded(agent, customer, e.Item == CallState.Busy ? ProgressState.Rejected : ProgressState.Completed); } } _startedCalls.TryRemove(call); } } }
private void ExecuteAddNewVisaViewCommand() { if (Agents.Count == 0) { AddNewAgent(); } SelectedAgent = Agents.FirstOrDefault(); if (SelectedAgent != null) { SelectedVisa = CommonUtility.GetNewVisaDTO(SelectedAgent.Id); } EmployeesCount = "Not Assigned"; EmptyControlVisibility = true; EditCommandVisibility = false; //_checkDuplicate = true; }
public override void HandleSignal(Signal signal) { if (signal is Cytokine && ((Cytokine)signal).Type == CytokineType.IL1) { // send the sender cell to a lymph node var agent = Agents.FirstOrDefault(a => a.Address == signal.Sender); if (agent != null && agent is Cell) { var cell = (Cell)agent; if (cell.IsAlive) { SendCellToRandomTissue(cell, TissueType.LymphNode); } } } else { // forward the signal to some randomly-selected children ForwardSignal(signal); } base.HandleSignal(signal); }
public AgentStatus GetAgentStatus(string agentId) { var agent = Agents.FirstOrDefault(r => r.Id.ToString() == agentId); return(agent == null ? AgentStatus.Offline : agent.Status); }
public Agent GetAgent(int agentId) { return(Agents.FirstOrDefault(a => a.Id == agentId)); }
public Agent GetById(int id) { return(Agents.FirstOrDefault(x => x.AgentId == id)); }
public virtual void SaveAgentInfo() { try { #region 验证重复 if (string.IsNullOrWhiteSpace(SelectedAgent.vchar_AGname)) { MessageBoxService.ShowMessage("商业伙伴名称不能为空", "提示信息", MessageButton.OK, MessageIcon.Error); return; } if (string.IsNullOrWhiteSpace(SelectedAgent.vchar_AGcontect)) { MessageBoxService.ShowMessage("联系方式不能为空", "提示信息", MessageButton.OK, MessageIcon.Error); return; } if (string.IsNullOrWhiteSpace(SelectedAgent.vchar_AGLinkMan)) { MessageBoxService.ShowMessage("联系人不能为空", "提示信息", MessageButton.OK, MessageIcon.Error); return; } if (string.IsNullOrWhiteSpace(SelectedAgent.vchar_AGcode)) { MessageBoxService.ShowMessage("商业伙伴代码不能为空", "提示信息", MessageButton.OK, MessageIcon.Error); return; } string sqlStr = string.Empty; if (SelectedAgent.bit_synOpen) { if (string.IsNullOrWhiteSpace(SelectedAgent.vchar_synVerify) || string.IsNullOrWhiteSpace(SelectedAgent.vchar_synStopKeyWord)) { MessageBoxService.ShowMessage("检查点同步信息不可为空", "提示信息", MessageButton.OK, MessageIcon.Error); return; } sqlStr = $"SELECT [vchar_AGcode],[vchar_synVerify] FROM [dbo].[tb_Agent] WHERE [vchar_AGcode]='{SelectedAgent.vchar_AGcode}' OR [vchar_synVerify]='{SelectedAgent.vchar_synVerify}'"; IList <Agent> agents = (SQLHelper.GetObject <Agent>(sqlStr)).ToList(); if (agents.Count != 0) { Agent agent = agents.FirstOrDefault(); if (SelectedAgent.vchar_AGcode == agent.vchar_AGcode) { MessageBoxService.ShowMessage("与其他商业伙伴代码重复,请更换", "提示信息", MessageButton.OK, MessageIcon.Error); return; } if (SelectedAgent.vchar_synVerify == agent.vchar_synVerify) { MessageBoxService.ShowMessage("与其他商业伙伴同步接口校验码重复,请更换", "提示信息", MessageButton.OK, MessageIcon.Error); return; } } } if (SelectedAgent.bit_synQuery) { if (string.IsNullOrWhiteSpace(SelectedAgent.vchar_QueryVerify)) { MessageBoxService.ShowMessage("检查点查询信息不可为空", "提示信息", MessageButton.OK, MessageIcon.Error); return; } sqlStr = $"SELECT [vchar_QueryVerify] FROM [dbo].[tb_Agent] WHERE [vchar_QueryVerify]='{SelectedAgent.vchar_QueryVerify}'"; IList <Agent> agents = (SQLHelper.GetObject <Agent>(sqlStr)).ToList(); if (agents.Count != 0) { Agent agent = agents.FirstOrDefault(); if (SelectedAgent.vchar_QueryVerify == agent.vchar_QueryVerify) { MessageBoxService.ShowMessage("与其他商业伙伴查询接口校验码重复,请更换", "提示信息", MessageButton.OK, MessageIcon.Error); return; } } } if (SelectedAgent.bit_synPush) { if (string.IsNullOrWhiteSpace(SelectedAgent.vchar_PushUser) || string.IsNullOrWhiteSpace(SelectedAgent.vchar_PushVerify)) { MessageBoxService.ShowMessage("检查点推送信息不可为空", "提示信息", MessageButton.OK, MessageIcon.Error); return; } sqlStr = $"SELECT [vchar_PushUser],[vchar_PushVerify] FROM [dbo].[tb_Agent] WHERE [vchar_PushUser]='{SelectedAgent.vchar_PushUser}' OR [vchar_PushVerify]='{SelectedAgent.vchar_PushVerify}'"; IList <Agent> agents = (SQLHelper.GetObject <Agent>(sqlStr)).ToList(); if (agents.Count != 0) { Agent agent = agents.FirstOrDefault(); if (SelectedAgent.vchar_PushUser == agent.vchar_PushUser) { MessageBoxService.ShowMessage("与其他商业伙伴推送接口用户重复,请更换", "提示信息", MessageButton.OK, MessageIcon.Error); return; } if (SelectedAgent.vchar_PushVerify == agent.vchar_PushVerify) { MessageBoxService.ShowMessage("与其他商业伙伴推送接口校验码重复,请更换", "提示信息", MessageButton.OK, MessageIcon.Error); return; } } } #endregion #region 插入数据 SplashScreenService.ShowSplashScreen(); if (SelectedAgent.int_AGid == 0) { if (SelectedAgent.int_AGtype == "检查点提供方") { sqlStr = $"INSERT INTO tb_Agent (vchar_AGcode, vchar_AGname, vchar_AGLinkMan, vchar_AGcontect, int_AGtype, bit_synOpen, vchar_synVerify,vchar_synStopKeyWord,int_synSpacing)VALUES ('{SelectedAgent.vchar_AGcode}', N'{SelectedAgent.vchar_AGname}', N'{SelectedAgent.vchar_AGLinkMan}', '{SelectedAgent.vchar_AGcontect}', 0, {(SelectedAgent.bit_synOpen ? 1 : 0)}, '{SelectedAgent.vchar_synVerify}', N'{SelectedAgent.vchar_synStopKeyWord}',{SelectedAgent.int_synSpacing}) "; } else if (SelectedAgent.int_AGtype == "检查点查询方") { sqlStr = $"INSERT INTO tb_Agent(vchar_AGcode, vchar_AGname, vchar_AGLinkMan, vchar_AGcontect, int_AGtype, bit_synQuery, vchar_QueryVerify)VALUES ('{SelectedAgent.vchar_AGcode}', N'{SelectedAgent.vchar_AGname}',N'{SelectedAgent.vchar_AGLinkMan}', '{SelectedAgent.vchar_AGcontect}', 1, {(SelectedAgent.bit_synQuery ? 1 : 0)}, '{SelectedAgent.vchar_QueryVerify}') "; } else if (SelectedAgent.int_AGtype == "检查点推送接收方") { sqlStr = $"INSERT INTO tb_Agent(vchar_AGcode, vchar_AGname, vchar_AGLinkMan, vchar_AGcontect, int_AGtype,bit_synPush, vchar_PushUser, vchar_PushVerify) VALUES ('{SelectedAgent.vchar_AGcode}', N'{SelectedAgent.vchar_AGname}', N'{SelectedAgent.vchar_AGLinkMan}', '{SelectedAgent.vchar_AGcontect}', 2, {(SelectedAgent.bit_synPush ? 1 : 0)}, '{SelectedAgent.vchar_PushUser}', '{SelectedAgent.vchar_PushVerify}') "; } if (SQLHelper.UpDateSQL(sqlStr)) { MessageBoxService.ShowMessage("保存成功", "提示信息", MessageButton.OK, MessageIcon.Information); } else { MessageBoxService.ShowMessage("保存失败", "提示信息", MessageButton.OK, MessageIcon.Error); } Agents.Add(SelectedAgent); } else { if (SelectedAgent.int_AGtype == "检查点提供方") { sqlStr = $"UPDATE tb_Agent SET vchar_AGcode = '{SelectedAgent.vchar_AGcode}', vchar_AGname = N'{SelectedAgent.vchar_AGname}', vchar_AGLinkMan = N'{SelectedAgent.vchar_AGLinkMan}', vchar_AGcontect = '{SelectedAgent.vchar_AGcontect}',int_AGtype = 0, bit_synOpen = {(SelectedAgent.bit_synOpen ? 1 : 0)}, vchar_synVerify = '{SelectedAgent.vchar_synVerify}', vchar_synStopKeyWord = N'{SelectedAgent.vchar_synStopKeyWord}', bit_synQuery = 0,vchar_QueryVerify = NULL, bit_synPush = 0, vchar_PushUser = NULL, vchar_PushVerify = NULL,int_synSpacing= {SelectedAgent.int_synSpacing} WHERE [int_AGid]={SelectedAgent.int_AGid}"; } else if (SelectedAgent.int_AGtype == "检查点查询方") { sqlStr = $"UPDATE tb_Agent SET vchar_AGcode = '{SelectedAgent.vchar_AGcode}', vchar_AGname = N'{SelectedAgent.vchar_AGname}', vchar_AGLinkMan = N'{SelectedAgent.vchar_AGLinkMan}', vchar_AGcontect = '{SelectedAgent.vchar_AGcontect}', int_AGtype = 1, bit_synOpen = 0, vchar_synVerify = NULL, vchar_synStopKeyWord = NULL, bit_synQuery = {(SelectedAgent.bit_synQuery ? 1 : 0)}, vchar_QueryVerify = '{SelectedAgent.vchar_QueryVerify}', bit_synPush = 0, vchar_PushUser = NULL, vchar_PushVerify = NULL WHERE [int_AGid]={SelectedAgent.int_AGid}"; } else if (SelectedAgent.int_AGtype == "检查点推送接收方") { sqlStr = $"UPDATE tb_Agent SET vchar_AGcode ='{SelectedAgent.vchar_AGcode}', vchar_AGname = N'{SelectedAgent.vchar_AGname}', vchar_AGLinkMan = N'{SelectedAgent.vchar_AGLinkMan}', vchar_AGcontect ='{SelectedAgent.vchar_AGcontect}',int_AGtype =2, bit_synOpen = 0, vchar_synVerify = NULL, vchar_synStopKeyWord = NULL, bit_synQuery = 0, vchar_QueryVerify = NULL, bit_synPush = {(SelectedAgent.bit_synPush ? 1 : 0)}, vchar_PushUser = '******', vchar_PushVerify = '{SelectedAgent.vchar_PushVerify}' WHERE [int_AGid]={SelectedAgent.int_AGid}"; } if (SQLHelper.UpDateSQL(sqlStr)) { MessageBoxService.ShowMessage("保存成功", "提示信息", MessageButton.OK, MessageIcon.Information); } else { MessageBoxService.ShowMessage("保存失败", "提示信息", MessageButton.OK, MessageIcon.Error); } var item = Agents.FirstOrDefault(a => a.int_AGid == SelectedAgent.int_AGid); if (item != null) { item = SelectedAgent; } } SplashScreenService.HideSplashScreen(); #endregion } catch (Exception ex) { SplashScreenService.HideSplashScreen(); MessageBoxService.ShowMessage($"保存失败:{ex.Message}", "提示信息", MessageButton.OK, MessageIcon.Error); } }
public Agent GetAgent(int x, int y) { return(Agents.FirstOrDefault(a => a.X == x && a.Y == y)); }