public void UnregisterHierarchy(IVsHierarchy hierarchy)
        {
            if ((null == hierarchy) || !hierarchies.ContainsKey(hierarchy))
            {
                return;
            }
            HierarchyListener listener = hierarchies[hierarchy];

            if (null != listener)
            {
                listener.Dispose();
            }
            hierarchies.Remove(hierarchy);
            if (0 == hierarchies.Count)
            {
                UnregisterRDTEvents();
            }
            lock (files) {
                ModuleId[] keys = new ModuleId[files.Keys.Count];
                files.Keys.CopyTo(keys, 0);
                foreach (ModuleId id in keys)
                {
                    if (hierarchy.Equals(id.Hierarchy))
                    {
                        library.RemoveNode(files[id]);
                        files.Remove(id);
                    }
                }
            }
            // Remove the document listeners.
            uint[] docKeys = new uint[documents.Keys.Count];
            documents.Keys.CopyTo(docKeys, 0);
            foreach (uint id in docKeys)
            {
                TextLineEventListener docListener = documents[id];
                if (hierarchy.Equals(docListener.FileID.Hierarchy))
                {
                    documents.Remove(id);
                    docListener.Dispose();
                }
            }
        }
        public void RegisterHierarchy(IVsHierarchy hierarchy)
        {
            if ((null == hierarchy) || hierarchies.ContainsKey(hierarchy))
            {
                return;
            }
            if (0 == objectManagerCookie)
            {
                IVsObjectManager2 objManager = provider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
                if (null == objManager)
                {
                    return;
                }
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    objManager.RegisterSimpleLibrary(library, out objectManagerCookie));
            }
            HierarchyListener listener = new HierarchyListener(hierarchy);

            listener.OnAddItem    += new EventHandler <HierarchyEventArgs>(OnNewFile);
            listener.OnDeleteItem += new EventHandler <HierarchyEventArgs>(OnDeleteFile);
            listener.StartListening(true);
            hierarchies.Add(hierarchy, listener);
            RegisterForRDTEvents();
        }
 public void RegisterHierarchy(IVsHierarchy hierarchy)
 {
     if ((null == hierarchy) || hierarchies.ContainsKey(hierarchy)) {
         return;
     }
     if (0 == objectManagerCookie) {
         IVsObjectManager2 objManager = provider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
         if (null == objManager) {
             return;
         }
         Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
             objManager.RegisterSimpleLibrary(library, out objectManagerCookie));
     }
     HierarchyListener listener = new HierarchyListener(hierarchy);
     listener.OnAddItem += new EventHandler<HierarchyEventArgs>(OnNewFile);
     listener.OnDeleteItem += new EventHandler<HierarchyEventArgs>(OnDeleteFile);
     listener.StartListening(true);
     hierarchies.Add(hierarchy, listener);
     RegisterForRDTEvents();
 }