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

            if (itemName != null)
            {
                projectRelativePath = Path.Combine(Path.GetDirectoryName(projectRelativePath) ?? "", itemName);
            }
            return(projectRelativePath);
        }
Ejemplo n.º 3
0
 protected override void SetupListeningToFiles()
 {
     foreach (var projectItem in VsxHelper.GetAllPhysicalFileProjectItem(project))
     {
         if (IsItemRelevant(projectItem))
         {
             StartListeningToFile(projectItem);
         }
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
        int IVsSolutionEvents.OnQueryUnloadProject(IVsHierarchy pRealHierarchy, ref int pfCancel)
        {
            var project = VsxHelper.GetProject(pRealHierarchy);

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

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

            return(File.GetLastWriteTime(filePath));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 protected override void OnFileBecomesIrrelevant(ProjectItem item, string oldName)
 {
     if (followTrackingAfterRename)
     {
         fileName = VsxHelper.GetProjectRelativePath(item);
         OnFileRenamed(item, fileName);
     }
     else
     {
         OnFileOutOfScope(item, GetProjectRelativePathWithFileName(item, oldName));
     }
 }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
                }
            }
        }
Ejemplo n.º 13
0
        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);
            }
        }
Ejemplo n.º 14
0
 public ProjectItem GetProjectItem()
 {
     return(VsxHelper.FindProjectItemByProjectRelativePath(project, fileName));
 }
Ejemplo n.º 15
0
 private void SetLastChangeDate(ProjectItem projectItem)
 {
     LastChangeDate = VsxHelper.GetLastChangeDate(projectItem);
 }
Ejemplo n.º 16
0
        protected void StartListeningToFile(ProjectItem item)
        {
            var file = VsxHelper.GetFileName(item);

            dteWithEvents.FileChangeEventsListener.StartListeningToFile(file);
        }
Ejemplo n.º 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);
                }
            };
        }
Ejemplo n.º 18
0
 public VsProjectFileTracker(ProjectItem projectItem, DteWithEvents dteWithEvents, IVisualStudioTracer visualStudioTracer, bool followTrackingAfterRename = false) :
     this(projectItem.ContainingProject, VsxHelper.GetProjectRelativePath(projectItem), dteWithEvents, visualStudioTracer, followTrackingAfterRename)
 {
 }