/// <summary> /// Activates the functional agent. /// The caller should to an 'await' /// on this to wait for it to complete. This is because some /// functional agents return data and the caller has to wait /// for the functional agent to exit so it can get the data. Eg /// FileBrowser agent that returns a filename /// </summary> /// <param name="agent"></param> /// <returns></returns> private async Task activateAgent(IFunctionalAgent agent) { var form = new Form { WindowState = FormWindowState.Minimized, Visible = false, ShowInTaskbar = false }; form.Load += form_Load; form.Show(); if (agent is FunctionalAgentBase) { var funcAgent = (FunctionalAgentBase)agent; Task t = Task.Factory.StartNew(() => { Log.Debug("Calling funcAgent.activate: " + agent.Name); funcAgent.IsClosing = false; funcAgent.ExitCommand = null; form.Invoke(new MethodInvoker(() => funcAgent.Activate())); // This event is triggered by the functional agent when // it exits Log.Debug("Waiting on CloseEvent...: " + agent.Name); funcAgent.CloseEvent.WaitOne(); Log.Debug("Returned from CloseEvent: " + agent.Name); }); await t; } Windows.CloseForm(form); }
/// <summary> /// Activates a functional agent. The caller should to an 'await' /// on this to wait for it to complete. This is because some /// functional agents return data and the caller has to wait /// for the functional agent to exit so it can get the data. Eg /// FileBrowser agent that returns a filename /// </summary> /// <param name="caller">The calling agent (can be null)</param> /// <param name="agent">Functional agent to activate</param> /// <returns>the task to wait on</returns> public async Task ActivateAgent(IApplicationAgent caller, IFunctionalAgent agent) { lock (_syncActivateAgent) { if (_currentAgent != null && _currentAgent != agent) { if (caller == null && !_currentAgent.QueryAgentSwitch(agent)) { return; } _currentAgent.OnFocusLost(); } if (caller != null) { agent.Parent = caller; caller.OnPause(); } _textControlAgent = agent.TextControlAgent; setAgent(agent); } Log.Debug("Calling activateAgent: " + agent.Name); await activateAgent(agent); CompletionCode exitCode = agent.ExitCode; Log.Debug("Returned from activateAgent: " + agent.Name); setAgent(null); if (agent.ExitCommand != null) { if (agent.ExitCommand.ContextSwitch) { Context.AppPanelManager.CloseCurrentPanel(); } RunCommandDispatcher.Dispatch(agent.ExitCommand.Command); } else if (exitCode == CompletionCode.ContextSwitch) { Context.AppPanelManager.CloseCurrentPanel(); EnumWindows.RestoreFocusToTopWindow(); WindowActivityMonitor.GetActiveWindow(); } else { PausePanelChangeRequests(); EnumWindows.RestoreFocusToTopWindow(); ResumePanelChangeRequests(false); } }
/// <summary> /// Executes the command /// </summary> /// <param name="handled">set to true if the command was handled</param> /// <returns>true on success</returns> public override bool Execute(ref bool handled) { handled = true; switch (Command) { case "CmdTalkWindowToggle": { // first check if a functional agent is currently active // if it is, instruct it to close and then execute the command // after it has exited IApplicationAgent agent = AgentManager.Instance.ActiveAgent; if (agent is IFunctionalAgent) { IFunctionalAgent funcAgent = (IFunctionalAgent)agent; if (funcAgent.ExitCommand == null) { funcAgent.ExitCommand = new PostExitCommand { Command = this, ContextSwitch = true }; funcAgent.OnRequestClose(); break; } } Context.AppTalkWindowManager.ToggleTalkWindow(); } break; case "CmdTalkWindowClear": if (Context.AppTalkWindowManager.IsTalkWindowActive) { Context.AppAgentMgr.RunCommand("ClearTalkWindowText", ref handled); } break; case "CmdTalkWindowClose": Context.AppTalkWindowManager.CloseTalkWindow(); break; default: handled = false; break; } return(true); }
/// <summary> /// Activates the specified functional agent. /// The caller should to an 'await' /// on this to wait for it to complete. This is because some /// functional agents return data and the caller has to wait /// for the functional agent to exit so it can get the data. Eg /// FileBrowser agent that returns a filename /// </summary> /// <param name="agent">agent to activate</param> /// <returns>Task to wait on</returns> public async Task ActivateAgent(IFunctionalAgent agent) { await ActivateAgent(null, agent); }
/// <summary> /// Activates the functional agent. /// The caller should to an 'await' /// on this to wait for it to complete. This is because some /// functional agents return data and the caller has to wait /// for the functional agent to exit so it can get the data. Eg /// FileBrowser agent that returns a filename /// </summary> /// <param name="agent"></param> /// <returns></returns> private async Task activateAgent(IFunctionalAgent agent) { if (!(agent is FunctionalAgentBase)) { return; } var form = new Form { WindowState = FormWindowState.Minimized, Visible = false, ShowInTaskbar = false }; form.Load += form_Load; form.Show(); var funcAgent = (FunctionalAgentBase)agent; Task task = Task.Factory.StartNew(() => { Log.Debug("Calling funcAgent.activate: " + agent.Name); funcAgent.IsClosing = false; funcAgent.ExitCommand = null; form.Invoke(new MethodInvoker(delegate() { Context.AppPanelManager.NewStack(); funcAgent.Activate(); Context.AppPanelManager.CloseStack(); })); // This event is triggered by the functional agent when it exits Log.Debug("Waiting on CloseEvent...: " + agent.Name); funcAgent.CloseEvent.WaitOne(); Log.Debug("Returned from CloseEvent: " + agent.Name); }); await task; Windows.CloseForm(form); }
/// <summary> /// Activates the specified functional agent. /// The caller should to an 'await' /// on this to wait for it to complete. This is because some /// functional agents return data and the caller has to wait /// for the functional agent to exit so it can get the data. Eg /// FileBrowser agent that returns a filename /// </summary> /// <param name="agent">agent to activate</param> /// <returns>Task to wait on</returns> public async Task ActivateAgent(IFunctionalAgent agent) { await ActivateAgent(null, agent); }
/// <summary> /// Activates a functional agent. The caller should to an 'await' /// on this to wait for it to complete. This is because some /// functional agents return data and the caller has to wait /// for the functional agent to exit so it can get the data. Eg /// FileBrowser agent that returns a filename /// </summary> /// <param name="caller">The calling agent (can be null)</param> /// <param name="agent">Functional agent to activate</param> /// <returns>the task to wait on</returns> public async Task ActivateAgent(IApplicationAgent caller, IFunctionalAgent agent) { lock (_syncActivateAgent) { if (_currentAgent != null && _currentAgent != agent) { if (caller == null && !_currentAgent.QueryAgentSwitch(agent)) { return; } _currentAgent.OnFocusLost(); } if (caller != null) { agent.Parent = caller; caller.OnPause(); } _textControlAgent = agent.TextControlAgent; setAgent(agent); } Log.Debug("Calling activateAgent: " + agent.Name); await activateAgent(agent); CompletionCode exitCode = agent.ExitCode; Log.Debug("Returned from activateAgent: " + agent.Name); setAgent(null); if (agent.ExitCommand != null) { if (agent.ExitCommand.ContextSwitch) { Context.AppPanelManager.CloseCurrentPanel(); } RunCommandDispatcher.Dispatch(agent.ExitCommand.Command); } else if (exitCode == CompletionCode.ContextSwitch) { //Context.AppPanelManager.CloseCurrentPanel(); Context.AppPanelManager.ClearStack(); EnumWindows.RestoreFocusToTopWindow(); WindowActivityMonitor.GetActiveWindow(); } else { PausePanelChangeRequests(); EnumWindows.RestoreFocusToTopWindow(); ResumePanelChangeRequests(false); } }
/// <summary> /// Executes the command /// </summary> /// <param name="handled">set to true if the command was handled</param> /// <returns>true on success</returns> public override bool Execute(ref bool handled) { handled = true; switch (Command) { case "CmdTalkWindowToggle": { // first check if a functional agent is currently active // if it is, instruct it to close and then execute the command // after it has exited IApplicationAgent agent = AgentManager.Instance.ActiveAgent; if (agent is IFunctionalAgent) { IFunctionalAgent funcAgent = (IFunctionalAgent)agent; if (funcAgent.ExitCommand == null) { funcAgent.ExitCommand = new PostExitCommand { Command = this, ContextSwitch = true }; funcAgent.OnRequestClose(); break; } } Context.AppTalkWindowManager.ToggleTalkWindow(); } break; case "CmdTalkWindowClear": if (Context.AppTalkWindowManager.IsTalkWindowActive) { Context.AppAgentMgr.RunCommand("ClearTalkWindowText", ref handled); } break; case "CmdTalkWindowShow": { // first check if a functional agent is currently active // if it is, instruct it to close and then execute the command // after it has exited IApplicationAgent agent = AgentManager.Instance.ActiveAgent; if (agent is IFunctionalAgent) { IFunctionalAgent funcAgent = (IFunctionalAgent)agent; if (funcAgent.ExitCommand == null) { funcAgent.ExitCommand = new PostExitCommand { Command = this, ContextSwitch = true }; funcAgent.OnRequestClose(); break; } } Context.AppTalkWindowManager.ShowTalkWindow(); } break; case "CmdTalkWindowClose": Context.AppTalkWindowManager.CloseTalkWindow(); break; case "CmdTalkApp": var form = PanelManager.Instance.CreatePanel("TalkApplicationScanner"); if (form != null) { // Add ad-hoc agent that will handle the form var agent = Context.AppAgentMgr.GetAgentByName("Talk Application Agent"); if (agent != null) { Context.AppAgentMgr.AddAgent(form.Handle, agent); Context.AppPanelManager.ShowDialog(form as IPanel); } } break; default: handled = false; break; } return(true); }