Пример #1
0
        /// <summary>
        /// Constructor used for everything which isn't a Form
        /// </summary>
        /// <param name="parentForm">The form the control belongs to</param>
        /// <param name="descriptionOfControl">The human readable description of the control</param>
        /// <param name="identParams">The identifier(s) of the control</param>
        protected GUIObject(GUIForm parentForm, string descriptionOfControl, params Identifier[] identParams)
        {
            ParentForm = parentForm;
            Identity   = GUI.BuildIdentity(parentForm, descriptionOfControl, identParams);

            GUI.m_APE.AddFirstMessageFindByProperty(Identity);
            GUI.m_APE.SendMessages(EventSet.APE);
            GUI.m_APE.WaitForMessages(EventSet.APE);
            GUI.m_APE.DecodeControl(1, out Identity);

            Input.WaitForInputIdle(Handle, GUI.m_APE.TimeOut);
        }
Пример #2
0
        private void BuildTree()
        {
            LocateButton.Enabled = false;

            //store a temp copy of m_Identity
            ControlIdentifier temp = m_Identity;

            WindowTree.Nodes.Clear();
            PropertyListbox.Items.Clear();
            m_CurrentAttached = (KeyValuePair <Process, string>)WinformsProcessesCombobox.SelectedItem;

            if (m_CurrentAttached.Key.HasExited)
            {
                WinformsProcessesCombobox.SelectedIndex = 0;
                Populate();
            }
            else
            {
                if (m_CurrentAttached.Key.Id != Process.GetCurrentProcess().Id)
                {
                    ListOfTopLevelWindows = new Dictionary <IntPtr, string>();

                    NM.EnumWindowsProc WindowsCallback = new NM.EnumWindowsProc(EnumProc);

                    if (m_APE != null)
                    {
                        m_APE.RemoveFileMapping();
                    }

                    if (AppDomainComboBox.Enabled)
                    {
                        string NewDomain = AppDomainComboBox.SelectedItem.ToString();
                        m_APE = new APEIPC(m_CurrentAttached.Key, NewDomain);
                    }
                    else
                    {
                        m_APE = new APEIPC(m_CurrentAttached.Key);
                    }
                    m_APE.TimeOut = 0;

                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    NM.EnumWindows(WindowsCallback, new IntPtr(m_CurrentAttached.Key.Id));
                }
            }
            //restore m_Identity
            m_Identity = temp;
        }
Пример #3
0
        private ControlIdentifier GetIdentity(ControlIdentifier identity)
        {
            try
            {
                m_APE.AddFirstMessageFindByProperty(identity);
                m_APE.SendMessages(EventSet.APE);
                m_APE.WaitForMessages(EventSet.APE);
                m_APE.DecodeControl(1, out identity);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + "\r\n" + ex.StackTrace.ToArray());
                identity.Handle = IntPtr.Zero;
            }

            return(identity);
        }
Пример #4
0
        private void btnSelect_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedNode == null)
            {
                ErrorAlert.Show("No node selected.\nPlease select a node.");
                return;
            }
            ControlIdentifier            = new ControlIdentifier();
            ControlIdentifier.Name       = Utils.GetFriendlyHtmlName(SelectedNode);
            ControlIdentifier.Identifier = SelectedNode.XPath;

            SectionIdentifier            = new SectionIdentifier();
            SectionIdentifier.Name       = Utils.GetFriendlyHtmlName(SelectedNode);
            SectionIdentifier.Identifier = SelectedNode.XPath;

            Close();
        }
