public DocumentProvider( IVisualStudioHostProjectContainer projectContainer, IServiceProvider serviceProvider, bool signUpForFileChangeNotification) { var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); _projectContainer = projectContainer; this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); this.EditorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>(); this.ContentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>(); _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>(); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); // In the CodeSense scenario we will receive file change notifications from the native // Language Services, so we don't want to sign up for them ourselves. if (signUpForFileChangeNotification) { _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); } var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); if (shell == null) { // This can happen only in tests, bail out. return; } int installed; Marshal.ThrowExceptionForHR(shell.IsPackageInstalled(Guids.RoslynPackageId, out installed)); IsRoslynPackageInstalled = installed != 0; var runningDocumentTableForEvents = (IVsRunningDocumentTable)RunningDocumentTable; Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie)); }
/// <summary> /// Creates a document provider. /// </summary> /// <param name="projectContainer">Project container for the documents.</param> /// <param name="serviceProvider">Service provider</param> /// <param name="documentTrackingService">An optional <see cref="VisualStudioDocumentTrackingService"/> to track active and visible documents.</param> public DocumentProvider( IVisualStudioHostProjectContainer projectContainer, IServiceProvider serviceProvider, VisualStudioDocumentTrackingService documentTrackingService) { var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); _projectContainer = projectContainer; this._documentTrackingServiceOpt = documentTrackingService; this._runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); this._editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>(); this._contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>(); _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>(); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); if (shell == null) { // This can happen only in tests, bail out. return; } var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable; Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie)); }
public RuleSetFile(string filePath, IVsFileChangeEx fileChangeService, VisualStudioRuleSetManager ruleSetManager) { _filePath = filePath; _ruleSetManager = ruleSetManager; ImmutableArray<string> includes; try { includes = RuleSet.GetEffectiveIncludesFromFile(filePath); } catch (Exception e) { // We couldn't read the rule set for whatever reason. Capture the exception // so we can surface the error later, and subscribe to file change notifications // so that we'll automatically reload the file if the user can fix the issue. _optionsRead = true; _specificDiagnosticOptions = ImmutableDictionary<string, ReportDiagnostic>.Empty; _exception = e; includes = ImmutableArray.Create(filePath); } _trackers = new List<FileChangeTracker>(capacity: includes.Length); foreach (var include in includes) { var tracker = new FileChangeTracker(fileChangeService, include); tracker.UpdatedOnDisk += IncludeUpdated; tracker.StartFileChangeListeningAsync(); _trackers.Add(tracker); } }
public VisualStudioRuleSetManager( IVsFileChangeEx fileChangeService, IForegroundNotificationService foregroundNotificationService, IAsynchronousOperationListener listener) { _fileChangeService = fileChangeService; _foregroundNotificationService = foregroundNotificationService; _listener = listener; }
public FileChangeEventsListener(IIdeTracer tracer) { this.tracer = tracer; InitNullEvents(); fileChangeEx = Package.GetGlobalService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; }
private FileChangeMonitor(IServiceProvider serviceProvider) { IVsFileChangeEx fileChangeService = serviceProvider.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; this.fileChangeService = fileChangeService; this.cookies = new Dictionary<string, uint>(); }
public AnalyzerFileWatcherService( VisualStudioWorkspaceImpl workspace, HostDiagnosticUpdateSource hostDiagnosticUpdateSource, SVsServiceProvider serviceProvider) { _workspace = workspace; _updateSource = hostDiagnosticUpdateSource; _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); }
public StandardTextDocument( DocumentProvider documentProvider, IVisualStudioHostProject project, DocumentKey documentKey, IReadOnlyList<string> folderNames, SourceCodeKind sourceCodeKind, ITextUndoHistoryRegistry textUndoHistoryRegistry, IVsFileChangeEx fileChangeService, ITextBuffer openTextBuffer, DocumentId id, EventHandler updatedOnDiskHandler, EventHandler<bool> openedHandler, EventHandler<bool> closingHandler) { Contract.ThrowIfNull(documentProvider); this.Project = project; this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker); this.Folders = folderNames; _documentProvider = documentProvider; this.Key = documentKey; this.SourceCodeKind = sourceCodeKind; _itemMoniker = documentKey.Moniker; _textUndoHistoryRegistry = textUndoHistoryRegistry; _fileChangeTracker = new FileChangeTracker(fileChangeService, this.FilePath); _fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk; _openTextBuffer = openTextBuffer; _snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer); // The project system does not tell us the CodePage specified in the proj file, so // we use null to auto-detect. _doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null); // If we aren't already open in the editor, then we should create a file change notification if (openTextBuffer == null) { _fileChangeTracker.StartFileChangeListeningAsync(); } if (updatedOnDiskHandler != null) { UpdatedOnDisk += updatedOnDiskHandler; } if (openedHandler != null) { Opened += openedHandler; } if (closingHandler != null) { Closing += closingHandler; } }
public DefaultFileEventListenerFactory(ISolutionFilesService solutionFilesService, IVsFileChangeEx fileChangeService, IOutputService outputService, ICommandErrorReporter errorReporter) { this.solutionFilesService = solutionFilesService; this.fileChangeService = fileChangeService; this.outputService = outputService; this.globMatcher = new RegexGlobMatcher(); this.onChangeTaskDispatcher = new SynchronousOnChangeTaskDispatcher(this.outputService); this.actionFactory = new PowerShellGooseActionFactory(new PowerShellTaskFactory(this.outputService, errorReporter, new JsonCommandLogParser()), new PowerShellCommandBuilder()); }
public AnalyzerFileWatcherService( VisualStudioWorkspaceImpl workspace, HostDiagnosticUpdateSource hostDiagnosticUpdateSource, SVsServiceProvider serviceProvider) { _workspace = workspace; _updateSource = hostDiagnosticUpdateSource; _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); InMemoryAssemblyProvider.AssemblyLoad += AnalyzerFileReference_AssemblyLoad; }
public VisualStudioAnalyzer(string fullPath, IVsFileChangeEx fileChangeService, HostDiagnosticUpdateSource hostDiagnosticUpdateSource, ProjectId projectId, Workspace workspace, string language) { _fullPath = fullPath; _tracker = new FileChangeTracker(fileChangeService, fullPath); _tracker.UpdatedOnDisk += OnUpdatedOnDisk; _tracker.StartFileChangeListeningAsync(); _tracker.EnsureSubscription(); _hostDiagnosticUpdateSource = hostDiagnosticUpdateSource; _projectId = projectId; _workspace = workspace; _language = language; }
internal VisualStudioMetadataReferenceManager(IServiceProvider serviceProvider, ITemporaryStorageService temporaryStorageService) { _metadataCache = new MetadataCache(); _runtimeDirectories = GetRuntimeDirectories(); _xmlMemberIndexService = (IVsXMLMemberIndexService)serviceProvider.GetService(typeof(SVsXMLMemberIndexService)); _smartOpenScopeService = (IVsSmartOpenScope)serviceProvider.GetService(typeof(SVsSmartOpenScope)); _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); _temporaryStorageService = temporaryStorageService; Debug.Assert(_xmlMemberIndexService != null); Debug.Assert(_smartOpenScopeService != null); Debug.Assert(_fileChangeService != null); Debug.Assert(temporaryStorageService != null); }
protected override void Initialize() { var solution = (IVsSolution)this.GetService(typeof(SVsSolution)); this.solutionFilesService = new SolutionFilesService(solution); this.outputService = this.outputService ?? new OutputService(this); this.fileChangeService = this.fileChangeService ?? (IVsFileChangeEx)this.GetService(typeof(SVsFileChangeEx)); var errorListProviderFacade = new GooseErrorListProviderFacade(this, this.solutionFilesService); var errorTaskHandler = new GooseErrorTaskHandler(errorListProviderFacade); this.errorReporter = new CommandErrorReporter(errorTaskHandler, new JsonCommandLogParser()); var fileEventListenerFactory = new DefaultFileEventListenerFactory(solutionFilesService, this.fileChangeService, this.outputService, errorReporter); this.solutionEventListener = this.solutionEventListener ?? new SolutionEventListener(solution, fileEventListenerFactory, this.outputService); base.Initialize(); }
public StandardTextDocument( DocumentProvider documentProvider, IVisualStudioHostProject project, DocumentKey documentKey, uint itemId, SourceCodeKind sourceCodeKind, ITextBufferFactoryService textBufferFactoryService, ITextUndoHistoryRegistry textUndoHistoryRegistry, IVsFileChangeEx fileChangeService, ITextBuffer openTextBuffer, DocumentId id) { Contract.ThrowIfNull(documentProvider); Contract.ThrowIfNull(textBufferFactoryService); this.Project = project; this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker); this.Folders = project.GetFolderNames(itemId); // TODO: // this one doesn't work for asynchronous project load situation where shared projects is loaded after one uses shared file. // we need to figure out what to do on those case. but this works for project k case. // opened an issue to track this issue - https://github.com/dotnet/roslyn/issues/1859 this.SharedHierarchy = project.Hierarchy == null ? null : LinkedFileUtilities.GetSharedHierarchyForItem(project.Hierarchy, itemId); _documentProvider = documentProvider; this.Key = documentKey; this.SourceCodeKind = sourceCodeKind; _itemMoniker = documentKey.Moniker; _textBufferFactoryService = textBufferFactoryService; _textUndoHistoryRegistry = textUndoHistoryRegistry; _fileChangeTracker = new FileChangeTracker(fileChangeService, this.FilePath); _fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk; _openTextBuffer = openTextBuffer; _snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer); // The project system does not tell us the CodePage specified in the proj file, so // we use null to auto-detect. _doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null); // If we aren't already open in the editor, then we should create a file change notification if (openTextBuffer == null) { _fileChangeTracker.StartFileChangeListeningAsync(); } }
/// <summary> /// Overloaded ctor. /// </summary> /// <param name="nodeParam">An instance of a project item.</param> internal FileChangeManager(IServiceProvider serviceProvider) { #region input validation if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } #endregion this.fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); if (this.fileChangeService == null) { // VS is in bad state, since the SVsFileChangeEx could not be proffered. throw new InvalidOperationException(); } }
/// <summary> /// Overloaded ctor. /// </summary> /// <param name="nodeParam">An instance of a project item.</param> public FileChangeManager(IServiceProvider serviceProvider) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } this.fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); if (this.fileChangeService == null) { // VS is in bad state, since the SVsFileChangeEx could not be proffered. throw new InvalidOperationException(); } this.fileChangeEvents = new FileChangeEvents(this); }
internal VisualStudioMetadataReferenceManager(IServiceProvider serviceProvider, ITemporaryStorageService temporaryStorageService) { _metadataCache = new MetadataCache(); _runtimeDirectories = GetRuntimeDirectories(); XmlMemberIndexService = (IVsXMLMemberIndexService)serviceProvider.GetService(typeof(SVsXMLMemberIndexService)); Assumes.Present(XmlMemberIndexService); SmartOpenScopeServiceOpt = (IVsSmartOpenScope)serviceProvider.GetService(typeof(SVsSmartOpenScope)); Assumes.Present(SmartOpenScopeServiceOpt); FileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); Assumes.Present(FileChangeService); _temporaryStorageService = temporaryStorageService; Assumes.Present(_temporaryStorageService); }
public void Dispose() { if (!this.disposed) { this.disposed = true; foreach (var cookie in this.watchedFiles.Values) { this.fileWatcher.UnadviseFileChange(cookie); } foreach (var cookie in this.watchedFolders.Values) { this.fileWatcher.UnadviseDirChange(cookie); } this.watchedFiles.Clear(); this.watchedFolders.Clear(); this.fileWatcher = null; } }
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; } } } }
/// <summary> /// Initialize the watcher. /// </summary> protected override void Initialize() { _fileChangeService = _serviceProvider.GetService <IVsFileChangeEx, SVsFileChangeEx>(); // The tree source to get changes to the tree so that we can identify when the assets file changes. var treeSource = _fileSystemTreeProvider.Tree.SyncLinkOptions(); // The property source used to get the value of the $ProjectAssetsFile property so that we can identify the location of the assets file. var sourceLinkOptions = new StandardRuleDataflowLinkOptions { RuleNames = Empty.OrdinalIgnoreCaseStringSet.Add(ConfigurationGeneral.SchemaName), PropagateCompletion = true }; var propertySource = _activeConfiguredProjectSubscriptionService.ProjectRuleSource.SourceBlock.SyncLinkOptions(sourceLinkOptions); var target = new ActionBlock <IProjectVersionedValue <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > >(new Action <IProjectVersionedValue <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > >(DataFlow_Changed)); // Join the two sources so that we get synchronized versions of the data. _treeWatcher = ProjectDataSources.SyncLinkTo(treeSource, propertySource, target); }
/// <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 StandardTextDocument( DocumentProvider documentProvider, IVisualStudioHostProject project, DocumentKey documentKey, uint itemId, SourceCodeKind sourceCodeKind, ITextBufferFactoryService textBufferFactoryService, ITextUndoHistoryRegistry textUndoHistoryRegistry, IVsFileChangeEx fileChangeService, ITextBuffer openTextBuffer, DocumentId id) { Contract.ThrowIfNull(documentProvider); Contract.ThrowIfNull(textBufferFactoryService); this.Project = project; this.Id = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker); this.Folders = project.GetFolderNames(itemId); this.SharedHierarchy = project.Hierarchy == null ? null : LinkedFileUtilities.GetSharedHierarchyForItem(project.Hierarchy, itemId); _documentProvider = documentProvider; this.Key = documentKey; this.SourceCodeKind = sourceCodeKind; _itemMoniker = documentKey.Moniker; _textBufferFactoryService = textBufferFactoryService; _textUndoHistoryRegistry = textUndoHistoryRegistry; _fileChangeTracker = new FileChangeTracker(fileChangeService, this.FilePath); _fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk; _openTextBuffer = openTextBuffer; _snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer); // The project system does not tell us the CodePage specified in the proj file, so // we use null to auto-detect. _doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null); // If we aren't already open in the editor, then we should create a file change notification if (openTextBuffer == null) { _fileChangeTracker.StartFileChangeListeningAsync(); } }
private async Task RegisterFileWatcherAsync(string projectLockJsonFilePath) { // Note file change service is free-threaded if (projectLockJsonFilePath != null) { _previousContentsHash = GetFileHashOrNull(projectLockJsonFilePath); _taskDelayScheduler = new TaskDelayScheduler( s_notifyDelay, _projectServices.ThreadingService, CreateLinkedCancellationToken()); IVsFileChangeEx fileChangeService = await _fileChangeService.GetValueAsync(); int hr = fileChangeService.AdviseFileChange(projectLockJsonFilePath, (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Size | _VSFILECHANGEFLAGS.VSFILECHG_Add | _VSFILECHANGEFLAGS.VSFILECHG_Del), this, out _filechangeCookie); ErrorHandler.ThrowOnFailure(hr); } _fileBeingWatched = projectLockJsonFilePath; }
private BundleOnSave(Package package) { if (package == null) { throw new ArgumentNullException("package"); } _package = package; _fileChangeService = this.ServiceProvider.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; _dte = this.ServiceProvider.GetService(typeof(DTE)) as DTE2; if (_fileChangeService != null && _dte != null) { _dte.Application.Events.SolutionEvents.ProjectAdded += HandleProjectAdded; _dte.Application.Events.SolutionEvents.ProjectRemoved += HandleProjectRemoved; // Solution "Opened" calls ProjectAdded for each Project in the solution, but closing a solution does not call ProjectRemoved. _dte.Application.Events.SolutionEvents.BeforeClosing += HandleSolutionClosing; } }
public DocumentProvider( IVisualStudioHostProjectContainer projectContainer, IServiceProvider serviceProvider, bool signUpForFileChangeNotification) { var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); _projectContainer = projectContainer; this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable)); this.EditorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>(); this.ContentTypeRegistryService = componentModel.GetService <IContentTypeRegistryService>(); _textUndoHistoryRegistry = componentModel.GetService <ITextUndoHistoryRegistry>(); _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager)); // In the CodeSense scenario we will receive file change notifications from the native // Language Services, so we don't want to sign up for them ourselves. if (signUpForFileChangeNotification) { _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx)); } var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell)); if (shell == null) { // This can happen only in tests, bail out. return; } int installed; Marshal.ThrowExceptionForHR(shell.IsPackageInstalled(Guids.RoslynPackageId, out installed)); IsRoslynPackageInstalled = installed != 0; var runningDocumentTableForEvents = (IVsRunningDocumentTable)RunningDocumentTable; Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie)); }
public void InitializeFileTracking(IVsFileChangeEx fileChangeService) { lock (_gate) { if (_trackers == null) { ImmutableArray <string> includes; try { includes = RuleSet.GetEffectiveIncludesFromFile(FilePath); } catch (Exception e) { // We couldn't read the rule set for whatever reason. Capture the exception // so we can surface the error later, and subscribe to file change notifications // so that we'll automatically reload the file if the user can fix the issue. _optionsRead = true; _specificDiagnosticOptions = ImmutableDictionary <string, ReportDiagnostic> .Empty; _exception = e; includes = ImmutableArray.Create(FilePath); } _trackers = new List <FileChangeTracker>(capacity: includes.Length); foreach (var include in includes) { var tracker = new FileChangeTracker(fileChangeService, include); tracker.UpdatedOnDisk += IncludeUpdated; tracker.StartFileChangeListeningAsync(); _trackers.Add(tracker); } } } }
public VisualStudioFileChangeTrackerFactory( ForegroundDispatcher foregroundDispatcher, ErrorReporter errorReporter, IVsFileChangeEx fileChangeService) { if (foregroundDispatcher == null) { throw new ArgumentNullException(nameof(foregroundDispatcher)); } if (errorReporter == null) { throw new ArgumentNullException(nameof(errorReporter)); } if (fileChangeService == null) { throw new ArgumentNullException(nameof(fileChangeService)); } _foregroundDispatcher = foregroundDispatcher; _errorReporter = errorReporter; _fileChangeService = fileChangeService; }
/// <summary> /// Initialize the watcher. /// </summary> protected override async Task InitializeCoreAsync(CancellationToken cancellationToken) { _fileChangeService = (IVsFileChangeEx)(await _asyncServiceProvider.GetServiceAsync(typeof(SVsFileChangeEx)).ConfigureAwait(false)); // Explicitly get back to the thread pool for the rest of this method so we don't tie up the UI thread; await TaskScheduler.Default; await _projectTasksService.LoadedProjectAsync(() => { // The tree source to get changes to the tree so that we can identify when the assets file changes. ProjectDataSources.SourceBlockAndLink <IProjectVersionedValue <IProjectTreeSnapshot> > treeSource = _fileSystemTreeProvider.Tree.SyncLinkOptions(); // The property source used to get the value of the $ProjectAssetsFile property so that we can identify the location of the assets file. StandardRuleDataflowLinkOptions sourceLinkOptions = DataflowOption.WithRuleNames(ConfigurationGeneral.SchemaName); ProjectDataSources.SourceBlockAndLink <IProjectVersionedValue <IProjectSubscriptionUpdate> > propertySource = _activeConfiguredProjectSubscriptionService.ProjectRuleSource.SourceBlock.SyncLinkOptions(sourceLinkOptions); var target = new ActionBlock <IProjectVersionedValue <Tuple <IProjectTreeSnapshot, IProjectSubscriptionUpdate> > >(DataFlow_ChangedAsync); // Join the two sources so that we get synchronized versions of the data. _treeWatcher = ProjectDataSources.SyncLinkTo(treeSource, propertySource, target); return(Task.CompletedTask); }).ConfigureAwait(false); }
/// <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); }
public FileChangeSubscriber(IVsFileChangeEx fileChangeEx) { this.fileChangeEx = fileChangeEx; }
public SccDocumentLock(OpenDocumentTracker tracker, HybridCollection<string> locked, HybridCollection<string> ignoring, HybridCollection<string> readOnly) { if (tracker == null) throw new ArgumentNullException("tracker"); else if (locked == null) throw new ArgumentNullException("locked"); else if (ignoring == null) throw new ArgumentNullException("ignoring"); else if (readOnly == null) throw new ArgumentNullException("readOnly"); _tracker = tracker; _locked = locked; _ignoring = ignoring; _readonly = readOnly; _fsIgnored = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase); _changedPaths = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase); _monitor = new Dictionary<uint, string>(); _altMonitor = new Dictionary<string, FileInfo>(); _change = tracker.GetService<IVsFileChangeEx>(typeof(SVsFileChangeEx)); foreach (string file in locked) { // This files auto reload could not be suspended by calling Ignore on the document // We must therefore stop posting messages to it by stopping it in the change monitor // But to be able to tell if there are changes.. We keep some stats ourselves if (!ignoring.Contains(file) && ErrorHandler.Succeeded(_change.IgnoreFile(0, file, 1))) { _fsIgnored.Add(file); FileInfo info = new FileInfo(file); info.Refresh(); if (info.Exists) { GC.KeepAlive(info.LastWriteTime); GC.KeepAlive(info.CreationTime); GC.KeepAlive(info.Length); } _altMonitor.Add(file, info); } } }
public void Dispose() { StopListening(); fileChangeEx = null; }
private /*readonly*/ IVsFileChangeEx fileWatcher; // writeable for dispose public TestFilesUpdateWatcher(IServiceProvider serviceProvider) { ValidateArg.NotNull(serviceProvider, nameof(serviceProvider)); this.fileWatcher = serviceProvider.GetService <IVsFileChangeEx>(typeof(SVsFileChangeEx)); }
public DotvvmConfigurationProvider() { fileChangeService = ServiceProvider.GlobalProvider.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; }
/// <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 FileChangeTracker(IVsFileChangeEx fileChangeService, string filePath) { this.fileChangeService = fileChangeService; this.filePath = filePath; }
public FileChangeTracker(IVsFileChangeEx fileChangeService, string filePath) { _fileChangeService = fileChangeService; _filePath = filePath; _fileChangeCookie = s_none; }
/// <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="fileNameToNotify">File name string</param> /// <param name="startNotify">TRUE indicates advise, FALSE indicates unadvise.</param> /// <returns>Result of the operation</returns> private int SetFileChangeNotification(string fileNameToNotify, bool startNotify) { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "\t **** Inside SetFileChangeNotification ****")); int result = VSConstants.E_FAIL; //Get the File Change service if (null == vsFileChangeEx) vsFileChangeEx = (IVsFileChangeEx) GetVsService(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), 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; }
// HACK HACK: this is to work around the SwitchToMainThread in the constructor above not // being practical to run in unit tests. That SwitchToMainThread is working around a now-fixed // bug in the shell where GetServiceAsync() might deadlock in the VS service manager // if the UI thread was also dealing with the service at the same time. I'd remove the // SwitchToMainThreadAsync right now instead of this doing this hack, but we're targeting this // fix for a preview release that's too risky to do it in. Other options involve more extensive // mocking or extracting of interfaces which is also just churn that will be immediately undone // once we clean up the constructor either. internal void TrySetFileChangeService_TestOnly(IVsFileChangeEx fileChange) { _fileChangeService.TrySetResult(fileChange); }