Exemple #1
0
 internal static void OpenFile(String fileName)
 {
     // Keep track if the assembly was actually loaded, if
     // not then it must already be loaded, so handle adding
     // it to the tree.
     _assyLoadedNode = null;
     LoadAssembly(fileName);
     if (_assyLoadedNode == null)
     {
         Assembly assy = Assembly.LoadFrom(fileName);
         if (assy.Equals(Assembly.GetExecutingAssembly()))
         {
             throw new Exception("You may not inspect the Component Inspector");
         }
         // Already loaded
         _assyLoadedNode = FindAssemblyNode(assy);
         if (_assyLoadedNode == null)
         {
             AssemblyTreeNode node = AddAssy(assy, null);
             RememberAssembly(assy, null, null);
             _assyLoadedNode = node;
         }
     }
     // Make sure this node is presented and selected
     SelectAssyTab();
     _assyLoadedNode.PointToNode();
 }
Exemple #2
0
        /// <summary>
        /// Opens a <see cref="BrowserDialog"/> form, waits for successful
        /// design and updates slideshow with the designed <see cref="BrowserTreeNode"/>.
        /// </summary>
        /// <param name="node">Contains the node that is
        /// modified or null if this should be a new slide.</param>
        private void OpenBrowserDesignerForm(BrowserTreeNode node)
        {
            BrowserDialog dlg = new BrowserDialog();

            if (node != null)
            {
                dlg.BrowserNode = node;
            }

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                BrowserTreeNode newNode = dlg.BrowserNode;
                if (node != null)
                {
                    newNode.UrlToID.Clear();
                    newNode.UrlToID.Add(newNode.OriginURL, Convert.ToInt32(node.Name));
                    node = newNode;
                }
                else
                {
                    this.AddBrowserSlide(newNode);
                }

                this.SlideShowModified();
            }
        }
 internal BrowserFinder(String findWhat,
                        int compareType,
                        int maxLevel,
                        bool useName,
                        bool useValue,
                        BrowserTreeNode startNode,
                        SearchNodeDelegate nodeFound,
                        SearchNodeDelegate nodeLooking,
                        SearchStatusDelegate searchStatus,
                        SearchInvalidateDelegate searchInvalidate)
 {
     _findWhat         = findWhat;
     _compareType      = compareType;
     _maxLevel         = maxLevel;
     _useName          = useName;
     _useValue         = useValue;
     _startNode        = startNode;
     _tree             = startNode.TreeView;
     _nodeFound        = nodeFound;
     _nodeLooking      = nodeLooking;
     _searchStatus     = searchStatus;
     _searchInvalidate = searchInvalidate;
     _searchStack      = new Stack();
     _browserFinder    = this;
 }
