internal static ErrorTask CreateErrorTask( string document, string errorMessage, TextSpan textSpan, TaskErrorCategory taskErrorCategory, IVsHierarchy hierarchy, uint itemID, MARKERTYPE markerType) { ErrorTask errorTask = null; IOleServiceProvider oleSp = null; hierarchy.GetSite(out oleSp); IServiceProvider sp = new ServiceProvider(oleSp); // see if Document is open IVsTextLines buffer = null; var docData = VSHelpers.GetDocData(sp, document); if (docData != null) { buffer = VSHelpers.GetVsTextLinesFromDocData(docData); } if (buffer != null) { errorTask = new EFModelDocumentTask(sp, buffer, markerType, textSpan, document, itemID, errorMessage, hierarchy); errorTask.ErrorCategory = taskErrorCategory; } else { errorTask = new EFModelErrorTask( document, errorMessage, textSpan.iStartLine, textSpan.iEndLine, taskErrorCategory, hierarchy, itemID); } return(errorTask); }
private static EFArtifact GetArtifactForValidation(Uri uri, IVsHierarchy hierarchy, ModelManager modelManager) { IServiceProvider oleServiceProvider = null; var modelListener = PackageManager.Package.ModelChangeEventListener; hierarchy.GetSite(out oleServiceProvider); System.IServiceProvider sp = new ServiceProvider(oleServiceProvider); var escherDocData = VSHelpers.GetDocData(sp, uri.LocalPath) as IEntityDesignDocData; EFArtifact artifact = null; // // If we opened the document with Escher, then use the XmlEditor's xlinq tree // If we opened the document with the xml editor, but not escher, then // we don't want to use the XmlEditor's xlinq tree, because then we would be receiving events when // the document changes, and we currently don't support that. // if (escherDocData != null) { artifact = PackageManager.Package.ModelManager.GetNewOrExistingArtifact( uri, new VSXmlModelProvider(PackageManager.Package, PackageManager.Package)); if (modelListener != null) { modelListener.OnBeforeValidateModel(VSHelpers.GetProject(hierarchy), artifact, true); } } else { if (Path.GetExtension(uri.LocalPath).Equals(EntityDesignArtifact.ExtensionEdmx, StringComparison.OrdinalIgnoreCase)) { // no doc data exists for this document, so load it into a temp model manager that can be disposed of when we're done. // Using the LoaderBasedXmlModelProvider will let us catch XML scanner and parser errors (the xml editor will try to // recover from these, and we won't know that the problem occurred. artifact = modelManager.GetNewOrExistingArtifact(uri, new StandaloneXmlModelProvider(PackageManager.Package)); if (modelListener != null) { modelListener.OnBeforeValidateModel(VSHelpers.GetProject(hierarchy), artifact, true); } } } return(artifact); }
internal static void NavigateTo(Object sender, EventArgs arguments) { Debug.Assert(_dslDesignerOnNavigate != null, "DSL navigation delegate is null!"); var task = sender as ErrorTask; if (task == null) { Debug.Fail("unable to cast sender to Task instance"); return; } var efTask = task as IXmlModelErrorTask; if (efTask == null) { Debug.Fail("Unable to cast errorTask to IEFErrorTask"); return; } if (String.IsNullOrEmpty(task.Document)) { return; } var serviceProvider = efTask.ServiceProvider; var docDataObject = VSHelpers.GetDocData(serviceProvider, task.Document); if (docDataObject == null) { // document wasn't opened var uri = Utils.FileName2Uri(task.Document); if (Path.GetExtension(uri.LocalPath) .Equals(EntityDesignArtifact.ExtensionEdmx, StringComparison.OrdinalIgnoreCase)) { // load a temp model to determine if the document is designer safe (only for EDMX, don't do this for converter docs) var isArtifactDesignerSafe = IsUnloadedDocumentDesignerSafe(uri); if (isArtifactDesignerSafe) { // this will open the document in escher EscherDesignerNavigate(serviceProvider, uri, task); } else { // if the document cannot be displayed in the designer, so open it in the XML Editor and navigate to the error var logicalView = VSConstants.LOGVIEWID_Primary; VsShellUtilities.OpenDocumentWithSpecificEditor( serviceProvider, uri.LocalPath, CommonPackageConstants.xmlEditorGuid, logicalView); docDataObject = VSHelpers.GetDocData(serviceProvider, task.Document); Debug.Assert( docDataObject != null, "attempt to open EDMX document in XML Editor - docDataObject should not be null"); VSHelpers.TextBufferNavigateTo( serviceProvider, docDataObject, logicalView, task.Line, task.Column); } } else { // document is not EDMX, so navigate to the document in the docdata's primary editor VsShellUtilities.OpenDocument(serviceProvider, task.Document); docDataObject = VSHelpers.GetDocData(serviceProvider, task.Document); Debug.Assert( docDataObject != null, "attempt to open non-EDMX document with primary Editor - docDataObject should not be null"); VSHelpers.TextBufferNavigateTo( serviceProvider, docDataObject, VSConstants.LOGVIEWID_Primary, task.Line, task.Column); } } else if (docDataObject is IEntityDesignDocData) { // attempt to get the artifact. This will return non-null if the document is open in either XML Editor or the designer var uri = Utils.FileName2Uri(task.Document); var artifact = PackageManager.Package.ModelManager.GetArtifact(uri); if (artifact == null) { Debug.Fail("didn't find artifact for document opened in Escher"); return; } if (artifact.IsDesignerSafe) { // navigate to the correct place in the Escher designer EscherDesignerNavigate(serviceProvider, uri, task); } else { // if the document cannot be displayed in the designer, so open it in the XML Editor and navigate to the error var logicalView = VSConstants.LOGVIEWID_Primary; VsShellUtilities.OpenDocumentWithSpecificEditor( serviceProvider, uri.LocalPath, CommonPackageConstants.xmlEditorGuid, logicalView); docDataObject = VSHelpers.GetDocData(serviceProvider, task.Document); Debug.Assert( docDataObject != null, "EDMX document already open - attempt to open in XML Editor resulted in null docDataObject"); VSHelpers.TextBufferNavigateTo(serviceProvider, docDataObject, logicalView, task.Line, task.Column); } } else { // document is opened, but not in Escher, so navigate to the document in the text editor VSHelpers.TextBufferNavigateTo( serviceProvider, docDataObject, VSConstants.LOGVIEWID_Primary, task.Line, task.Column); } }
public object GetDocData(IServiceProvider site, string documentPath) { return(VSHelpers.GetDocData(site, documentPath)); }