public bool Init(IEnumerable <String> extensionDirs) { if (_agentsCache == null) { _agentsCache = new AgentsCache(); _agentsCache.EvtAgentAdded += _agentsCache_EvtAgentAdded; _agentsCache.Init(extensionDirs); _genericAppAgent = _agentsCache.GetAgent(GenericAppAgentName); if (_genericAppAgent == null) { _agentsCache.AddAgentByType(typeof(UnsupportedAppAgent)); _genericAppAgent = _agentsCache.GetAgent(GenericAppAgentName); } _agentsCache.AddAgentByType(typeof(NullAgent)); _nullAgent = _agentsCache.GetAgent(NullAgentName); _dialogAgent = _agentsCache.GetAgent(DialogControlAgentName); _menuControlAgent = _agentsCache.GetAgent(MenuControlAgentName); _textControlAgent = _genericAppAgent.TextControlAgent; WindowActivityMonitor.EvtFocusChanged += WindowActivityMonitor_EvtFocusChanged; getKeyboardActuator(); WindowActivityMonitor.GetActiveWindow(); } return(true); }
/// <summary> /// Returns the preferred agent for the specified process /// </summary> /// <param name="process">Process</param> /// <returns>Agent object</returns> public IApplicationAgent GetAgent(Process process) { IApplicationAgent retVal = _preferredAgents.GetPreferredAgentForProcess(process); if (retVal != null) { return(retVal); } // check if there is a preferred agent. If not // look up the cache for the supported agent var supportedAgents = (List <IApplicationAgent>)_agentLookupTableByProcessName[process.ProcessName.ToLower()]; if (supportedAgents != null) { foreach (var agent in supportedAgents) { foreach (var processInfo in agent.ProcessesSupported) { if (String.IsNullOrEmpty(processInfo.ExecutablePath)) { retVal = agent; } else if (String.Compare(process.MainModule.FileName, processInfo.ExecutablePath, true) == 0) { return(agent); } } } } return(retVal); }
/// <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) { bool retVal = true; handled = true; Form form = Dispatcher.Scanner.Form; form.Invoke(new MethodInvoker(delegate() { IApplicationAgent switchWindowsAgent = Context.AppAgentMgr.GetAgentByName("Switch Windows Agent"); if (switchWindowsAgent == null) { retVal = false; } else { Context.AppTalkWindowManager.CloseTalkWindow(); IntPtr foregroundWindow = Windows.GetForegroundWindow(); var process = WindowActivityMonitor.GetProcessForWindow(foregroundWindow); IExtension extension = switchWindowsAgent; extension.GetInvoker().SetValue("FilterByProcessName", process.ProcessName); Context.AppAgentMgr.ActivateAgent(switchWindowsAgent as IFunctionalAgent); WindowActivityMonitor.GetActiveWindow(); } })); return(retVal); }
private void updateProcessLookupTable(IApplicationAgent agent) { foreach (var processInfo in agent.ProcessesSupported) { if (!String.IsNullOrEmpty(processInfo.Name)) { List <IApplicationAgent> supportedAgents; var processName = processInfo.Name.ToLower(); if (!_agentLookupTableByProcessName.ContainsKey(processName)) { supportedAgents = new List <IApplicationAgent>(); _agentLookupTableByProcessName.Add(processName, supportedAgents); } else { supportedAgents = (List <IApplicationAgent>)_agentLookupTableByProcessName[processName]; } bool found = false; foreach (var supportedAgent in supportedAgents) { if (supportedAgent == agent) { found = true; break; } } if (!found) { supportedAgents.Add(agent); } } } }
/// <summary> /// Activates the File Browser functional agent. /// </summary> public static async void ShowFileBrowser(String action) { try { if (!Context.AppAgentMgr.CanActivateFunctionalAgent()) { return; } IApplicationAgent fileBrowserAgent = Context.AppAgentMgr.GetAgentByCategory("FileBrowserAgent"); if (fileBrowserAgent == null) { return; } fileBrowserAgent.GetInvoker().SetValue("AutoLaunchFile", true); fileBrowserAgent.GetInvoker().SetValue("Action", action); await Context.AppAgentMgr.ActivateAgent(fileBrowserAgent as IFunctionalAgent); } catch (Exception ex) { Log.Debug(ex.ToString()); } }
/// <summary> /// Activates the Switch Windows functional agent to enable the /// user to switch windows/apps. If taskname /// is not null, it only shows windows belonging to the task (eg /// notepad, word) /// </summary> /// <param name="taskName">filter by this process name</param> public static async void ShowTaskSwitcher(string taskName = "") { try { if (!Context.AppAgentMgr.CanActivateFunctionalAgent()) { return; } IApplicationAgent switchWindowsAgent = Context.AppAgentMgr.GetAgentByCategory("SwitchWindowsAgent"); if (switchWindowsAgent == null) { return; } IExtension extension = switchWindowsAgent; extension.GetInvoker().SetValue("FilterByProcessName", taskName); await Context.AppAgentMgr.ActivateAgent(switchWindowsAgent as IFunctionalAgent); Log.Debug("Returned from activate agent"); } catch (Exception ex) { Log.Debug(ex.ToString()); } }
/// <summary> /// Agent manager loads all agents on startup. However, /// agents can also be added at runtime and this function /// allows for that. /// Adds an ad-hoc agent for the specified window. Whenever /// this window becomes active, the agent is activated. /// </summary> /// <param name="handle"></param> /// <param name="agent"></param> /// <returns></returns> public bool AddAgent(IntPtr handle, IApplicationAgent agent) { Log.Debug("hwnd: " + handle + ", " + agent.Name); agent.EvtPanelRequest += agent_EvtPanelRequest; _agentsCache.AddAgent(handle, agent); return(true); }
/// <summary> /// Add the specified agent to the adhoc table. When the window /// identified by 'handle' is activated, the agent is also /// activated. Useful to add agents dynamically at runtime. /// </summary> /// <param name="handle">An application window handle</param> /// <param name="agent">Agent that supports the application</param> public void AddAgent(IntPtr handle, IApplicationAgent agent) { _adhocAgentTable[handle] = agent; if (EvtAgentAdded != null) { EvtAgentAdded(agent); } }
/// <summary> /// Launches the abbreivations agent /// </summary> private async void handleAbbreviationSettings() { IApplicationAgent abbrAgent = Context.AppAgentMgr.GetAgentByCategory("AbbreviationsAgent"); if (abbrAgent != null) { await Context.AppAgentMgr.ActivateAgent(abbrAgent as IFunctionalAgent); } }
/// <summary> /// Activates the "Phrases" agent that allows the user to /// convert canned phrases to speech /// </summary> private async void handlePhraseSpeak() { notifyRequestClose(); IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("Phrase Speak Agent"); if (agent != null) { await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); } }
/// <summary> /// Launches the abbreivations agent /// </summary> private async void handleAbbreviationSettings() { Context.AppTalkWindowManager.CloseTalkWindow(true); IApplicationAgent abbrAgent = Context.AppAgentMgr.GetAgentByName("Abbreviations Agent"); if (abbrAgent != null) { await Context.AppAgentMgr.ActivateAgent(abbrAgent as IFunctionalAgent); } }
/// <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> /// Displays the new file dailog /// </summary> private async void showNewFileDialog() { IApplicationAgent agent = Context.AppAgentMgr.GetAgentByCategory("NewFileAgent"); if (agent == null) { return; } await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); }
private async void showNewFileMenu() { IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("New File Agent"); if (agent == null) { return; } Context.AppTalkWindowManager.CloseTalkWindow(true); await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); }
private async void showNewFileMenu() { IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("New File Agent"); if (agent == null) { return; } Context.AppTalkWindowManager.CloseTalkWindow(true); Windows.CloseForm(Dispatcher.Scanner.Form); // TODO move this to main menu await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); }
/// <summary> /// Activates the file browser functional agent /// </summary> private async void launchFileBrowser() { IApplicationAgent fileBrowserAgent = Context.AppAgentMgr.GetAgentByName("FileBrowser Agent"); if (fileBrowserAgent == null) { return; } fileBrowserAgent.GetInvoker().SetValue("AutoLaunchFile", true); fileBrowserAgent.GetInvoker().SetValue("SelectActionOpen", !Common.AppPreferences.FileBrowserShowFileOperationsMenu); await Context.AppAgentMgr.ActivateAgent(fileBrowserAgent as IFunctionalAgent); }
/// <summary> /// Removes a previously added ad-hoc agent /// </summary> /// <param name="handle">window handle for the agent</param> public void RemoveAgent(IntPtr handle) { IApplicationAgent agent = _agentsCache.GetAgent(handle); if (agent != null) { agent.EvtPanelRequest -= agent_EvtPanelRequest; _agentsCache.RemoveAgent(handle); if (agent == _currentAgent) { _currentAgent = null; } } }
/// <summary> /// Launches the phrase speak agent to edit phrases /// </summary> private async void handlePhrasesEdit() { IApplicationAgent agent = Context.AppAgentMgr.GetAgentByCategory("PhraseSpeakAgent"); if (agent != null) { if (agent is IExtension) { agent.GetInvoker().SetValue("PhraseListEdit", true); } await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); } }
/// <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> /// Launches the phrase speak agent /// </summary> private async void handlePhraseSpeak() { Context.AppTalkWindowManager.CloseTalkWindow(true); IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("Phrase Speak Agent"); if (agent != null) { if (agent is IExtension) { var invoker = agent.GetInvoker(); invoker.SetValue("EnableSearch", true); } await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); } }
/// <summary> /// Handler for when an agents exits. /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void agent_EvtAgentClose(object sender, AgentCloseEventArgs e) { if (sender is IApplicationAgent) { var agent = (IApplicationAgent)sender; if (agent.Parent == null) { return; } IApplicationAgent parent = agent.Parent; setAgent(parent); parent.OnResume(); agent.Parent = null; } }
/// <summary> /// Activates the "Phrases" agent that allows the user to /// convert canned phrases to speech /// </summary> private async void handlePhraseSpeak() { notifyRequestClose(); IApplicationAgent agent = Context.AppAgentMgr.GetAgentByCategory("PhraseSpeakAgent"); if (agent != null) { if (agent is IExtension) { var invoker = agent.GetInvoker(); invoker.SetValue("EnableSearch", true); invoker.SetValue("PhraseListEdit", false); } await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); } }
/// <summary> /// Launches lecture manager with text from the MS Word window. This /// function returns only after lecture manager has exited /// </summary> /// <returns>task</returns> protected async void launchLectureManager(String fileName, String text) { IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("Lecture Manager Agent"); if (agent != null) { IExtension extension = agent; extension.GetInvoker().SetValue("LoadFromFile", false); if (!String.IsNullOrEmpty(fileName)) { extension.GetInvoker().SetValue("LectureFile", fileName); } extension.GetInvoker().SetValue("LectureText", text); await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); } }
/// <summary> /// Activates the functional agent responsible for launching /// applications /// </summary> public static async void ShowAppLauncher() { try { Context.AppTalkWindowManager.CloseTalkWindow(); IApplicationAgent launchAppAgent = Context.AppAgentMgr.GetAgentByName("Launch App Agent"); if (launchAppAgent == null) { return; } await Context.AppAgentMgr.ActivateAgent(launchAppAgent as IFunctionalAgent); } catch (Exception ex) { Log.Debug(ex.ToString()); } }
/// <summary> /// Launches lecture manager with text from the wordpad window. This /// function returns only after lecture manager has exited /// </summary> /// <returns>task</returns> private async Task launchLectureManager() { IApplicationAgent agent = Context.AppAgentMgr.GetAgentByCategory("LectureManagerAgent"); if (agent != null) { IExtension extension = agent; extension.GetInvoker().SetValue("LoadFromFile", false); String fileName = getFileNameFromWindow(); if (!String.IsNullOrEmpty(fileName)) { extension.GetInvoker().SetValue("LectureFile", fileName); } extension.GetInvoker().SetValue("LectureText", TextControlAgent.GetText()); await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); } }
/// <summary> /// Activates the file browser agent to get the /// name of the file to attach /// </summary> /// <returns>the task</returns> private async Task getFileToAttach() { IApplicationAgent fileBrowserAgent = Context.AppAgentMgr.GetAgentByCategory("FileBrowserAgent"); if (fileBrowserAgent == null) { return; } fileBrowserAgent.GetInvoker().SetValue("AutoLaunchFile", false); fileBrowserAgent.GetInvoker().SetValue("Action", "Open"); fileBrowserAgent.GetInvoker().SetValue("IncludeFileExtensions", new[] { "*.", "txt", "doc", "docx" }); fileBrowserAgent.GetInvoker().SetValue("ActionVerb", "Attach"); Log.Debug("Calling ActivateAgent"); await Context.AppAgentMgr.ActivateAgent(fileBrowserAgent as IFunctionalAgent); Log.Debug("Returned from ActivateAgent"); _fileAttachment = fileBrowserAgent.GetInvoker().GetStringValue("SelectedFile"); }
/// <summary> /// Activates the File Browser functional agent. /// </summary> public static async void ShowFileBrowser() { try { Context.AppTalkWindowManager.CloseTalkWindow(); IApplicationAgent fileBrowserAgent = Context.AppAgentMgr.GetAgentByName("FileBrowser Agent"); if (fileBrowserAgent == null) { return; } fileBrowserAgent.GetInvoker().SetValue("AutoLaunchFile", true); await Context.AppAgentMgr.ActivateAgent(fileBrowserAgent as IFunctionalAgent); } catch (Exception ex) { Log.Debug(ex.ToString()); } }
/// <summary> /// Activates the functional agent responsible for launching /// applications /// </summary> public static async void ShowAppLauncher() { try { if (!Context.AppAgentMgr.CanActivateFunctionalAgent()) { return; } IApplicationAgent launchAppAgent = Context.AppAgentMgr.GetAgentByCategory("LaunchAppAgent"); if (launchAppAgent == null) { return; } await Context.AppAgentMgr.ActivateAgent(launchAppAgent as IFunctionalAgent); } catch (Exception ex) { Log.Debug(ex.ToString()); } }
/// <summary> /// Activates the file browser agent to get the /// name of the file to attach /// </summary> /// <returns>the task</returns> private async Task getFileToAttach() { IApplicationAgent fileBrowserAgent = Context.AppAgentMgr.GetAgentByName("FileBrowser Agent"); if (fileBrowserAgent == null) { return; } fileBrowserAgent.GetInvoker().SetValue("AutoLaunchFile", false); fileBrowserAgent.GetInvoker().SetValue("SelectActionOpen", true); fileBrowserAgent.GetInvoker().SetValue("Folders", Common.AppPreferences.GetFavoriteFolders());//.FavoriteFolders.Split(';')); fileBrowserAgent.GetInvoker().SetValue("IncludeFileExtensions", new[] { "*.", "txt", "doc", "docx" }); fileBrowserAgent.GetInvoker().SetValue("ExcludeFileExtensions", getExcludeExtensions()); fileBrowserAgent.GetInvoker().SetValue("ActionVerb", "Attach"); Log.Debug("Calling ActivateAgent"); await Context.AppAgentMgr.ActivateAgent(fileBrowserAgent as IFunctionalAgent); Log.Debug("Returned from ActivateAgent"); _fileAttachment = fileBrowserAgent.GetInvoker().GetStringValue("SelectedFile"); }
/// <summary> /// Launches the lecture manager. First launches the /// file browser to get lecture file and then launches lecture /// manager with the file. /// </summary> /// <param name="form">scanner form</param> private async void launchLectureManager(Form form) { // First launch the file browser to get // the file name from the user IApplicationAgent fileBrowserAgent = Context.AppAgentMgr.GetAgentByName("FileBrowser Agent"); if (fileBrowserAgent == null) { return; } fileBrowserAgent.GetInvoker().SetValue("AutoLaunchFile", false); fileBrowserAgent.GetInvoker().SetValue("SelectActionOpen", true); fileBrowserAgent.GetInvoker().SetValue("Folders", Common.AppPreferences.GetFavoriteFolders());//.AppPreferences.FavoriteFolders.Split(';')); fileBrowserAgent.GetInvoker().SetValue("IncludeFileExtensions", new[] { "*.", "txt", "doc", "docx" }); fileBrowserAgent.GetInvoker().SetValue("ExcludeFileExtensions", getExcludeExtensions()); await Context.AppAgentMgr.ActivateAgent(fileBrowserAgent as IFunctionalAgent); String selectedFile = fileBrowserAgent.GetInvoker().GetStringValue("SelectedFile"); if (!String.IsNullOrEmpty(selectedFile)) { // now launch lecture manager for the selected file IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("Lecture Manager Agent"); if (agent != null) { Windows.CloseForm(form); IExtension extension = agent as IExtension; extension.GetInvoker().SetValue("LoadFromFile", true); extension.GetInvoker().SetValue("LectureFile", selectedFile); Log.Debug("Invoking LectureManager agent"); await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); Log.Debug("Returned from LectureManager 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> /// Event handler for when an agent is added to the cache. /// Subscribe to agent events /// </summary> /// <param name="agent">Agent that was added</param> private void _agentsCache_EvtAgentAdded(IApplicationAgent agent) { agent.EvtPanelRequest += agent_EvtPanelRequest; agent.EvtTextChanged += ApplicationAgent_EvtTextChanged; agent.EvtAgentClose += agent_EvtAgentClose; }
/// <summary> /// Don't context switch to the app agent that /// handles the foreground process other than the agent for the current /// assembly. Either use the agent responsible for the executing assembly or use /// the null agent. /// </summary> /// <param name="monitorInfo">fg process info</param> private void disallowContextSwitch(WindowActivityMonitorInfo monitorInfo) { bool handled = false; // check if there is an adhoc agent for the current window // if not, check if there is an agent for the current process var agent = _agentsCache.GetAgent(monitorInfo.FgHwnd); if (agent == null) { if (String.Compare(monitorInfo.FgProcess.ProcessName, _currentProcessName, true) == 0) { agent = _agentsCache.GetAgent(_currentProcessName) ?? DefaultAgentForContextSwitchDisable; } } if (agent == null) { agent = DefaultAgentForContextSwitchDisable; } if (agent == null) { agent = _genericAppAgent; } Log.Debug("agent : " + agent.Name); if (_getContextMenu) { _getContextMenu = false; agent.OnContextMenuRequest(monitorInfo); return; } if (agent != _currentAgent && _currentAgent != null) { _currentAgent.OnFocusLost(); } _currentAgent = agent; agent.OnFocusChanged(monitorInfo, ref handled); }
/// <summary> /// Agent manager loads all agents on startup. However, /// agents can also be added at runtime and this function /// allows for that. /// Adds an ad-hoc agent for the specified window. Whenever /// this window becomes active, the agent is activated. /// </summary> /// <param name="handle">window handle</param> /// <param name="agent">agent to add</param> public void AddAgent(IntPtr handle, IApplicationAgent agent) { Log.Debug("hwnd: " + handle + ", " + agent.Name); agent.EvtPanelRequest += agent_EvtPanelRequest; _agentsCache.AddAgent(handle, agent); var fgWindow = User32Interop.GetForegroundWindow(); if (fgWindow != IntPtr.Zero) { if (fgWindow == handle) { WindowActivityMonitor.GetActiveWindowAsync(); } } }
/// <summary> /// Updates _currentAgent to the agent specified /// </summary> /// <param name="agent">sets the agent</param> private void setAgent(IApplicationAgent agent) { Log.Debug("Setting agent to " + ((agent != null) ? agent.Name : "null")); _currentAgent = agent; }
/// <summary> /// Invoked before the agent is deactivated. Override this and return true if it is /// OK to deactivate the agent, false otherwise /// </summary> /// <param name="newAgent">Agent that will be activated</param> /// <returns>true/false</returns> public virtual bool QueryAgentSwitch(IApplicationAgent newAgent) { return true; }
private void updateProcessLookupTable(IApplicationAgent agent) { foreach (var processInfo in agent.ProcessesSupported) { if (!String.IsNullOrEmpty(processInfo.Name)) { List<IApplicationAgent> supportedAgents; var processName = processInfo.Name.ToLower(); if (!_agentLookupTableByProcessName.ContainsKey(processName)) { supportedAgents = new List<IApplicationAgent>(); _agentLookupTableByProcessName.Add(processName, supportedAgents); } else { supportedAgents = (List<IApplicationAgent>)_agentLookupTableByProcessName[processName]; } bool found = false; foreach (var supportedAgent in supportedAgents) { if (supportedAgent == agent) { found = true; break; } } if (!found) { supportedAgents.Add(agent); } } } }
/// <summary> /// Add the specified agent to the adhoc table. When the window /// identified by 'handle' is activated, the agent is also /// activated. Useful to add agents dynamically at runtime. /// </summary> /// <param name="handle">An application window handle</param> /// <param name="agent">Agent that supports the application</param> public void AddAgent(IntPtr handle, IApplicationAgent agent) { _adhocAgentTable[handle] = agent; }
/// <summary> /// Agent manager loads all agents on startup. However, /// agents can also be added at runtime and this function /// allows for that. /// Adds an ad-hoc agent for the specified window. Whenever /// this window becomes active, the agent is activated. /// </summary> /// <param name="handle"></param> /// <param name="agent"></param> /// <returns></returns> public bool AddAgent(IntPtr handle, IApplicationAgent agent) { Log.Debug("hwnd: " + handle + ", " + agent.Name); agent.EvtPanelRequest += agent_EvtPanelRequest; _agentsCache.AddAgent(handle, agent); return true; }
/// <summary> /// Sets the current agent to the specified one and raises /// a text changed event. /// </summary> /// <param name="agent">agent to set as the current agent</param> private void updateCurrentAgentAndNotify(IApplicationAgent agent) { _textControlAgent = agent.TextControlAgent; setAgent(agent); notifyTextChanged(_textControlAgent); }
public bool Init(IEnumerable<String> extensionDirs) { if (_agentsCache == null) { _agentsCache = new AgentsCache(); _agentsCache.EvtAgentAdded += _agentsCache_EvtAgentAdded; _agentsCache.Init(extensionDirs); _genericAppAgent = _agentsCache.GetAgent(GenericAppAgentName); if (_genericAppAgent == null) { _agentsCache.AddAgentByType(typeof(UnsupportedAppAgent)); _genericAppAgent = _agentsCache.GetAgent(GenericAppAgentName); } _agentsCache.AddAgentByType(typeof(NullAgent)); _nullAgent = _agentsCache.GetAgent(NullAgentName); _dialogAgent = _agentsCache.GetAgent(DialogControlAgentName); _menuControlAgent = _agentsCache.GetAgent(MenuControlAgentName); _textControlAgent = _genericAppAgent.TextControlAgent; WindowActivityMonitor.EvtFocusChanged += WindowActivityMonitor_EvtFocusChanged; //WindowActivityMonitor.GetActiveWindow(); } return true; }