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 void buttonSave_Click(object sender, EventArgs e) { if (dialogSaveModel.ShowDialog() == DialogResult.OK) { int filterIndex = dialogSaveModel.FilterIndex; try { switch (filterIndex) { // OPT model case 2: Model optModel = ModelsConverter.ConvertToOptimization(ModelStorage.Instance.Model); XmlModelProvider.Save(optModel, dialogSaveModel.FileName); break; // OPT.ID model case 1: default: XmlIdentificationModelProvider.Save(ModelStorage.Instance.Model, dialogSaveModel.FileName); break; } } catch (Exception ex) { MessageBoxHelper.ShowError(ex.Message); } dialogSaveModel.FileName = string.Empty; } }
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; }
/// <summary> /// This will be called in the CommandProcessor and can contain custom /// logic to short-circuit any model edits. This is useful for example, /// to query the VS SCC provider. /// </summary> internal virtual bool CanEditArtifact() { if (XmlModelProvider != null) { var xmlModel = XmlModelProvider.GetXmlModel(Uri); if (xmlModel != null) { return(xmlModel.CanEditXmlModel()); } } Debug.Fail("In trying to determine whether we CanEditArtifact(), we could not find the XML model attached to this EFArtifact"); return(false); }
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> /// 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); } }
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); }
// <summary> // Constructs a VSDiagramArtifact for the passed in URI // </summary> // <param name="modelManager">A reference of ModelManager</param> // <param name="uri">The Diagram File URI</param> // <param name="xmlModelProvider">If you pass null, then you must derive from this class and implement CreateModelProvider().</param> internal VSDiagramArtifact(ModelManager modelManager, Uri uri, XmlModelProvider xmlModelProvider) : base(modelManager, uri, xmlModelProvider) { }
/// <summary> /// Returns the XObject for the given line & column number. /// </summary> internal XObject FindXObjectForLineAndColumn(int lineNumber, int columnNumber) { var xmlModel = XmlModelProvider.GetXmlModel(Uri); return(xmlModel.GetXObject(lineNumber, columnNumber)); }
/// <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) { }
internal XObjectLineNumberService(XmlModelProvider xmlModelProvider) { Debug.Assert(xmlModelProvider != null, "xmlModelProvider != null"); _xmlModelProvider = xmlModelProvider; }
/// <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) }); }
internal MockEFArtifactHelper() : base(new EntityDesignModelManager(new EFArtifactFactory(), new EFArtifactSetFactory())) { _modelProvider = new VanillaXmlModelProvider(); }
/// <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 entry may not be // in the _artifactsByUri table. artifacts.ForEach( artifact => { artifact.Dispose(); ClearArtifact(artifact.Uri); }); } throw; } return(artifacts); } }