private void ProjectItemsEventsOnItemRemoved(ProjectItem item)
 {
     visualStudioTracer.Trace("Item Removed: " + item.Name, "VsProjectFileTracker");
     if (IsItemRelevant(item))
     {
         OnFileOutOfScope(item, VsxHelper.GetProjectRelativePath(item));
     }
 }
        protected string GetProjectRelativePathWithFileName(ProjectItem projectItem, string itemName)
        {
            var projectRelativePath = VsxHelper.GetProjectRelativePath(projectItem);

            if (itemName != null)
            {
                projectRelativePath = Path.Combine(Path.GetDirectoryName(projectRelativePath) ?? "", itemName);
            }
            return(projectRelativePath);
        }
Beispiel #3
0
 protected override void SetupListeningToFiles()
 {
     foreach (var projectItem in VsxHelper.GetAllPhysicalFileProjectItem(project))
     {
         if (IsItemRelevant(projectItem))
         {
             StartListeningToFile(projectItem);
         }
     }
 }
Beispiel #4
0
        public VsProjectFileTracker(Project project, string fileName, DteWithEvents dteWithEvents, IVisualStudioTracer visualStudioTracer, bool followTrackingAfterRename = false)
        {
            this.project = project;
            this.followTrackingAfterRename = followTrackingAfterRename;
            this.fileName           = fileName;
            this.visualStudioTracer = visualStudioTracer;

            SetLastChangeDate(VsxHelper.FindProjectItemByProjectRelativePath(project, fileName));
            SubscribeToDteEvents(dteWithEvents);
        }
        int IVsSolutionEvents.OnQueryUnloadProject(IVsHierarchy pRealHierarchy, ref int pfCancel)
        {
            var project = VsxHelper.GetProject(pRealHierarchy);

            if (project != null)
            {
                OnQueryUnloadProject(project);
            }
            return(VSConstants.S_OK);
        }
Beispiel #6
0
        private DateTime?GetLastChangeDate(ProjectItem projectItem)
        {
            string filePath;

            if (projectItem == null || !File.Exists(filePath = VsxHelper.GetFileName(projectItem)))
            {
                return(null);
            }

            return(File.GetLastWriteTime(filePath));
        }
Beispiel #7
0
        private bool IsFileNameMatching(ProjectItem projectItem, string itemName = null)
        {
            var projectRelativePath = VsxHelper.GetProjectRelativePath(projectItem);

            if (itemName != null)
            {
                projectRelativePath = Path.Combine(Path.GetDirectoryName(projectRelativePath) ?? "", itemName);
            }

            return(string.Equals(fileName, projectRelativePath, StringComparison.InvariantCultureIgnoreCase));
        }
        private void BuildEventsOnOnBuildDone(vsBuildScope scope, vsBuildAction action)
        {
            this.visualStudioTracer.Trace("Build Done.", "VsProjectFileTracker");
            ProjectItem item          = VsxHelper.FindProjectItemByProjectRelativePath(project, fileName);
            var         newChangeDate = GetLastChangeDate(item);

            if (newChangeDate != LastChangeDate)
            {
                OnFileChanged(item);
            }
        }
        protected override bool IsFileNameMatching(ProjectItem projectItem, string itemName = null)
        {
            var projectRelativePath = VsxHelper.GetProjectRelativePath(projectItem);

            if (itemName != null)
            {
                projectRelativePath = Path.Combine(Path.GetDirectoryName(projectRelativePath) ?? "", itemName);
            }

            return(fileNameRe.Match(projectRelativePath).Success);
        }
 protected override void OnFileBecomesIrrelevant(ProjectItem item, string oldName)
 {
     if (followTrackingAfterRename)
     {
         fileName = VsxHelper.GetProjectRelativePath(item);
         OnFileRenamed(item, fileName);
     }
     else
     {
         OnFileOutOfScope(item, GetProjectRelativePathWithFileName(item, oldName));
     }
 }
        private void FileChangedOnDisk(string filePath)
        {
            var item = VsxHelper.FindProjectItemByFilePath(project, filePath);

            if (item == null || !IsItemRelevant(item))
            {
                return;
            }

            tracer.Trace("File change on disk handling queued: {0}", this, filePath);
            QueueHandlingFileOnDiskChange(filePath);
        }
        private void HandleFilesChangedOnDisk(object _)
        {
            if (filesChangedOnDisk.Count == 0)
            {
                return;
            }
            var filesChanged = filesChangedOnDisk;

            filesChangedOnDisk = new HashSet <string>();

            foreach (var filePath in filesChanged)
            {
                try
                {
                    var item = VsxHelper.FindProjectItemByFilePath(project, filePath);
                    if (item == null)
                    {
                        return;
                    }

                    // if the file is open, we have to wait until VS reloads the file content, because
                    // until it is not reloaded, the file code model might be out of sync with the new content.
                    if (item.IsOpen[Constants.vsViewKindAny])
                    {
                        string contentOnDisk = VsxHelper.GetFileContent(item, loadLastSaved: true);
                        string contentInVS   = VsxHelper.GetFileContent(item, loadLastSaved: false);

                        if (!contentOnDisk.Equals(contentInVS))
                        {
                            tracer.Trace("File is open and not in sync, reschedule update: {0}", this, filePath);
                            QueueHandlingFileOnDiskChange(filePath);
                            continue;
                        }
                    }

                    tracer.Trace("File changed outside of Visual Studio: {0}", this, filePath);
                    if (IsItemRelevant(item))
                    {
                        OnFileChanged(item);
                    }
                }
                catch (Exception ex)
                {
                    tracer.Trace("Error during file change handling: {0}", this, ex);
                }
            }
        }
        private void DocumentEventsOnDocumentSaved(Document document)
        {
            ProjectItem item = document.ProjectItem;

            if (item == null || !IsItemRelevant(item))
            {
                return;
            }

            tracer.Trace("Document Saved: {0}", this, VsxHelper.GetFileName(document.ProjectItem));

            // if the file was saved throgh VS, we remove from the processing of "outside of vs" change handling
            filesChangedOnDisk.Remove(VsxHelper.GetFileName(item));

            if (IsItemRelevant(item))
            {
                OnFileChanged(item);
            }
        }
 public ProjectItem GetProjectItem()
 {
     return(VsxHelper.FindProjectItemByProjectRelativePath(project, fileName));
 }
