/// <summary> /// Add a symbol to the global symbol table that maps to the passed in item. /// </summary> /// <param name="symbol"></param> /// <param name="item"></param> internal void AddSymbol(Symbol symbol, EFElement item) { if (!_symbolTable.ContainsKey(symbol)) { var list = new List<EFElement>(1); list.Add(item); _symbolTable.Add(symbol, list); } else { var current = LookupSymbol(symbol); if (current.Identity != item.Identity) { // duplicate symbol. Add the new item to the list _symbolTable[symbol].Add(item); // make it ready to display to the user var displayableSymbol = EFNormalizableItem.ConvertSymbolToExternal(symbol); // add an duplicate symbol error var msg = String.Format(CultureInfo.CurrentCulture, Resources.NORMALIZE_DUPLICATE_SYMBOL_DEFINED, displayableSymbol); var errorInfo = new ErrorInfo( ErrorInfo.Severity.ERROR, msg, item, ErrorCodes.NORMALIZE_DUPLICATE_SYMBOL_DEFINED, ErrorClass.ResolveError); AddError(errorInfo); } } }
/// <summary> /// Create a new NormalizedName with the passed in Symbol's parts as the prefix parts of the new symbol /// </summary> internal NormalizedName( Symbol originalReferenceAsSymbol, string aliasPart, string namespacePart, string remainingPart) { Debug.Assert( (null == aliasPart || null == namespacePart), "One or both of aliasPart or namespacePart should be null. Received aliasPart " + aliasPart + ", namespacePart " + namespacePart); _referenceAsSymbol = originalReferenceAsSymbol; _aliasPart = aliasPart; _namespacePart = namespacePart; _remainingPart = remainingPart; }
/// <summary> /// Create a new Symbol with the passed in Symbol's parts as the prefix parts of the new symbol /// </summary> /// <param name="symbol"></param> /// <param name="parts"></param> internal Symbol(Symbol symbol, params string[] parts) { _parts = new String[symbol._parts.Length + parts.Length]; var i = 0; for (; i < symbol._parts.Length; i++) { _parts[i] = symbol._parts[i]; } for (var j = 0; j < parts.Length; j++) { _parts[i + j] = parts[j]; } }
internal static NormalizedName DefaultNameNormalizerForEDM(EFElement parent, string refName) { var model = ModelHelper.GetBaseModelRoot(parent); NormalizedName normalizedName = null; if (model != null) { string potentialAliasOrNamespacePart = null; string nonAliasOrNamespacePart = null; SeparateRefNameIntoParts(refName, out potentialAliasOrNamespacePart, out nonAliasOrNamespacePart); // does the name start with the schema's namespace or alias? if (!string.IsNullOrEmpty(potentialAliasOrNamespacePart)) { refName = nonAliasOrNamespacePart; var symbol = new Symbol(model.NamespaceValue, refName); if (potentialAliasOrNamespacePart.Equals(model.NamespaceValue, StringComparison.CurrentCultureIgnoreCase)) { // it starts with the namespace normalizedName = new NormalizedName(symbol, null, model.NamespaceValue, refName); } else if (potentialAliasOrNamespacePart.Equals(model.AliasValue, StringComparison.CurrentCultureIgnoreCase)) { // it starts with the alias normalizedName = new NormalizedName(symbol, model.AliasValue, null, refName); } } else { // now, the name doesn't start with the alias or the namespace, so tack on the namespace var symbol = new Symbol(model.NamespaceValue, refName); normalizedName = new NormalizedName(symbol, null, null, refName); } } else { var symbol = new Symbol(refName); normalizedName = new NormalizedName(symbol, null, null, refName); } return normalizedName; }
// return true if the given symbol is for a valid key on the principal end private bool IsValidPrincipalKey(Symbol key, HashSet<Property> principalKeys) { IEnumerable<EFElement> symbols = _association.Artifact.ArtifactSet.GetSymbolList(key); foreach (var el in symbols) { var p = el as Property; if (p != null) { if (principalKeys.Contains(p)) { return true; } } } return false; }
internal KeyListItem(Symbol key) { _key = key; }
internal MappingListItem(Symbol principalSymbol, Symbol dependentSymbol, bool isValidPrincipalKey) { _principalSymbol = principalSymbol; DependentProperty = dependentSymbol; IsValidPrincipalKey = isValidPrincipalKey; }
// given a symbol and an entity type, return the property that matches a key for that entity type private static Property GetKeyForType(Symbol symbol, EntityType entityType, HashSet<Property> keys) { IEnumerable<EFElement> elements = entityType.Artifact.ArtifactSet.GetSymbolList(symbol); foreach (var e in elements) { var p = e as Property; if (keys.Contains(p)) { return p; } } return null; }
internal static NormalizedName DefaultNameNormalizerForMSL(EFElement parent, string refName) { var model = MappingModel.GetMappingRoot(parent); string potentialAliasOrNamespacePart = null; string nonAliasOrNamespacePart = null; SeparateRefNameIntoParts(refName, out potentialAliasOrNamespacePart, out nonAliasOrNamespacePart); Symbol symbol = null; NormalizedName normalizedName = null; if (!string.IsNullOrEmpty(potentialAliasOrNamespacePart)) { // see if our type name starts with any of the defined aliases var startsWithAlias = false; foreach (var a in model.Aliases()) { if (potentialAliasOrNamespacePart.Equals(a.Key.Value, StringComparison.CurrentCultureIgnoreCase)) { if (a.State == EFElementState.Parsed) { // alias is only in a parsed state, skip for now and don't add an error // we'll end up looping around again later once its been resolved return new NormalizedName(new Symbol(refName), null, null, refName); } if (a.State != EFElementState.Resolved || a.Value.Status != BindingStatus.Known) { var msg = string.Format(CultureInfo.CurrentCulture, Resources.RESOLVE_UNRESOLVED_ALIAS, refName); var artifactSet = parent.Artifact.ModelManager.GetArtifactSet(parent.Artifact.Uri); var errorInfo = new ErrorInfo( ErrorInfo.Severity.ERROR, msg, parent, ErrorCodes.RESOLVE_UNRESOLVED_ALIAS, ErrorClass.ResolveError); artifactSet.AddError(errorInfo); return new NormalizedName(new Symbol(String.Empty), null, null, refName); } // in the symbol replace alias with the full namespace symbol = new Symbol(a.Value.Target.Namespace.Value, nonAliasOrNamespacePart); normalizedName = new NormalizedName(symbol, a.Key.Value, null, nonAliasOrNamespacePart); startsWithAlias = true; break; } } if (startsWithAlias == false && model.Artifact.ConceptualModel() != null && model.Artifact.StorageModel() != null) { var conceptualNamespace = model.Artifact.ConceptualModel().Namespace.Value; var storageNamespace = model.Artifact.StorageModel().Namespace.Value; var currentNamespace = string.Empty; var convertIt = false; var startsWithConceptualNamespace = false; var startsWithStorageNamespace = false; if (potentialAliasOrNamespacePart.Equals(conceptualNamespace, StringComparison.CurrentCultureIgnoreCase)) { startsWithConceptualNamespace = true; } if (potentialAliasOrNamespacePart.Equals(storageNamespace, StringComparison.CurrentCultureIgnoreCase)) { startsWithStorageNamespace = true; } if (startsWithConceptualNamespace && startsWithStorageNamespace) { // in this case, the two namespaces start with the same thing and we got a match // on both; for example if there is pubsModel & pubsModel.Store and we are checking // on a string 'pubsModel.Store.Customer'; whichever is longer is the real one if (conceptualNamespace.Length > storageNamespace.Length) { currentNamespace = conceptualNamespace; convertIt = true; } else { currentNamespace = storageNamespace; convertIt = true; } } else if (startsWithConceptualNamespace) { currentNamespace = conceptualNamespace; convertIt = true; } else if (startsWithStorageNamespace) { currentNamespace = storageNamespace; convertIt = true; } if (convertIt) { // convert to our normalized name format symbol = new Symbol(currentNamespace, nonAliasOrNamespacePart); normalizedName = new NormalizedName(symbol, null, currentNamespace, nonAliasOrNamespacePart); } } } if (symbol == null) { // either there was no Alias or Namespace part or it didn't // match any of the known Aliases or Namespaces symbol = new Symbol(refName); normalizedName = new NormalizedName(symbol, null, null, refName); } return normalizedName; }
/// <summary> /// Removes the passed in symbol. /// </summary> /// <param name="symbol"></param> /// <param name="item"></param> internal void RemoveSymbol(Symbol symbol, EFElement item) { if (_symbolTable.ContainsKey(symbol)) { var items = _symbolTable[symbol]; if (items.Count == 1) { _symbolTable.Remove(symbol); } else { items.Remove(item); if (items.Count == 1) { // remove any duplicate symbol errors on the last remaining item with this symbol var otherItem = items[0]; RemoveErrorsForEFObject(otherItem, ErrorClass.ResolveError, ErrorCodes.NORMALIZE_DUPLICATE_SYMBOL_DEFINED); } } // remove any existing duplicate symbol errors on this item RemoveErrorsForEFObject(item, ErrorClass.ResolveError, ErrorCodes.NORMALIZE_DUPLICATE_SYMBOL_DEFINED); } }
/// <summary> /// Returns the complete list of items associated with the passed in symbol. /// </summary> /// <param name="symbol"></param> /// <returns>The list of items with the symbol, the list may be empty</returns> internal IList<EFElement> GetSymbolList(Symbol symbol) { List<EFElement> symbolList; return _symbolTable.TryGetValue(symbol, out symbolList) ? symbolList : new List<EFElement>(); }
/// <summary> /// Looks up the symbol and returns the item (if any) /// </summary> /// <param name="symbol"></param> /// <returns>Returns null if the symbol isn't found</returns> internal EFElement LookupSymbol(Symbol symbol) { if (!_symbolTable.ContainsKey(symbol)) { return null; } // just return first entry in the list return _symbolTable[symbol][0]; }
/// <summary> /// This removes our separator and replaces it with the runtime's separator /// </summary> internal static string ConvertSymbolToExternal(Symbol symbol) { return symbol.ToDisplayString(); }
private Symbol _normalizedName; // = string.Empty; /// <summary> /// This returns the last "part" of the normalized name /// </summary> internal static string GetLocalNameFromNormalizedName(Symbol normalizedName) { var localName = normalizedName.GetLocalName(); Debug.Assert(string.IsNullOrEmpty(localName) == false); return localName; }