Ejemplo n.º 1
0
 private void ProjectItemsEventsOnItemRemoved(ProjectItem item)
 {
     tracer.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);
        }
 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 tracer, bool followTrackingAfterRename = false) :
            base(project, dteWithEvents, tracer)
        {
            this.followTrackingAfterRename = followTrackingAfterRename;
            this.fileName = fileName;

            SetLastChangeDate(VsxHelper.FindProjectItemByProjectRelativePath(project, fileName));

            SubscribeToDteEvents();
        }
        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 void BuildEventsOnOnBuildDone(vsBuildScope scope, vsBuildAction action)
        {
            this.tracer.Trace("Build Done.", "VsProjectFileTracker");
            ProjectItem item          = VsxHelper.FindProjectItemByProjectRelativePath(project, fileName);
            var         newChangeDate = VsxHelper.GetLastChangeDate(item);

            if (newChangeDate != LastChangeDate)
            {
                OnFileChanged(item);
            }
        }
Ejemplo n.º 7
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.º 8
0
 protected override void OnFileBecomesIrrelevant(ProjectItem item, string oldName)
 {
     if (followTrackingAfterRename)
     {
         fileName = VsxHelper.GetProjectRelativePath(item);
         OnFileRenamed(item, fileName);
     }
     else
     {
         OnFileOutOfScope(item, GetProjectRelativePathWithFileName(item, oldName));
     }
 }
        protected override bool IsFileNameMatching(ProjectItem projectItem, string itemName = null)
        {
            var projectRelativePath = VsxHelper.GetProjectRelativePath(projectItem);

            if (projectRelativePath == null)
            {
                return(false);
            }

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

            return(fileNameRe.Match(projectRelativePath).Success);
        }
Ejemplo n.º 10
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[EnvDTE.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.º 11
0
        private void DocumentEventsOnDocumentSaved(Document document)
        {
            ProjectItem item = VsxHelper.TryGetProjectItem(document);

            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.º 12
0
        protected void StartListeningToFile(ProjectItem item)
        {
            var file = VsxHelper.GetFileName(item);

            dteWithEvents.FileChangeEventsListener.StartListeningToFile(file);
        }
Ejemplo n.º 13
0
 private void SetLastChangeDate(ProjectItem projectItem)
 {
     LastChangeDate = VsxHelper.GetLastChangeDate(projectItem);
 }
Ejemplo n.º 14
0
 public VsProjectFileTracker(ProjectItem projectItem, DteWithEvents dteWithEvents, IVisualStudioTracer visualStudioTracer, bool followTrackingAfterRename = false) :
     this(projectItem.ContainingProject, VsxHelper.GetProjectRelativePath(projectItem), dteWithEvents, visualStudioTracer, followTrackingAfterRename)
 {
 }
Ejemplo n.º 15
0
 public ProjectItem GetProjectItem()
 {
     return(VsxHelper.FindProjectItemByProjectRelativePath(project, fileName));
 }