public IDisposable MarkIgnoreFile(string path) { ThreadHelper.ThrowIfNotOnUIThread(); if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } IVsFileChangeEx change = GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx)); if (change != null) { Marshal.ThrowExceptionForHR(change.IgnoreFile(0, path, 1)); return(new DelegateRunner( delegate() { ThreadHelper.ThrowIfNotOnUIThread(); change.SyncFile(path); change.IgnoreFile(0, path, 0); })); } else { return(null); } }
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)); } }
private IDisposable MarkIgnoreRecursive(string newDir) { ThreadHelper.ThrowIfNotOnUIThread(); IAnkhOpenDocumentTracker dt = GetService <IAnkhOpenDocumentTracker>(); IVsFileChangeEx change = GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx)); if (dt == null || change == null) { return(null); } ICollection <string> files = dt.GetDocumentsBelow(newDir); if (files == null || files.Count == 0) { return(null); } foreach (string file in files) { Marshal.ThrowExceptionForHR(change.IgnoreFile(0, file, 1)); } return(new DelegateRunner( delegate() { ThreadHelper.ThrowIfNotOnUIThread(); foreach (string file in files) { change.SyncFile(file); change.IgnoreFile(0, file, 0); } })); }
/// <summary> /// In this function we suspend receiving file change events for /// a file or we reinstate a previously suspended file depending /// on the value of the given fSuspend flag. /// </summary> /// <param name="pszFileName">File name string</param> /// <param name="fSuspend">TRUE indicates that the events needs to be suspended</param> /// <returns></returns> private int SuspendFileChangeNotification(string pszFileName, int fSuspend) { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "\t **** Inside SuspendFileChangeNotification ****")); if (null == vsFileChangeEx) { vsFileChangeEx = (IVsFileChangeEx)GetService(typeof(SVsFileChangeEx)); } if (null == vsFileChangeEx) { return(VSConstants.E_UNEXPECTED); } if (0 == fSuspend) { // we are transitioning from suspended to non-suspended state - so force a // sync first to avoid asynchronous notifications of our own change if (vsFileChangeEx.SyncFile(pszFileName) == VSConstants.E_FAIL) { return(VSConstants.E_FAIL); } } //If we use the VSCOOKIE parameter to specify the file, then pszMkDocument parameter //must be set to a null reference and vice versa return(vsFileChangeEx.IgnoreFile(vsFileChangeCookie, null, fSuspend)); }
private void NotifyDocChanged(string filePath) { IVsFileChangeEx fileChangeEx = (IVsFileChangeEx)GetService(typeof(SVsFileChangeEx)); int hr; hr = fileChangeEx.SyncFile(filePath); }
private void ResumeChangeNotifications(string filePath) { IVsFileChangeEx service = (IVsFileChangeEx)this.VisualStudio.ServiceProvider.GetService(typeof(IVsFileChangeEx)); try { Marshal.ThrowExceptionForHR(service.SyncFile(filePath)); } finally { Marshal.ThrowExceptionForHR(service.IgnoreFile(0, filePath, 0)); } }
internal void ReloadModified() { ThreadHelper.ThrowIfNotOnUIThread(); if (_monitor == null || _change == null) { return; } foreach (string file in _monitor.Values) { _change.SyncFile(file); } foreach (KeyValuePair <string, FileInfo> item in new List <KeyValuePair <string, FileInfo> >(_altMonitor)) { string file = item.Key; FileInfo from = item.Value; FileInfo to = new FileInfo(file); if (from.Exists && to.Exists && ((from.LastWriteTime != to.LastWriteTime) || (from.Length != to.Length) || (from.CreationTime != to.CreationTime))) { if (!_changedPaths.Contains(file)) { _changedPaths.Add(file); _altMonitor[file] = to; } } } List <string> changed = new List <string>(_changedPaths); _changedPaths.Clear(); Reload(changed); }
private void NotifyDocChanged(string filePath) { if (filePath.EndsWith(".sln")) { this.dte.Solution.Close(true); this.dte.Solution.Open(filePath); OpenSelectedFile(filePath, true); } else { IVsFileChangeEx fileChangeEx = (IVsFileChangeEx)GetService(typeof(SVsFileChangeEx)); int hr; hr = fileChangeEx.SyncFile(filePath); } }
public void GetLatest(string item) { Workspace workspace = this.GetWorkspace(item); if (workspace == null) { return; } string serverPath = workspace.TryGetServerItemForLocalItem(item); if (serverPath != null) { using (UIHost.GetWaitCursor()) { IVsFileChangeEx fce = serviceProvider.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; int hr = 0; if (fce != null) { try { // Ignore file changes, so there is no Reload dialog hr = fce.IgnoreFile(VSConstants.VSCOOKIE_NIL, item, 1); Debug.Assert(hr == VSConstants.S_OK); GetRequest getRequest = new GetRequest(serverPath, RecursionType.None, VersionSpec.Latest); GetStatus status = workspace.Get(getRequest, GetOptions.None, null, null); if (status != null && status.NumConflicts > 0) { // Trigger resolve conflicts tool window if there are any, to be consistent with solution explorer this.dte.ExecuteCommand("File.TfsResumeConflictResolution"); } } finally { // Sync file so that file changes do not trigger events later when we un-ignore hr = fce.SyncFile(item); Debug.Assert(hr == VSConstants.S_OK); hr = fce.IgnoreFile(VSConstants.VSCOOKIE_NIL, item, 0); Debug.Assert(hr == VSConstants.S_OK); } } } } }
private void ResumeChangeNotifications(string filePath) { IVsFileChangeEx fileChangeService = (IVsFileChangeEx)visualStudio.ServiceProvider.GetService(typeof(IVsFileChangeEx)); int hr; try { // We need to call sync to 'flush' events that have piled up for the file, this prevents a notification // from being delivered after we turn notifications back on. hr = fileChangeService.SyncFile(filePath); Marshal.ThrowExceptionForHR(hr); } finally { // We want to turn notifications back on if the sync fails for some reason // // This is a COM interface that wants the Win32 FALSE, which is why the third value is 0. hr = fileChangeService.IgnoreFile(0u, filePath, 0); Marshal.ThrowExceptionForHR(hr); } }