Exemple #4
0
        /// <summary>
        /// This method adds the given <see cref="BrowserTreeNode"/> at the
        /// current treeview position.
        /// </summary>
        /// <param name="newBrowserSlideNode">The new <see cref="BrowserTreeNode"/> to be added to the slideshow.</param>
        private void AddBrowserSlide(BrowserTreeNode newBrowserSlideNode)
        {
            // Add node
            string newID = this.slideshow.GetUnusedNodeID();

            newBrowserSlideNode.Name = newID;
            newBrowserSlideNode.UrlToID.Add(newBrowserSlideNode.OriginURL, Convert.ToInt32(newID));

            // Get root node for insertion
            SlideshowTreeNode firstNode = this.trvSlideshow.Nodes[0] as SlideshowTreeNode;

            // If there is a selected node use this instead
            NodesCollection selectedNodes = this.trvSlideshow.SelectedNodes;

            if (selectedNodes.Count > 0)
            {
                firstNode = selectedNodes[0] as SlideshowTreeNode;
                this.trvSlideshow.SelectedNodes.Clear();
            }

            // Add to node, if it is a slide node add to parent instead
            if (firstNode.Slide != null)
            {
                firstNode.Parent.Nodes.Add(newBrowserSlideNode);
            }
            else
            {
                firstNode.Nodes.Add(newBrowserSlideNode);
            }

            // Select added node.
            this.trvSlideshow.SelectedNodes.Add(newBrowserSlideNode);

            this.UpdateListView(this.trvSlideshow.SelectedNodes);
        }
 protected BrowserTreeNode SearchNode(BrowserTreeNode startNode, String searchName)
 {
     startNode.ExpandNode();
     foreach (ComMemberTreeNode node in startNode.LogicalNodes)
     {
         if (node.MemberInfo.Name.Equals(searchName))
         {
             return(node);
         }
     }
     return(null);
 }
        ConstructorInfo FindConstructor(ConstructorInfo[] constructors)
        {
            ConstructorInfo constructor = null;

            if (constructors.Length > 1)
            {
                // Ask them to chose a constructor, if the
                // constructor requires parameters, then select
                // it and get out, otherwise go ahead.
                constructor = ConstructorDialog.
                              GetConstructor(constructors);
                if (constructor != null &&
                    constructor.GetParameters().Length != 0)
                {
                    AssemblySupport.SelectAssyTab();
                    MemberTreeNode.FindMember(constructor).PointToNode();
                    return(null);
                }
            }
            else
            {
                constructor = constructors[0];
            }

            // This was cancelled
            if (constructor == null)
            {
                return(null);
            }

            // Since we need to get parameters, we can't finish
            // this operation now, we refer then to the constructor
            // that they should use and they can drag that
            // constructor where they want the object to do
            if (constructor.GetParameters().Length != 0)
            {
                BrowserTreeNode selNode =
                    MemberTreeNode.FindMember(constructor);
                ErrorDialog.
                Show("Please select the constructor member " +
                     "of this Type, fill in the parameters, " +
                     "and then drag " +
                     "the constructor to where you " +
                     "want this object " +
                     "to be created.",
                     "Provide Parameters",
                     MessageBoxIcon.Information);
                AssemblySupport.SelectAssyTab();
                selNode.PointToNode();
                return(null);
            }
            return(constructor);
        }
Exemple #7
0
        internal static void SelectTypeLib(TypeLibrary lib)
        {
            // Find and select the registered node
            BrowserTreeNode typeLibNode = FindTypeLib(lib.Key);

            if (typeLibNode != null)
            {
                typeLibNode.PointToNode();
            }
            else
            {
                throw new Exception("Bug, expected to be in type lib tree: "
                                    + lib);
            }
        }
        /// <summary>
        /// This method deletes the given node from the listview,
        /// and updates the views.
        /// </summary>
        /// <param name="treeNode">The <see cref="SlideshowTreeNode"/> to delete.</param>
        private void DeleteNode(SlideshowTreeNode treeNode)
        {
            if (treeNode == null)
            {
                return;
            }

            Slide deleteSlide = treeNode.Slide;

            if (deleteSlide != null)
            {
                deleteSlide.Dispose();
            }

            foreach (SlideshowTreeNode subNode in treeNode.Nodes)
            {
                this.DeleteNode(subNode);
            }

            // Update UrlToID dictionary of BrowserTreeNodes
            if (treeNode.Parent is BrowserTreeNode)
            {
                BrowserTreeNode parent      = (BrowserTreeNode)treeNode.Parent;
                string          keyToRemove = string.Empty;
                foreach (KeyValuePair <string, int> urlToID in parent.UrlToID)
                {
                    if (urlToID.Value == Convert.ToInt32(treeNode.Name))
                    {
                        keyToRemove = urlToID.Key;
                    }
                }

                if (keyToRemove != string.Empty)
                {
                    var fileName = Path.Combine(Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, keyToRemove);
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                    parent.UrlToID.Remove(keyToRemove);
                }
            }

            // Update TreeView.
            treeNode.Remove();
            this.UpdateListView(this.trvSlideshow.SelectedNodes);
        }
