Exemplo n.º 1
0
            /// <summary>
            /// Constructor to initialize and display the form
            /// </summary>
            /// <param name="consumer">DSRef Consumer with selection to display</param>
            public DSRefNavigatorVisualizer(IDSRefConsumer consumer)
            {
                // Add the tree to the form
                Text = "DSRef Consumer Selection Debug Display";
                TreeView tree = new TreeView();

                tree.Dock = DockStyle.Fill;
                Controls.Add(tree);
                tree.BeginUpdate();

                // Create the root node and build the tree
                TreeNode root = new TreeNode();

                BuildTree(consumer, DSRefNavigator.RootNode, root);

                // Display the debuging form
                tree.Nodes.Add(root);
                tree.ExpandAll();
                tree.EndUpdate();
            }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor to create the DSRef navigator from a stream
        /// </summary>
        /// <param name="data">Stream containing the DSRef consumer</param>
        public DSRefNavigator(Stream data)
        {
            _consumer = null;

            // Pointers to unmanaged resources
            IntPtr ptr = IntPtr.Zero;
            IntPtr stream = IntPtr.Zero;
            IntPtr native = IntPtr.Zero;

            // Get a reference to the DSRef Consumer from the stream
            try
            {
                // Read the stream containing the DSRef Consumer
                byte[] buffer = new byte[data.Length];
                data.Seek(0, SeekOrigin.Begin);
                data.Read(buffer, 0, buffer.Length);

                // Copy the DSRef Consumer to native memory
                native = Marshal.AllocHGlobal(buffer.Length);
                Marshal.Copy(buffer, 0, native, buffer.Length);

                // Create a COM stream from the memory
                int result = CreateStreamOnHGlobal(native, false, ref stream);
                Marshal.ThrowExceptionForHR(result);

                // Load the DSRef Consumer from the COM stream
                result = OleLoadFromStream(stream,
                                           typeof (IDSRefConsumer).GUID.ToByteArray(), ref ptr);
                Marshal.ThrowExceptionForHR(result);

                // Get the DSRef consumer
                _consumer = Marshal.GetObjectForIUnknown(ptr) as IDSRefConsumer;
            }
            finally
            {
                // Release all of the unmanaged resources
                Marshal.Release(ptr);
                Marshal.Release(stream);
                Marshal.Release(native);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor to create the DSRef navigator from a stream
        /// </summary>
        /// <param name="data">Stream containing the DSRef consumer</param>
        public DSRefNavigator(Stream data)
        {
            _consumer = null;

            // Pointers to unmanaged resources
            IntPtr ptr    = IntPtr.Zero;
            IntPtr stream = IntPtr.Zero;
            IntPtr native = IntPtr.Zero;

            // Get a reference to the DSRef Consumer from the stream
            try
            {
                // Read the stream containing the DSRef Consumer
                byte[] buffer = new byte[data.Length];
                data.Seek(0, SeekOrigin.Begin);
                data.Read(buffer, 0, buffer.Length);

                // Copy the DSRef Consumer to native memory
                native = Marshal.AllocHGlobal(buffer.Length);
                Marshal.Copy(buffer, 0, native, buffer.Length);

                // Create a COM stream from the memory
                int result = CreateStreamOnHGlobal(native, false, ref stream);
                Marshal.ThrowExceptionForHR(result);

                // Load the DSRef Consumer from the COM stream
                result = OleLoadFromStream(stream,
                                           typeof(IDSRefConsumer).GUID.ToByteArray(), ref ptr);
                Marshal.ThrowExceptionForHR(result);

                // Get the DSRef consumer
                _consumer = Marshal.GetObjectForIUnknown(ptr) as IDSRefConsumer;
            }
            finally
            {
                // Release all of the unmanaged resources
                Marshal.Release(ptr);
                Marshal.Release(stream);
                Marshal.Release(native);
            }
        }
Exemplo n.º 4
0
            /// <summary>
            /// Build a tree of the DSRef Consumer's selection starting with the provided
            /// node in the DSRef Consumer and node in the TreeView
            /// </summary>
            /// <param name="consumer">DSRef Consumer containing the selection</param>
            /// <param name="node">Current node in the DSRef Consumer</param>
            /// <param name="treeNode">Node in the tree</param>
            private void BuildTree(IDSRefConsumer consumer, IntPtr node,
                                   System.Windows.Forms.TreeNode treeNode)
            {
                // Copy the properties for the current node given its type
                treeNode.Text = "";
                __DSREFTYPE type = consumer.GetType(node);

                if ((type & __DSREFTYPE.DSREFTYPE_HASNAME) ==
                    __DSREFTYPE.DSREFTYPE_HASNAME)
                {
                    treeNode.Text = string.Format("{0} ", consumer.GetName(node));
                }
                treeNode.Text += string.Format("(Type: {0}", GetNodeTypes(type));
                string structure = GetNodeStructure(type);

                if (!string.IsNullOrEmpty(structure))
                {
                    treeNode.Text += string.Format(" || Structure: {0}", structure);
                }
                if ((type & __DSREFTYPE.DSREFTYPE_HASOWNER) ==
                    __DSREFTYPE.DSREFTYPE_HASOWNER)
                {
                    treeNode.Text += string.Format(" || Owner: {0}", consumer.GetOwner(node));
                }
                treeNode.Text += ")";

                // Iterate over the children
                IntPtr child = consumer.GetFirstChildNode(node);

                while (child != IntPtr.Zero)
                {
                    // Create a tree node for the child and set its properties
                    TreeNode next = new TreeNode();
                    treeNode.Nodes.Add(next);
                    BuildTree(consumer, child, next);

                    // Move to the next child
                    child = consumer.GetNextSiblingNode(child);
                }
            }