Exemplo n.º 1
0
        public ComPtrTreeNode(string caption, ComPtr comPtr)
            : base(caption)
        {
            if (comPtr != null)
            {
                _comPtr = comPtr;

                if (_comPtr.IsInvalid == false)
                {
                    ComTypeInfo comTypeInfo = _comPtr.TryGetComTypeInfo();
                    if (comTypeInfo != null)
                    {
                        TypeFullName = comTypeInfo.FullName;
                    }
                    else
                    {
                        TypeFullName = "IUnknown";
                    }

                    _isCollection = _comPtr.TryIsCollection();

                    if (_isCollection)
                    {
                        _collectionCount = _comPtr.TryGetItemCount();
                    }

                    string[] propertyNames = { "Name", "Caption", "StyleName", "ID", "Count", "Environment", "Description", "CommandString" };
                    var      value         = comPtr.TryGetFirstAvailableProperty(propertyNames);

                    if (value != null)
                    {
                        Value = value.ToString();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private ComTreeNode[] GetChildren(ComPtr comPtr)
        {
            if (comPtr == null) return new ComTreeNode[] { };

            ComTypeInfo comTypeInfo = comPtr.TryGetComTypeInfo();

            if (comTypeInfo == null) return new ComTreeNode[] { };

            List<ComTreeNode> childNodes = new List<ComTreeNode>();

            try
            {
                foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.Properties)
                {
                    // Special case. MailSession is a PITA property that causes modal dialog.
                    if (comPropertyInfo.Name.Equals("MailSession"))
                    {
                        continue;
                    }

                    ComTreeNode comTreeNode = GetChild(comPtr, comPropertyInfo);

                    if (comTreeNode != null)
                    {
                        if ((comTreeNode is ComPropertyTreeNode) && (_showProperties == false))
                        {
                            continue;
                        }

                        childNodes.Add(comTreeNode);
                    }
                }

                if (comPtr.TryIsCollection())
                {
                    int count = comPtr.TryGetItemCount();

                    try
                    {
                        ComFunctionInfo comFunctionInfo = comTypeInfo.Methods.Where(x => x.Name.Equals("Item", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                        if (comFunctionInfo != null)
                        {
                            // Solid Edge is supposed to be 1 based index but some collections are 0 based.
                            // Application->Customization->RibbonBarThemes seems to be 0 based.
                            for (int i = 0; i <= count; i++)
                            {
                                object returnValue = null;
                                if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { i }, out returnValue)))
                                {
                                    ComPtr pItem = returnValue as ComPtr;
                                    if ((pItem != null) && (pItem.IsInvalid == false))
                                    {
                                        ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                        comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, i);
                                        comPtrItemTreeNode.Nodes.Add("...");
                                        childNodes.Add(comPtrItemTreeNode);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        GlobalExceptionHandler.HandleException();
                    }
                }

                if (_showMethods)
                {
                    foreach (ComFunctionInfo comFunctionInfo in comTypeInfo.GetMethods(true))
                    {
                        if (comFunctionInfo.IsRestricted) continue;

                        ComMethodTreeNode comMethodTreeNode = new ComMethodTreeNode(comFunctionInfo);
                        childNodes.Add(comMethodTreeNode);
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            return childNodes.ToArray();
        }
Exemplo n.º 3
0
        public ComPtrTreeNode(string caption, ComPtr comPtr)
            : base(caption)
        {
            if (comPtr != null)
            {
                _comPtr = comPtr;

                if (_comPtr.IsInvalid == false)
                {
                    ComTypeInfo comTypeInfo = _comPtr.TryGetComTypeInfo();
                    if (comTypeInfo != null)
                    {
                        TypeFullName = comTypeInfo.FullName;
                    }
                    else
                    {
                        TypeFullName = "IUnknown";
                    }

                    _isCollection = _comPtr.TryIsCollection();

                    if (_isCollection)
                    {
                        _collectionCount = _comPtr.TryGetItemCount();
                    }

                    string[] propertyNames = { "Name", "Caption", "StyleName", "ID", "Count", "Environment", "Description", "CommandString" };
                    var value = comPtr.TryGetFirstAvailableProperty(propertyNames);

                    if (value != null)
                    {
                        Value = value.ToString();
                    }
                }
            }
        }
Exemplo n.º 4
0
        private ComTreeNode[] GetChildren(ComPtr comPtr)
        {
            if (comPtr == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            ComTypeInfo comTypeInfo = comPtr.TryGetComTypeInfo();

            if (comTypeInfo == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            List <ComTreeNode> childNodes = new List <ComTreeNode>();

            try
            {
                foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.Properties)
                {
                    // Special case. MailSession is a PITA property that causes modal dialog.
                    if (comPropertyInfo.Name.Equals("MailSession"))
                    {
                        continue;
                    }

                    ComTreeNode comTreeNode = GetChild(comPtr, comPropertyInfo);

                    if (comTreeNode != null)
                    {
                        if ((comTreeNode is ComPropertyTreeNode) && (_showProperties == false))
                        {
                            continue;
                        }

                        childNodes.Add(comTreeNode);
                    }
                }

                if (comPtr.TryIsCollection())
                {
                    List <ComTreeNode> collectionChildNodes = new List <ComTreeNode>();
                    int count      = comPtr.TryGetItemCount();
                    int foundCount = 0;

                    try
                    {
                        ComFunctionInfo comFunctionInfo = comTypeInfo.Methods.Where(x => x.Name.Equals("Item", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                        if (comFunctionInfo != null)
                        {
                            object returnValue = null;

                            // Solid Edge is supposed to be 1 based index.
                            for (int i = 1; i <= count; i++)
                            {
                                returnValue = null;
                                if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { i }, out returnValue)))
                                {
                                    ComPtr pItem = returnValue as ComPtr;
                                    if ((pItem != null) && (pItem.IsInvalid == false))
                                    {
                                        ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                        comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, i);
                                        comPtrItemTreeNode.Nodes.Add("...");
                                        collectionChildNodes.Add(comPtrItemTreeNode);
                                        foundCount++;
                                    }
                                }
                            }

                            try
                            {
                                // Some collections are 0 based.
                                // Application->Customization->RibbonBarThemes seems to be 0 based.
                                if (foundCount == (count - 1))
                                {
                                    returnValue = null;
                                    if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { 0 }, out returnValue)))
                                    {
                                        ComPtr pItem = returnValue as ComPtr;
                                        if ((pItem != null) && (pItem.IsInvalid == false))
                                        {
                                            ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                            comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, 0);
                                            comPtrItemTreeNode.Nodes.Add("...");
                                            collectionChildNodes.Insert(0, comPtrItemTreeNode);
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                        GlobalExceptionHandler.HandleException();
                    }

                    childNodes.AddRange(collectionChildNodes.ToArray());
                }

                if (_showMethods)
                {
                    foreach (ComFunctionInfo comFunctionInfo in comTypeInfo.GetMethods(true))
                    {
                        if (comFunctionInfo.IsRestricted)
                        {
                            continue;
                        }

                        ComMethodTreeNode comMethodTreeNode = new ComMethodTreeNode(comFunctionInfo);
                        childNodes.Add(comMethodTreeNode);
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            return(childNodes.ToArray());
        }