Exemple #1
0
        /// <summary>
        /// Stop observing when the file is updated on disk.
        /// </summary>
        /// <param name="fileName">File to stop observing.</param>
        internal void StopObservingItem(string fileName)
        {
            #region Input validation
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter), "fileName");
            }
            #endregion

            var fullFileName = Utilities.CanonicalizeFileName(fileName);

            if (this.observedItems.ContainsKey(fullFileName))
            {
                // Get the cookie that was used for this.observedItems to this file.
                var itemInfo = this.observedItems[fullFileName];

                // Remove the file from our observed list. It's important that this is done before the call to
                // UnadviseFileChange, because for some reason, the call to UnadviseFileChange can trigger a
                // FilesChanged event, and we want to be able to filter that event away.
                this.observedItems.Remove(fullFileName);

                // Stop observing the file
                ErrorHandler.ThrowOnFailure(this.fileChangeService.UnadviseFileChange(itemInfo.FileChangeCookie));
            }
        }
Exemple #2
0
        /// <summary>
        /// Called when one of the file have changed on disk.
        /// </summary>
        /// <param name="numberOfFilesChanged">Number of files changed.</param>
        /// <param name="filesChanged">Array of file names.</param>
        /// <param name="flags">Array of flags indicating the type of changes. See _VSFILECHANGEFLAGS.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        int IVsFileChangeEvents.FilesChanged(uint numberOfFilesChanged, string[] filesChanged, uint[] flags)
        {
            if (filesChanged == null)
            {
                throw new ArgumentNullException("filesChanged");
            }

            if (flags == null)
            {
                throw new ArgumentNullException("flags");
            }

            if (this.FileChangedOnDisk != null)
            {
                for (var i = 0; i < numberOfFilesChanged; i++)
                {
                    var fullFileName = Utilities.CanonicalizeFileName(filesChanged[i]);
                    if (this.observedItems.ContainsKey(fullFileName))
                    {
                        var info = this.observedItems[fullFileName];
                        this.FileChangedOnDisk(this, new FileChangedOnDiskEventArgs(fullFileName, info.ItemID, (_VSFILECHANGEFLAGS)flags[i]));
                    }
                }
            }

            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Ignore item file changes for the specified item.
        /// </summary>
        /// <param name="fileName">File to ignore observing.</param>
        /// <param name="ignore">Flag indicating whether or not to ignore changes (1 to ignore, 0 to stop ignoring).</param>
        internal void IgnoreItemChanges(string fileName, bool ignore)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter), nameof(fileName));
            }

            var fullFileName = Utilities.CanonicalizeFileName(fileName);

            if (this.observedItems.ContainsKey(fullFileName))
            {
                // Call ignore file with the flags specified.
                ErrorHandler.ThrowOnFailure(this.fileChangeService.IgnoreFile(0, fileName, ignore ? 1 : 0));
            }
        }
