private void ProcessErrors(IList <EdmSchemaError> schemaErrors, Uri projectItemUri, EFArtifact artifact) { // since we will inevitably add *all* errors from the artifact set into the error list, we can easily // clear the entire error list here even though we just validate the CSDL. var errorList = ErrorListHelper.GetSingleDocErrorList(projectItemUri); if (errorList != null) { errorList.Clear(); } if (artifact == null) { Debug.Fail("Where is the artifact? We should have created it at least through the temporary model manager"); return; } // we have to remove both the RMV and SFG CSDL errors to prevent duplicates artifact.ArtifactSet.RemoveErrorsForArtifact(artifact, ErrorClass.Runtime_CSDL); // add all CSDL-based SFG errors to the artifact set if (schemaErrors.Count > 0) { foreach (var error in schemaErrors) { // construct an ErrorInfo with correct line/column number and add it to the artifact set. Note that the CodeGen EdmSchemaError line // refers to the line of the error inside the CSDL, so to get the line of the error in the edmx file we have to offset it by the line // number where the conceptual model begins. var edmxErrorLine = error.Line + artifact.ConceptualModel().GetLineNumber(); var efobject = artifact.FindEFObjectForLineAndColumn(edmxErrorLine, error.Column); var errorInfo = new ErrorInfo( GetErrorInfoSeverity(error), error.Message, efobject, error.ErrorCode, ErrorClass.Runtime_CSDL); artifact.ArtifactSet.AddError(errorInfo); } } // get all the ErrorInfos for this artifact and add it to the error list var artifactSet = artifact.ArtifactSet; Debug.Assert(artifactSet != null, "Where is the artifact set for this artifact?"); if (artifactSet != null) { var errors = artifactSet.GetArtifactOnlyErrors(artifact); if (errors.Count > 0) { // resolve the hierarchy and item id for adding to the error list var hierarchy = VSHelpers.GetVsHierarchy(ProjectItem.ContainingProject, Services.ServiceProvider); var itemId = VsUtils.GetProjectItemId(hierarchy, ProjectItem); Debug.Assert(hierarchy != null, "Why isn't there a hierarchy associated with this project item?"); Debug.Assert(itemId != VSConstants.VSITEMID_NIL, "There should be an item ID associated with this project item"); if (hierarchy != null && itemId != VSConstants.VSITEMID_NIL) { ErrorListHelper.AddErrorInfosToErrorList(errors, hierarchy, itemId); } } } }
// <summary> // This will do analysis to determine if a document should be opened // only in the XmlEditor. // </summary> internal override void DetermineIfArtifactIsDesignerSafe() { VsUtils.EnsureProvider(this); base.DetermineIfArtifactIsDesignerSafe(); // // TODO: we need to figure out how to deal with errors from the wizard. // when we clear the error list below, we lose errors that we put into the error // list when running the wizard. // // // Now update the VS error list with all of the errors we want to display, which are now in the EFArtifactSet. // var errorInfos = ArtifactSet.GetAllErrors(); if (errorInfos.Count > 0) { var currentProject = VSHelpers.GetProjectForDocument(Uri.LocalPath, PackageManager.Package); if (currentProject != null) { var hierarchy = VsUtils.GetVsHierarchy(currentProject, Services.ServiceProvider); if (hierarchy != null) { var fileFinder = new VSFileFinder(Uri.LocalPath); fileFinder.FindInProject(hierarchy); Debug.Assert(fileFinder.MatchingFiles.Count <= 1, "Unexpected count of matching files in project"); // if the EDMX file is not part of the project. if (fileFinder.MatchingFiles.Count == 0) { var docData = VSHelpers.GetDocData(PackageManager.Package, Uri.LocalPath) as IEntityDesignDocData; ErrorListHelper.AddErrorInfosToErrorList(errorInfos, docData.Hierarchy, docData.ItemId); } else { foreach (var vsFileInfo in fileFinder.MatchingFiles) { if (vsFileInfo.Hierarchy == VsUtils.GetVsHierarchy(currentProject, Services.ServiceProvider)) { var errorList = ErrorListHelper.GetSingleDocErrorList(vsFileInfo.Hierarchy, vsFileInfo.ItemId); if (errorList != null) { errorList.Clear(); ErrorListHelper.AddErrorInfosToErrorList(errorInfos, vsFileInfo.Hierarchy, vsFileInfo.ItemId); } else { Debug.Fail("errorList is null!"); } } } } } } } }