Пример #5
0
        /// <summary>
        /// Checks if the specified control currently exists
        /// </summary>
        /// <param name="parentForm">The identifier(s) of the control</param>
        /// <param name="identParams"></param>
        /// <returns></returns>
        public static bool Exists(GUIForm parentForm, params Identifier[] identParams)
        {
            ControlIdentifier Identity = GUI.BuildIdentity(parentForm, null, identParams);

            GUI.m_APE.AddFirstMessageControlExistsByProperty(Identity);
            GUI.m_APE.SendMessages(EventSet.APE);
            GUI.m_APE.WaitForMessages(EventSet.APE);
            //Get the value(s) returned MUST be done straight after the WaitForMessages call
            GUI.m_APE.DecodeControl(1, out Identity);
            if (Identity.Handle == IntPtr.Zero)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #6
0
        private void GetIdentity(IntPtr Parent, IntPtr Handle)
        {
            m_Identity = new ControlIdentifier();

            try
            {
                if (Parent != Handle)
                {
                    m_Identity.ParentHandle = Parent;
                }
                m_Identity.Handle = Handle;
                m_APE.AddFirstMessageFindByProperty(m_Identity);
                m_APE.SendMessages(EventSet.APE);
                m_APE.WaitForMessages(EventSet.APE);
                m_APE.DecodeControl(1, out m_Identity);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetIdentity by handle failed " + Parent.ToString() + " " + Handle.ToString() + ": " + ex.Message + "\r\n" + ex.StackTrace.ToArray());

                //if (NM.IsTopLevelWindow(m_Identity.Handle))
                //{
                //    IntPtr menu = NM.GetMenu(m_Identity.Handle);
                //    if (menu == IntPtr.Zero)
                //    {
                //        IntPtr contextMenu = NM.GetContextMenu(m_Identity.Handle);
                //        if (contextMenu != IntPtr.Zero)
                //        {
                //            Debug.WriteLine("----- " + NM.GetMenuString(contextMenu, 0, NM.GetMenuFlag.MF_BYPOSITION));
                //        }
                //    }
                //    else
                //    {
                //        Debug.WriteLine("----- " + NM.GetMenuString(menu, 0, NM.GetMenuFlag.MF_BYPOSITION));
                //    }
                //}
            }
        }
Пример #7
0
        private string GetAPEType(ControlIdentifier Identity)
        {
            string APEType = "";

            // TODO will this always be the case?
            if (Identity.ParentHandle == IntPtr.Zero)
            {
                APEType = "GUIForm";
            }

            if (Identity.TechnologyType == "Windows Forms (WinForms)")
            {
                m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                m_APE.AddMessageGetRecognisedType(DataStores.Store0, DataStores.Store1);
                m_APE.AddMessageGetApeTypeFromObject(DataStores.Store0, DataStores.Store2);
                m_APE.AddMessageGetApeTypeFromType(DataStores.Store1, DataStores.Store3);
                m_APE.AddRetrieveMessageGetValue(DataStores.Store2);
                m_APE.AddRetrieveMessageGetValue(DataStores.Store3);
                m_APE.SendMessages(EventSet.APE);
                m_APE.WaitForMessages(EventSet.APE);
                //Get the value(s) returned MUST be done straight after the WaitForMessages call;
                string APEDirectType = m_APE.GetValueFromMessage();
                string APEBaseType   = m_APE.GetValueFromMessage();

                if (APEDirectType != "")
                {
                    APEType = APEDirectType;
                }
                else if (APEBaseType != "")
                {
                    APEType = APEBaseType + "*";     //Make it clear that its the base class which is supported rather than the extended control
                }
            }

            return(APEType);
        }
Пример #8
0
        private void PopulatePropertyListbox(IntPtr Parent, IntPtr Handle)
        {
            GetIdentity(Parent, Handle);
            string APEType = GetAPEType(m_Identity);

            PropertyListbox.Items.Clear();
            PropertyListbox.Items.Add("Control Handle\t: " + m_Identity.Handle);
            PropertyListbox.Items.Add("Form Handle\t: " + m_Identity.ParentHandle);
            PropertyListbox.Items.Add("Name\t\t: " + m_Identity.Name);
            PropertyListbox.Items.Add("Text\t\t: " + m_Identity.Text);
            PropertyListbox.Items.Add("TypeName\t: " + m_Identity.TypeName);
            PropertyListbox.Items.Add("TypeNameSpace\t: " + m_Identity.TypeNameSpace);
            PropertyListbox.Items.Add("TechnologyType\t: " + m_Identity.TechnologyType);
            PropertyListbox.Items.Add("ModuleName\t: " + m_Identity.ModuleName);

            //Workout the index
            Guid notUsed;

            m_Identity.Index = 0;
            while (true)
            {
                m_Identity.Index++;

                ControlIdentifier identity = new ControlIdentifier();
                identity.ParentHandle   = m_Identity.ParentHandle;
                identity.TechnologyType = m_Identity.TechnologyType;
                if (m_Identity.Name != "" && m_Identity.Name != null && !Guid.TryParse(m_Identity.Name, out notUsed) && m_Identity.Name != "DinamicallyLoadedControl")
                {
                    //Use Name as the index key
                    identity.Name = m_Identity.Name;
                }
                else if (m_Identity.Text != "" && m_Identity.Text != null)
                {
                    //Use Typename and Text as the index key
                    identity.Text     = "^" + Regex.Escape(m_Identity.Text) + "$";
                    identity.TypeName = m_Identity.TypeName;
                }
                else
                {
                    //Use type as the index key
                    identity.TypeNameSpace = m_Identity.TypeNameSpace;
                    identity.TypeName      = m_Identity.TypeName;
                }
                identity.Index = m_Identity.Index;
                identity       = GetIdentity(identity);

                if (identity.Handle == m_Identity.Handle)
                {
                    break;
                }

                if (identity.Handle == IntPtr.Zero)
                {
                    m_Identity.Index = -1;
                    break;
                }
            }

            string mainLocatorText   = "";
            string indexLocatorText  = "";
            string parentLocatorText = "";

            if (m_Identity.Name != "" && m_Identity.Name != null && !Guid.TryParse(m_Identity.Name, out notUsed) && m_Identity.Name != "DinamicallyLoadedControl")
            {
                PropertyListbox.Items.Add("Index (by Name)\t: " + m_Identity.Index);
                mainLocatorText = ", new Identifier(Identifiers.Name, \"" + m_Identity.Name + "\")";
            }
            else if (m_Identity.Text != "" && m_Identity.Text != null)
            {
                PropertyListbox.Items.Add("Index (by Text and\t: " + m_Identity.Index);
                PropertyListbox.Items.Add(" TypeName)");
                mainLocatorText = ", new Identifier(Identifiers.Text, @\"^" + Regex.Escape(m_Identity.Text) + "$\"), new Identifier(Identifiers.TypeName, \"" + m_Identity.TypeName + "\")";
            }
            else
            {
                PropertyListbox.Items.Add("Index (by Type)\t: " + m_Identity.Index);
                mainLocatorText = ", new Identifier(Identifiers.TypeName, \"" + m_Identity.TypeName + "\")";
            }

            if (m_Identity.Index > 1)
            {
                indexLocatorText = ", new Identifier(Identifiers.Index, " + m_Identity.Index + ")";
            }

            if (m_Identity.ParentHandle != IntPtr.Zero)
            {
                parentLocatorText = "$parentForm$, ";
            }

            PropertyListbox.Items.Add("APEType\t\t: " + APEType);

            if (APEType == "")
            {
                m_ObjectCodeLocator = "";
            }
            else
            {
                m_ObjectCodeLocator = APEType.TrimEnd(new char[] { '*' }) + " $name$ = new " + APEType.TrimEnd(new char[] { '*' }) + "(" + parentLocatorText + "$friendlyName$" + mainLocatorText + indexLocatorText + ");";
            }

            PropertyListbox.Items.Add("");

            switch (APEType)
            {
            case "GUIToolStrip":
            case "GUIMenuStrip":
            case "GUIStatusStrip":
                AddGUIToolStripToPropertyListbox();
                break;

            case "GUIStatusBar":
                AddGUIStatusBarToPropertyListbox();
                break;

            case "GUITitleFrame":
                AddGUITitleFrameToPropertyListbox();
                break;

            case "GUIElementStripGrid":
                AddGUIElementStripGridToPropertyListbox();
                break;

            default:
                switch (m_Identity.TypeName)
                {
                case "ToolStripDropDownMenu":
                    AddToolStripDropDownMenuToPropertyListbox();
                    break;
                }
                break;
            }
        }
Пример #9
0
 /// <summary>
 /// Constructor used for TitleFrame objects
 /// </summary>
 /// <param name="parentTitleFrame">The parent title frame the object belongs to</param>
 /// <param name="descriptionOfControl">A description of the control which would make sense to a human.
 /// <para/>This text is used in the logging method.  For example: OK button</param>
 /// <param name="identParams">One or more identifier object(s) used to locate the control.
 /// <para/>Normally you would just use the name identifier</param>
 protected GUITitleFrameObject(GUITitleFrame parentTitleFrame, string descriptionOfControl, params Identifier[] identParams)
 {
     ParentTitleFrame = parentTitleFrame;
     Identity         = GUI.BuildIdentity(null, descriptionOfControl, identParams);
     UpdateIndex();
 }
Пример #10
0
        public bool MenuItemCheckOnClick(IntPtr parent, IntPtr control, int menuIndex, string menuItem, ref ControlIdentifier controlIdentity)
        {
            //Get CheckOnClick state
            GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, parent, control);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "Items", MemberTypes.Property);
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Item", MemberTypes.Property, new Parameter(GUI.m_APE, menuIndex));
            GUI.m_APE.AddQueryMessageReflect(DataStores.Store2, DataStores.Store3, "CheckOnClick", MemberTypes.Property);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3);
            GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store4);
            GUI.m_APE.SendMessages(EventSet.APE);
            GUI.m_APE.WaitForMessages(EventSet.APE);
            //get the values returned
            bool isCheckOnClick = GUI.m_APE.GetValueFromMessage();

            return(isCheckOnClick);
        }
