internal static ContentProjectItemNode FromXElement(XElement element) { if (element == null) throw new ArgumentNullException("element"); ContentProjectItemNode item = new ContentProjectItemNode(); item.Name = element.GetRequiredAttributeValue("Name"); var importNode = element.Element("Import"); if (importNode != null) item.Import = ContentProjectImportNode.FromXElement(importNode); var processorsNode = element.Element("Processors"); if (processorsNode != null) { foreach (var processorNode in processorsNode.Elements()) { item.Processors.Add(ContentProjectProcessorNode.FromXElement(processorNode)); } } var serializeNode = element.Element("Serialize"); if (serializeNode != null) item.Serialize = ContentProjectSerializeNode.FromXElement(serializeNode); return item; }
internal static ContentProjectImportNode FromXElement(XElement element) { if (element == null) throw new ArgumentNullException("element"); ContentProjectImportNode import = new ContentProjectImportNode(); import.FileName = element.GetRequiredAttributeValue("FileName"); return import; }
internal static ContentProjectReferenceNode FromXElement(XElement element) { if (element == null) throw new ArgumentNullException("element"); ContentProjectReferenceNode reference = new ContentProjectReferenceNode(); reference.FileName = element.GetRequiredAttributeValue("FileName"); return reference; }
internal static ContentProjectSerializeNode FromXElement(XElement element) { if (element == null) throw new ArgumentNullException("element"); ContentProjectSerializeNode serializer = new ContentProjectSerializeNode(); serializer.FileName = element.GetRequiredAttributeValue("FileName"); foreach (XAttribute attribute in element.Attributes().Where(x => x.Name != "FileName")) { serializer.Parameters[attribute.Name.ToString()] = attribute.Value; } return serializer; }
private void RegisterNominalTypes(XElement schemaElement) { this.AssertXsdlElement(schemaElement, "Schema"); string namespaceName = schemaElement.GetRequiredAttributeValue("Namespace"); foreach (var entityTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityType"))) { string name = entityTypeElement.GetRequiredAttributeValue("Name"); this.entityTypeFullNames.Add(namespaceName + "." + name); } foreach (var complexTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "ComplexType"))) { string name = complexTypeElement.GetRequiredAttributeValue("Name"); this.complexTypeFullNames.Add(namespaceName + "." + name); } foreach (var enumTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EnumType"))) { string name = enumTypeElement.GetRequiredAttributeValue("Name"); this.enumTypeFullNames.Add(namespaceName + "." + name); } }
private AssociationSetEnd ParseAssociationSetEnd(XElement associationSetEndElement) { string roleName = associationSetEndElement.GetRequiredAttributeValue("Role"); var entitySetName = associationSetEndElement.GetRequiredAttributeValue("EntitySet"); var associationSetEnd = new AssociationSetEnd(roleName, entitySetName); this.ParseAnnotations(associationSetEnd, associationSetEndElement); return associationSetEnd; }
private AssociationSet ParseAssociationSet(XElement associationSetElement) { string associationSetName = associationSetElement.GetRequiredAttributeValue("Name"); string associationTypeNamespace = this.ParseEdmTypeName(associationSetElement.GetRequiredAttributeValue("Association"))[0]; string associationTypeName = this.ParseEdmTypeName(associationSetElement.GetRequiredAttributeValue("Association"))[1]; var associationSet = new AssociationSet(associationSetName, new AssociationTypeReference(associationTypeNamespace, associationTypeName)); foreach (var associationSetEndElement in associationSetElement.Elements().Where(el => this.IsXsdlElement(el, "End"))) { associationSet.Ends.Add(this.ParseAssociationSetEnd(associationSetEndElement)); } this.ParseAnnotations(associationSet, associationSetElement); return associationSet; }
/// <summary> /// Parse a Property from its XElement /// </summary> /// <param name="propertyElement">XElement to parse Property from</param> /// <returns>A memberProperty</returns> protected virtual MemberProperty ParseProperty(XElement propertyElement) { var name = propertyElement.GetRequiredAttributeValue("Name"); DataType dataType = this.ParsePropertyDataType(propertyElement); var memberProperty = new MemberProperty(name, dataType); if (propertyElement.GetOptionalAttributeValue("ConcurrencyMode", "None") == "Fixed") { memberProperty.Annotations.Add(new ConcurrencyTokenAnnotation()); } this.ParseAnnotations(memberProperty, propertyElement); return memberProperty; }
/// <summary> /// Parses a XElement that contains type information /// Accepts an element that is a CollectionType, RowType, ReferenceType, and TypeRef /// </summary> /// <param name="typeElement">XElement that contains a Type element</param> /// <returns>DataType represented by the XElement</returns> protected DataType ParseType(XElement typeElement) { if (typeElement.Name.LocalName == "CollectionType") { string elementTypeName = typeElement.GetOptionalAttributeValue("ElementType", null); if (elementTypeName != null) { bool isNullable = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("Nullable", "true")); DataType dataType = this.ParseType(elementTypeName, isNullable, typeElement.Attributes()); return DataTypes.CollectionType.WithElementDataType(dataType); } else { var elementType = typeElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName)); return DataTypes.CollectionType.WithElementDataType(this.ParseType(elementType)); } } else if (typeElement.Name.LocalName == "RowType") { var row = new RowType(); foreach (var propertyElement in typeElement.Elements().Where(el => this.IsXsdlElement(el, "Property"))) { row.Properties.Add(this.ParseProperty(propertyElement)); } return DataTypes.RowType.WithDefinition(row); } else if (typeElement.Name.LocalName == "ReferenceType") { DataType dataType = this.ParseType(typeElement.GetRequiredAttributeValue("Type"), true, null); return DataTypes.ReferenceType.WithEntityType((dataType as EntityDataType).Definition); } else if (typeElement.Name.LocalName == "TypeRef") { bool isNullable = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("Nullable", "true")); DataType dataType = this.ParseType(typeElement.GetRequiredAttributeValue("Type"), isNullable, typeElement.Attributes()); return dataType; } else { throw new TaupoNotSupportedException("Unsupported data type element: " + typeElement.Name.LocalName); } }
private EnumMember ParseEnumMember(XElement memberElement) { string name = memberElement.GetRequiredAttributeValue("Name"); string valueString = memberElement.GetOptionalAttributeValue("Value", null); var member = new EnumMember(name, valueString); this.ParseAnnotations(member, memberElement); return member; }
private AssociationEnd ParseAssociationEnd(XElement associationEndElement) { var roleName = associationEndElement.GetRequiredAttributeValue("Role"); string entityTypeNamespace = this.ParseEdmTypeName(associationEndElement.GetRequiredAttributeValue("Type"))[0]; string entityTypeName = this.ParseEdmTypeName(associationEndElement.GetRequiredAttributeValue("Type"))[1]; EndMultiplicity multiplicity = this.ParseEndMultiplicity(associationEndElement.GetRequiredAttributeValue("Multiplicity")); OperationAction onDeleteAction = associationEndElement.Descendants().Any(e => e.Name.LocalName.Equals("OnDelete") && e.Attribute("Action").Value.Equals("Cascade")) ? OperationAction.Cascade : OperationAction.None; AssociationEnd end = new AssociationEnd(roleName, new EntityTypeReference(entityTypeNamespace, entityTypeName), multiplicity, onDeleteAction); this.ParseAnnotations(end, associationEndElement); return end; }
/// <summary> /// Parses a function element /// </summary> /// <param name="parameterElement">the function element in the schema file</param> /// <returns>the function parameter representation in the entity model schema</returns> protected FunctionParameter ParseFunctionParameter(XElement parameterElement) { string parameterName = parameterElement.GetRequiredAttributeValue("Name"); DataType parameterType; string parameterTypeName = parameterElement.GetOptionalAttributeValue("Type", null); bool isNullable = XmlConvert.ToBoolean(parameterElement.GetOptionalAttributeValue("Nullable", "true")); if (parameterTypeName != null) { parameterType = this.ParseType(parameterTypeName, isNullable, parameterElement.Attributes()); } else { var parameterTypeElement = parameterElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName)); parameterType = this.ParseType(parameterTypeElement); } FunctionParameter parameter = new FunctionParameter() { Name = parameterName, DataType = parameterType, }; string parameterMode = parameterElement.GetOptionalAttributeValue("Mode", null); if (parameterMode != null) { parameter.Mode = (FunctionParameterMode)Enum.Parse(typeof(FunctionParameterMode), parameterMode, true); } this.ParseAnnotations(parameter, parameterElement); return parameter; }
/// <summary> /// Parses an entity type element in the csdl/ssdl file. /// </summary> /// <param name="entityTypeElement">the entity type element to parse</param> /// <returns>the parsed entity type object in the entity model schema</returns> protected virtual EntityType ParseEntityType(XElement entityTypeElement) { string name = entityTypeElement.GetRequiredAttributeValue("Name"); var entityType = new EntityType(this.CurrentNamespace, name); foreach (var propertyElement in entityTypeElement.Elements().Where(el => this.IsXsdlElement(el, "Property"))) { entityType.Properties.Add(this.ParseProperty(propertyElement)); } var keyElement = entityTypeElement.Elements().Where(c => this.IsXsdlElement(c, "Key")).SingleOrDefault(); if (keyElement != null) { foreach (var propertyRefElement in keyElement.Elements().Where(c => this.IsXsdlElement(c, "PropertyRef"))) { string propertyName = propertyRefElement.GetRequiredAttributeValue("Name"); var property = entityType.Properties.Single(p => p.Name == propertyName); property.IsPrimaryKey = true; } } this.ParseAnnotations(entityType, entityTypeElement); return entityType; }
/// <summary> /// Parses an entity container element in the csdl/ssdl file. /// </summary> /// <param name="entityContainerElement">the entity container element to parse</param> /// <returns>the parsed entity container object in the entity model schema</returns> protected virtual EntityContainer ParseEntityContainer(XElement entityContainerElement) { string name = entityContainerElement.GetRequiredAttributeValue("Name"); var entityContainer = new EntityContainer(name); foreach (var entitySetElement in entityContainerElement.Elements().Where(el => this.IsXsdlElement(el, "EntitySet"))) { entityContainer.Add(this.ParseEntitySet(entitySetElement)); } foreach (var entitySetElement in entityContainerElement.Elements().Where(el => this.IsXsdlElement(el, "AssociationSet"))) { entityContainer.Add(this.ParseAssociationSet(entitySetElement)); } this.ParseAnnotations(entityContainer, entityContainerElement); return entityContainer; }
private ComplexType ParseComplexType(XElement complexTypeElement) { string name = complexTypeElement.GetRequiredAttributeValue("Name"); var complexType = new ComplexType(this.CurrentNamespace, name); this.ParseNamedStructuralTypeAttributes(complexTypeElement, complexType); foreach (var propertyElement in complexTypeElement.Elements().Where(el => this.IsXsdlElement(el, "Property"))) { complexType.Properties.Add(this.ParseProperty(propertyElement)); } this.ParseAnnotations(complexType, complexTypeElement); return complexType; }
private FunctionImport ParseFunctionImport(XElement functionImportElement) { string functionImportName = functionImportElement.GetRequiredAttributeValue("Name"); var functionImport = new FunctionImport(functionImportName); bool isComposable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsComposable", "false")); functionImport.IsComposable = isComposable; bool isBindable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsBindable", "false")); functionImport.IsBindable = isBindable; bool isSideEffecting = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsSideEffecting", "true")); functionImport.IsSideEffecting = isSideEffecting; string entitySetPath = functionImportElement.GetOptionalAttributeValue("EntitySetPath", null); if (entitySetPath != null) { functionImport.Annotations.Add(new EntitySetPathAnnotation(entitySetPath)); } foreach (var parameterElement in functionImportElement.Elements().Where(el => this.IsXsdlElement(el, "Parameter"))) { functionImport.Parameters.Add(this.ParseFunctionParameter(parameterElement)); } string returnTypeName = functionImportElement.GetOptionalAttributeValue("ReturnType", null); if (returnTypeName != null) { bool isNullable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("Nullable", "true")); var returnType = new FunctionImportReturnType(this.ParseType(returnTypeName, isNullable, null)); string entitySetName = functionImportElement.GetOptionalAttributeValue("EntitySet", null); if (entitySetName != null) { returnType.EntitySet = new EntitySetReference(entitySetName); } functionImport.Add(returnType); } foreach (var returnTypeElement in functionImportElement.Elements().Where(el => this.IsXsdlElement(el, "ReturnType"))) { var type = returnTypeElement.GetRequiredAttributeValue("Type"); var returnType = new FunctionImportReturnType(this.ParseType(type, true, null)); var entitySet = returnTypeElement.GetOptionalAttributeValue("EntitySet", null); if (entitySet != null) { returnType.EntitySet = new EntitySetReference(entitySet); } functionImport.ReturnTypes.Add(returnType); } string methodaccess = functionImportElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "MethodAccess", null); if (methodaccess != null) { functionImport.Annotations.Add(new MethodAccessModifierAnnotation(this.GetAccessModifier(methodaccess))); } this.ParseAnnotations(functionImport, functionImportElement); return functionImport; }
private NavigationProperty ParseNavigationProperty(XElement navigationPropertyElement) { var name = navigationPropertyElement.GetRequiredAttributeValue("Name"); string relationshipNamespace = this.ParseEdmTypeName(navigationPropertyElement.GetRequiredAttributeValue("Relationship"))[0]; string relationshipName = this.ParseEdmTypeName(navigationPropertyElement.GetRequiredAttributeValue("Relationship"))[1]; string fromRole = navigationPropertyElement.GetRequiredAttributeValue("FromRole"); string toRole = navigationPropertyElement.GetRequiredAttributeValue("ToRole"); var navProp = new NavigationProperty(name, new AssociationTypeReference(relationshipNamespace, relationshipName), fromRole, toRole); this.ParseAnnotations(navProp, navigationPropertyElement); string getteraccess = navigationPropertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "GetterAccess", null); string setteraccess = navigationPropertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "SetterAccess", null); if (getteraccess != null || setteraccess != null) { AccessModifier setter; AccessModifier getter; this.GetGetterAndSetterModifiers(getteraccess, setteraccess, out setter, out getter); navProp.Annotations.Add(new PropertyAccessModifierAnnotation(setter, getter)); } return navProp; }
private void SetupNamespaceAndAliases(XElement schemaElement) { string namespaceName = schemaElement.GetRequiredAttributeValue("Namespace"); string alias = schemaElement.GetOptionalAttributeValue("Alias", null); this.CurrentNamespace = namespaceName; this.alias2namespace = new Dictionary<string, string>(); if (alias != null) { this.alias2namespace.Add(alias, namespaceName); } foreach (var usingElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Using"))) { alias = usingElement.GetRequiredAttributeValue("Alias"); namespaceName = usingElement.GetRequiredAttributeValue("Namespace"); this.alias2namespace[alias] = namespaceName; } }
private AssociationType ParseAssociation(XElement associationTypeElement) { string name = associationTypeElement.GetRequiredAttributeValue("Name"); var association = new AssociationType(this.CurrentNamespace, name); foreach (var associationEndElement in associationTypeElement.Elements().Where(el => this.IsXsdlElement(el, "End"))) { association.Ends.Add(this.ParseAssociationEnd(associationEndElement)); } var constraintElement = associationTypeElement.Elements().Where(el => this.IsXsdlElement(el, "ReferentialConstraint")).SingleOrDefault(); if (constraintElement != null) { association.ReferentialConstraint = this.ParseReferentialConstraint(constraintElement); } this.ParseAnnotations(association, associationTypeElement); return association; }
/// <summary> /// Deserialize a <see cref="DataFieldDescriptor"/>. /// </summary> /// <param name="element">Deserialized DataFieldDescriptor</param> /// <returns></returns> public static DataFieldDescriptor FromXml(XElement element) { if (element.Name != "DataFieldDescriptor") throw new ArgumentException("The xml is not correctly formatted"); Guid id = (Guid)element.GetRequiredAttribute("id"); string name = element.GetRequiredAttributeValue("name"); bool isNullable = (bool)element.GetRequiredAttribute("isNullable"); int position = (int)element.GetRequiredAttribute("position"); bool inherited = (bool)element.GetRequiredAttribute("inherited"); XAttribute groupByPriorityAttribute = element.Attribute("groupByPriority"); XAttribute instanceTypeAttribute = element.GetRequiredAttribute("instanceType"); XAttribute storeTypeAttribute = element.GetRequiredAttribute("storeType"); XAttribute isReadOnlyAttribute = element.Attribute("isReadOnly"); XAttribute newInstanceDefaultFieldValueAttribute = element.Attribute("newInstanceDefaultFieldValue"); bool isReadOnly = isReadOnlyAttribute != null && (bool) isReadOnlyAttribute; int groupByPriority = groupByPriorityAttribute != null ? (int)groupByPriorityAttribute : 0; XAttribute defaultValueAttribute = element.Attribute("defaultValue"); XAttribute foreignKeyReferenceTypeNameAttribute = element.Attribute("foreignKeyReferenceTypeName"); XElement formRenderingProfileElement = element.Element("FormRenderingProfile"); XElement treeOrderingProfileElement = element.Element("TreeOrderingProfile"); XElement validationFunctionMarkupsElement = element.Element("ValidationFunctionMarkups"); XElement dataUrlProfileElement = element.Element("DataUrlProfile"); Type instanceType = TypeManager.GetType(instanceTypeAttribute.Value); StoreFieldType storeType = StoreFieldType.Deserialize(storeTypeAttribute.Value); var dataFieldDescriptor = new DataFieldDescriptor(id, name, storeType, instanceType, inherited) { IsNullable = isNullable, Position = position, GroupByPriority = groupByPriority, IsReadOnly = isReadOnly }; if (newInstanceDefaultFieldValueAttribute != null) { dataFieldDescriptor.NewInstanceDefaultFieldValue = newInstanceDefaultFieldValueAttribute.Value; } if (defaultValueAttribute != null) { DefaultValue defaultValue = DefaultValue.Deserialize(defaultValueAttribute.Value); dataFieldDescriptor.DefaultValue = defaultValue; } if (foreignKeyReferenceTypeNameAttribute != null) { string typeName = foreignKeyReferenceTypeNameAttribute.Value; typeName = TypeManager.FixLegasyTypeName(typeName); dataFieldDescriptor.ForeignKeyReferenceTypeName = typeName; } if (formRenderingProfileElement != null) { XAttribute labelAttribute = formRenderingProfileElement.Attribute("label"); XAttribute helpTextAttribute = formRenderingProfileElement.Attribute("helpText"); XAttribute widgetFunctionMarkupAttribute = formRenderingProfileElement.Attribute("widgetFunctionMarkup"); var dataFieldFormRenderingProfile = new DataFieldFormRenderingProfile(); if (labelAttribute != null) { dataFieldFormRenderingProfile.Label = labelAttribute.Value; } if (helpTextAttribute != null) { dataFieldFormRenderingProfile.HelpText = helpTextAttribute.Value; } if (widgetFunctionMarkupAttribute != null) { dataFieldFormRenderingProfile.WidgetFunctionMarkup = widgetFunctionMarkupAttribute.Value; } dataFieldDescriptor.FormRenderingProfile = dataFieldFormRenderingProfile; } if (dataUrlProfileElement != null) { int order = (int)dataUrlProfileElement.GetRequiredAttribute("Order"); var formatStr = (string)dataUrlProfileElement.Attribute("Format"); DataUrlSegmentFormat? format = null; if (formatStr != null) { format = (DataUrlSegmentFormat) Enum.Parse(typeof(DataUrlSegmentFormat), formatStr); } dataFieldDescriptor.DataUrlProfile = new DataUrlProfile {Order = order, Format = format}; } if (treeOrderingProfileElement != null) { int? orderPriority = (int?)treeOrderingProfileElement.Attribute("orderPriority"); bool orderDescending = (bool)treeOrderingProfileElement.Attribute("orderDescending"); dataFieldDescriptor.TreeOrderingProfile = new DataFieldTreeOrderingProfile { OrderPriority = orderPriority, OrderDescending = orderDescending }; } dataFieldDescriptor.ValidationFunctionMarkup = new List<string>(); if (validationFunctionMarkupsElement != null) { foreach (XElement validationFunctionMarkupElement in validationFunctionMarkupsElement.Elements("ValidationFunctionMarkup")) { string markup = validationFunctionMarkupElement.GetRequiredAttributeValue("markup"); dataFieldDescriptor.ValidationFunctionMarkup.Add(markup); } } return dataFieldDescriptor; }
/// <summary> /// Parses the entity set /// </summary> /// <param name="entitySetElement">the entityset element to parse</param> /// <returns>the entityset presentation in the entity model schema</returns> protected virtual EntitySet ParseEntitySet(XElement entitySetElement) { string entitySetName = entitySetElement.GetRequiredAttributeValue("Name"); string entityTypeNamespace = this.ParseEdmTypeName(entitySetElement.GetRequiredAttributeValue("EntityType"))[0]; string entityTypeName = this.ParseEdmTypeName(entitySetElement.GetRequiredAttributeValue("EntityType"))[1]; var entitySet = new EntitySet(entitySetName, new EntityTypeReference(entityTypeNamespace, entityTypeName)); this.ParseAnnotations(entitySet, entitySetElement); return entitySet; }
private EnumType ParseEnumType(XElement enumTypeElement) { string name = enumTypeElement.GetRequiredAttributeValue("Name"); string underlyingTypeString = enumTypeElement.GetOptionalAttributeValue("UnderlyingType", null); Type underlyingType = null; if (underlyingTypeString != null) { string underlyingTypeName = this.ParseEdmTypeName(underlyingTypeString)[1]; underlyingType = Type.GetType("System." + underlyingTypeName); } var isFlagsString = enumTypeElement.Attribute("IsFlags"); var enumType = new EnumType(this.CurrentNamespace, name) { IsFlags = isFlagsString == null ? (bool?)null : bool.Parse(isFlagsString.Value), UnderlyingType = underlyingType }; foreach (var memberElement in enumTypeElement.Elements().Where(el => this.IsXsdlElement(el, "Member"))) { enumType.Members.Add(this.ParseEnumMember(memberElement)); } this.ParseAnnotations(enumType, enumTypeElement); return enumType; }
internal static DataTypeDescriptor FromXml(XElement element, bool inheritedFieldsIncluded) { Verify.ArgumentNotNull(element, "element"); if (element.Name != "DataTypeDescriptor") throw new ArgumentException("The xml is not correctly formatted."); Guid dataTypeId = (Guid) element.GetRequiredAttribute("dataTypeId"); string name = element.GetRequiredAttributeValue("name"); string @namespace = element.GetRequiredAttributeValue("namespace"); bool isCodeGenerated = (bool) element.GetRequiredAttribute("isCodeGenerated"); XAttribute cachableAttribute = element.Attribute("cachable"); XAttribute buildNewHandlerTypeNameAttribute = element.Attribute("buildNewHandlerTypeName"); XElement dataAssociationsElement = element.GetRequiredElement("DataAssociations"); XElement dataScopesElement = element.GetRequiredElement("DataScopes"); XElement keyPropertyNamesElement = element.GetRequiredElement("KeyPropertyNames"); XElement versionKeyPropertyNamesElement = element.Element("VersionKeyPropertyNames"); XElement superInterfacesElement = element.GetRequiredElement("SuperInterfaces"); XElement fieldsElement = element.GetRequiredElement("Fields"); XElement indexesElement = element.Element("Indexes"); XAttribute titleAttribute = element.Attribute("title"); XAttribute labelFieldNameAttribute = element.Attribute("labelFieldName"); XAttribute internalUrlPrefixAttribute = element.Attribute("internalUrlPrefix"); string typeManagerTypeName = (string) element.Attribute("typeManagerTypeName"); bool cachable = cachableAttribute != null && (bool)cachableAttribute; var dataTypeDescriptor = new DataTypeDescriptor(dataTypeId, @namespace, name, isCodeGenerated) { Cachable = cachable }; if (titleAttribute != null) dataTypeDescriptor.Title = titleAttribute.Value; if (labelFieldNameAttribute != null) dataTypeDescriptor.LabelFieldName = labelFieldNameAttribute.Value; if (internalUrlPrefixAttribute != null) dataTypeDescriptor.InternalUrlPrefix = internalUrlPrefixAttribute.Value; if (typeManagerTypeName != null) { typeManagerTypeName = TypeManager.FixLegasyTypeName(typeManagerTypeName); dataTypeDescriptor.TypeManagerTypeName = typeManagerTypeName; } if (buildNewHandlerTypeNameAttribute != null) dataTypeDescriptor.BuildNewHandlerTypeName = buildNewHandlerTypeNameAttribute.Value; foreach (XElement elm in dataAssociationsElement.Elements()) { var dataTypeAssociationDescriptor = DataTypeAssociationDescriptor.FromXml(elm); dataTypeDescriptor.DataAssociations.Add(dataTypeAssociationDescriptor); } foreach (XElement elm in dataScopesElement.Elements("DataScopeIdentifier")) { string dataScopeName = elm.GetRequiredAttributeValue("name"); if (DataScopeIdentifier.IsLegasyDataScope(dataScopeName)) { Log.LogWarning(LogTitle, "Ignored legacy data scope '{0}' on type '{1}.{2}' while deserializing DataTypeDescriptor. The '{0}' data scope is no longer supported.".FormatWith(dataScopeName, @namespace, name)); continue; } DataScopeIdentifier dataScopeIdentifier = DataScopeIdentifier.Deserialize(dataScopeName); dataTypeDescriptor.DataScopes.Add(dataScopeIdentifier); } foreach (XElement elm in superInterfacesElement.Elements("SuperInterface")) { string superInterfaceTypeName = elm.GetRequiredAttributeValue("type"); if (superInterfaceTypeName.StartsWith("Composite.Data.ProcessControlled.IDeleteControlled")) { Log.LogWarning(LogTitle, $"Ignored legacy super interface '{superInterfaceTypeName}' on type '{@namespace}.{name}' while deserializing DataTypeDescriptor. This super interface is no longer supported."); continue; } Type superInterface; try { superInterface = TypeManager.GetType(superInterfaceTypeName); } catch (Exception ex) { throw XmlConfigurationExtensionMethods.GetConfigurationException($"Failed to load super interface '{superInterfaceTypeName}'", ex, elm); } dataTypeDescriptor.AddSuperInterface(superInterface, !inheritedFieldsIncluded); } foreach (XElement elm in fieldsElement.Elements()) { var dataFieldDescriptor = DataFieldDescriptor.FromXml(elm); try { dataTypeDescriptor.Fields.Add(dataFieldDescriptor); } catch (Exception ex) { throw XmlConfigurationExtensionMethods.GetConfigurationException("Failed to add a data field: " + ex.Message, ex, elm); } } foreach (XElement elm in keyPropertyNamesElement.Elements("KeyPropertyName")) { var propertyName = elm.GetRequiredAttributeValue("name"); bool isDefinedOnSuperInterface = dataTypeDescriptor.SuperInterfaces.Any(f => f.GetProperty(propertyName) != null); if (!isDefinedOnSuperInterface) { dataTypeDescriptor.KeyPropertyNames.Add(propertyName); } } if (versionKeyPropertyNamesElement != null) { foreach (XElement elm in versionKeyPropertyNamesElement.Elements("VersionKeyPropertyName")) { var propertyName = elm.GetRequiredAttributeValue("name"); dataTypeDescriptor.VersionKeyPropertyNames.Add(propertyName); } } if (indexesElement != null) { dataTypeDescriptor.Indexes = indexesElement.Elements("Index").Select(DataTypeIndex.FromXml).ToList(); } // Loading field rendering profiles for static data types if (!isCodeGenerated && typeManagerTypeName != null) { Type type = Type.GetType(typeManagerTypeName); if (type != null) { foreach (var fieldDescriptor in dataTypeDescriptor.Fields) { var property = type.GetProperty(fieldDescriptor.Name); if (property != null) { var formRenderingProfile = DynamicTypeReflectionFacade.GetFormRenderingProfile(property); if (formRenderingProfile != null) { fieldDescriptor.FormRenderingProfile = formRenderingProfile; } } } } } return dataTypeDescriptor; }
/// <summary> /// Parses a function element /// </summary> /// <param name="functionElement">the XElement to represent a Function</param> /// <returns>the Function representation in entity data model</returns> protected virtual Function ParseFunction(XElement functionElement) { string name = functionElement.GetRequiredAttributeValue("Name"); var function = new Function(this.CurrentNamespace, name); string returnTypeName = functionElement.GetOptionalAttributeValue("ReturnType", null); if (returnTypeName != null) { bool isNullable = XmlConvert.ToBoolean(functionElement.GetOptionalAttributeValue("Nullable", "true")); function.ReturnType = this.ParseType(returnTypeName, isNullable, null); } var returnTypeElement = functionElement.Elements().SingleOrDefault(el => this.IsXsdlElement(el, "ReturnType")); if (returnTypeElement != null) { returnTypeName = returnTypeElement.GetOptionalAttributeValue("Type", null); bool isNullable = XmlConvert.ToBoolean(returnTypeElement.GetOptionalAttributeValue("Nullable", "true")); if (returnTypeName != null) { function.ReturnType = this.ParseType(returnTypeName, isNullable, returnTypeElement.Attributes()); } else { function.ReturnType = this.ParseType(returnTypeElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName))); } } foreach (var parameterElement in functionElement.Elements().Where(el => this.IsXsdlElement(el, "Parameter"))) { function.Parameters.Add(this.ParseFunctionParameter(parameterElement)); } this.ParseAnnotations(function, functionElement); return function; }