///------------------------------------------------------------------------------------------------------------- /// <summary> /// Constructor. Aquires edit lock on document. /// </summary> ///------------------------------------------------------------------------------------------------------------- public LockedDocData(IServiceProvider serviceProvider, string fileName) : base(serviceProvider, fileName) { _serviceProvider = serviceProvider; _rdt = new RunningDocumentTable(serviceProvider); // Locate and lock the document _rdt.FindDocument(fileName, out _cookie); _rdt.LockDocument(_VSRDTFLAGS.RDT_EditLock , _cookie); }
public static IVsHierarchy GetVsHierarchy(string filePath, IServiceProvider serviceProvider) { IVsHierarchy hier = null; var rdt = new RunningDocumentTable(serviceProvider); uint itemId = 0; uint docCookie = 0; rdt.FindDocument(filePath, out hier, out itemId, out docCookie); return hier; }
/// <summary> /// Get the ORMTestWindow structure for the given ORM file /// </summary> /// <param name="ormHooks">An ORMTestHooks instance</param> /// <param name="fullName">The full name of the file. Retrieve from a Document.FullName property. /// If fullName is null or empty then the path of the active document is used.</param> /// <returns>ORMTestWindow structure. May be empty.</returns> public static ORMTestWindow FindORMTestWindow(ORMTestHooks ormHooks, string fullName) { if (fullName == null || fullName.Length == 0) { fullName = ormHooks.DTE.ActiveDocument.FullName; } RunningDocumentTable docTable = new RunningDocumentTable(ormHooks.ServiceProvider); ORMDesignerDocData document = docTable.FindDocument(fullName) as ORMDesignerDocData; if (document != null) { ORMDesignerDocView docView = (ORMDesignerDocView)document.DocViews[0]; return(new ORMTestWindow(docView.CurrentDesigner.DiagramClientView, ormHooks)); } return(Empty); }
private async void GenerateDocumentAsync(DocumentViewModel documentViewModel) { try { CurrentDocumentInfo = null; IsLoading = true; string text = null; var rdt = new RunningDocumentTable(_services); var document = rdt.FindDocument(documentViewModel.FilePath); if (document != null) { text = GetTextFromRDT(document); } if (text == null) { var invisibleEditorMangager = (IVsInvisibleEditorManager)_services.GetService(typeof(SVsInvisibleEditorManager)); IVsInvisibleEditor editor; int hr = invisibleEditorMangager.RegisterInvisibleEditor( documentViewModel.FilePath, null, 0, null, out editor); Marshal.ThrowExceptionForHR(hr); text = GetTextFromInvisibleEditor(editor); } if (text != null) { var project = _workspace.CurrentSolution.GetProject(CurrentProject.Snapshot.Project.WorkspaceProject.Id); var generated = await _documentGenerator.GenerateDocumentAsync(_workspace, project, documentViewModel.FilePath, text); CurrentDocumentInfo = new DocumentInfoViewModel(generated); } } catch (Exception ex) { Console.WriteLine(ex); } IsLoading = false; }
public override object GetHostProject(ITextBuffer textBuffer) { if (textBuffer == null) { throw new ArgumentNullException(nameof(textBuffer)); } // If there's no document we can't find the FileName, or look for a matching hierarchy. if (!_documentFactory.TryGetTextDocument(textBuffer, out var textDocument)) { return(null); } _documentTable.FindDocument(textDocument.FilePath, out var hierarchy, out _, out _); // We don't currently try to look a Roslyn ProjectId at this point, we just want to know some // basic things. // See https://github.com/dotnet/roslyn/blob/4e3db2b7a0732d45a720e9ed00c00cd22ab67a14/src/VisualStudio/Core/SolutionExplorerShim/HierarchyItemToProjectIdMap.cs#L47 // for a more complete implementation. return(hierarchy); }
protected override void OnBeforeHandleXmlModelTransactionCompleted(object sender, XmlTransactionEventArgs args) { base.OnBeforeHandleXmlModelTransactionCompleted(sender, args); #if DEBUG var rDT = new RunningDocumentTable(PackageManager.Package); uint cookie = 0; rDT.FindDocument(Uri.LocalPath, out cookie); var info = rDT.GetDocumentInfo(cookie); Debug.Print( string.Format( CultureInfo.CurrentCulture, "There are now {0} Edit Locks, and {1} Read Locks.", info.EditLocks, info.ReadLocks)); #endif }
/// <summary> /// Get the ORMTestWindow structure for the given ORM file /// </summary> /// <param name="ormHooks">An ORMTestHooks instance</param> /// <param name="fullName">The full name of the file. Retrieve from a Document.FullName property. /// If fullName is null or empty then the path of the active document is used.</param> /// <returns>ORMTestWindow structure. May be empty.</returns> public static ORMTestWindow FindORMTestWindow(ORMTestHooks ormHooks, string fullName) { if (fullName == null || fullName.Length == 0) { fullName = ormHooks.DTE.ActiveDocument.FullName; } RunningDocumentTable docTable = new RunningDocumentTable(ormHooks.ServiceProvider); ORMDesignerDocData document = docTable.FindDocument(fullName) as ORMDesignerDocData; if (document != null) { ORMDesignerDocView docView = (ORMDesignerDocView)document.DocViews[0]; return new ORMTestWindow(docView.CurrentDesigner.DiagramClientView, ormHooks); } return Empty; }
internal void OnCloseFrame(FrameWrapper closingFrame) { if (_mapFrameToUri.ContainsKey(closingFrame)) { _mapFrameToUri.Remove(closingFrame); if (null != closingFrame.Uri) { var rdt = new RunningDocumentTable(_package); var doc = rdt.FindDocument(closingFrame.Uri.LocalPath); if (doc != null) { var isModified = false; using (var docData = new DocData(doc)) { isModified = docData.Modified; } if (isModified) { // document was modified but was closed without saving changes; // we need to refresh all sets that refer to the document // so that they revert to the document that is persisted in the file system // TODO: add this functinality //ModelManager.RefreshModelForLocation(closingFrame.Uri); } } } } }