Пример #11
0
 private void lsbDiscoveredControls_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     SelectedNode = (lsbDiscoveredControls.SelectedItem as ListBoxItem).Tag as ControlIdentifier;
 }
Пример #12
0
        internal static ControlIdentifier BuildIdentity(GUIForm parentForm, string descriptionOfControl, params Identifier[] identParams)
        {
            ControlIdentifier Identity = new ControlIdentifier();

            Identity.Description = descriptionOfControl;
            if (parentForm != null)
            {
                Identity.ParentHandle = parentForm.Handle;
            }

            foreach (Identifier i in identParams)
            {
                switch (i.IdentifierType)
                {
                case Identifiers.Handle:
                    Identity.Handle = i.IdentifierValue;
                    break;

                case Identifiers.Name:
                    Identity.Name = i.IdentifierValue;
                    break;

                case Identifiers.TechnologyType:
                    Identity.TechnologyType = i.IdentifierValue;
                    break;

                case Identifiers.TypeNameSpace:
                    Identity.TypeNameSpace = i.IdentifierValue;
                    break;

                case Identifiers.TypeName:
                    Identity.TypeName = i.IdentifierValue;
                    break;

                case Identifiers.ModuleName:
                    Identity.ModuleName = i.IdentifierValue;
                    break;

                case Identifiers.AssemblyName:
                    Identity.AssemblyName = i.IdentifierValue;
                    break;

                case Identifiers.Index:
                    Identity.Index = i.IdentifierValue;
                    break;

                case Identifiers.Text:
                    Identity.Text = i.IdentifierValue;
                    break;

                case Identifiers.ChildOf:
                    Identity.ChildOf = i.IdentifierValue.Handle;
                    break;

                case Identifiers.SiblingOf:
                    Identity.SiblingOf = i.IdentifierValue.Handle;
                    break;

                default:
                    throw new Exception("Unsupported identifier: " + i.ToString());
                }
            }

            if (Identity.TechnologyType == null)
            {
                Identity.TechnologyType = "Windows Forms (WinForms)";
            }

            return(Identity);
        }
