internal static bool ConvertException(System.Runtime.InteropServices.COMException e, out Exception uiaException)
        {
            bool handled = true;

            switch (e.ErrorCode)
            {
            case UiaCoreIds.UIA_E_ELEMENTNOTAVAILABLE:
                uiaException = new ElementNotAvailableException(e);
                break;

            case UiaCoreIds.UIA_E_ELEMENTNOTENABLED:
                uiaException = new ElementNotEnabledException(e);
                break;

            case UiaCoreIds.UIA_E_NOCLICKABLEPOINT:
                uiaException = new NoClickablePointException(e);
                break;

            case UiaCoreIds.UIA_E_PROXYASSEMBLYNOTLOADED:
                uiaException = new ProxyAssemblyNotLoadedException(e);
                break;

            default:
                uiaException = null;
                handled      = false;
                break;
            }
            return(handled);
        }
Beispiel #2
0
        private static Exception BuildException(string exceptionInfo)
        {
            int colonIndex = exceptionInfo.IndexOf(": ");

            if (colonIndex == -1)
            {
                return(null);
            }
            string errorName    = exceptionInfo.Substring(0, colonIndex);
            string errorMessage = exceptionInfo.Substring(colonIndex + 2);

            Exception ret = null;

            if (errorName == dbusInvalidArgsError)
            {
                ret = new ArgumentException(exceptionInfo);
            }
            if (Array.BinarySearch(dbusErrorList, errorName) >= 0)
            {
                ret = new ElementNotAvailableException(exceptionInfo);
            }
            else
            {
                try {
                    Type type = GetType(errorName);
                    if (type != null)
                    {
                        ret = Activator.CreateInstance(type, errorMessage) as Exception;
                    }
                } catch {
                    ret = null;
                }
            }
            return(ret);
        }
 public void Ctor_Message()
 {
     var exception = new ElementNotAvailableException("Message");
     Assert.Equal("Message", exception.Message);
     Assert.Null(exception.InnerException);
     Assert.Equal(E_ELEMENTNOTAVAILABLE, exception.HResult);
 }
 public void Ctor_Message_InnerException()
 {
     var innerException = new Exception();
     var exception = new ElementNotAvailableException("Message", innerException);
     Assert.Equal("Message", exception.Message);
     Assert.Same(innerException, exception.InnerException);
     Assert.Equal(E_ELEMENTNOTAVAILABLE, exception.HResult);
 }
Beispiel #5
0
        /// <summary>
        /// Tries to convert a com exception to a more usable exception.
        /// </summary>
        public static bool ConvertException(System.Runtime.InteropServices.COMException ex, out Exception uiaException)
        {
            var handled = true;

            switch ((uint)ex.ErrorCode)
            {
            case UIA_E_ELEMENTNOTENABLED:
                uiaException = new ElementNotEnabledException(ex);
                break;

            case UIA_E_ELEMENTNOTAVAILABLE:
                uiaException = new ElementNotAvailableException(ex);
                break;

            case UIA_E_NOCLICKABLEPOINT:
                uiaException = new NoClickablePointException(ex);
                break;

            case UIA_E_PROXYASSEMBLYNOTLOADED:
                uiaException = new ProxyAssemblyNotLoadedException(ex);
                break;

            case UIA_E_TIMEOUT:
                uiaException = new TimeoutException("UIA Timeout", ex);
                break;

            case UIA_E_NOTSUPPORTED:
                uiaException = new Exceptions.NotSupportedException(ex);
                break;

            case UIA_E_INVALIDOPERATION:
                uiaException = new InvalidOperationException("UIA Invalid Operation", ex);
                break;

            default:
                uiaException = null;
                handled      = false;
                break;
            }
            return(handled);
        }
Beispiel #6
0
 private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
 {
     this.CurrentElement = this.dic[e.Node];
     try
     {
         AutomationElement.AutomationElementInformation current = this.CurrentElement.Current;
         bool flag = !current.IsOffscreen;
         if (flag)
         {
             this.ShowProperty();
         }
     }
     catch (ElementNotAvailableException expr_3E)
     {
         ProjectData.SetProjectError(expr_3E);
         ElementNotAvailableException ex = expr_3E;
         this.ListView1.Items.Clear();
         MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Hand);
         ProjectData.ClearProjectError();
     }
 }