Exemple #9
0
        ///////////////////////////////////////////////////////////////////////////////
        // Methods and Eventhandling for Background tasks                            //
        ///////////////////////////////////////////////////////////////////////////////
        #region THREAD
        #endregion //THREAD

        ///////////////////////////////////////////////////////////////////////////////
        // Methods for doing main class job                                          //
        ///////////////////////////////////////////////////////////////////////////////
        #region PRIVATEMETHODS

        /// <summary>
        /// Update the dialog forms fields with the content from the given <see cref="BrowserTreeNode"/>.
        /// </summary>
        /// <param name="browserTreeNode">The <see cref="BrowserTreeNode"/> whichs content should
        /// be shown in the dialog.</param>
        private void PopulateDialogWithBrowserTreeNode(BrowserTreeNode browserTreeNode)
        {
            this.browserTreeNode = browserTreeNode;

            // Common properties
            this.txbName.Text         = browserTreeNode.Text;
            this.cbbCategory.Text     = browserTreeNode.Category;
            this.txbURL.Text          = browserTreeNode.OriginURL;
            this.nudBrowseDepth.Value = browserTreeNode.BrowseDepth;

            // Tab Timing
            foreach (StopCondition condition in browserTreeNode.Slide.StopConditions)
            {
                this.lsbStopConditions.Items.Add(condition);
            }
        }
        // This could either be a MemberInfo, Type or a TypeLibrary,
        // and we point
        // to the correct node
        public void ShowTarget(Object linkModifier)
        {
            BrowserTreeNode resultNode = null;

            // A type library
            if (linkModifier is TypeLibrary)
            {
                resultNode = ComSupport.FindTypeLib(((TypeLibrary)linkModifier).Key);
            }
            else
            {
                Type type;
                if (linkModifier is Type)
                {
                    type = (Type)linkModifier;
                }
                else
                {
                    type = ((MemberInfo)linkModifier).DeclaringType;
                }
                // Get the typelib node
                TypeLibrary typeLib = TypeLibrary.GetTypeLib(type);
                if (typeLib == null)
                {
                    return;
                }
                // Find the type, this could be a class or an interface
                ComTypeLibTreeNode typeLibNode = (ComTypeLibTreeNode)ComSupport.FindTypeLib(typeLib.Key);
                String             typeName    = typeLib.GetMemberName(type);
                typeLibNode.ExpandNode();
                resultNode = SearchNode(typeLibNode, typeName);
                // Find the member (Type is also a MemberInfo)
                if (!(linkModifier is Type))
                {
                    MemberInfo      mi           = (MemberInfo)linkModifier;
                    ComTypeTreeNode typeTreeNode = (ComTypeTreeNode)resultNode;
                    resultNode = FindMember(typeLibNode, typeTreeNode, mi);
                }
            }
            // Point to the result
            if (resultNode != null)
            {
                ObjectBrowser.TabControl.SelectedTab = ComSupport.ComTabPage;
                resultNode.PointToNode();
            }
        }
Exemple #11
0
        internal static void Init()
        {
            _comTree                      = new BrowserTree();
            _comTree.Dock                 = DockStyle.Fill;
            _comTree.BorderStyle          = BorderStyle.None;
            _comTree.UseIntermediateNodes = true;

            // Sucks, see comment in BrowserTreeNode.PostConstructor
            _comTree.Font = new Font(_comTree.Font, FontStyle.Bold);
            _comTabPage   = new TabPage();
            _comTabPage.Controls.Add(_comTree);
            _comTabPage.Text        = "ActiveX/COM";
            _comTabPage.BorderStyle = BorderStyle.None;

            // Favorite/recently accessed typelibs
            _favTypeLibNode      = new BrowserTreeNode();
            _favTypeLibNode.Text = StringParser.Parse("${res:ComponentInspector.ComTreeNode.Text}");
            _favTypeLibNode.ChildrenAlreadyAdded = true;
            _favTypeLibNode.SetPresInfo(PresentationMap.COM_FOLDER_TYPELIB);
            _typeLibNode            = new ComTypeLibRootTreeNode();
            _typeLibNode.NodeOrder  = 1;
            _progIdNode             = new ComProgIdRootTreeNode();
            _progIdNode.NodeOrder   = 2;
            _classCatNode           = new ComCatRootTreeNode();
            _classCatNode.NodeOrder = 3;
            _classNode                           = new ComClassRootTreeNode();
            _classNode.NodeOrder                 = 4;
            _interfaceNode                       = new ComInterfaceRootTreeNode();
            _interfaceNode.NodeOrder             = 5;
            _appIdNode                           = new ComAppIdRootTreeNode();
            _appIdNode.NodeOrder                 = 6;
            _registeredNode                      = new BrowserTreeNode();
            _registeredNode.Text                 = StringParser.Parse("${res:ComponentInspector.Registry.Text}");
            _registeredNode.ChildrenAlreadyAdded = true;
            _registeredNode.SetPresInfo(PresentationMap.FOLDER_CLOSED);
            _comTree.AddNode(_favTypeLibNode);
            _comTree.AddNode(_registeredNode);
            _registeredNode.AddLogicalNode(_typeLibNode);
            _registeredNode.AddLogicalNode(_classNode);
            _registeredNode.AddLogicalNode(_classCatNode);
            _registeredNode.AddLogicalNode(_appIdNode);
            _registeredNode.AddLogicalNode(_interfaceNode);
            _registeredNode.AddLogicalNode(_progIdNode);
            _registeredNode.Expand();
            _typelibs = ComponentInspectorProperties.PreviouslyOpenedTypeLibraries;
        }