Пример #13
0
        private void FindByIdentifierRenderedActiveX(ControlIdentifier identifier, ref IntPtr handle, ref string name, ref string theText, ref string typeNameSpace, ref string typeName, ref string technologyType, ref string uniqueId, ref bool foundControl)
        {
            IntPtr parentHandle = IntPtr.Zero;
            int    currentIndex = 0;

            if (Ax.Items.Count > 0)
            {
                lock (Ax.AxItemsLock)
                {
                    object control = null;
                    int    item;
                    int    items = Ax.Items.Count;
                    for (item = 0; item < items; item++)
                    {
                        if (Ax.Items[item].Control == null)
                        {
                            continue;
                        }

                        handle       = Ax.Items[item].Handle;
                        parentHandle = Ax.Items[item].ParentHandle;
                        name         = Ax.Items[item].Name;
                        uniqueId     = Ax.Items[item].UniqueId;
                        control      = Ax.Items[item].Control;

                        if (identifier.ParentHandle == parentHandle || NM.GetAncestor(identifier.ParentHandle, NM.GetAncestorFlags.GetRoot) == parentHandle || (identifier.ParentHandle == IntPtr.Zero && parentHandle == handle))
                        {
                        }
                        else
                        {
                            continue;
                        }

                        if (!NM.IsWindowVisible(handle))
                        {
                            continue;
                        }

                        //if (!Ax.Items[item].Rendered)
                        //{
                        //    continue;
                        //}

                        if (identifier.Name != null)
                        {
                            if (name != identifier.Name)
                            {
                                continue;
                            }
                        }

                        if (identifier.TechnologyType != null)
                        {
                            if ("Windows ActiveX" != identifier.TechnologyType)
                            {
                                continue;
                            }
                        }

                        if (identifier.TypeNameSpace != null)
                        {
                            typeNameSpace = Ax.Items[item].TypeNameSpace;   //Lazy load it only if we need it
                            if (typeNameSpace == null)
                            {
                                continue;
                            }
                            else
                            {
                                if (!Regex.IsMatch(typeNameSpace, identifier.TypeNameSpace))
                                {
                                    continue;
                                }
                            }
                        }

                        if (identifier.TypeName != null)
                        {
                            typeName = Ax.Items[item].TypeName; //Lazy load it only if we need it
                            if (typeName == null)
                            {
                                continue;
                            }
                            else
                            {
                                if (!Regex.IsMatch(typeName, identifier.TypeName))
                                {
                                    continue;
                                }
                            }
                        }

                        if (identifier.ModuleName != null)
                        {
                            if (Path.GetFileName(NM.GetWindowModuleFileName(handle)) != identifier.ModuleName)
                            {
                                continue;
                            }
                        }

                        if (identifier.AssemblyName != null)
                        {
                            continue;
                        }

                        if (identifier.ChildOf != IntPtr.Zero)
                        {
                            if (identifier.ChildOf == handle || NM.IsChild(identifier.ChildOf, handle))
                            {
                            }
                            else
                            {
                                continue;
                            }
                        }

                        if (identifier.SiblingOf != IntPtr.Zero)
                        {
                            continue;
                        }

                        if (identifier.ParentOf != IntPtr.Zero)
                        {
                            continue;
                        }

                        //Make sure the type name space and type name are populated
                        typeName      = Ax.Items[item].TypeName;
                        typeNameSpace = Ax.Items[item].TypeNameSpace;

                        if (typeName == "Label" && string.IsNullOrEmpty(typeNameSpace))
                        {
                            theText = (string)m_ComReflectDelegater.Invoke("Caption", Ax.Items[item].Control, null);
                        }
                        if (identifier.Text != null)
                        {
                            if (theText == null)
                            {
                                continue;
                            }
                            else
                            {
                                if (!Regex.IsMatch(theText, identifier.Text))
                                {
                                    continue;
                                }
                            }
                        }

                        if (identifier.AccessibilityObjectName != null)
                        {
                            continue;
                        }

                        currentIndex++;

                        if (identifier.Index > 0)
                        {
                            if (currentIndex != identifier.Index)
                            {
                                continue;
                            }
                        }

                        technologyType = "Windows ActiveX";
                        //WF.MessageBox.Show("Found handle: " + name + " " + handle.ToString());
                        foundControl = true;
                        return;
                    }
                }
            }
        }