Beispiel #15
0
 private void SetLastChangeDate(ProjectItem projectItem)
 {
     LastChangeDate = VsxHelper.GetLastChangeDate(projectItem);
 }
        protected void StartListeningToFile(ProjectItem item)
        {
            var file = VsxHelper.GetFileName(item);

            dteWithEvents.FileChangeEventsListener.StartListeningToFile(file);
        }
Beispiel #17
0
        private void SubscribeToDteEvents(DteWithEvents dteWithEvents)
        {
            dteWithEvents.ProjectItemsEvents.ItemAdded +=
                item =>
            {
                visualStudioTracer.Trace("Item Added: " + item.Name, "VsProjectFileTracker");
                if (IsItemRelevant(item))
                {
                    OnFileChanged(item);
                }
            };

            dteWithEvents.ProjectItemsEvents.ItemRemoved +=
                item =>
            {
                visualStudioTracer.Trace("Item Removed: " + item.Name, "VsProjectFileTracker");
                if (IsItemRelevant(item))
                {
                    OnFileChanged(null);
                }
            };

            dteWithEvents.ProjectItemsEvents.ItemRenamed +=
                (item, oldName) =>
            {
                visualStudioTracer.Trace("Item Renamed to: " + item.Name + " from " + oldName, "VsProjectFileTracker");
                if (IsItemRelevant(item))
                {
                    OnFileChanged(item);
                }
                else if (IsItemRelevant(item, oldName))
                {
                    if (followTrackingAfterRename)
                    {
                        fileName = VsxHelper.GetProjectRelativePath(item);
                        OnFileChanged(item);
                    }
                    else
                    {
                        OnFileChanged(null);
                    }
                }
            };

            dteWithEvents.DocumentEvents.DocumentSaved +=
                document =>
            {
                visualStudioTracer.Trace("Document Saved: " + document, "VsProjectFileTracker");
                ProjectItem item = document.ProjectItem;
                if (IsItemRelevant(item))
                {
                    OnFileChanged(item);
                }
            };

            dteWithEvents.BuildEvents.OnBuildDone +=
                (scope, action) =>
            {
                this.visualStudioTracer.Trace("Build Done.", "VsProjectFileTracker");
                ProjectItem item          = VsxHelper.FindProjectItemByProjectRelativePath(project, fileName);
                var         newChangeDate = GetLastChangeDate(item);
                if (newChangeDate != LastChangeDate)
                {
                    OnFileChanged(item);
                }
            };
        }
 public VsProjectFileTracker(ProjectItem projectItem, DteWithEvents dteWithEvents, IVisualStudioTracer visualStudioTracer, bool followTrackingAfterRename = false) :
     this(projectItem.ContainingProject, VsxHelper.GetProjectRelativePath(projectItem), dteWithEvents, visualStudioTracer, followTrackingAfterRename)
 {
 }