Exemple #1
0
        private void UnregisterProject(IReloadableProject project)
        {
            uint filechangeCookie;

            lock (_registeredProjects)
            {
                _registeredProjects.TryGetValue(project, out filechangeCookie);
            }

            if (filechangeCookie != VSConstants.VSCOOKIE_NIL)
            {
                // Remove watch
                IVsFileChangeEx fileChangeService = _serviceProvider.GetService <IVsFileChangeEx, SVsFileChangeEx>();
                if (fileChangeService != null)
                {
                    int hr = fileChangeService.UnadviseFileChange(filechangeCookie);
                    System.Diagnostics.Debug.Assert(ErrorHandler.Succeeded(hr));
                }

                // Always remove the watcher from our list
                lock (_registeredProjects)
                {
                    _registeredProjects.Remove(project);
                }
            }
        }
        public void StopFileChangeListening()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(FileChangeTracker));
            }

            // there is a slight chance that we haven't subscribed to the service yet so we subscribe and unsubscribe
            // both here unnecessarily. but I believe that probably is a theoretical problem and never happen in real life.
            // and even if that happens, it will be just a perf hit
            if (_fileChangeCookie == s_none)
            {
                return;
            }

            var fileChangeCookie = _fileChangeCookie.Value;
            _fileChangeCookie = s_none;

            // We may have tried to subscribe but failed, so have to check a second time
            if (fileChangeCookie.HasValue)
            {
                try
                {
                    Marshal.ThrowExceptionForHR(
                        _fileChangeService.UnadviseFileChange(fileChangeCookie.Value));
                }
                catch (Exception e) when (ReportException(e))
                {
                }
            }
        }
Exemple #3
0
            public void Dispose()
            {
                if (_cookie != 0)
                {
                    uint ck = _cookie;
                    _cookie = 0;

                    IVsFileChangeEx fx = GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx));

                    if (fx != null)
                    {
                        if (!_monitorDir)
                        {
                            fx.UnadviseFileChange(ck);
                        }
                        else
                        {
                            fx.UnadviseDirChange(ck);
                        }
                    }
                }

                if (_odt != null)
                {
                    _odt.IgnoreChanges(_toMonitor, false);
                    _odt = null;
                }
            }
Exemple #4
0
 private void UnregisterFileWatcherIfAny()
 {
     if (_filechangeCookie != VSConstants.VSCOOKIE_NIL && _fileChangeService != null)
     {
         // There's nothing for us to do if this fails. So ignore the return value.
         _fileChangeService?.UnadviseFileChange(_filechangeCookie);
     }
 }
        /// <summary>
        ///     Stops this instance.
        /// </summary>
        public void Stop()
        {
            if (!_isRunning)
            {
                throw new InvalidOperationException("The file tracker is not running");
            }

            _fileChangeService.UnadviseFileChange(_fileChangeCookie);
            _isRunning = false;
        }
 public void StopListening()
 {
     if (fileChangeEx != null && listenInfos.Any())
     {
         var cookies = listenInfos.Select(i => i.Value).ToArray();
         listenInfos.Clear();
         foreach (var cookie in cookies)
         {
             fileChangeEx.UnadviseFileChange(cookie);
         }
     }
 }
Exemple #7
0
 private void UnregisterFileWatcherIfAny()
 {
     // Note file change service is free-threaded
     if (_filechangeCookie != VSConstants.VSCOOKIE_NIL && _fileChangeService != null)
     {
         // There's nothing for us to do if this fails. So ignore the return value.
         _fileChangeService?.UnadviseFileChange(_filechangeCookie);
         _watchedFileResetCancellationToken?.Cancel();
         _watchedFileResetCancellationToken?.Dispose();
         _taskDelayScheduler?.Dispose();
     }
 }
        private void UnadviseAllAndClear(IVsFileChangeEx fileChange, IList <uint> cookies)
        {
            Trace.TraceInformation($"{nameof(LastWriteFileChangeMonitor)}.{nameof(LastWriteFileChangeMonitor.UnadviseAllAndClear)}");

            foreach (var c in cookies)
            {
                ErrorHandler.ThrowOnFailure(
                    fileChange.UnadviseFileChange(c));
            }

            cookies.Clear();
        }