Пример #14
0
        private void FindByIdentifierActiveX(ControlIdentifier identifier, ref IntPtr handle, ref string name, ref string theText, ref string typeNameSpace, ref string typeName, ref int currentIndex, ref string uniqueId, ref bool foundControl)
        {
            bool   found        = false;
            IntPtr parentHandle = IntPtr.Zero;

            if (Ax.Items.Count > 0)
            {
                lock (Ax.AxItemsLock)
                {
                    object control = null;
                    int    item;
                    int    items = Ax.Items.Count;
                    for (item = 0; item < items; item++)
                    {
                        if (Ax.Items[item].Handle == handle)
                        {
                            parentHandle = Ax.Items[item].ParentHandle;
                            name         = Ax.Items[item].Name;
                            uniqueId     = Ax.Items[item].UniqueId;
                            control      = Ax.Items[item].Control;
                            found        = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        return;
                    }

                    if (identifier.ParentHandle == parentHandle || (identifier.ParentHandle == IntPtr.Zero && parentHandle == handle))
                    {
                    }
                    else
                    {
                        return;
                    }

                    if (identifier.Name != null)
                    {
                        if (name != identifier.Name)
                        {
                            return;
                        }
                    }

                    if (identifier.TechnologyType != null)
                    {
                        if ("Windows ActiveX" != identifier.TechnologyType)
                        {
                            return;
                        }
                    }

                    if (identifier.TypeNameSpace != null)
                    {
                        typeNameSpace = Ax.Items[item].TypeNameSpace;   //Lazy load it only if we need it
                        if (typeNameSpace == null)
                        {
                            return;
                        }
                        else
                        {
                            if (!Regex.IsMatch(typeNameSpace, identifier.TypeNameSpace))
                            {
                                return;
                            }
                        }
                    }

                    if (identifier.TypeName != null)
                    {
                        typeName = Ax.Items[item].TypeName; //Lazy load it only if we need it
                        if (typeName == null)
                        {
                            return;
                        }
                        else
                        {
                            if (!Regex.IsMatch(typeName, identifier.TypeName))
                            {
                                return;
                            }
                        }
                    }

                    if (identifier.ModuleName != null)
                    {
                        if (Path.GetFileName(NM.GetWindowModuleFileName(handle)) != identifier.ModuleName)
                        {
                            return;
                        }
                    }

                    if (identifier.AssemblyName != null)
                    {
                        return;
                    }

                    if (identifier.ChildOf != IntPtr.Zero)
                    {
                        if (!NM.IsChild(identifier.ChildOf, handle))
                        {
                            return;
                        }
                    }

                    if (identifier.SiblingOf != IntPtr.Zero)
                    {
                        if (!NM.IsSibling(identifier.SiblingOf, handle))
                        {
                            return;
                        }
                    }

                    if (identifier.ParentOf != IntPtr.Zero)
                    {
                        if (!NM.IsChild(handle, identifier.ParentOf))
                        {
                            return;
                        }
                    }

                    theText = GetWindowTextViaWindowMessage(handle);
                    if (identifier.Text != null)
                    {
                        if (theText == null)
                        {
                            return;
                        }
                        else
                        {
                            if (!Regex.IsMatch(theText, identifier.Text))
                            {
                                return;
                            }
                        }
                    }

                    if (identifier.AccessibilityObjectName != null)
                    {
                        return;
                    }

                    currentIndex++;
                    if (identifier.Index > 0)
                    {
                        if (currentIndex != identifier.Index)
                        {
                            return;
                        }
                    }

                    //Make sure the type name space and type name are populated
                    typeName      = Ax.Items[item].TypeName;
                    typeNameSpace = Ax.Items[item].TypeNameSpace;

                    //we have a match
                    foundControl = true;
                }
            }
        }
Пример #15
0
 private void btnSelectCustomNode_Click(object sender, RoutedEventArgs e)
 {
     manualSelector.ShowSelector();
     SelectedNode = manualSelector.ControlIdentifier;
     FinishSelection();
 }
Пример #16
0
 private void BtnCancel_Click(object sender, RoutedEventArgs e)
 {
     SelectedNode = null;
     Close();
 }
Пример #17
0
        unsafe public void ProcessMessages(int APEPID, string AppDomainToLoadInto)
        {
            m_ManagedThreadId = Thread.CurrentThread.ManagedThreadId;
            try
            {
                AUTProcess = Process.GetCurrentProcess();
                string AUTProcessId = AUTProcess.Id.ToString();
                string APEProcessId = APEPID.ToString();

                // Set the thread name so its easy to find in the debugger
                Thread.CurrentThread.Name = "APE_" + APEProcessId + "_" + AppDomainToLoadInto + "_" + AUTProcessId;

                m_HandleMemoryMappedFileStringStore      = NM.CreateFileMapping((IntPtr)(NM.INVALID_HANDLE_VALUE), (IntPtr)0, NM.FileMapProtection.PageReadWrite, 0, StringSpaceBytes, APEProcessId + "_String_" + AppDomainToLoadInto + "_" + AUTProcessId);
                m_IntPtrMemoryMappedFileViewStringStore  = NM.MapViewOfFile(m_HandleMemoryMappedFileStringStore, NM.FileMapAccess.FileMapAllAccess, 0, 0, (UIntPtr)StringSpaceBytes);
                m_HandleMemoryMappedFileMessageStore     = NM.CreateFileMapping((IntPtr)(NM.INVALID_HANDLE_VALUE), (IntPtr)0, NM.FileMapProtection.PageReadWrite, 0, (uint)sizeof(MessageStore), APEProcessId + "_Message_" + AppDomainToLoadInto + "_" + AUTProcessId);
                m_IntPtrMemoryMappedFileViewMessageStore = NM.MapViewOfFile(m_HandleMemoryMappedFileMessageStore, NM.FileMapAccess.FileMapAllAccess, 0, 0, (UIntPtr)sizeof(MessageStore));
                m_PtrMessageStore = (MessageStore *)m_IntPtrMemoryMappedFileViewMessageStore.ToPointer();

                m_eventIPC = new EventWaitHandle(false, EventResetMode.AutoReset, APEProcessId + "_EventIPC_" + AppDomainToLoadInto + "_" + AUTProcessId);

                Side = EventSet.AUT;
                try
                {
                    ApeProcess = Process.GetProcessById(APEPID);
                }
                catch
                {
                }

                // Setup the hook procedures
                SetupmouseHelperHooks();
                EnumThreadProcedue = new NM.EnumWindow(EnumThreadCallback);

                // Setup the delegates
                m_GetWPFHandleAndNameAndTitleDelegater = new GetWPFHandleAndNameAndTitleDelegate(GetWPFHandleAndNameAndTitle);
                m_ConvertTypeDelegater = new ConvertTypeDelegate(Cast);
                m_GetTextDelegater     = new GetTextDelegate(GetText);
                m_GetAccessibilityObjectNameDelegater = new GetAccessibilityObjectNameDelegate(GetAccessibilityObjectName);
                SetupSentinelGridsHelperDelegates();
                SetupFlexgridHelperDelegates();
                SetupComHelperDelegates();
                SetupGridControlHelperDelegates();
                SetupFormHelperDelegates();
                SetupDictionaryHelperDelegates();
                SetupDataGridViewHelperDelegates();

                //Process all the messages
                while (true)
                {
                    WaitForMessages(EventSet.AUT);
                    if (m_Abort)
                    {
                        RemoveFileMapping();
                        break;
                    }

                    string result           = null;
                    int    messageNumber    = -1;
                    int    numberOfMessages = -1;

                    try
                    {
                        numberOfMessages = m_PtrMessageStore->NumberOfMessages;
                        m_PtrMessageStore->NumberOfMessages = 0;
                        m_StringStoreOffset = 0;

                        for (messageNumber = 1; messageNumber <= numberOfMessages; messageNumber++)
                        {
                            Message *ptrMessage = (Message *)(m_IntPtrMemoryMappedFileViewMessageStore + ((messageNumber - 1) * m_SizeOfMessage));

                            DebugLogging.WriteLog("Processing message " + ptrMessage->Action.ToString());
                            //get the message action:
                            switch (ptrMessage->Action)
                            {
                            case MessageAction.GetListViewGroupRectangle:
                                GetListViewGroupRectangle(messageNumber);
                                break;

                            case MessageAction.GetListViewItemRectangle:
                                GetListViewItemRectangle(messageNumber);
                                break;

                            case MessageAction.ControlExists:
                                string findText = Find(messageNumber, 0);
                                if (findText != null)
                                {
                                    ControlIdentifier newIdentifier = new ControlIdentifier();
                                    AddIdentifierMessage(newIdentifier);
                                }
                                break;

                            case MessageAction.Find:
                                result = Find(messageNumber, m_TimeOut);
                                break;

                            case MessageAction.RefindByHandle:
                                RefindByHandle(messageNumber);
                                break;

                            case MessageAction.RefindByUniqueId:
                                RefindByUniqueId(messageNumber);
                                break;

                            case MessageAction.ReflectGet:
                                Reflect(messageNumber);
                                break;

                            case MessageAction.ConvertType:
                                ConvertType(messageNumber);
                                break;

                            case MessageAction.SentinelGridsGetUnderlyingGrid:
                                SentinelGridsGetUnderlyingGrid(ptrMessage);
                                break;

                            case MessageAction.ReflectPoll:
                                ReflectPoll(messageNumber);
                                break;

                            case MessageAction.GetResult:
                                GetResult(messageNumber);
                                break;

                            case MessageAction.AddMouseHook:
                                AddMouseHook(ptrMessage, messageNumber);
                                break;

                            case MessageAction.RemoveMouseHook:
                                RemoveMouseHook(ptrMessage, messageNumber);
                                break;

                            case MessageAction.WaitForMouseState:
                                WaitForMouseState(ptrMessage, messageNumber);
                                break;

                            case MessageAction.SetTimeOuts:
                                SetTimeOuts(messageNumber);
                                break;

                            case MessageAction.GetTitleBarItemRectangle:
                                GetTitleBarItemRectangle(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GarbageCollect:
                                GarbageCollect(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GetContextMenuStrip:
                                GetContextMenuStrip(messageNumber);
                                break;

                            case MessageAction.GetAppDomains:
                                GetAppDomains(messageNumber);
                                break;

                            case MessageAction.GetRecognisedType:
                                GetRecognisedType(messageNumber);
                                break;

                            case MessageAction.GetApeTypeFromType:
                                GetApeTypeFromType(messageNumber);
                                break;

                            case MessageAction.GetApeTypeFromObject:
                                GetApeTypeFromObject(messageNumber);
                                break;

                            // Flexgrid helper methods
                            case MessageAction.FlexgridGetCellRangeBackColourName:
                                FlexgridGetCellRange(ptrMessage, CellProperty.BackColourName);
                                break;

                            case MessageAction.FlexgridGetCellRangeForeColourName:
                                FlexgridGetCellRange(ptrMessage, CellProperty.ForeColourName);
                                break;

                            case MessageAction.FlexgridGetCellRangeDataType:
                                FlexgridGetCellRange(ptrMessage, CellProperty.DataType);
                                break;

                            case MessageAction.FlexgridGetCellRangeCheckBox:
                                FlexgridGetCellRange(ptrMessage, CellProperty.CheckBox);
                                break;

                            case MessageAction.FlexgridGetCellRangeImage:
                                FlexgridGetCellRange(ptrMessage, CellProperty.Image);
                                break;

                            case MessageAction.FlexgridGetCellRangeBackgroundImage:
                                FlexgridGetCellRange(ptrMessage, CellProperty.BackgroundImage);
                                break;

                            case MessageAction.FlexgridGetAllColumnsHidden:
                                FlexgridGetAllColumnsHidden(ptrMessage);
                                break;

                            case MessageAction.FlexgridGetAllRowsHidden:
                                FlexgridGetAllRowsHidden(ptrMessage);
                                break;

                            case MessageAction.FlexgridGetAllColumnsWidth:
                                FlexgridGetAllColumnsWidth(ptrMessage);
                                break;

                            case MessageAction.FlexgridGetAllRowsHeight:
                                FlexgridGetAllRowsHeight(ptrMessage);
                                break;

                            case MessageAction.GridControlGetTitleRows:
                                GridControlGetTitleRows(ptrMessage);
                                break;

                            case MessageAction.GridControlGetTitleRowCount:
                                GridControlGetTitleRowCount(ptrMessage);
                                break;

                            case MessageAction.GridControlGetAllColumnsHidden:
                                GridControlGetAllColumnsVisible(ptrMessage);
                                break;

                            case MessageAction.GetDateTimePickerCheckboxRectangle:
                                GetDateTimePickerCheckboxRectangle(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GetDateTimePickerButtonRectangle:
                                GetDateTimePickerButtonRectangle(ptrMessage, messageNumber);
                                break;

                            case MessageAction.ScrollControlIntoView:
                                ScrollControlIntoView(ptrMessage, messageNumber);
                                break;

                            case MessageAction.PeakMessage:
                                PeakMessage(ptrMessage, messageNumber);
                                break;

                            case MessageAction.SetFocus:
                                SetFocus(ptrMessage, messageNumber);
                                break;

                            case MessageAction.SetFocusAsync:
                                SetFocusAsync(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GridControlEnsureTitleCellVisible:
                                GridControlEnsureTitleCellVisible(ptrMessage);
                                break;

                            case MessageAction.DictionaryContainsKey:
                                DictionaryContainsKey(ptrMessage);
                                break;

                            case MessageAction.AddMouseClickHandler:
                                AddMouseClickHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveMouseClickHandler:
                                WaitForAndRemoveMouseClickHandler(ptrMessage);
                                break;

                            case MessageAction.RemoveMouseClickHandler:
                                RemoveMouseClickHandler(ptrMessage);
                                break;

                            case MessageAction.AddFlexgridCellChangedHandler:
                                AddFlexgridCellChangedHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveFlexgridCellChangedHandler:
                                WaitForAndRemoveFlexgridCellChangedHandler(ptrMessage);
                                break;

                            case MessageAction.AddFlexgridAfterRowColChangeHandler:
                                AddFlexgridAfterRowColChangeHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveFlexgridAfterRowColChangeHandler:
                                WaitForAndRemoveFlexgridAfterRowColChangeHandler(ptrMessage);
                                break;

                            case MessageAction.RemoveFlexgridAfterRowColChangeHandler:
                                RemoveFlexgridAfterRowColChangeHandler(ptrMessage);
                                break;

                            case MessageAction.AddGenericWalkerSelectedHandler:
                                AddGenericWalkerSelectedHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveGenericWalkerSelectedHandler:
                                WaitForAndRemoveGenericWalkerSelectedHandler(ptrMessage);
                                break;

                            case MessageAction.RemoveGenericWalkerSelectedHandler:
                                RemoveGenericWalkerSelectedHandler(ptrMessage);
                                break;

                            case MessageAction.VisualStyleSupported:
                                VisualStyleSupported(ptrMessage, messageNumber);
                                break;

                            case MessageAction.DataGridViewShowCell:
                                DataGridViewShowCell(ptrMessage);
                                break;

                            case MessageAction.GetToolTip:
                                GetToolTip(ptrMessage, messageNumber);
                                break;

                            case MessageAction.DumpActiveX:
                                DumpActiveX(ptrMessage, messageNumber);
                                break;

                            case MessageAction.FlexgridGetNodeCollapsedState:
                                FlexgridGetNodeCollapsedState(ptrMessage);
                                break;

                            case MessageAction.GetTypeInformationActiveX:
                                GetTypeInformationActiveX(ptrMessage);
                                break;

                            case MessageAction.GetTabRect:
                                GetTabRect(ptrMessage);
                                break;

                            case MessageAction.GetInvokeFormActiveX:
                                GetInvokeFormActiveX(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GetComboBoxExItemText:
                                GetComboBoxExItemText(ptrMessage, messageNumber);
                                break;

                            case MessageAction.WaitForMouseMove:
                                WaitForMouseMove(ptrMessage, messageNumber);
                                break;

                            case MessageAction.AddToolStripItemEnteredHandler:
                                AddToolStripItemEnteredHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveToolStripItemEnteredHandler:
                                WaitForAndRemoveToolStripItemEnteredHandler(ptrMessage);
                                break;

                            case MessageAction.DumpControl:
                                DumpControl(ptrMessage, messageNumber);
                                break;

                            case MessageAction.FlexgridGetCellRangeTextDisplay:
                                FlexgridGetCellRange(ptrMessage, CellProperty.TextDisplay);
                                break;

                            case MessageAction.FlexgridGetCellRangeFontStyle:
                                FlexgridGetCellRange(ptrMessage, CellProperty.FontStyle);
                                break;

                            case MessageAction.FlexgridGetCellBackgroundImage:
                                FlexgridGetCellBackgroundImage(ptrMessage);
                                break;

                            default:
                                throw new Exception("Unknown action for message " + messageNumber.ToString() + " : " + ptrMessage->Action.ToString());
                            }

                            if (result != null)
                            {
                                break;
                            }
                        }

                        if (result == null)
                        {
                            AddResultMessage(MessageResult.Success);
                        }
                    }
                    catch (Exception ex)
                    {
                        result  = "Message " + messageNumber.ToString() + " of " + numberOfMessages + " failed:\r\n";
                        result += ex.GetType().Name + " " + ex.Message + "\r\n" + ex.StackTrace;
                        if (ex.InnerException != null)
                        {
                            //TODO make this better?
                            result += "\r\n" + ex.InnerException.GetType().Name + " " + ex.InnerException.Message + "\r\n" + ex.InnerException.StackTrace;
                        }
                    }

                    if (result != null)
                    {
                        //clean up all the messages
                        for (messageNumber = 1; messageNumber <= MessageStore.MaxMessages; messageNumber++)
                        {
                            Message *ptrMessage = (Message *)(m_IntPtrMemoryMappedFileViewMessageStore + ((messageNumber - 1) * m_SizeOfMessage));
                            CleanUpMessage(ptrMessage);
                        }

                        m_PtrMessageStore->NumberOfMessages = 0;
                        m_StringStoreOffset = 0;

                        AddResultMessage(MessageResult.Failure, result);
                    }

                    //clear the data stores so we don't hold any references to objects in the AUT
                    //which would stop them being garbage collected
                    if (tempStore0ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore0);
                        tempStore0ReleaseComObject = false;
                    }
                    tempStore0 = null;
                    if (tempStore1ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore1);
                        tempStore1ReleaseComObject = false;
                    }
                    tempStore1 = null;
                    if (tempStore2ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore2);
                        tempStore2ReleaseComObject = false;
                    }
                    tempStore2 = null;
                    if (tempStore3ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore3);
                        tempStore3ReleaseComObject = false;
                    }
                    tempStore3 = null;
                    if (tempStore4ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore4);
                        tempStore4ReleaseComObject = false;
                    }
                    tempStore4 = null;
                    if (tempStore5ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore5);
                        tempStore5ReleaseComObject = false;
                    }
                    tempStore5 = null;
                    if (tempStore6ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore6);
                        tempStore6ReleaseComObject = false;
                    }
                    tempStore6 = null;
                    if (tempStore7ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore7);
                        tempStore7ReleaseComObject = false;
                    }
                    tempStore7 = null;
                    if (tempStore8ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore8);
                        tempStore8ReleaseComObject = false;
                    }
                    tempStore8 = null;
                    if (tempStore9ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore9);
                        tempStore9ReleaseComObject = false;
                    }
                    tempStore9 = null;

                    //send back our response
                    SendMessages(EventSet.AUT);
                }
            }
            catch (Exception ex)
            {
                TextWriter log = File.AppendText(Environment.GetEnvironmentVariable("TEMP") + @"\critical.log");
                log.WriteLine(DateTime.Now.ToString() + "\t" + ex.Message);
                log.WriteLine(DateTime.Now.ToString() + "\t" + ex.StackTrace);
                log.Close();
                throw;
            }
        }
