internal EFArtifact GetNewOrExistingArtifact(Uri artifactUri, XmlModelProvider modelProvider) { Debug.Assert(artifactUri != null, "artifactUri must not be null."); Debug.Assert(modelProvider != null, "modelProvider must not be null."); return _modelManager.GetNewOrExistingArtifact(artifactUri, modelProvider); }
private static DiagramArtifact GetDiagramArtifactIfAvailable( ModelManager modelManager, Uri modelUri, XmlModelProvider xmlModelProvider) { var diagramFileName = modelUri.OriginalString + EntityDesignArtifact.ExtensionDiagram; return File.Exists(diagramFileName) ? new VSDiagramArtifact(modelManager, new Uri(diagramFileName), xmlModelProvider) : null; }
/// <summary> /// Constructs an EFArtifact for the passed in URI. /// Note: this class will call Dispose() on the provided (or created) XmlModelProvider when it Dispose(true) is called /// </summary> /// <param name="modelManager">A reference of ModelManager</param> /// <param name="uri">The URI to the EDMX file that this artifact will load</param> /// <param name="xmlModelProvider">If you pass null, then you must derive from this class and implement CreateModelProvider().</param> internal EFArtifact(ModelManager modelManager, Uri uri, XmlModelProvider xmlModelProvider) : base(null, null) { Debug.Assert(modelManager != null, "You need to pass in a valid ModelManager reference"); Debug.Assert(uri != null, "You need to pass in a valid URI"); Debug.Assert(xmlModelProvider != null, "xmlModelProvider != null"); _modelManager = modelManager; _uri = uri; _xmlModelProvider = xmlModelProvider; }
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; }
internal XNodeReaderLineNumberService(XmlModelProvider xmlModelProvider, XmlReader xmlReader, Uri uri) : base(xmlModelProvider) { Debug.Assert(xmlReader != null, "xmlReader != null"); Debug.Assert(uri != null, "uri != null"); Debug.Assert( xmlReader.GetType().Name == "XNodeReader", "Unexpected type for XmlReader. Expected reader to be System.Xml.Linq.XNodeReader"); Debug.Assert(_sourceFieldInfo != null, "_sourceFieldInfo != null"); Debug.Assert(_parentFieldInfo != null, "_parentFieldInfo != null"); _xmlReader = xmlReader; _uri = uri; }
/// <summary> /// Constructs an EntityDesignArtifact for the passed in URI /// </summary> /// <param name="modelManager">A reference of ModelManager</param> /// <param name="uri">The URI to the EDMX file that this artifact will load</param> /// <param name="xmlModelProvider">If you pass null, then you must derive from this class and implement CreateModelProvider().</param> internal EntityDesignArtifact(ModelManager modelManager, Uri uri, XmlModelProvider xmlModelProvider) : base(modelManager, uri, xmlModelProvider) { }
// <summary> // Creates an instance of an EFArtifact for use inside Visual Studio // </summary> // <param name="modelManager">A reference of ModelManager</param> // <param name="uri">The URI to the EDMX file that this artifact will load</param> // <param name="xmlModelProvider">We are ignoring this parameter, sending null to base class so that it will call CreateModelProvider()</param> internal VSArtifact(ModelManager modelManager, Uri uri, XmlModelProvider xmlModelProvider) : base(modelManager, uri, xmlModelProvider) { }
/// <summary> /// Load an artifact with a give URI. /// Depending on the artifactset mode, a new artifact set might be created for the newly created artifact(s). /// </summary> /// <param name="fileUri"></param> /// <param name="xmlModelProvider"></param> /// <returns></returns> private IList<EFArtifact> Load(Uri fileUri, XmlModelProvider xmlModelProvider) { lock (this) { List<EFArtifact> artifacts = null; EFArtifactSet artifactSet = null; try { artifacts = _artifactFactory.Create(this, fileUri, xmlModelProvider) as List<EFArtifact>; // Case where the artifact factory failed to instantiate artifact(s). if (artifacts == null && artifacts.Count <= 0) { Debug.Assert(false, "Could not create EFArtifact using current factory"); return null; } // Case where artifact factory failed to load the artifact with give URI. else if (artifacts.Where(a => a.Uri == fileUri).FirstOrDefault() == null) { Debug.Assert(false, "Artifact Factory does not created an artifact with URI:" + fileUri.LocalPath); return null; } EFArtifactSet efArtifactSet = null; // Initialize each artifact in the list. foreach (var artifact in artifacts) { Debug.Assert( _artifact2ArtifactSets.ContainsKey(artifact) == false, "Unexpected entry for artifact in artifact2ArtifactSet"); if (_artifact2ArtifactSets.ContainsKey(artifact) == false) { if (efArtifactSet == null) { efArtifactSet = _artifactSetFactory.CreateArtifactSet(artifact); } RegisterArtifact(artifact, efArtifactSet); } } artifactSet = GetArtifactSet(fileUri); ParseArtifactSet(artifactSet); NormalizeArtifactSet(artifactSet); ResolveArtifactSet(artifactSet); // Tell the artifacts that they are loaded and ready artifacts.ForEach((a) => { a.OnLoaded(); }); } catch (Exception) { // an exception occurred during loading, dispose each artifact in the list and rethrow. if (artifacts != null) { // call dispose & clear the artifact. We need both since the the entry may not be // in the _artifactsByUri table. artifacts.ForEach( artifact => { artifact.Dispose(); ClearArtifact(artifact.Uri); }); } throw; } return artifacts; } }
/// <summary> /// Get the EFArtifact for a particular Uri or load it if it hasn't been loaded. /// </summary> /// <param name="uri"></param> /// <param name="provider">This should alway be NULL except for our unit tests</param> /// <remarks>virtual for testing</remarks> internal virtual EFArtifact GetNewOrExistingArtifact(Uri uri, XmlModelProvider xmlModelProvider) { lock (this) { var result = GetArtifact(uri); if (result == null) { // Loading an artifact might cause related artifacts to be automatically loaded. var artifacts = Load(uri, xmlModelProvider); if (artifacts != null) { result = artifacts.Where(a => a.Uri == uri).FirstOrDefault(); } } return result; } }
internal XObjectLineNumberService(XmlModelProvider xmlModelProvider) { Debug.Assert(xmlModelProvider != null, "xmlModelProvider != null"); _xmlModelProvider = xmlModelProvider; }
internal MockEFArtifactHelper() : base(new EntityDesignModelManager(new EFArtifactFactory(), new EFArtifactSetFactory())) { _modelProvider = new VanillaXmlModelProvider(); }
/// <summary> /// Factory method for EntityDesignArtifact. /// Note that this method will not create DiagramArtifact. /// Please use VSArtifactFactory instead if DiagramArtifact needs to be created and loaded. /// </summary> public IList<EFArtifact> Create(ModelManager modelManager, Uri uri, XmlModelProvider xmlModelProvider) { return new List<EFArtifact> { new EntityDesignArtifact(modelManager, uri, xmlModelProvider) }; }