Exemple #4
0
        /// <summary>
        /// Ignore item file changes for the specified item.
        /// </summary>
        /// <param name="fileName">File to ignore observing.</param>
        /// <param name="ignore">Flag indicating whether or not to ignore changes (1 to ignore, 0 to stop ignoring).</param>
        internal void IgnoreItemChanges(string fileName, bool ignore)
        {
            #region Input validation
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, CultureInfo.CurrentUICulture), "fileName");
            }
            #endregion

            string fullFileName = Utilities.CanonicalizeFileName(fileName);
            if (this.observedItems.ContainsKey(fullFileName))
            {
                // Call ignore file with the flags specified.
                ErrorHandler.ThrowOnFailure(this.fileChangeService.IgnoreFile(0, fileName, ignore ? 1 : 0));
            }
        }
        public bool StopObservingFolder(string folderName)
        {
            this.CheckDisposed();

            if (string.IsNullOrEmpty(folderName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter), nameof(folderName));
            }

            var fullFolderName = Utilities.CanonicalizeFileName(folderName);

            if (this.observedFolders.TryRemove(fullFolderName, out var cookie))
            {
                // Stop observing the file
                return(ErrorHandler.Succeeded(this.fileChangeService.UnadviseDirChange(cookie)));
            }
            return(false);
        }
        public void ObserveFolder(string folderName)
        {
            this.CheckDisposed();

            if (string.IsNullOrEmpty(folderName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter), nameof(folderName));
            }

            var fullFolderName = Utilities.CanonicalizeFileName(folderName);

            if (!this.observedFolders.ContainsKey(fullFolderName))
            {
                // Observe changes to the file
                ErrorHandler.ThrowOnFailure(this.fileChangeService.AdviseDirChange(fullFolderName, /*fWatchSubDir*/ 1, this.fileChangeEvents, out var folderChangeCookie));

                // Remember that we're observing this file (used in FilesChanged event handler)
                this.observedFolders.TryAdd(fullFolderName, folderChangeCookie);
            }
        }
        /// <summary>
        /// Observe when the given file is updated on disk.
        /// </summary>
        /// <param name="fileName">File to observe.</param>
        /// <param name="id">The item id of the item to observe.</param>
        public void ObserveFile(string fileName)
        {
            this.CheckDisposed();

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter), nameof(fileName));
            }

            var fullFileName = Utilities.CanonicalizeFileName(fileName);

            if (!this.observedFiles.ContainsKey(fullFileName))
            {
                // Observe changes to the file
                ErrorHandler.ThrowOnFailure(this.fileChangeService.AdviseFileChange(fullFileName, (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Del), this.fileChangeEvents, out var fileChangeCookie));

                // Remember that we're observing this file (used in FilesChanged event handler)
                this.observedFiles.TryAdd(fullFileName, fileChangeCookie);
            }
        }
        /// <summary>
        /// Stop observing when the file is updated on disk.
        /// </summary>
        /// <param name="fileName">File to stop observing.</param>
        public bool StopObservingFile(string fileName)
        {
            this.CheckDisposed();

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter), nameof(fileName));
            }

            var fullFileName = Utilities.CanonicalizeFileName(fileName);

            // Remove the file from our observed list. It's important that this is done before the call to
            // UnadviseFileChange, because for some reason, the call to UnadviseFileChange can trigger a
            // FilesChanged event, and we want to be able to filter that event away.
            if (this.observedFiles.TryRemove(fullFileName, out var fileChangeCookie))
            {
                // Stop observing the file
                return(ErrorHandler.Succeeded(this.fileChangeService.UnadviseFileChange(fileChangeCookie)));
            }
            return(false);
        }
        /// <summary>
        /// Observe when the given file is updated on disk.
        /// </summary>
        /// <param name="fileName">File to observe.</param>
        /// <param name="id">The item id of the item to observe.</param>
        internal void ObserveItem(string fileName, uint id)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter), nameof(fileName));
            }

            var fullFileName = Utilities.CanonicalizeFileName(fileName);

            if (!this.observedItems.ContainsKey(fullFileName))
            {
                // Observe changes to the file
                ErrorHandler.ThrowOnFailure(this.fileChangeService.AdviseFileChange(fullFileName, (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Del), this, out var fileChangeCookie));

                var itemInfo = new ObservedItemInfo();
                itemInfo.ItemID           = id;
                itemInfo.FileChangeCookie = fileChangeCookie;

                // Remember that we're observing this file (used in FilesChanged event handler)
                this.observedItems.Add(fullFileName, itemInfo);
            }
        }
            /// <summary>
            /// Called when one of the file have changed on disk.
            /// </summary>
            /// <param name="numberOfFilesChanged">Number of files changed.</param>
            /// <param name="filesChanged">Array of file names.</param>
            /// <param name="flags">Array of flags indicating the type of changes. See _VSFILECHANGEFLAGS.</param>
            /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
            public int FilesChanged(uint numberOfFilesChanged, string[] filesChanged, uint[] flags)
            {
                if (filesChanged == null)
                {
                    throw new ArgumentNullException(nameof(filesChanged));
                }

                if (flags == null)
                {
                    throw new ArgumentNullException(nameof(flags));
                }

                for (var i = 0; i < numberOfFilesChanged; i++)
                {
                    var fullFileName = Utilities.CanonicalizeFileName(filesChanged[i]);
                    if (this.fileChangeManager.observedFiles.TryGetValue(fullFileName, out var value))
                    {
                        var(ItemID, FileChangeCookie) = value;
                        this.fileChangeManager.FileChangedOnDisk?.Invoke(this, new FileChangedOnDiskEventArgs(fullFileName, ItemID, (_VSFILECHANGEFLAGS)flags[i]));
                    }
                }

                return(VSConstants.S_OK);
            }