/// <summary> /// Asks every EFElement in the given EFArtifactSet to resolve references to other EFElements in the EFArtifactSet, /// i.e., a ScalarProperty will link up to its entity and storage properties. /// </summary> private void ResolveArtifactSet(EFArtifactSet artifactSet) { lock (this) { var visitor = new ResolvingVisitor(artifactSet); var lastMissedCount = visitor.MissedCount; while (visitor.MissedCount != 0) { visitor.ResetMissedCount(); foreach (var artifact in artifactSet.Artifacts) { visitor.Traverse(artifact); } // if we can't resolve any more then we are done if (lastMissedCount == visitor.MissedCount) { break; } lastMissedCount = visitor.MissedCount; } } }
/// <summary> /// Asks every EFElement in the given EFArtifactSet to create its normalized name and load that into /// the global symbol table. /// </summary> private void NormalizeArtifactSet(EFArtifactSet artifactSet) { lock (this) { var visitor = new NormalizingVisitor(); var lastMissedCount = -1; while (visitor.MissedCount != 0) { visitor.ResetMissedCount(); foreach (var artifact in artifactSet.Artifacts) { visitor.Traverse(artifact); } // every item should be able to normalize if (lastMissedCount == visitor.MissedCount) { throw new InvalidDataException("Subsequent passes didn't normalize any new items."); } lastMissedCount = visitor.MissedCount; } } }
internal static EntityDesignArtifact GetEntityDesignArtifact(this EFArtifactSet artifactSet) { // For now, we only expect only 1 instance of EntityDesignArtifact exists in the ArtifactSet (with the exception of our unit-test). // We need to change this once we support multiple entity-design-artifact per set. Debug.Assert( artifactSet.Artifacts.OfType<EntityDesignArtifact>().Count() == 1, "Expect to have 1 instance of EntityDesignArtifactSet in the artifactSet's Artifacts collection. Found: " + artifactSet.Artifacts.OfType<EntityDesignArtifact>().Count()); return artifactSet.Artifacts.OfType<EntityDesignArtifact>().FirstOrDefault(); }
internal static IEnumerable<ConceptualEntityType> ConceptualEntityTypes(this EFArtifactSet thisArtifactSet) { var derivedArtifactSet = thisArtifactSet as EntityDesignArtifactSet; Debug.Assert( derivedArtifactSet != null, "Every EFArtifactSet must be an EntityDesignArtifactSet to be used with the EFExtensions extension methods."); if (derivedArtifactSet != null) { return derivedArtifactSet.ConceptualEntityTypes; } return null; }
protected static Binding <T> CreateBindingInstance <T>( EFArtifactSet artifactSet, Symbol normalizedName, ItemBinding parentItemBinding) where T : EFNormalizableItem { var status = BindingStatus.None; T target = null; var items = artifactSet.GetSymbolList(normalizedName); if (items.Count == 0) { // TODO: Enable this assert once we can suppress it during our InvalidDocumentTests. This will help in providing guidance for BindingStatus.Unknown issues. //Debug.Fail("Attempted to CreateBindingInstance for '" + parentItemBinding.ToPrettyString() + "' given the symbol: '" + // normalizedName.ToDebugString() + "' but this symbol was not found in the ArtifactSet. This can happen if the given symbol " + // " is composed of a name that is not constructed correctly. Check the custom NameNormalizer code for this ItemBinding."); status = BindingStatus.Unknown; } else { // Loop through items collection to find an element with the same type foreach (var element in items) { target = element as T; if (null != target) { break; } } // Ideal case: where there is only 1 instance with the same name if (null != target && items.Count == 1) { status = BindingStatus.Known; } else if (null != target && items.Count > 1) { status = BindingStatus.Duplicate; } else // target is null { // TODO: Enable this assert once we can suppress it during our InvalidDocumentTests. This will help in providing guidance for BindingStatus.Unknown issues. //Debug.Fail("Attempted to CreateBindingInstance for '" + parentItemBinding.ToPrettyString() + "' given the symbol: '" + // normalizedName.ToDebugString() + "' but none of the symbols found in the ArtifactSet match the type " + typeof(T).ToString()); status = BindingStatus.Unknown; } } return(new Binding <T>(parentItemBinding, status, target)); }
/// <summary> /// Parses all of the loaded Entity and Mapping models in the given EFArtifactSet, creating EFElements for /// every node in the XLinq tree. /// </summary> private void ParseArtifactSet(EFArtifactSet artifactSet) { lock (this) { foreach (var a in artifactSet.Artifacts) { if (a.State == EFElementState.None) { HashSet <XName> s = null; #if DEBUG s = a.UnprocessedElements; s.Clear(); #endif a.Parse(s); } } } }
/// <summary> /// This method will do the following. /// - Add EFArtifact reference to the EFArtifactSet. /// - Update artifactsByUri and artifact2ArtifactSet dictionaries. /// - Initialize the EFArtifact. /// </summary> /// <param name="efArtifact"></param> /// <param name="efArtifactSet"></param> internal void RegisterArtifact(EFArtifact efArtifact, EFArtifactSet efArtifactSet) { Debug.Assert( _artifactsByUri.ContainsKey(efArtifact.Uri) == false && _artifact2ArtifactSets.ContainsKey(efArtifact) == false, "This artifact has been registered in model manager."); if (_artifactsByUri.ContainsKey(efArtifact.Uri) == false && _artifact2ArtifactSets.ContainsKey(efArtifact) == false) { if (efArtifactSet.Artifacts.Contains(efArtifact) == false) { efArtifactSet.Add(efArtifact); } _artifactsByUri[efArtifact.Uri] = efArtifact; var artifactSetList = new List <EFArtifactSet>(1); artifactSetList.Add(efArtifactSet); _artifact2ArtifactSets[efArtifact] = artifactSetList; efArtifact.Init(); } }
internal override void Resolve(EFArtifactSet artifactSet) { State = EFElementState.Resolved; }
/// <summary> /// This method will do the following. /// - Add EFArtifact reference to the EFArtifactSet. /// - Update artifactsByUri and artifact2ArtifactSet dictionaries. /// - Initialize the EFArtifact. /// </summary> /// <param name="efArtifact"></param> /// <param name="efArtifactSet"></param> internal void RegisterArtifact(EFArtifact efArtifact, EFArtifactSet efArtifactSet) { Debug.Assert( _artifactsByUri.ContainsKey(efArtifact.Uri) == false && _artifact2ArtifactSets.ContainsKey(efArtifact) == false, "This artifact has been registered in model manager."); if (_artifactsByUri.ContainsKey(efArtifact.Uri) == false && _artifact2ArtifactSets.ContainsKey(efArtifact) == false) { if (efArtifactSet.Artifacts.Contains(efArtifact) == false) { efArtifactSet.Add(efArtifact); } _artifactsByUri[efArtifact.Uri] = efArtifact; var artifactSetList = new List<EFArtifactSet>(1); artifactSetList.Add(efArtifactSet); _artifact2ArtifactSets[efArtifact] = artifactSetList; efArtifact.Init(); } }
/// <summary> /// Parses all of the loaded Entity and Mapping models in the given EFArtifactSet, creating EFElements for /// every node in the XLinq tree. /// </summary> private void ParseArtifactSet(EFArtifactSet artifactSet) { lock (this) { foreach (var a in artifactSet.Artifacts) { if (a.State == EFElementState.None) { HashSet<XName> s = null; #if DEBUG s = a.UnprocessedElements; s.Clear(); #endif a.Parse(s); } } } }
protected virtual void DoResolve(EFArtifactSet artifactSet) { State = EFElementState.Resolved; }
/// <summary> /// References to EFNameableItems will be normalized and an attempt is made to bind these references /// to any found items (that is, the normalized reference is found in the symbol table). /// </summary> internal override void Resolve(EFArtifactSet artifactSet) { PreResolve(); DoResolve(artifactSet); PostResolve(); }
internal abstract void Resolve(EFArtifactSet artifactSet);
/// <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); } }