/// <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> /// 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); } }