public bool IsVisible( DomainConfiguration configuration, InvocationContext context, IEdmModel model, IEdmSchemaElement element) { if (element.Name == "TestName") { return false; } return true; }
public void AddElement(IEdmSchemaElement element) { List<IEdmStructuredType> edmStructuredTypes = null; EdmUtil.CheckArgumentNull<IEdmSchemaElement>(element, "element"); this.elements.Add(element); IEdmStructuredType edmStructuredType = element as IEdmStructuredType; if (edmStructuredType != null && edmStructuredType.BaseType != null) { if (!this.derivedTypeMappings.TryGetValue(edmStructuredType.BaseType, out edmStructuredTypes)) { edmStructuredTypes = new List<IEdmStructuredType>(); this.derivedTypeMappings[edmStructuredType.BaseType] = edmStructuredTypes; } edmStructuredTypes.Add(edmStructuredType); } base.RegisterElement(element); }
private static int GetTargetDepth(IEdmSchemaElement target, OdcmClass odcmClass) { int depth = 0; if (target != null && odcmClass != null) { for (; odcmClass.FullName != target.FullName(); odcmClass = odcmClass.Base) { if (odcmClass.Base == null) { throw new InvalidOperationException($"Could not find target {target.FullName()}"); } ++depth; } } return(depth); }
public static string ParameterizedName(IEdmFunctionBase function) { string str; int num = 0; int num1 = function.Parameters.Count <IEdmFunctionParameter>(); StringBuilder stringBuilder = new StringBuilder(); IEdmSchemaElement edmSchemaElement = function as IEdmSchemaElement; if (edmSchemaElement != null) { stringBuilder.Append(edmSchemaElement.Namespace); stringBuilder.Append("."); } stringBuilder.Append(function.Name); stringBuilder.Append("("); foreach (IEdmFunctionParameter parameter in function.Parameters) { if (!parameter.Type.IsCollection()) { if (!parameter.Type.IsEntityReference()) { str = parameter.Type.FullName(); } else { str = string.Concat("Ref(", parameter.Type.AsEntityReference().EntityType().FullName(), ")"); } } else { str = string.Concat("Collection(", parameter.Type.AsCollection().ElementType().FullName(), ")"); } stringBuilder.Append(str); num++; if (num >= num1) { continue; } stringBuilder.Append(", "); } stringBuilder.Append(")"); return(stringBuilder.ToString()); }
/// <summary> /// Adds a schema element to this model. /// </summary> /// <param name="element">Element to be added.</param> public void AddElement(IEdmSchemaElement element) { EdmUtil.CheckArgumentNull(element, "element"); this.elements.Add(element); IEdmStructuredType structuredType = element as IEdmStructuredType; if (structuredType != null && structuredType.BaseType != null) { List<IEdmStructuredType> derivedTypes; if (!this.derivedTypeMappings.TryGetValue(structuredType.BaseType, out derivedTypes)) { derivedTypes = new List<IEdmStructuredType>(); this.derivedTypeMappings[structuredType.BaseType] = derivedTypes; } derivedTypes.Add(structuredType); } this.RegisterElement(element); }
/// <summary> /// Indicates if a schema element is currently visible. /// </summary> /// <param name="configuration"> /// A domain configuration. /// </param> /// <param name="context"> /// An optional invocation context. /// </param> /// <param name="model"> /// A model. /// </param> /// <param name="element"> /// A schema element. /// </param> /// <returns> /// <c>true</c> if the element is currently /// visible; otherwise, <c>false</c>. /// </returns> public bool IsVisible( DomainConfiguration configuration, InvocationContext context, IEdmModel model, IEdmSchemaElement element) { Ensure.NotNull(element); // TODO GitHubIssue#34 : Filter out proper visible types if (element is IEdmType || element is IEdmOperation) { return(true); } return(this.IsVisible( configuration, context, element.Namespace, element.Name)); }
public void AddSchemaElement(IEdmSchemaElement element) { if (element.SchemaElementKind == EdmSchemaElementKind.Action || element.SchemaElementKind == EdmSchemaElementKind.Function) { IEdmOperation operation = (IEdmOperation)element; IList <IEdmSchemaElement> operationList; if (!this.operations.TryGetValue(operation.Name, out operationList)) { operationList = new List <IEdmSchemaElement>(); this.operations[operation.Name] = operationList; } operationList.Add(operation); } else { this.schemaElements.Add(element); } }
/// <summary> /// Adds a schema element to this model. /// </summary> /// <param name="element">Element to be added.</param> public void AddElement(IEdmSchemaElement element) { EdmUtil.CheckArgumentNull(element, "element"); this.elements.Add(element); IEdmStructuredType structuredType = element as IEdmStructuredType; if (structuredType != null && structuredType.BaseType != null) { List <IEdmStructuredType> derivedTypes; if (!this.derivedTypeMappings.TryGetValue(structuredType.BaseType, out derivedTypes)) { derivedTypes = new List <IEdmStructuredType>(); this.derivedTypeMappings[structuredType.BaseType] = derivedTypes; } derivedTypes.Add(structuredType); } this.RegisterElement(element); }
/// <summary> /// Indicates if a schema element is currently visible. /// </summary> /// <param name="configuration"> /// A domain configuration. /// </param> /// <param name="context"> /// An optional invocation context. /// </param> /// <param name="model"> /// A model. /// </param> /// <param name="element"> /// A schema element. /// </param> /// <returns> /// <c>true</c> if the element is currently /// visible; otherwise, <c>false</c>. /// </returns> public bool IsVisible( DomainConfiguration configuration, InvocationContext context, IEdmModel model, IEdmSchemaElement element) { Ensure.NotNull(element); // TODO GitHubIssue#34 : Filter out proper visible types if (element is IEdmType || element is IEdmOperation) { return true; } return this.IsVisible( configuration, context, element.Namespace, element.Name); }
internal static string ODataFullName(this IEdmType type) { IEdmCollectionType type2 = type as IEdmCollectionType; if (type2 != null) { string str = type2.ElementType.ODataFullName(); if (str == null) { return(null); } return("Collection(" + str + ")"); } IEdmSchemaElement element = type as IEdmSchemaElement; if (element == null) { return(null); } return(element.FullName()); }
protected override void ProcessSchemaElement(IEdmSchemaElement element) { string namespaceName = element.Namespace; // Put all of the namespaceless stuff into one schema. if (EdmUtil.IsNullOrWhiteSpaceInternal(namespaceName)) { namespaceName = string.Empty; } EdmSchema schema; if (!this.modelSchemas.TryGetValue(namespaceName, out schema)) { schema = new EdmSchema(namespaceName); this.modelSchemas.Add(namespaceName, schema); } schema.AddSchemaElement(element); this.activeSchema = schema; base.ProcessSchemaElement(element); }
internal static void RegisterSchemaElement(IEdmSchemaElement element, Dictionary <string, IEdmSchemaType> schemaTypeDictionary, Dictionary <string, IEdmValueTerm> valueTermDictionary, Dictionary <string, object> functionGroupDictionary, Dictionary <string, IEdmEntityContainer> containerDictionary) { string str = element.FullName(); EdmSchemaElementKind schemaElementKind = element.SchemaElementKind; switch (schemaElementKind) { case EdmSchemaElementKind.None: { throw new InvalidOperationException(Strings.EdmModel_CannotUseElementWithTypeNone); } case EdmSchemaElementKind.TypeDefinition: { RegistrationHelper.AddElement <IEdmSchemaType>((IEdmSchemaType)element, str, schemaTypeDictionary, new Func <IEdmSchemaType, IEdmSchemaType, IEdmSchemaType>(RegistrationHelper.CreateAmbiguousTypeBinding)); return; } case EdmSchemaElementKind.Function: { RegistrationHelper.AddFunction <IEdmFunction>((IEdmFunction)element, str, functionGroupDictionary); return; } case EdmSchemaElementKind.ValueTerm: { RegistrationHelper.AddElement <IEdmValueTerm>((IEdmValueTerm)element, str, valueTermDictionary, new Func <IEdmValueTerm, IEdmValueTerm, IEdmValueTerm>(RegistrationHelper.CreateAmbiguousValueTermBinding)); return; } case EdmSchemaElementKind.EntityContainer: { RegistrationHelper.AddElement <IEdmEntityContainer>((IEdmEntityContainer)element, str, containerDictionary, new Func <IEdmEntityContainer, IEdmEntityContainer, IEdmEntityContainer>(RegistrationHelper.CreateAmbiguousEntityContainerBinding)); RegistrationHelper.AddElement <IEdmEntityContainer>((IEdmEntityContainer)element, element.Name, containerDictionary, new Func <IEdmEntityContainer, IEdmEntityContainer, IEdmEntityContainer>(RegistrationHelper.CreateAmbiguousEntityContainerBinding)); return; } } throw new InvalidOperationException(Strings.UnknownEnumVal_SchemaElementKind(element.SchemaElementKind)); }
internal static void RegisterSchemaElement(IEdmSchemaElement element, Dictionary <string, IEdmSchemaType> schemaTypeDictionary, Dictionary <string, IEdmTerm> valueTermDictionary, Dictionary <string, IList <IEdmOperation> > functionGroupDictionary, Dictionary <string, IEdmEntityContainer> containerDictionary) { string qualifiedName = element.FullName(); switch (element.SchemaElementKind) { case EdmSchemaElementKind.Action: case EdmSchemaElementKind.Function: AddOperation((IEdmOperation)element, qualifiedName, functionGroupDictionary); break; case EdmSchemaElementKind.TypeDefinition: AddElement((IEdmSchemaType)element, qualifiedName, schemaTypeDictionary, CreateAmbiguousTypeBinding); break; case EdmSchemaElementKind.Term: AddElement((IEdmTerm)element, qualifiedName, valueTermDictionary, CreateAmbiguousTermBinding); break; case EdmSchemaElementKind.EntityContainer: // Only one entity container can be added. if (containerDictionary.Count > 0) { throw new InvalidOperationException(Edm.Strings.EdmModel_CannotAddMoreThanOneEntityContainerToOneEdmModel); } IEdmEntityContainer container = (IEdmEntityContainer)element; AddElement(container, qualifiedName, containerDictionary, CreateAmbiguousEntityContainerBinding); AddElement(container, element.Name, containerDictionary, CreateAmbiguousEntityContainerBinding); break; case EdmSchemaElementKind.None: throw new InvalidOperationException(Edm.Strings.EdmModel_CannotUseElementWithTypeNone); default: throw new InvalidOperationException(Edm.Strings.UnknownEnumVal_SchemaElementKind(element.SchemaElementKind)); } }
public void VisitSchemaElement(IEdmSchemaElement element) { EdmSchemaElementKind schemaElementKind = element.SchemaElementKind; switch (schemaElementKind) { case EdmSchemaElementKind.None: { this.ProcessSchemaElement(element); return; } case EdmSchemaElementKind.TypeDefinition: { this.VisitSchemaType((IEdmType)element); return; } case EdmSchemaElementKind.Function: { this.ProcessFunction((IEdmFunction)element); return; } case EdmSchemaElementKind.ValueTerm: { this.ProcessValueTerm((IEdmValueTerm)element); return; } case EdmSchemaElementKind.EntityContainer: { this.ProcessEntityContainer((IEdmEntityContainer)element); return; } } throw new InvalidOperationException(Strings.UnknownEnumVal_SchemaElementKind(element.SchemaElementKind)); }
protected override void ProcessSchemaElement(IEdmSchemaElement element) { string namespaceName = element.Namespace; // Put all of the namespaceless stuff into one schema. if (EdmUtil.IsNullOrWhiteSpaceInternal(namespaceName)) { namespaceName = string.Empty; } EdmSchema schema; if (!this.modelSchemas.TryGetValue(namespaceName, out schema)) { schema = new EdmSchema(namespaceName); this.modelSchemas.Add(namespaceName, schema); } schema.AddSchemaElement(element); this.activeSchema = schema; base.ProcessSchemaElement(element); }
protected void RegisterElement(IEdmSchemaElement element) { EdmUtil.CheckArgumentNull<IEdmSchemaElement>(element, "element"); RegistrationHelper.RegisterSchemaElement(element, this.schemaTypeDictionary, this.valueTermDictionary, this.functionDictionary, this.containersDictionary); }
internal void RemoveElement(IEdmSchemaElement element) { this.removedElements[element] = true; }
protected virtual void ProcessSchemaElement(IEdmSchemaElement element) { this.ProcessVocabularyAnnotatable(element); this.ProcessNamedElement(element); }
private EdmTypeCacheValue GetOrCreateEdmTypeInternal(IEdmStructuredType edmBaseType, Type type, PropertyInfo[] keyProperties, bool isEntity, bool?hasProperties) { Debug.Assert(type != null, "type != null"); Debug.Assert(keyProperties != null, "keyProperties != null"); EdmTypeCacheValue cachedEdmType; lock (this.clrToEdmTypeCache) { this.clrToEdmTypeCache.TryGetValue(type, out cachedEdmType); } if (cachedEdmType == null) { Type collectionType; bool isOpen = false; IEdmSchemaElement edmSchemaElement = null; if (EdmStructuredSchemaElements.TryGetValue(ClientTypeUtil.GetServerDefinedTypeName(type), out edmSchemaElement)) { var edmStructuredType = edmSchemaElement as IEdmStructuredType; if (edmStructuredType != null) { isOpen = edmStructuredType.IsOpen; } } if (PrimitiveType.IsKnownNullableType(type)) { PrimitiveType primitiveType; PrimitiveType.TryGetPrimitiveType(type, out primitiveType); Debug.Assert(primitiveType != null, "primitiveType != null"); cachedEdmType = new EdmTypeCacheValue(primitiveType.CreateEdmPrimitiveType(), hasProperties); } else if ((collectionType = ClientTypeUtil.GetImplementationType(type, typeof(ICollection <>))) != null && ClientTypeUtil.GetImplementationType(type, typeof(IDictionary <,>)) == null) { // Collection Type Type elementType = collectionType.GetGenericArguments()[0]; IEdmType itemType = this.GetOrCreateEdmType(elementType); // Note that // 1. throw here because collection of a collection is not allowed // 2. will also throw during SaveChanges(), validated by unit test case 'SerializationOfCollection'in CollectionTests.cs. if ((itemType.TypeKind == EdmTypeKind.Collection)) { throw new ODataException(Strings.ClientType_CollectionOfCollectionNotSupported); } cachedEdmType = new EdmTypeCacheValue(new EdmCollectionType(itemType.ToEdmTypeReference(ClientTypeUtil.CanAssignNull(elementType))), hasProperties); } else { Type enumTypeTmp = null; if (isEntity) { Action <EdmEntityTypeWithDelayLoadedProperties> delayLoadEntityProperties = (entityType) => { // Create properties without modifying the entityType. // This will leave entityType intact in case of an exception during loading. List <IEdmProperty> loadedProperties = new List <IEdmProperty>(); List <IEdmStructuralProperty> loadedKeyProperties = new List <IEdmStructuralProperty>(); foreach (PropertyInfo property in ClientTypeUtil.GetPropertiesOnType(type, /*declaredOnly*/ edmBaseType != null).OrderBy(p => p.Name)) { IEdmProperty edmProperty = this.CreateEdmProperty((EdmStructuredType)entityType, property); loadedProperties.Add(edmProperty); if (edmBaseType == null && keyProperties.Any(k => k.DeclaringType == type && k.Name == property.Name)) { Debug.Assert(edmProperty.PropertyKind == EdmPropertyKind.Structural, "edmProperty.PropertyKind == EdmPropertyKind.Structural"); Debug.Assert(edmProperty.Type.TypeKind() == EdmTypeKind.Primitive || edmProperty.Type.TypeKind() == EdmTypeKind.Enum, "edmProperty.Type.TypeKind() == EdmTypeKind.Primitive || edmProperty.Type.TypeKind() == EdmTypeKind.Enum"); loadedKeyProperties.Add((IEdmStructuralProperty)edmProperty); } } // Now add properties to the entityType. foreach (IEdmProperty property in loadedProperties) { entityType.AddProperty(property); } entityType.AddKeys(loadedKeyProperties); }; // Creating an entity type Debug.Assert(edmBaseType == null || edmBaseType.TypeKind == EdmTypeKind.Entity, "baseType == null || baseType.TypeKind == EdmTypeKind.Entity"); bool hasStream = GetHasStreamValue((IEdmEntityType)edmBaseType, type); cachedEdmType = new EdmTypeCacheValue( new EdmEntityTypeWithDelayLoadedProperties(CommonUtil.GetModelTypeNamespace(type), CommonUtil.GetModelTypeName(type), (IEdmEntityType)edmBaseType, c.PlatformHelper.IsAbstract(type), isOpen, hasStream, delayLoadEntityProperties), hasProperties); } else if ((enumTypeTmp = Nullable.GetUnderlyingType(type) ?? type) != null && enumTypeTmp.IsEnum()) { Action <EdmEnumTypeWithDelayLoadedMembers> delayLoadEnumMembers = (enumType) => { #if PORTABLELIB foreach (FieldInfo tmp in enumTypeTmp.GetFields().Where(fieldInfo => fieldInfo.IsStatic)) #else foreach (FieldInfo tmp in enumTypeTmp.GetFields(BindingFlags.Static | BindingFlags.Public)) #endif { object memberValue = Enum.Parse(enumTypeTmp, tmp.Name, false); enumType.AddMember(new EdmEnumMember(enumType, tmp.Name, new EdmEnumMemberValue((long)Convert.ChangeType(memberValue, typeof(long), CultureInfo.InvariantCulture.NumberFormat)))); } }; // underlying type may be Edm.Byte, Edm.SByte, Edm.Int16, Edm.Int32, or Edm.Int64. Type underlyingType = Enum.GetUnderlyingType(enumTypeTmp); IEdmPrimitiveType underlyingEdmType = (IEdmPrimitiveType)EdmCoreModel.Instance.FindDeclaredType("Edm." + underlyingType.Name); Debug.Assert(underlyingEdmType != null, "underlyingEdmType != null"); bool isFlags = enumTypeTmp.GetCustomAttributes(false).Any(s => s is FlagsAttribute); cachedEdmType = new EdmTypeCacheValue( new EdmEnumTypeWithDelayLoadedMembers(CommonUtil.GetModelTypeNamespace(enumTypeTmp), CommonUtil.GetModelTypeName(enumTypeTmp), underlyingEdmType, isFlags, delayLoadEnumMembers), null); } else { Action <EdmComplexTypeWithDelayLoadedProperties> delayLoadComplexProperties = (complexType) => { // Create properties without modifying the complexType. // This will leave complexType intact in case of an exception during loading. List <IEdmProperty> loadedProperties = new List <IEdmProperty>(); foreach (PropertyInfo property in ClientTypeUtil.GetPropertiesOnType(type, /*declaredOnly*/ edmBaseType != null).OrderBy(p => p.Name)) { IEdmProperty edmProperty = this.CreateEdmProperty(complexType, property); loadedProperties.Add(edmProperty); } // Now add properties to the complexType. foreach (IEdmProperty property in loadedProperties) { complexType.AddProperty(property); } }; // Creating a complex type Debug.Assert(edmBaseType == null || edmBaseType.TypeKind == EdmTypeKind.Complex, "baseType == null || baseType.TypeKind == EdmTypeKind.Complex"); cachedEdmType = new EdmTypeCacheValue( new EdmComplexTypeWithDelayLoadedProperties(CommonUtil.GetModelTypeNamespace(type), CommonUtil.GetModelTypeName(type), (IEdmComplexType)edmBaseType, c.PlatformHelper.IsAbstract(type), isOpen, delayLoadComplexProperties), hasProperties); } } Debug.Assert(cachedEdmType != null, "cachedEdmType != null"); IEdmType edmType = cachedEdmType.EdmType; ClientTypeAnnotation clientTypeAnnotation = this.GetOrCreateClientTypeAnnotation(edmType, type); this.SetClientTypeAnnotation(edmType, clientTypeAnnotation); if (edmType.TypeKind == EdmTypeKind.Entity || edmType.TypeKind == EdmTypeKind.Complex) { IEdmStructuredType edmStructuredType = edmType as IEdmStructuredType; Debug.Assert(edmStructuredType != null, "edmStructuredType != null"); this.SetMimeTypeForProperties(edmStructuredType); } // Need to cache the type before loading the properties so we don't stack overflow because // loading the property can trigger calls to GetOrCreateEdmType on the same type. lock (this.clrToEdmTypeCache) { EdmTypeCacheValue existing; if (this.clrToEdmTypeCache.TryGetValue(type, out existing)) { cachedEdmType = existing; } else { this.clrToEdmTypeCache.Add(type, cachedEdmType); } } } return(cachedEdmType); }
private static string GetFullName(IEdmSchemaElement schemaElement) { return(schemaElement.FullName()); }
protected override void ProcessSchemaElement(IEdmSchemaElement element) { EdmSchema edmSchema = null; string @namespace = element.Namespace; if (EdmUtil.IsNullOrWhiteSpaceInternal(@namespace)) { @namespace = string.Empty; } if (!this.modelSchemas.TryGetValue(@namespace, out edmSchema)) { edmSchema = new EdmSchema(@namespace); this.modelSchemas.Add(@namespace, edmSchema); } edmSchema.AddSchemaElement(element); this.activeSchema = edmSchema; base.ProcessSchemaElement(element); }
public static string FullyQualifiedName(IEdmVocabularyAnnotatable element) { IEdmSchemaElement schemaElement = element as IEdmSchemaElement; if (schemaElement != null) { IEdmFunction function = schemaElement as IEdmFunction; if (function != null) { return(ParameterizedName(function)); } else { return(schemaElement.FullName()); } } else { IEdmEntityContainerElement containerElement = element as IEdmEntityContainerElement; if (containerElement != null) { IEdmFunctionImport functionImport = containerElement as IEdmFunctionImport; if (functionImport != null) { return(functionImport.Container.FullName() + "/" + ParameterizedName(functionImport)); } else { return(containerElement.Container.FullName() + "/" + containerElement.Name); } } else { IEdmProperty property = element as IEdmProperty; if (property != null) { IEdmSchemaType declaringSchemaType = property.DeclaringType as IEdmSchemaType; if (declaringSchemaType != null) { string propertyOwnerName = FullyQualifiedName(declaringSchemaType); if (propertyOwnerName != null) { return(propertyOwnerName + "/" + property.Name); } } } else { IEdmFunctionParameter parameter = element as IEdmFunctionParameter; if (parameter != null) { string parameterOwnerName = FullyQualifiedName(parameter.DeclaringFunction); if (parameterOwnerName != null) { return(parameterOwnerName + "/" + parameter.Name); } } } } } return(null); }
/// <summary> /// Creates a new type dynamically and register it in the EDM model. /// </summary> /// <param name="properties">List of properties for the new type.</param> /// <param name="context">The OData query context.</param> /// <param name="asEdmEntity">Should the new type be defined as entity or complex type in the EDM model.</param> /// <returns>The new generated type.</returns> public static Type CreateType(List <Tuple <Type, string> > properties, ODataQueryContext context, bool asEdmEntity) { Contract.Assert(properties != null); Contract.Assert(context != null); Contract.Assert(properties.Any()); string typeName = GenerateClassName(properties, asEdmEntity); var tempPath = Path.GetTempPath(); string outputfile = Path.Combine(tempPath, typeName + ".dll"); var lockHandle = AggregationDynamicTypeCollection.GetLock(typeName); lock (lockHandle) { Type result; if (AggregationDynamicTypeCollection.ExistingTypes.TryGetValue(typeName, out result)) { return(result); } List <string> referencedAssemblies = new List <string>(); foreach (var prop in properties) { if (prop.Item1.Assembly.GetName().Name != "mscorlib") { if (!string.IsNullOrEmpty(prop.Item1.Assembly.Location)) { referencedAssemblies.Add(prop.Item1.Assembly.Location); } else { referencedAssemblies.Add(Path.Combine(tempPath, prop.Item1.Name + ".dll")); } } } var code = CreateCode(typeName, properties); CSharpCodeProvider provider = new CSharpCodeProvider(); CompilerParameters parameters = new CompilerParameters(); parameters.GenerateInMemory = true; parameters.GenerateExecutable = false; parameters.OutputAssembly = outputfile; parameters.ReferencedAssemblies.AddRange(referencedAssemblies.Distinct().ToArray()); parameters.TempFiles = new TempFileCollection(tempPath, false); CompilerResults results = provider.CompileAssemblyFromSource(parameters, code); if (results.Errors.HasErrors) { StringBuilder sb = new StringBuilder(); foreach (CompilerError error in results.Errors) { sb.AppendLine(String.Format("Error ({0}): {1}", error.ErrorNumber, error.ErrorText)); } throw Error.InvalidOperation(sb.ToString()); } Assembly assembly = results.CompiledAssembly; AggregationDynamicTypeCollection.AddAssembly(assembly); var newType = assembly.GetType("ODataAggregation.DynamicTypes." + typeName); if (context.Model.FindDeclaredType(newType.FullName) == null) { var model = (EdmModel)context.Model; IEdmSchemaElement entityType = CreateEdmSechmaElement(newType, context, asEdmEntity); model.AddElement(entityType); // TODO: should be added as transient entity. // I suspect that we have to implement this as well as I found no support for transient entities in the current stack. // AggregationTransientEntityAnnotation was created to mark the entity as transient. // if (asEdmEntity) // { // model.SetAnnotationValue(entityType, // new AggregationTransientEntityAnnotation() { EntityState = "TransientEntity" }); // } } return(newType); } }
public void Add(IEdmSchemaElement element) { this.schemaElements.Add(element); this.RegisterElement(element); }
/// <summary> /// Gets the symbolic string of an annotated element. /// In the next breaking change, it's better to add a property into <see cref="IEdmVocabularyAnnotatable"/>. /// </summary> /// <param name="annotatedElement">The annotatable element.</param> /// <returns>null or a symbolic string.</returns> public static string GetSymbolicString(this IEdmVocabularyAnnotatable annotatedElement) { IEdmSchemaElement schemaElement = annotatedElement as IEdmSchemaElement; if (schemaElement != null) { // EntityType, ComplexType, EnumType, TypeDefinition if (schemaElement.SchemaElementKind == EdmSchemaElementKind.TypeDefinition) { IEdmType edmType = (IEdmType)schemaElement; switch (edmType.TypeKind) { case EdmTypeKind.Complex: return("ComplexType"); case EdmTypeKind.Entity: return("EntityType"); case EdmTypeKind.Enum: return("EnumType"); case EdmTypeKind.TypeDefinition: return("TypeDefinition"); default: return(null); } } else { // Action, Function, Term, EntityContainer return(schemaElement.SchemaElementKind.ToString()); } } IEdmEntityContainerElement containerElement = annotatedElement as IEdmEntityContainerElement; if (containerElement != null) { // ActionImport, FunctionImport, EntitySet, Singleton return(containerElement.ContainerElementKind.ToString()); } IEdmProperty property = annotatedElement as IEdmProperty; if (property != null) { // NavigationProperty, Property switch (property.PropertyKind) { case EdmPropertyKind.Navigation: return("NavigationProperty"); case EdmPropertyKind.Structural: return("Property"); default: return(null); } } IEdmExpression expression = annotatedElement as IEdmExpression; if (expression != null) { switch (expression.ExpressionKind) { case EdmExpressionKind.FunctionApplication: return("Apply"); case EdmExpressionKind.IsType: return("IsOf"); case EdmExpressionKind.Labeled: return("LabeledElement"); case EdmExpressionKind.Cast: case EdmExpressionKind.Collection: case EdmExpressionKind.If: case EdmExpressionKind.Null: case EdmExpressionKind.Record: return(expression.ExpressionKind.ToString()); default: return(null); } } if (annotatedElement is IEdmOperationParameter) { return("Parameter"); } else if (annotatedElement is IEdmOperationReturn) { return("ReturnType"); } else if (annotatedElement is IEdmReference) { return("Reference"); } else if (annotatedElement is IEdmInclude) { return("Include"); } else if (annotatedElement is IEdmReferentialConstraint) { return("ReferentialConstraint"); } else if (annotatedElement is IEdmEnumMember) { return("Member"); } else if (annotatedElement is IEdmVocabularyAnnotation) { return("Annotation"); } else if (annotatedElement is IEdmPropertyConstructor) { return("PropertyValue"); } // It's not supported "Schema, UrlRef, OnDelete" return(null); }
/// <summary> /// Adds a schema element /// </summary> /// <param name="schemaElement">the schema element</param> public void Add(IEdmSchemaElement schemaElement) { this.schemaElements.Add(schemaElement); }
public void Add(IEdmSchemaElement element) { this.schemaElements.Add(element); this.RegisterElement(element); }
/// <summary> /// Adds a schema element /// </summary> /// <param name="schemaElement">the schema element</param> public void Add(IEdmSchemaElement schemaElement) { this.schemaElements.Add(schemaElement); }
public static string FullyQualifiedName(IEdmVocabularyAnnotatable element) { IEdmSchemaElement edmSchemaElement = element as IEdmSchemaElement; if (edmSchemaElement == null) { IEdmEntityContainerElement edmEntityContainerElement = element as IEdmEntityContainerElement; if (edmEntityContainerElement == null) { IEdmProperty edmProperty = element as IEdmProperty; if (edmProperty == null) { IEdmFunctionParameter edmFunctionParameter = element as IEdmFunctionParameter; if (edmFunctionParameter != null) { string str = EdmUtil.FullyQualifiedName(edmFunctionParameter.DeclaringFunction); if (str != null) { return(string.Concat(str, "/", edmFunctionParameter.Name)); } } } else { IEdmSchemaType declaringType = edmProperty.DeclaringType as IEdmSchemaType; if (declaringType != null) { string str1 = EdmUtil.FullyQualifiedName(declaringType); if (str1 != null) { return(string.Concat(str1, "/", edmProperty.Name)); } } } return(null); } else { IEdmFunctionImport edmFunctionImport = edmEntityContainerElement as IEdmFunctionImport; if (edmFunctionImport == null) { return(string.Concat(edmEntityContainerElement.Container.FullName(), "/", edmEntityContainerElement.Name)); } else { return(string.Concat(edmFunctionImport.Container.FullName(), "/", EdmUtil.ParameterizedName(edmFunctionImport))); } } } else { IEdmFunction edmFunction = edmSchemaElement as IEdmFunction; if (edmFunction == null) { return(edmSchemaElement.FullName()); } else { return(EdmUtil.ParameterizedName(edmFunction)); } } }
internal static string FullyQualifiedName(IEdmVocabularyAnnotatable element) { IEdmSchemaElement schemaElement = element as IEdmSchemaElement; if (schemaElement != null) { IEdmOperation operation = schemaElement as IEdmOperation; if (operation != null) { return ParameterizedName(operation); } else { return schemaElement.FullName(); } } else { IEdmEntityContainerElement containerElement = element as IEdmEntityContainerElement; if (containerElement != null) { return containerElement.Container.FullName() + "/" + containerElement.Name; } else { IEdmProperty property = element as IEdmProperty; if (property != null) { IEdmSchemaType declaringSchemaType = property.DeclaringType as IEdmSchemaType; if (declaringSchemaType != null) { string propertyOwnerName = FullyQualifiedName(declaringSchemaType); if (propertyOwnerName != null) { return propertyOwnerName + "/" + property.Name; } } } else { IEdmOperationParameter parameter = element as IEdmOperationParameter; if (parameter != null) { string parameterOwnerName = FullyQualifiedName(parameter.DeclaringOperation); if (parameterOwnerName != null) { return parameterOwnerName + "/" + parameter.Name; } } else { IEdmEnumMember enumMember = element as IEdmEnumMember; if (enumMember != null) { string enumMemberOwnerName = FullyQualifiedName(enumMember.DeclaringType); if (enumMemberOwnerName != null) { return enumMemberOwnerName + "/" + enumMember.Name; } } } } } } return null; }
private static GraphIdentifier CreateGraphIdentifier(GraphVersion version, IEdmModel model, IEdmSchemaElement element) { return(new GraphIdentifier { Version = version, Name = element.Name, Description = model.GetDescriptionAnnotation(element), Namespace = element.Namespace, Kind = ((IEdmType)element).TypeKind.ToString() }); }
public void AddSchemaElement(IEdmSchemaElement element) { this.schemaElements.Add(element); }
private OdcmType ResolveType(IEdmSchemaElement realizedSchemaElement, TypeKind kind) { return(ResolveType(realizedSchemaElement.Name, realizedSchemaElement.Namespace, kind)); }
public void Init() { instance = new IEdmSchemaElement(); }
internal static string FullyQualifiedName(IEdmVocabularyAnnotatable element) { IEdmSchemaElement schemaElement = element as IEdmSchemaElement; if (schemaElement != null) { IEdmOperation operation = schemaElement as IEdmOperation; if (operation != null) { return(ParameterizedName(operation)); } else { return(schemaElement.FullName()); } } else { IEdmEntityContainerElement containerElement = element as IEdmEntityContainerElement; if (containerElement != null) { return(containerElement.Container.FullName() + "/" + containerElement.Name); } else { IEdmProperty property = element as IEdmProperty; if (property != null) { IEdmSchemaType declaringSchemaType = property.DeclaringType as IEdmSchemaType; if (declaringSchemaType != null) { string propertyOwnerName = FullyQualifiedName(declaringSchemaType); if (propertyOwnerName != null) { return(propertyOwnerName + "/" + property.Name); } } } else { IEdmOperationReturn operationReturn; IEdmEnumMember enumMember; IEdmOperationParameter parameter = element as IEdmOperationParameter; if (parameter != null) { string parameterOwnerName = FullyQualifiedName(parameter.DeclaringOperation); if (parameterOwnerName != null) { return(parameterOwnerName + "/" + parameter.Name); } } else if ((enumMember = element as IEdmEnumMember) != null) { string enumMemberOwnerName = FullyQualifiedName(enumMember.DeclaringType); if (enumMemberOwnerName != null) { return(enumMemberOwnerName + "/" + enumMember.Name); } } else if ((operationReturn = element as IEdmOperationReturn) != null) { string operationName = FullyQualifiedName(operationReturn.DeclaringOperation); if (operationName != null) { return(operationName + "/" + CsdlConstants.OperationReturnExternalTarget); } } } } } return(null); }
//fill all properties/name of the class template private string GetClrTypeName(IEdmTypeReference edmTypeReference) { string clrTypeName = edmTypeReference.ToString(); IEdmType edmType = edmTypeReference.Definition; if (edmTypeReference.IsPrimitive()) { return(EdmToClr(edmType as IEdmPrimitiveType)); } //@@@ v1.0.0-rc2 if (edmTypeReference.IsEnum()) { var ent = edmType as IEdmEnumType; if (ent != null) { return(ent.Name); } } if (edmTypeReference.IsComplex()) { var edmComplexType = edmType as IEdmComplexType; if (edmComplexType != null) { return(edmComplexType.Name); } } if (edmTypeReference.IsEntity()) { var ent = edmType as IEdmEntityType; if (ent != null) { return(ent.Name); } } if (edmTypeReference.IsCollection()) { IEdmCollectionType edmCollectionType = edmType as IEdmCollectionType; if (edmCollectionType != null) { IEdmTypeReference elementTypeReference = edmCollectionType.ElementType; IEdmPrimitiveType primitiveElementType = elementTypeReference.Definition as IEdmPrimitiveType; if (primitiveElementType == null) { IEdmSchemaElement schemaElement = elementTypeReference.Definition as IEdmSchemaElement; if (schemaElement != null) { clrTypeName = schemaElement.Name; //@@@ 1.0.0-rc2 // clrTypeName = string.Format("ICollection<{0}>", clrTypeName); clrTypeName = string.Format("List<{0}>", clrTypeName); //to support RestSharp } return(clrTypeName); } clrTypeName = EdmToClr(primitiveElementType); clrTypeName = string.Format("List<{0}>", clrTypeName); } return(clrTypeName); }//IsCollection return(clrTypeName); }
/// <summary> /// Returns the text representation of the current object. /// </summary> /// <param name="schemaElement">Reference to the calling object.</param> /// <returns>The text representation of the current object.</returns> public static string ToTraceString(this IEdmSchemaElement schemaElement) { return(schemaElement.FullName()); }
private void CheckSchemaElementReference(IEdmSchemaElement element) { this.CheckSchemaElementReference(element.Namespace); }
private void CheckSchemaElementReference(IEdmSchemaElement element) { this.CheckSchemaElementReference(element.Namespace); }
private bool IsSchemaElementVisible(IEdmSchemaElement element) { var entityContainer = element as IEdmEntityContainer; if (entityContainer != null) { return entityContainer.Elements.Any(); } return this.Configuration .GetHookPoints<IModelVisibilityFilter>().Reverse() .All(filter => filter.IsVisible( this.Configuration, this.Context, this.InnerModel, element)); }
protected void RegisterElement(IEdmSchemaElement element) { EdmUtil.CheckArgumentNull <IEdmSchemaElement>(element, "element"); RegistrationHelper.RegisterSchemaElement(element, this.schemaTypeDictionary, this.valueTermDictionary, this.functionDictionary, this.containersDictionary); }
public void AddSchemaElement(IEdmSchemaElement element) { this.schemaElements.Add(element); }