ACAT.Lib.Extension.AppAgents.Outlook.OutlookAgentBase.attachFile C# (CSharp) Method

attachFile() protected method

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
protected attachFile ( ) : void
return void
        protected async void attachFile()
        {
            _fileAttachment = String.Empty;
            await getFileToAttach();

            if (String.IsNullOrEmpty(_fileAttachment))
            {
                return;
            }

            Thread.Sleep(500);
            EnumWindows.RestoreFocusToTopWindow();
            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 (info1.Title == "Insert 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);
            }
        }