Exemple #12
0
        // Adds the remembered type lib to the favorites part
        // of the type library tree
        internal static BrowserTreeNode AddTypeLib(TypeLibrary lib)
        {
            BrowserTreeNode findRoot;

            findRoot = _favTypeLibNode;
            if (findRoot == null)
            {
                return(null);
            }
            BrowserTreeNode typeLibNode = FindTypeLib(lib.Key, findRoot);

            if (typeLibNode == null)
            {
                typeLibNode = new ComTypeLibTreeNode(lib);
                // This might be called on the thread to restore open typelibs
                _comTree.Invoke(new BrowserTreeNode.AddLogicalInvoker(findRoot.AddLogicalNode),
                                new Object[] { typeLibNode });
            }
            return(typeLibNode);
        }
Exemple #13
0
 internal static void Init()
 {
     _assyTree = new BrowserTree();
     SetupTree(_assyTree);
     _assyRootNode      = new BrowserTreeNode();
     _assyRootNode.Text = StringParser.Parse("${res:ComponentInspector.AssemblyTreeNode.Text}");
     _assyRootNode.ChildrenAlreadyAdded = true;
     _assyRootNode.SetPresInfo(PresentationMap.FOLDER_CLOSED);
     _assyTree.AddNode(_assyRootNode);
     _assyTabPage = new TabPage();
     _assyTabPage.Controls.Add(_assyTree);
     _assyTabPage.Text        = StringParser.Parse("${res:ComponentInspector.FindDialog.AssembliesRadioButton}");
     _assyTabPage.BorderStyle = BorderStyle.None;
     _controlTree             = new ControlTree();
     SetupTree(_controlTree);
     _controlTabPage = new TabPage();
     _controlTabPage.Controls.Add(_controlTree);
     _controlTabPage.Text        = StringParser.Parse("${res:ComponentInspector.ControlsTab}");
     _controlTabPage.BorderStyle = BorderStyle.None;
     _assemblies = ComponentInspectorProperties.PreviouslyOpenedAssemblies;
 }
