public void Ignore(string filepath, bool ignore, bool prelowered)
        {
            if (fileChangeEx != null && !String.IsNullOrEmpty(filepath))
            {
                if (!prelowered)
                {
                    filepath = filepath.ToLower();
                }

                uint cookie;
                lock (eventCookies)
                {
                    if (eventCookies.TryGetValue(filepath, out cookie))
                    {
                        ErrorHandler.ThrowOnFailure(fileChangeEx.IgnoreFile(cookie, filepath, (ignore) ? 0 : 1));
                        MyPackage.OutputGeneral("Ignoring \"" + filepath + "\"");
                    }
                }
            }
        }
        public void Unsubscribe(string filepath, bool prelowered)
        {
            if (fileChangeEx != null && !String.IsNullOrEmpty(filepath))
            {
                if (!prelowered)
                {
                    filepath = filepath.ToLower();
                }

                uint cookie;
                lock (eventCookies)
                {
                    if (eventCookies.TryGetValue(filepath, out cookie))
                    {
                        ErrorHandler.ThrowOnFailure(fileChangeEx.UnadviseFileChange(cookie));
                        MyPackage.OutputGeneral("Not Tracking \"" + filepath + "\"");
                    }
                }
            }
        }
        public void Subscribe(string filepath, bool prelowered)
        {
            if (fileChangeEx != null && !String.IsNullOrEmpty(filepath))
            {
                if (!prelowered)
                {
                    filepath = filepath.ToLower();
                }

                lock (eventCookies)
                {
                    if (!eventCookies.ContainsKey(filepath))
                    {
                        uint cookie;
                        ErrorHandler.ThrowOnFailure(fileChangeEx.AdviseFileChange(filepath, (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Time), this, out cookie));
                        MyPackage.OutputGeneral("Tracking \"" + filepath + "\"");
                        eventCookies.Add(filepath, cookie);
                    }
                }
            }
        }
