Ejemplo n.º 1
0
        public void Resume()
        {
            if (!mIsSuspending || mPersistDocData == null)
            {
                return;
            }

            if (mPersistDocData != null && mReloadDocument)
            {
                mPersistDocData.ReloadDocData(0);
            }

            IVsFileChangeEx fileChange = mSite.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;

            if (fileChange == null)
            {
                return;
            }

            mIsSuspending = false;
            ErrorHandler.ThrowOnFailure(fileChange.SyncFile(mDocumentFileName));
            ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(0, mDocumentFileName, 0));
            if (mFileChangeControl != null)
            {
                ErrorHandler.ThrowOnFailure(mFileChangeControl.IgnoreFileChanges(0));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Turns on/off file ignore option. When file changes are ignored, VS doesn't display a dialog asking user about reloading the changes.
        /// </summary>
        public static void SetIgnoreFileChanges(string path, bool ignore)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            IVsHierarchy ppHier;
            uint         pitemid;
            IntPtr       pPunkDocData;
            uint         pdwCookie;
            int          hr = IVsRunningDocumentTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, path,
                                                                          out ppHier, out pitemid, out pPunkDocData, out pdwCookie);

            Marshal.ThrowExceptionForHR(hr);

            if (pPunkDocData != IntPtr.Zero)
            {
                IVsFileChangeEx fileChange = (IVsFileChangeEx)Package.GetGlobalService(typeof(SVsFileChangeEx));
                if (fileChange == null)
                {
                    throw new InvalidOperationException("Cannot consume IVsFileChangeEx.");
                }

                IVsDocDataFileChangeControl changeControl = (IVsDocDataFileChangeControl)Marshal.GetObjectForIUnknown(pPunkDocData);

                if (ignore)
                {
                    hr = fileChange.IgnoreFile(0, path, 1);
                    Marshal.ThrowExceptionForHR(hr);

                    hr = changeControl.IgnoreFileChanges(1);
                }
                else
                {
                    hr = fileChange.IgnoreFile(0, path, 0);
                    Marshal.ThrowExceptionForHR(hr);

                    hr = changeControl.IgnoreFileChanges(0);
                }
            }
        }
Ejemplo n.º 3
0
        void SuspendWatchingProjectFileChanges()
        {
            if (_suspended || this.Site == null) return;

            IVsRunningDocumentTable pRDT = this.Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (pRDT == null)
                return;

            IVsHierarchy ppHier;
            uint pid;
            IntPtr docData;
            uint docCookie;

            NativeMethods.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, filename, out ppHier, out pid, out docData, out docCookie));
            if (docCookie == 0 || docData == IntPtr.Zero)
                return;

            IVsFileChangeEx fce = this.Site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;

            if (fce != null)
            {
                _suspended = true;
                NativeMethods.ThrowOnFailure(fce.IgnoreFile(0, filename, 1));
                try
                {
                    _ddfcc = Marshal.GetTypedObjectForIUnknown(docData, typeof(IVsDocDataFileChangeControl)) as IVsDocDataFileChangeControl;
                    if (_ddfcc != null)
                    {
                        NativeMethods.ThrowOnFailure(_ddfcc.IgnoreFileChanges(1));
                    }
                }
                catch (Exception) {}
            }
            // bugbug: do I need to "release" the docData IUnknown pointer
            // or does interop take care of it?
        }
Ejemplo n.º 4
0
        public void Suspend()
        {
            if (mIsSuspending)
            {
                return;
            }

            mDocData = IntPtr.Zero;
            try
            {
                IVsRunningDocumentTable rdt = mSite.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
                if (rdt == null)
                {
                    return;
                }

                ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, mDocumentFileName,
                                                                    out IVsHierarchy hierarchy, out uint itemId, out mDocData, out uint docCookie));

                if ((docCookie == (uint)ShellConstants.VSDOCCOOKIE_NIL) || mDocData == IntPtr.Zero)
                {
                    return;
                }

                IVsFileChangeEx fileChange = mSite.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;
                if (fileChange == null)
                {
                    return;
                }

                mIsSuspending = true;
                ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(0, mDocumentFileName, 1));
                if (mDocData == IntPtr.Zero)
                {
                    return;
                }

                mPersistDocData = null;
                object unknown = Marshal.GetObjectForIUnknown(mDocData);
                if (!(unknown is IVsPersistDocData))
                {
                    return;
                }

                mPersistDocData = (IVsPersistDocData)unknown;
                if (!(mPersistDocData is IVsDocDataFileChangeControl))
                {
                    return;
                }

                mFileChangeControl = (IVsDocDataFileChangeControl)mPersistDocData;
                if (mFileChangeControl != null)
                {
                    ErrorHandler.ThrowOnFailure(mFileChangeControl.IgnoreFileChanges(1));
                }
            }
            catch (InvalidCastException e)
            {
                Trace.WriteLine("Exception" + e.Message);
            }
            finally
            {
                if (mDocData != IntPtr.Zero)
                {
                    Marshal.Release(mDocData);
                }
            }
        }
Ejemplo n.º 5
0
        public void Suspend()
        {
            if (isSuspending)
                return;

            var docData = IntPtr.Zero;
            try
            {
                var rdt = site.GetService(typeof (SVsRunningDocumentTable)) as IVsRunningDocumentTable;

                IVsHierarchy hierarchy;
                uint itemId;
                uint docCookie;
                IVsFileChangeEx fileChange;


                if (rdt == null) return;

                ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint) _VSRDTFLAGS.RDT_NoLock, documentFileName,
                    out hierarchy, out itemId, out docData, out docCookie));

                if ((docCookie == (uint) ShellConstants.VSDOCCOOKIE_NIL) || docData == IntPtr.Zero)
                    return;

                fileChange = site.GetService(typeof (SVsFileChangeEx)) as IVsFileChangeEx;

                if (fileChange != null)
                {
                    isSuspending = true;
                    ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(0, documentFileName, 1));
                    if (docData != IntPtr.Zero)
                    {
                        IVsPersistDocData persistDocData = null;

                        // if interface is not supported, return null
                        var unknown = Marshal.GetObjectForIUnknown(docData);
                        if (unknown is IVsPersistDocData)
                        {
                            persistDocData = (IVsPersistDocData) unknown;
                            if (persistDocData is IVsDocDataFileChangeControl)
                            {
                                fileChangeControl = (IVsDocDataFileChangeControl) persistDocData;
                                if (fileChangeControl != null)
                                {
                                    ErrorHandler.ThrowOnFailure(fileChangeControl.IgnoreFileChanges(1));
                                }
                            }
                        }
                    }
                }
            }
            catch (InvalidCastException e)
            {
                Trace.WriteLine("Exception" + e.Message);
            }
            finally
            {
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                }
            }
        }