Пример #18
0
        public void ClickMenuItem(IntPtr parent, IntPtr control, int menuIndex, string menuItem, ref ControlIdentifier controlIdentity)
        {
            //Check its enabled and visible then click on it
            Stopwatch timer = Stopwatch.StartNew();

            while (true)
            {
                //Get visible, enabled and bounds
                GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, parent, control);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "Items", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Item", MemberTypes.Property, new Parameter(GUI.m_APE, menuIndex));
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store2, DataStores.Store3, "Visible", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store2, DataStores.Store4, "Enabled", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store2, DataStores.Store5, "Bounds", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store5, DataStores.Store6, "Width", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store5, DataStores.Store7, "Height", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store5, DataStores.Store8, "X", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store5, DataStores.Store9, "Y", MemberTypes.Property);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store4);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store6);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store7);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store8);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store9);
                GUI.m_APE.SendMessages(EventSet.APE);
                GUI.m_APE.WaitForMessages(EventSet.APE);
                //get the values returned
                bool isVisible = GUI.m_APE.GetValueFromMessage();
                bool isEnabled = GUI.m_APE.GetValueFromMessage();
                int  width     = GUI.m_APE.GetValueFromMessage();
                int  height    = GUI.m_APE.GetValueFromMessage();
                int  x         = GUI.m_APE.GetValueFromMessage();
                int  y         = GUI.m_APE.GetValueFromMessage();

                if (isVisible)
                {
                    if (isEnabled)
                    {
                        Input.MouseSingleClick(parent, control, x + (width / 2), y + (height / 2), MouseButton.Left, MouseKeyModifier.None);
                        break;
                    }
                }

                if (timer.ElapsedMilliseconds > 3000)
                {
                    if (!isVisible)
                    {
                        throw new Exception("Menu item " + menuItem + " not visible");
                    }
                    else
                    {
                        throw new Exception("Menu item " + menuItem + " not enabled");
                    }
                }

                Thread.Sleep(15);
            }
        }