/// <summary> /// Attaches a file to the current email being composed. The currently /// focused window has to be the mail compose window. Sends a /// Ctrl+H command to. Launches the file browser to get the file to attach /// from the user. Then inserts the filename into the attachment field /// in the mail compose window /// </summary> protected async void attachFile() { var info = WindowActivityMonitor.GetForegroundWindowInfo(); if (!isMailComposeMessageWindow(info.FocusedElement) && !isMailComposeWindow(info.FocusedElement)) { Log.Debug("Wrong window"); return; } _fileAttachment = String.Empty; await getFileToAttach(); if (String.IsNullOrEmpty(_fileAttachment)) { return; } Thread.Sleep(500); EnumWindows.RestoreFocusToTopWindow(); Thread.Sleep(500); SendKeys.SendWait("^h"); Thread.Sleep(1000); for (int ii = 0; ii < 10; ii++) { var info1 = WindowActivityMonitor.GetForegroundWindowInfo(); if (info1.Title == "Attach File") { Log.Debug("YES! Found Attach file window"); var automationElement = AgentUtils.GetElementOrAncestorByAutomationId( info1.FocusedElement, "Edit", "ControlType.Edit", "1148"); if (automationElement != null) { Log.Debug("element is not null"); AgentUtils.InsertTextIntoElement(automationElement, _fileAttachment); SendKeys.Send("{ENTER}"); } else { Log.Debug("element is null"); } break; } Thread.Sleep(500); } }
/// <summary> /// Attaches a file to the current email being composed. /// Launches the file browser to get the file to attach from the user. /// Sends a command to bring up the Outlook "Insert File" dialog. /// Inserts the filename into the file name field in the dialog /// </summary> protected async void attachFile() { _fileAttachment = String.Empty; await getFileToAttach(); if (String.IsNullOrEmpty(_fileAttachment)) { return; } Thread.Sleep(500); EnumWindows.RestoreFocusToTopWindowOnDesktop(); Thread.Sleep(500); AgentManager.Instance.Keyboard.Send(Keys.F10); AgentManager.Instance.Keyboard.Send(Keys.H); AgentManager.Instance.Keyboard.Send(Keys.A); AgentManager.Instance.Keyboard.Send(Keys.F); Thread.Sleep(1000); for (int ii = 0; ii < 10; ii++) { var info1 = WindowActivityMonitor.GetForegroundWindowInfo(); if (String.Compare(info1.Title, R.GetString2("OutlookAttachFileWindowTitle"), true) == 0) { Log.Debug("YES! Found Attach file window"); var automationElement = AgentUtils.GetElementOrAncestorByAutomationId( info1.FocusedElement, "Edit", "ControlType.Edit", "1148"); if (automationElement != null) { Log.Debug("element is not null"); AgentUtils.InsertTextIntoElement(automationElement, _fileAttachment); SendKeys.Send("{ENTER}"); } else { Log.Debug("element is null"); } break; } Thread.Sleep(500); } }
/// <summary> /// Is the active window an open Outlook "Note" window? /// </summary> /// <param name="monitorInfo">Active window info</param> /// <param name="subType">The focused Outlook window control element </param> /// <returns>true if it is</returns> public bool IsOpenNoteWindow(WindowActivityMonitorInfo monitorInfo, ref OutlookControlSubType subType) { bool retVal = false; subType = OutlookControlSubType.Unknown; var element = AgentUtils.GetElementOrAncestorByAutomationId(monitorInfo.FocusedElement, "RichEdit20WPT", "ControlType.Edit", "4159"); if (element != null) { var name = element.Current.Name; retVal = (name == "Note text"); } if (retVal) { if (AgentUtils.IsElementByAutomationId(monitorInfo.FocusedElement, "RichEdit20WPT", "ControlType.Edit", "4159")) { subType = OutlookControlSubType.OpenNoteMessageBodyField; } } return(retVal); }