public IList<EFArtifact> Create(ModelManager modelManager, Uri uri, XmlModelProvider xmlModelProvider) { var artifact = new VSArtifact(modelManager, uri, xmlModelProvider); var artifacts = new List<EFArtifact> { artifact }; var diagramArtifact = GetDiagramArtifactIfAvailable(modelManager, uri, xmlModelProvider); if (diagramArtifact != null) { artifact.DiagramArtifact = diagramArtifact; artifacts.Add(diagramArtifact); } return artifacts; }
public void GetModelGenErrors_returns_errors_stored_in_ModelGenCache() { var modelGenCache = new ModelGenErrorCache(); var errors = new List<EdmSchemaError>(new[] { new EdmSchemaError("test", 42, EdmSchemaErrorSeverity.Error) }); modelGenCache.AddErrors(@"C:\temp.edmx", errors); var mockPackage = new Mock<IEdmPackage>(); mockPackage.Setup(p => p.ModelGenErrorCache).Returns(modelGenCache); PackageManager.Package = mockPackage.Object; var modelManager = new Mock<ModelManager>(null, null).Object; var modelProvider = new Mock<XmlModelProvider>().Object; using (var vsArtifact = new VSArtifact(modelManager, new Uri(@"C:\temp.edmx"), modelProvider)) { Assert.Same(errors, vsArtifact.GetModelGenErrors()); } }
public IList <EFArtifact> Create(ModelManager modelManager, Uri uri, XmlModelProvider xmlModelProvider) { var artifact = new VSArtifact(modelManager, uri, xmlModelProvider); var artifacts = new List <EFArtifact> { artifact }; var diagramArtifact = GetDiagramArtifactIfAvailable(modelManager, uri, xmlModelProvider); if (diagramArtifact != null) { artifact.DiagramArtifact = diagramArtifact; artifacts.Add(diagramArtifact); } return(artifacts); }
public void GetModelGenErrors_returns_errors_stored_in_ModelGenCache() { var modelGenCache = new ModelGenErrorCache(); var errors = new List <EdmSchemaError>(new[] { new EdmSchemaError("test", 42, EdmSchemaErrorSeverity.Error) }); modelGenCache.AddErrors(@"C:\temp.edmx", errors); var mockPackage = new Mock <IEdmPackage>(); mockPackage.Setup(p => p.ModelGenErrorCache).Returns(modelGenCache); PackageManager.Package = mockPackage.Object; var modelManager = new Mock <ModelManager>(null, null).Object; var modelProvider = new Mock <XmlModelProvider>().Object; using (var vsArtifact = new VSArtifact(modelManager, new Uri(@"C:\temp.edmx"), modelProvider)) { Assert.Same(errors, vsArtifact.GetModelGenErrors()); } }
internal static bool TryGetBufferViaExtensions( IServiceProvider serviceProvider, ProjectItem projectItem, string fileContents, Lazy <IModelConversionExtension, IEntityDesignerConversionData>[] converters, Lazy <IModelTransformExtension>[] serializers, out string documentViaExtensions, out List <ExtensionError> errors) { Debug.Assert(serviceProvider != null, "serviceProvider != null"); Debug.Assert(projectItem != null, "projectItem != null"); Debug.Assert(VsUtils.EntityFrameworkSupportedInProject(projectItem.ContainingProject, serviceProvider, false)); Debug.Assert(serializers != null && converters != null, "extensions must not be null"); Debug.Assert(serializers.Any() || converters.Any(), "at least one extension expected"); errors = new List <ExtensionError>(); documentViaExtensions = ""; ModelConversionContextImpl conversionContext = null; ModelTransformContextImpl transformContext = null; try { var targetSchemaVersion = EdmUtils.GetEntityFrameworkVersion(projectItem.ContainingProject, serviceProvider); Debug.Assert(targetSchemaVersion != null, "should not get here for a Misc project"); // get the extension of the file being loaded (might not be EDMX); this API will include the preceding "." var filePath = projectItem.get_FileNames(1); var fileExtension = Path.GetExtension(filePath); XDocument originalDocument = null; // see if we are loading an EDMX file or not, and if we have any converters if (!string.Equals( fileExtension, EntityDesignArtifact.ExtensionEdmx, StringComparison.OrdinalIgnoreCase)) { conversionContext = new ModelConversionContextImpl( projectItem.ContainingProject, projectItem, new FileInfo(filePath), targetSchemaVersion, fileContents); // we aren't loading an EDMX file, so call the extensions who can process this file extension // when this finishes, then output should be a valid EDMX document VSArtifact.DispatchToConversionExtensions(converters, fileExtension, conversionContext, true); // we are done with the non-EDMX extensions so CurrentDocument will be a valid EDMX document // create the serialization context for further extensions to act on transformContext = new ModelTransformContextImpl( projectItem, targetSchemaVersion, conversionContext.CurrentDocument); } else { // we are loading an EDMX file, we can parse file contents into an XDocument try { originalDocument = XDocument.Parse(fileContents, LoadOptions.PreserveWhitespace); transformContext = new ModelTransformContextImpl( projectItem, targetSchemaVersion, originalDocument); } catch (XmlException) { // If there's an error here, don't do anything. We will want to gracefully step out of the extension loading // since the designer itself won't load. } } if (transformContext != null && originalDocument != null) { // now dispatch to those that want to work on EDMX files VSArtifact.DispatchToSerializationExtensions(serializers, transformContext, true); // TODO: this does not seem to be correct if severity is Message or Warning if (transformContext.Errors.Count == 0) { // see if any extension changed things. Note that we need to compare the serialization of // the XDocuments together since the original buffer may have different whitespace after creating the XDocument. // TODO: Why not use XNode.DeepEquals()? string newBufferContents; using (var currentDocWriter = new Utf8StringWriter()) { transformContext.CurrentDocument.Save(currentDocWriter, SaveOptions.None); newBufferContents = currentDocWriter.ToString(); } string originalBufferContents; using (var originalDocWriter = new Utf8StringWriter()) { originalDocument.Save(originalDocWriter, SaveOptions.None); originalBufferContents = originalDocWriter.ToString(); } if (!string.Equals(originalBufferContents, newBufferContents, StringComparison.Ordinal)) { documentViaExtensions = newBufferContents; return(true); } } else { errors.AddRange(transformContext.Errors); return(false); } } } finally { var errorList = ErrorListHelper.GetExtensionErrorList(serviceProvider); errorList.Clear(); // log any errors if (conversionContext != null && conversionContext.Errors.Count > 0) { ErrorListHelper.LogExtensionErrors(conversionContext.Errors, projectItem); } if (transformContext != null && transformContext.Errors.Count > 0) { ErrorListHelper.LogExtensionErrors(transformContext.Errors, projectItem); } } return(false); }