public void RegisterDocumentListener()
        {
            Log(nameof(RegisterDocumentListener), false, true);
            var documentTable = (IVsRunningDocumentTable)GetGlobalService(typeof(SVsRunningDocumentTable));

            if (documentTable == null)
            {
                Log($"Failed to get solution in {nameof(SVsRunningDocumentTable)} service in {nameof(RegisterDocumentListener)}");
                return;
            }
            var maybeSolution = dte?.Solution;

            if (maybeSolution == null)
            {
                Log($"Failed to get solution in {nameof(RegisterDocumentListener)}");
                return;
            }
            Log($"dte.Solution.FullName: \"{maybeSolution?.FullName}\"", false, true);

            // Create a new document repository for the solution
            var solutionDirectory = Path.GetDirectoryName(maybeSolution?.FullName);

            Debug.Assert(solutionDirectory != null, $"{nameof(solutionDirectory)} != null");
            var repositoryDirectory = Utils.GetRootRepositoryPath(solutionDirectory);

            Log(
                $"Creating {nameof(DocumentRepository)} "
                + $"with {nameof(solutionDirectory)}: \"{solutionDirectory}\" "
                + $"and {nameof(repositoryDirectory)}: \"{repositoryDirectory}\"", false);
            documentRepository = new DocumentRepository(solutionDirectory, repositoryDirectory);

            // Create and register a document listener that will handle save events
            documentListener = new LocalHistoryDocumentListener(documentTable, documentRepository);

            var adviseResult = documentTable.AdviseRunningDocTableEvents(documentListener, out rdtCookie);

            if (adviseResult != VSConstants.S_OK)
            {
                Log($"Failed to AdviseRunningDocTableEvents. Error code is: {adviseResult}");
            }
        }
Esempio n. 2
0
 public LocalHistoryDocumentListener(IVsRunningDocumentTable documentTable, DocumentRepository documentRepository)
 {
     this.documentTable      = documentTable;
     this.documentRepository = documentRepository;
 }