Exemple #14
0
 public static void AssemblyLoadHandler(object sender, AssemblyLoadEventArgs args)
 {
     try {
         lock (_assyTree) {
             TraceUtil.WriteLineInfo(null, "Assembly loaded: "
                                     + args.LoadedAssembly.FullName);
             try {
                 String junk = args.LoadedAssembly.CodeBase;
             } catch (NotSupportedException) {
                 // This will happen in the case of COM typelib
                 // being converted (because a dynamic assembly
                 // does not have a CodeBase), just ignore it since
                 // we will get a later assembly load notification when
                 // the saved assembly is used the first time.
                 return;
             }
             // This is an in memory version the real one will
             // come along later
             Module[] mods = args.LoadedAssembly.GetModules();
             if (mods[0].Name.Equals("<Unknown>"))
             {
                 return;
             }
             if (FindAssemblyTreeNode(args.LoadedAssembly) == null)
             {
                 AssemblyTreeNode node = AddAssy(args.LoadedAssembly, null);
                 RememberAssembly(args.LoadedAssembly, null, null);
                 // Already loaded
                 _assyLoadedNode = node;
                 ComSupport.AssemblyLoadHandler(args.LoadedAssembly,
                                                node);
             }
         }
     } catch (Exception ex) {
         TraceUtil.WriteLineIf(null, TraceLevel.Error,
                               "Exception processing assy load event: "
                               + args.LoadedAssembly.FullName
                               + " " + ex);
     }
 }
        protected BrowserTreeNode FindMember(ComTypeLibTreeNode typeLibNode, ComTypeTreeNode typeTreeNode, MemberInfo mi)
        {
            // If we have a class, we need to look at all of
            // its implemented interfaces
            if (typeTreeNode.MemberInfo is ComClassInfo)
            {
                BrowserTreeNode resultNode = null;

                ComClassInfo classInfo = (ComClassInfo)typeTreeNode.MemberInfo;
                foreach (BasicInfo iface in classInfo.Interfaces)
                {
                    BrowserTreeNode ifaceNode =
                        SearchNode(typeLibNode, iface.Name);
                    String searchName = mi.Name;
                    // See if its a member name qualified by this
                    // interface name
                    if (mi.Name.StartsWith(iface.Name))
                    {
                        searchName = mi.Name.Substring(iface.Name.Length + 1);
                        if (mi is EventInfo &&
                            searchName.StartsWith("Event_"))
                        {
                            searchName = searchName.Substring(6);
                        }
                    }
                    resultNode = SearchNode(ifaceNode, searchName);
                    if (resultNode != null)
                    {
                        return(resultNode);
                    }
                }
                throw new Exception("(bug) - cant find member " + mi);
            }
            else
            {
                return(SearchNode(typeTreeNode, mi.Name));
            }
        }
Exemple #16
0
        // s/b protected, stupid compiler
        internal static BrowserTreeNode FindTypeLib(TypeLibKey libKey, BrowserTreeNode parent)
        {
            BrowserTreeNode typeLibNode = null;

            // Will happen if not COM product
            if (parent == null)
            {
                return(null);
            }
            // Make sure we get all of the children added
            parent.ExpandNode();
            foreach (BrowserTreeNode node in parent.LogicalNodes)
            {
                if (node is ComTypeLibTreeNode)
                {
                    if (((ComTypeLibTreeNode)node).TypeLib.Key.Equals(libKey))
                    {
                        typeLibNode = node;
                        break;
                    }
                }
            }
            return(typeLibNode);
        }
        public BrowserTree(browsers[] parsedBrowserFiles)
            : this()
        {
            if (null == parsedBrowserFiles)
            {
                throw new ArgumentNullException("parsedBrowserFiles");
            }

            // Step 1, load all nodes into the internal map & figure out the root node.
            foreach (browsers bFile in parsedBrowserFiles)
            {
                foreach (object item in bFile.Items)
                {
                    IBrowserFileElement browserItem = item as IBrowserFileElement;
                    if (item == null)
                    {
                        throw new ArgumentNullException("Item type {0} is not supported", item.ToString());
                    }

                    BrowserTreeNode<IBrowserFileElement> node = new BrowserTreeNode<IBrowserFileElement>(browserItem);
                    if (String.IsNullOrEmpty(node.ID))
                    {
                        if (String.IsNullOrEmpty(node.RefID))
                        {
                            throw new DeviceDetectorException(String.Format("Found node with neither ID nor RefID"));
                        }
                        refNodes.Add(node);
                        continue;
                    }
                    if (!this.internalMap.ContainsKey(node.ID))
                    {
                        this.internalMap.Add(node.ID, node);
                    }
                    else
                    {
                        throw new DeviceDetectorException("Node with ID \"" + node.ID + "\" is duplicated");
                    }

                    if (String.IsNullOrEmpty(node.ParentID))
                    {
                        if (this.root == null)
                        {
                            this.root = node;
                        }
                        else
                        {
                            throw new DeviceDetectorException(String.Format("Multiple root nodes detected, current root \"{0}\", duplicate root \"{1}\"", this.root.ID, node.ID));
                        }
                    }
                }
            }

            // Step 2, update the parent-child relationships between nodes.
            foreach (var mapPair in this.internalMap)
            {
                if (String.IsNullOrEmpty(mapPair.Value.ParentID))
                {
                    continue;
                }
                mapPair.Value.Parent = this.internalMap[mapPair.Value.ParentID];
                mapPair.Value.Parent.Children.Add(mapPair.Value);
            }

            // Step 3, update the ref relationship
            foreach (var node in refNodes)
            {
                if (!this.internalMap.ContainsKey(node.RefID))
                {
                    throw new DeviceDetectorException("A node that reference a non existing node detected");
                }

                this.internalMap[node.RefID].RefNodes.Add(node);
            }

            // Step 4, compile capabilities
            this.root.UpdateCapabilities();
        }