Exemple #9
0
 private void UnregisterFileWatcherIfAny()
 {
     if (_filechangeCookie != VSConstants.VSCOOKIE_NIL)
     {
         IVsFileChangeEx fileChangeService = _serviceProvider.GetService <IVsFileChangeEx, SVsFileChangeEx>();
         if (fileChangeService != null)
         {
             // There's nothing for us to do if this fails. So ignore the return value.
             fileChangeService.UnadviseFileChange(_filechangeCookie);
         }
     }
 }
        public void StopFileChangeListening()
        {
            if (disposed)
            {
                throw new ObjectDisposedException("FileChangeTracker");
            }

            if (watchedFileId != null)
            {
                Marshal.ThrowExceptionForHR(fileChangeService.UnadviseFileChange(watchedFileId.Value));
                watchedFileId = null;
            }
        }
        private async Task UnregisterFileWatcherIfAnyAsync()
        {
            // Note file change service is free-threaded
            if (_filechangeCookie != VSConstants.VSCOOKIE_NIL)
            {
                IVsFileChangeEx fileChangeService = await _fileChangeService.GetValueAsync();

                // There's nothing for us to do if this fails. So ignore the return value.
                fileChangeService.UnadviseFileChange(_filechangeCookie);
                _watchedFileResetCancellationToken?.Cancel();
                _watchedFileResetCancellationToken?.Dispose();
                _taskDelayScheduler?.Dispose();
            }
        }
Exemple #12
0
            void StopMonitor()
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                // Stop monitoring
                foreach (uint v in _monitor.Keys)
                {
                    _change.UnadviseFileChange(v);
                }

                _monitor.Clear();

                foreach (string path in _fsIgnored)
                {
                    _change.SyncFile(path);
                    _change.IgnoreFile(0, path, 0);
                }

                _fsIgnored.Clear();

                // Sync all files for the last time
                // to make sure they are not reloaded for old changes after disposing
                foreach (string path in _locked)
                {
                    _change.SyncFile(path);
                }

                _locked.Clear();

                foreach (string path in _readonly)
                {
                    SccDocumentData dd;
                    if (_tracker._docMap.TryGetValue(path, out dd))
                    {
                        dd.SetReadOnly(false);
                    }
                }
                _readonly.Clear();

                foreach (string path in _ignoring)
                {
                    SccDocumentData dd;
                    if (_tracker._docMap.TryGetValue(path, out dd))
                    {
                        dd.IgnoreFileChanges(false);
                    }
                }

                _ignoring.Clear();
            }
        public void StopFileChangeListening()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(typeof(FileChangeTracker).Name);
            }

            // there is a slight chance that we haven't subscribed to the service yet so we subscribe and unsubscribe
            // both here unnecessarily. but I believe that probably is a theoretical problem and never happen in real life.
            // and even if that happens, it will be just a perf hit
            if (_fileChangeCookie != s_none)
            {
                Marshal.ThrowExceptionForHR(_fileChangeService.UnadviseFileChange(_fileChangeCookie.Value));
                _fileChangeCookie = s_none;
            }
        }
Exemple #14
0
        public override void StopListening()
        {
            _foregroundDispatcher.AssertForegroundThread();

            try
            {
                if (_fileChangeCookie != VSConstants.VSCOOKIE_NIL)
                {
                    var hr = _fileChangeService.UnadviseFileChange(_fileChangeCookie);
                    Marshal.ThrowExceptionForHR(hr);
                    _fileChangeCookie = VSConstants.VSCOOKIE_NIL;
                }
            }
            catch (Exception exception)
            {
                _errorReporter.ReportError(exception);
            }
        }
        private void HookFileChanges(bool reHook)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            IVsFileChangeEx fileChange = null;

            if (_fileChangeCookies != null)
            {
                fileChange = GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx));
                uint[] list = _fileChangeCookies;
                _fileChangeCookies = null;

                foreach (uint u in list)
                {
                    if (u != 0)
                    {
                        fileChange.UnadviseFileChange(u);
                    }
                }
            }

            if (reHook && _isFileDocument)
            {
                if (fileChange == null)
                {
                    fileChange = GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx));
                }

                List <string> items = new List <string>(GetService <IProjectFileMapper>().GetAllDocumentFiles(_name));

                uint[] cookies = new uint[items.Count];
                _fileChangeCookies = cookies;

                for (int i = 0; i < items.Count; i++)
                {
                    uint ck;
                    if (VSErr.Succeeded(fileChange.AdviseFileChange(items[i], (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Time), this, out ck)))
                    {
                        cookies[i] = ck;
                    }
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// In this function we inform the shell when we wish to receive
        /// events when our file is changed or we inform the shell when
        /// we wish not to receive events anymore.
        /// </summary>
        /// <param name="pszFileName">File name string</param>
        /// <param name="fStart">TRUE indicates advise, FALSE indicates unadvise.</param>
        /// <returns>Result of the operation</returns>
        private int SetFileChangeNotification(string pszFileName, bool fStart)
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "\t **** Inside SetFileChangeNotification ****"));

            int result = VSConstants.E_FAIL;

            //Get the File Change service
            if (null == vsFileChangeEx)
            {
                vsFileChangeEx = (IVsFileChangeEx)GetService(typeof(SVsFileChangeEx));
            }
            if (null == vsFileChangeEx)
            {
                return(VSConstants.E_UNEXPECTED);
            }

            // Setup Notification if fStart is TRUE, Remove if fStart is FALSE.
            if (fStart)
            {
                if (vsFileChangeCookie == VSConstants.VSCOOKIE_NIL)
                {
                    //Receive notifications if either the attributes of the file change or
                    //if the size of the file changes or if the last modified time of the file changes
                    result = vsFileChangeEx.AdviseFileChange(pszFileName,
                                                             (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Attr | _VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Time),
                                                             (IVsFileChangeEvents)this,
                                                             out vsFileChangeCookie);
                    if (vsFileChangeCookie == VSConstants.VSCOOKIE_NIL)
                    {
                        return(VSConstants.E_FAIL);
                    }
                }
            }
            else
            {
                if (vsFileChangeCookie != VSConstants.VSCOOKIE_NIL)
                {
                    result             = vsFileChangeEx.UnadviseFileChange(vsFileChangeCookie);
                    vsFileChangeCookie = VSConstants.VSCOOKIE_NIL;
                }
            }
            return(result);
        }
        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 + "\"");
                    }
                }
            }
        }