Beispiel #7
0
 private static void ThrowWindowsSoundException(ElementNotAvailableException ex)
 {
     throw new WindowsSoundException("There was an error processing the request.", ex);
 }
        internal static void BuildListviewControl(List <AutomationElement> childElements,
                                                  LAPListViewControl lapListViewObjects,
                                                  EventHandler linkItemClick
                                                  )
        {
            int[] checkedIndexes = lapListViewObjects.CheckedIndicesArray;

            ListView.SelectedIndexCollection selectedIndexs = lapListViewObjects.SelectedIndices;

            int selectIndex = selectedIndexs.Count == 0 ? 0 : selectedIndexs[0];

            lapListViewObjects.BeginUpdate();

            foreach (Control control in lapListViewObjects.Controls)
            {
                if (control.Name.IndexOf("linkLabel") >= 0)
                {
                    control.Click -= linkItemClick;// lvItem_lnLinkItemClick;
                    control.Dispose();
                }
            }


            lapListViewObjects.Items.Clear();
            if (0 == childElements.Count)
            {
                lapListViewObjects.EndUpdate();
                return;
            }


            int index = 0;
            int i = 0, j = 0;

            ElementNotAvailableException elementNotAvailableException = null;

            List <ElementProperties> propertiesList = null;

            Utility.AsyncCall(() =>
            {
                try
                {
                    propertiesList = childElements.ConvertAll <ElementProperties>((element) =>
                    {
                        System.Windows.Rect rect = element.Cached.BoundingRectangle;
                        if (rect.IsEmpty)
                        {
                            return(null);
                        }
                        return(new ElementProperties(element));
                    });
                }
                catch (ElementNotAvailableException ex)
                {
                    lapListViewObjects.Invoke(new Action(() => { lapListViewObjects.EndUpdate(); }));
                    //TODO, still not being handled by some handler
                    elementNotAvailableException = ex;
                }
            });

            if (elementNotAvailableException != null)
            {
                lapListViewObjects.EndUpdate();
                throw elementNotAvailableException;
            }

            foreach (var properties in propertiesList)
            {
                //zero size control will be skipped.
                if (properties == null)
                {
                    continue;
                }

                ListViewSubItem[] lvSubItem = new ListViewSubItem[3];
                Graphics          graphics  = lapListViewObjects.CreateGraphics();

                string    controlType = properties.ControlType.ControlTypeToString();
                LinkLabel linkLabel   = new LinkLabel();
                linkLabel.Name     = string.Format("linkLabel{0}", j++);
                linkLabel.Text     = controlType;
                linkLabel.AutoSize = true;
                linkLabel.Click   += linkItemClick; //lvItem_lnLinkItemClick;

                lvSubItem[0] = new ListViewSubItem()
                {
                    Text = string.Empty
                };
                lvSubItem[1] = new ListViewSubItem()
                {
                    Text = controlType, Tag = linkLabel
                };
                lvSubItem[2] = new ListViewSubItem()
                {
                    Text = properties.Name
                };

                graphics.Dispose();

                ListViewItem lvItem = new ListViewItem(lvSubItem, 0);

                if (checkedIndexes.Length > 0 && i < checkedIndexes.Length)
                {
                    if (index == checkedIndexes[i])
                    {
                        lvItem.Checked = true;
                        ++i;
                    }
                }
                //   lvItem.Checked = true;
                lvItem.Tag = properties;
                lapListViewObjects.Items.Add(lvItem);
                ++index;
            }

            if (lapListViewObjects.Items.Count > 0)
            {
                lapListViewObjects.Focus();
                ListViewItem lvItem = selectIndex >= lapListViewObjects.Items.Count ? lapListViewObjects.Items[0] : lapListViewObjects.Items[selectIndex];
                lvItem.Selected = true;
                lvItem.Focused  = true;
            }

            lapListViewObjects.EndUpdate();
        }