예제 #4
0
        private void ProcessNode(IVsHierarchy hierarchy, uint itemId, int recursionLevel)
        {
            try
            {
                MyLog.DebugEnter(this, "ProcessNode(hierarchy, " + itemId + ", " + recursionLevel + ")");

                int hr;

                object oRootName;
                hr = hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_Name, out oRootName);
                if (ErrorHandler.Failed(hr))
                {
                    MyPackage.OutputGeneral("ERROR: Could not get root name of item #" + itemId);
                    ErrorHandler.ThrowOnFailure(hr);
                }
                string rootName = oRootName as string;
                if (String.IsNullOrEmpty(rootName))
                {
                    rootName = Resources.RootUnknown;
                }
                Debug.WriteLine("rootName=" + rootName);

                string itemName;
                hr = hierarchy.GetCanonicalName(itemId, out itemName);
                if (ErrorHandler.Failed(hr))
                {
                    switch (hr)
                    {
                    case VSConstants.E_NOTIMPL:
                        // ignore; Nothing to do if we cannot get the file name, but below logic can handle null/empty name...
                        itemName = null;
                        break;

                    default:
                        MyPackage.OutputGeneral("ERROR: Could not get canonical name of item #" + itemId);
                        ErrorHandler.ThrowOnFailure(hr);
                        break;
                    }
                }
                Debug.WriteLine("itemName=\"" + itemName + "\"");

#if DEBUG && false
                if (BackgroundWorker != null && !String.IsNullOrEmpty(itemName))
                {
                    // Temporary until we call AddFilePathIfChanged after we find out what the item type is
                    BackgroundWorker.ReportProgress(0, itemName);
                }
#endif

                Guid guidTypeNode;
                hr = hierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_TypeGuid, out guidTypeNode);
                if (ErrorHandler.Failed(hr))
                {
                    switch (hr)
                    {
                    case VSConstants.E_NOTIMPL:
                        Debug.WriteLine("Guid property E_NOTIMPL for item #" + itemId + " \"" + itemName + "\"; assuming virtual/reference item and ignoring");
                        // ignore; Below logic can handle Guid.Empty
                        guidTypeNode = Guid.Empty;
                        break;

                    case VSConstants.DISP_E_MEMBERNOTFOUND:
                        Debug.WriteLine("Guid property DISP_E_MEMBERNOTFOUND for item #" + itemId + " \"" + itemName + "\"; assuming reference item and ignoring");
                        guidTypeNode = Guid.Empty;
                        break;

                    default:
                        MyPackage.OutputGeneral("ERROR: Could not get type guid of item #" + itemId + " \"" + itemName + "\"");
                        ErrorHandler.ThrowOnFailure(hr);
                        break;
                    }
                }
                Debug.WriteLine("guidTypeNode=" + guidTypeNode);

                //
                // Intentionally ordered from most commonly expected to least commonly expected...
                //
                if (Guid.Equals(guidTypeNode, VSConstants.GUID_ItemType_PhysicalFile))
                {
                    AddFilePathIfChanged(itemName, rootName, PostReview.ChangeType.Unknown);
                }
                else if (itemId == VSConstants.VSITEMID_ROOT)
                {
                    IVsProject project = hierarchy as IVsProject;
                    if (project != null)
                    {
                        string projectFile;
                        hr = project.GetMkDocument(VSConstants.VSITEMID_ROOT, out projectFile);
                        if (ErrorHandler.Failed(hr))
                        {
                            switch (hr)
                            {
                            case VSConstants.E_NOTIMPL:
                                // This apparently can happen if the item is a virtual "Solution Items" folder; nothing to do; return;
                                return;

                            default:
                                MyPackage.OutputGeneral("ERROR: Could not get document name of project \"" + rootName + "\"");
                                ErrorHandler.ThrowOnFailure(hr);
                                break;
                            }
                        }

                        AddFilePathIfChanged(projectFile, rootName, PostReview.ChangeType.Unknown);
                    }
                    else
                    {
                        IVsSolution solution = hierarchy as IVsSolution;
                        if (solution != null)
                        {
                            rootName = Resources.RootSolution;

                            string solutionDirectory, solutionFile, solutionUserOptions;
                            ErrorHandler.ThrowOnFailure(solution.GetSolutionInfo(out solutionDirectory, out solutionFile, out solutionUserOptions));

                            AddFilePathIfChanged(solutionFile, rootName, PostReview.ChangeType.Unknown);
                        }
                        else
                        {
                            MyPackage.OutputGeneral("ERROR: itemid==VSITEMID_ROOT, but hierarchy is neither Solution or Project");
                            ErrorHandler.ThrowOnFailure(VSConstants.E_UNEXPECTED);
                        }
                    }
                }
#if DEBUG
                else if (Guid.Equals(guidTypeNode, VSConstants.GUID_ItemType_PhysicalFolder))
                {
                    Debug.WriteLine("ignoring GUID_ItemType_PhysicalFolder");
                    // future enumeration will handle any individual subitems in this folder...
                }
                else if (Guid.Equals(guidTypeNode, VSConstants.GUID_ItemType_VirtualFolder))
                {
                    Debug.WriteLine("ignoring GUID_ItemType_VirtualFolder");
                    // future enumeration will handle any individual subitems in this virtual folder...
                }
                else if (Guid.Equals(guidTypeNode, VSConstants.GUID_ItemType_SubProject))
                {
                    Debug.WriteLine("ignoring GUID_ItemType_SubProject");
                    // future enumeration will handle any individual subitems in this sub project...
                }
                else if (Guid.Equals(guidTypeNode, Guid.Empty))
                {
                    Debug.WriteLine("ignoring itemName=" + itemName + "; guidTypeNode == Guid.Empty");
                    // future enumeration will handle any individual subitems in this item...
                }
                else
                {
                    MyPackage.OutputGeneral("ERROR: Unhandled node item/type itemName=" + itemName + ", guidTypeNode=" + guidTypeNode);
                    ErrorHandler.ThrowOnFailure(VSConstants.E_UNEXPECTED);
                }
#endif
            }
            finally
            {
                MyLog.DebugLeave(this, "ProcessNode(hierarchy, " + itemId + ", " + recursionLevel + ")");
            }
        }