Exemple #18
0
        /// <summary>
        /// Sets the file change notification - whether VS should be informed about outside-VS file changes
        /// </summary>
        /// <param name="fileNameToNotify">File path</param>
        /// <param name="startNotify">True to turn notifications on</param>
        private int SetFileChangeNotification(string fileNameToNotify, bool startNotify)
        {
            int result = VSConstants.E_FAIL;

            IVsFileChangeEx vsFileChangeEx = (IVsFileChangeEx)Package.GetGlobalService(typeof(SVsFileChangeEx));

            if (null == vsFileChangeEx)
            {
                return(VSConstants.E_UNEXPECTED);
            }

            // Setup Notification if startNotify is TRUE, Remove if startNotify is FALSE.
            if (startNotify)
            {
                if (vsFileChangeCookie == VSConstants.VSCOOKIE_NIL)
                {
                    //Receive notifications if either the attributes of the file change or
                    //if the size of the file changes or if the last modified time of the file changes
                    result = vsFileChangeEx.AdviseFileChange(fileNameToNotify,
                                                             (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Attr | _VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Time),
                                                             (IVsFileChangeEvents)this,
                                                             out vsFileChangeCookie);
                    if (vsFileChangeCookie == VSConstants.VSCOOKIE_NIL)
                    {
                        return(VSConstants.E_FAIL);
                    }
                }
                result = VSConstants.S_OK;
            }
            else
            {
                if (vsFileChangeCookie != VSConstants.VSCOOKIE_NIL)
                {
                    //if we want to unadvise and the cookieTextViewEvents isnt null then unadvise changes
                    result             = vsFileChangeEx.UnadviseFileChange(vsFileChangeCookie);
                    vsFileChangeCookie = VSConstants.VSCOOKIE_NIL;
                    result             = VSConstants.S_OK;
                }
            }
            return(result);
        }
Exemple #19
0
        public void StopFileChangeListening()
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(typeof(FileChangeTracker).Name);
            }

            // there is a slight chance that we haven't subscribed to the service yet so we subscribe and unsubscribe
            // both here unnecessarily. but I believe that probably is a theoretical problem and never happen in real life.
            // and even if that happens, it will be just a perf hit
            if (_fileChangeCookie != s_none)
            {
                var hr = _fileChangeService.UnadviseFileChange(_fileChangeCookie.Value);

                // Verify if the file still exists before reporting the unadvise failure.
                // This is a workaround for VSO #248774
                if (hr != VSConstants.S_OK && File.Exists(_filePath))
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                _fileChangeCookie = s_none;
            }
        }
 private void UnsubscribeFileChangeEvents(IVsFileChangeEx service, FileWatchingToken typedToken)
 {
     ErrorHandler.ThrowOnFailure(service.UnadviseFileChange(typedToken.Cookie.Value));
 }
 public void Stop()
 {
     fileChangeService.UnadviseFileChange(fileChangeCookie);
 }