private StructuralType GetStructuralTypeCore(String stName) { lock (_structuralTypes) { if (!TypeNameInfo.IsQualifiedTypeName(stName)) { String fullStName; if (_shortNameMap.TryGetValue(stName, out fullStName)) { stName = fullStName; } } var st = _structuralTypes[stName]; if (st == null) { var clrType = Configuration.Instance.GetClrType(stName); if (clrType == null) { return(null); } var stb = new StructuralTypeBuilder(this); st = stb.CreateStructuralType(clrType); _structuralTypes[stName] = st; } return(st); } }
/// <summary> /// Tries to get JTokens ref, id, and type from <paramref name="node"/>. Sets NodeRefId, NodeId, and ServerTypeNameInfo in the returned JsonNodeInfo object /// </summary> public JsonNodeInfo VisitNode(JObject node, MappingContext mappingContext, NodeContext nodeContext) { var result = new JsonNodeInfo(); JToken refToken; if (node.TryGetValue("$ref", out refToken)) { result.NodeRefId = refToken.Value <String>(); return(result); } JToken idToken; if (node.TryGetValue("$id", out idToken)) { result.NodeId = idToken.Value <String>(); } JToken typeToken; if (node.TryGetValue("$type", out typeToken)) { var clrTypeName = typeToken.Value <String>(); result.ServerTypeNameInfo = TypeNameInfo.FromClrTypeName(clrTypeName); } return(result); }
private string GetClientTypeNameFromShortName(string serverShortName) { var ns = GetNamespaceFor(serverShortName); var clientTypeName = new TypeNameInfo(serverShortName, ns).ToClient(MetadataStore).StructuralTypeName; return(clientTypeName); }
private void RegisterStructuralType(Type clrType) { lock (_clrTypeMap) { var stName = TypeNameInfo.FromClrType(clrType).StructuralTypeName; _clrTypeMap[stName] = clrType; } }
internal void UpdateFromJNode(JNode jNode) { var shortName = jNode.Get <String>("shortName"); var ns = jNode.Get <String>("namespace"); var name = TypeNameInfo.QualifyTypeName(shortName, ns); var et = MetadataStore.Instance.GetEntityType(name); Check(et.BaseEntityTypeName, jNode.Get <String>("baseTypeName"), "BaseEntityType"); // For now this doesn't need to match et.IsAbstract = jNode.Get <bool>("isAbstract"); et.AutoGeneratedKeyType = jNode.GetEnum <AutoGeneratedKeyType>("autoGeneratedKeyType"); var drn = jNode.Get <String>("defaultResourceName"); if (drn != null) { MetadataStore.Instance.SetResourceName(drn, et, true); } jNode.GetJNodeArray("dataProperties").ForEach(jn => { var dpName = jn.Get <String>("name"); var dp = et.GetDataProperty(dpName); dp.UpdateFromJNode(jn); }); jNode.GetJNodeArray("navigationProperties").ForEach(jn => { var npName = jn.Get <String>("name"); var np = et.GetNavigationProperty(npName); np.UpdateFromJNode(jn); }); et._validators = new ValidatorCollection(jNode.GetJNodeArray("validators")); // custom }
private string GetClientTypeNameFromShortName(string serverShortName) { var ns = GetNamespaceFor(serverShortName); var clientTypeName = new TypeNameInfo(serverShortName, ns).ToClient().Name; return(clientTypeName); }
/// <summary> /// Translates a client <see cref="TypeNameInfo"/> into a server TypeNameInfo. /// </summary> /// <param name="clientNameInfo"></param> /// <returns></returns> public virtual TypeNameInfo ClientTypeNameToServer(TypeNameInfo clientNameInfo) { String serverNs; if (_clientServerNamespaceMap.TryGetValue(clientNameInfo.Namespace, out serverNs)) { return new TypeNameInfo(clientNameInfo.ShortName, serverNs); } else { return clientNameInfo; } }
private Tuple <EntityKey, EntityKey> ToEntityKeys(KeyMapping keyMapping, MetadataStore metadataStore) { var serverTypeInfo = TypeNameInfo.FromClrTypeName(keyMapping.EntityTypeName); var clientEntityTypeName = serverTypeInfo.ToClient(metadataStore).StructuralTypeName; var et = metadataStore.GetEntityType(clientEntityTypeName); var oldKey = new EntityKey(et, keyMapping.TempValue); var newKey = new EntityKey(et, keyMapping.RealValue); return(Tuple.Create(oldKey, newKey)); }
internal String GetStructuralTypeNameFromJNode(JNode jNode, String key, bool isFromServer) { var stName = jNode.Get <String>(key); if (stName != null && isFromServer) { stName = TypeNameInfo.FromStructuralTypeName(stName).ToClient(this).StructuralTypeName; } return(stName); }
/// <summary> /// Translates a server <see cref="TypeNameInfo"/> into a client TypeNameInfo. /// </summary> /// <param name="serverNameInfo"></param> /// <returns></returns> public virtual TypeNameInfo ServerTypeNameToClient(TypeNameInfo serverNameInfo) { String clientNs; if (_serverClientNamespaceMap == null) { _serverClientNamespaceMap = _clientServerNamespaceMap.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); } if (_serverClientNamespaceMap.TryGetValue(serverNameInfo.Namespace, out clientNs)) { return new TypeNameInfo(serverNameInfo.ShortName, clientNs); } else { return serverNameInfo; } }
/// <summary> /// Translates a client <see cref="TypeNameInfo"/> into a server TypeNameInfo. /// </summary> /// <param name="clientNameInfo"></param> /// <returns></returns> public virtual TypeNameInfo ClientTypeNameToServer(TypeNameInfo clientNameInfo) { String serverNs; if (_clientTypeNamespaceMap.TryGetValue(clientNameInfo.Namespace, out serverNs)) { return(new TypeNameInfo(clientNameInfo.ShortName, serverNs)); } else { return(clientNameInfo); } }
/// <summary> /// Translates a server <see cref="TypeNameInfo"/> into a client TypeNameInfo. /// </summary> /// <param name="serverNameInfo"></param> /// <returns></returns> public virtual TypeNameInfo ServerTypeNameToClient(TypeNameInfo serverNameInfo) { String clientNs; if (_serverTypeNamespaceMap.TryGetValue(serverNameInfo.Namespace, out clientNs)) { return(new TypeNameInfo(serverNameInfo.ShortName, clientNs)); } else { return(serverNameInfo); } }
public void UpdateFromJNode(JNode jNode) { var shortName = jNode.Get <String>("shortName"); var ns = jNode.Get <String>("namespace"); Name = TypeNameInfo.QualifyTypeName(shortName, ns); // BaseTypeName = jnode.Get<String>("baseTypeName"); // IsAbstract = jnode.Get<bool>("isAbstract"); jNode.GetJNodeArray("dataProperties").ForEach(jn => { var dpName = jn.Get <String>("name"); var dp = this.GetDataProperty(dpName); dp.UpdateFromJNode(jn); }); // validators // custom }
internal String GetStructuralTypeNameFromJNode(JNode jNode, bool isFromServer) { var shortName = jNode.Get <String>("shortName"); var ns = jNode.Get <String>("namespace"); String stName; if (isFromServer) { stName = new TypeNameInfo(shortName, ns).ToClient(this).StructuralTypeName; } else { stName = TypeNameInfo.ToStructuralTypeName(shortName, ns); } return(stName); }
/// <summary> /// Translates a server <see cref="TypeNameInfo"/> into a client TypeNameInfo. /// </summary> /// <param name="serverNameInfo"></param> /// <returns></returns> public virtual TypeNameInfo ServerTypeNameToClient(TypeNameInfo serverNameInfo) { String clientNs; if (_serverClientNamespaceMap == null) { _serverClientNamespaceMap = _clientServerNamespaceMap.ToDictionary(kvp => kvp.Value, kvp => kvp.Key); } if (_serverClientNamespaceMap.TryGetValue(serverNameInfo.Namespace, out clientNs)) { return(new TypeNameInfo(serverNameInfo.ShortName, clientNs)); } else { return(serverNameInfo); } }
private void DeserializeFrom(JNode jNode, bool isFromServer) { MetadataVersion = jNode.Get <String>("metadataVersion"); // may be more than just a name var ncNode = jNode.GetJNode("namingConvention"); if (ncNode != null) { var nc = Configuration.Instance.FindOrCreateNamingConvention(ncNode); if (nc == null) { OnMetadataMismatch(null, null, MetadataMismatchTypes.MissingCLRNamingConvention, ncNode.ToString()); } else { // keep any preexisting ClientServerNamespaceMap info NamingConvention = nc.WithClientServerNamespaceMapping(this.NamingConvention.ClientServerNamespaceMap); } } // localQueryComparisonOptions jNode.GetJNodeArray("dataServices").Select(jn => new DataService(jn)).ForEach(ds => { if (GetDataService(ds.ServiceName) == null) { AddDataService(ds); } }); jNode.GetJNodeArray("structuralTypes") .ForEach(jn => UpdateStructuralTypeFromJNode(jn, isFromServer)); jNode.GetMap <String>("resourceEntityTypeMap").ForEach(kvp => { var stName = kvp.Value; if (isFromServer) { stName = TypeNameInfo.FromStructuralTypeName(stName).ToClient(this).StructuralTypeName; } // okIfNotFound because metadata may contain refs to types that were already excluded earlier in // UpdateStructuralTypeFromJNode var et = GetEntityType(stName, true); if (et != null) { SetResourceName(kvp.Key, et); } }); }
private void UpdateStructuralTypeFromJNode(JNode jNode) { var shortName = jNode.Get <String>("shortName"); var ns = jNode.Get <String>("namespace"); var name = TypeNameInfo.ToStructuralTypeName(shortName, ns); var isComplexType = jNode.Get <bool>("isComplexType", false); if (isComplexType) { var ct = MetadataStore.Instance.GetComplexType(name); ct.UpdateFromJNode(jNode); } else { var et = MetadataStore.Instance.GetEntityType(name); et.UpdateFromJNode(jNode); } }
public StructuralType GetStructuralType(Type clrType) { var stName = TypeNameInfo.FromClrTypeName(clrType.FullName).Name; TypePair tp; if (_map.TryGetValue(stName, out tp)) { return(tp.StructuralType); } else { _map.Add(stName, new TypePair() { ClrType = clrType }); return(null); } }
/// <summary> /// Returns an StructuralType (EntityType or ComplexType) given its CLR type. /// </summary> /// <param name="clrType"></param> /// <returns></returns> public StructuralType GetStructuralType(Type clrType) { if (!IsStructuralType(clrType)) { throw new ArgumentOutOfRangeException("clrType", "This type does not implement either IEntity or IComplexObject"); } // not need for okIfNotFound because we will create a type if one isn't found. var stName = TypeNameInfo.FromClrType(clrType).StructuralTypeName; lock (_structuralTypes) { var st = _structuralTypes[stName]; if (st == null) { var stb = new StructuralTypeBuilder(this); st = stb.CreateStructuralType(clrType); _structuralTypes[stName] = st; } return(st); } }
public EntityError Resolve(EntityManager em) { IsServerError = true; try { EntityType entityType = null; if (EntityTypeName != null) { var stName = TypeNameInfo.FromClrTypeName(EntityTypeName).ToClient(em.MetadataStore).StructuralTypeName; entityType = em.MetadataStore.GetEntityType(stName); var ek = new EntityKey(entityType, KeyValues); Entity = em.GetEntityByKey(ek); } if (entityType != null) { if (PropertyName != null) { Property = entityType.Properties.FirstOrDefault(p => p.NameOnServer == PropertyName); if (Property != null) { PropertyName = Property.Name; } } var vc = new ValidationContext(this.Entity); vc.Property = Property; var veKey = (ErrorName ?? ErrorMessage) + (PropertyName ?? ""); var ve = new ValidationError(null, vc, ErrorMessage, veKey); ve.IsServerError = true; this.Entity.EntityAspect.ValidationErrors.Add(ve); } } catch (Exception e) { ErrorMessage = (ErrorMessage ?? "") + ": Unable to Resolve this error: " + e.Message; } return(this); }