Exemple #18
0
        /// <summary>
        /// Creates a new <see cref="Slide"/> with the
        /// properties defined on this dialog and creates a thumb for it.
        /// </summary>
        /// <returns>The new <see cref="Slide"/> to be added to the slideshow.</returns>
        private BrowserTreeNode GetBrowserSlide()
        {
            if (this.browserTreeNode == null)
            {
                this.browserTreeNode = new BrowserTreeNode();
            }

            // Store category and name.
            this.browserTreeNode.Category    = this.cbbCategory.Text;
            this.browserTreeNode.Text        = this.txbName.Text;
            this.browserTreeNode.OriginURL   = this.txbURL.Text;
            this.browserTreeNode.BrowseDepth = (int)this.nudBrowseDepth.Value;

            // Add standard stop condition if none is specified.
            if (this.lsbStopConditions.Items.Count == 0)
            {
                this.lsbStopConditions.Items.Add(new TimeStopCondition(SlideDesignModule.SLIDEDURATIONINS * 1000));
            }

            Slide baseURLSlide = new Slide();

            baseURLSlide.Category           = this.cbbCategory.Text;
            baseURLSlide.Modified           = true;
            baseURLSlide.Name               = this.txbName.Text;
            baseURLSlide.PresentationSize   = Document.ActiveDocument.PresentationSize;
            baseURLSlide.MouseCursorVisible = true;

            // Store Stop conditions
            foreach (StopCondition cond in this.lsbStopConditions.Items)
            {
                baseURLSlide.StopConditions.Add(cond);
            }

            Bitmap screenshot = WebsiteThumbnailGenerator.GetWebSiteScreenshot(
                this.txbURL.Text,
                Document.ActiveDocument.PresentationSize);
            string screenshotFilename = GetFilenameFromUrl(new Uri(this.txbURL.Text));
            var    filename           = Path.Combine(Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, screenshotFilename);

            screenshot.Save(filename, System.Drawing.Imaging.ImageFormat.Png);

            VGScrollImage baseURLScreenshot = new VGScrollImage(
                ShapeDrawAction.None,
                Pens.Transparent,
                Brushes.Black,
                SystemFonts.DefaultFont,
                Color.Black,
                Path.GetFileName(screenshotFilename),
                Document.ActiveDocument.ExperimentSettings.SlideResourcesPath,
                ImageLayout.None,
                1f,
                Document.ActiveDocument.PresentationSize,
                VGStyleGroup.None,
                baseURLSlide.Name,
                string.Empty);

            baseURLSlide.VGStimuli.Add(baseURLScreenshot);
            this.browserTreeNode.Slide = baseURLSlide;

            // HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("a");
            // if (es != null && es.Count != 0)
            // {
            //  HtmlElement ele = es[0];
            //  //This line is optional, it only visually scolls the first link element into view
            //  ele.ScrollIntoView(true);
            //  ele.Focus();
            // SendKeys.Send("{ENTER}");
            // }
            return(this.browserTreeNode);
        }