/// <summary> /// Initializes inner controls. /// </summary> private void InitializeControl() { FieldLabel.Text = ResHelper.LocalizeString(FieldInfo.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver)); AttributeDropDownList.Items.Add(new ListItem()); foreach (EntityAttributeModel attributeModel in UserProfileModel.Items) { EntityAttributeValueConverterBase attributeValueConverter = AttributeValueConverterFactory.CreateConverter(attributeModel); if (attributeValueConverter != null && attributeValueConverter.IsCompatibleWithFormField(FieldInfo)) { ListItem item = new ListItem { Value = String.Format("{0}-{1}", GetAttributeTypeName(attributeModel), attributeModel.Name), Text = ResHelper.LocalizeString(attributeModel.DisplayName) }; AttributeDropDownList.Items.Add(item); } } if (SourceMappingItem != null) { EntityAttributeModel attributeModel = UserProfileModel.GetAttributeModel(SourceMappingItem.AttributeName); if (attributeModel != null) { AttributeDropDownList.SelectedValue = String.Format("{0}-{1}", GetAttributeTypeName(attributeModel), SourceMappingItem.AttributeName); } } }
/// <summary> /// Retrieves a display name of the specified Facebook user profile attribute, and returns it. /// </summary> /// <param name="attributeName">The Facebook user profile attribute name.</param> /// <returns>A display name of the specified Facebook user profile attribute, if found; otherwise, an empty string.</returns> protected string GetFacebookUserAttributeDisplayName(string attributeName) { EntityAttributeModel attributeModel = UserProfileModel.GetAttributeModel(attributeName); if (attributeModel == null) { return(String.Empty); } return(ResHelper.LocalizeString(attributeModel.DisplayName)); }
protected void AttributeRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { EntityAttributeModel attributeModel = e.Item.DataItem as EntityAttributeModel; MappingEditorItem control = e.Item.FindControl("MappingEditorItemControl") as MappingEditorItem; control.EntityModel = EntityModel; control.EntityAttributeModel = attributeModel; control.FormInfo = FormInfo; control.ConverterFactory = AttributeValueConverterFactory; control.SourceMappingItem = SourceMapping.GetItem(attributeModel.Name); control.Initialize(); MappingItems.Add(attributeModel.Name, control); }
/// <summary> /// Updates the mapping depending on user selection. /// </summary> /// <param name="mapping">The mapping to update.</param> public void UpdateMapping(EntityMapping mapping) { string value = AttributeDropDownList.SelectedValue; if (!String.IsNullOrEmpty(value)) { string[] tokens = value.Split('-'); if (tokens[0] == "Attribute" || tokens[0] == "RestrictedAttribute") { string attributeName = tokens[1]; EntityAttributeModel attributeModel = UserProfileModel.GetAttributeModel(attributeName); if (attributeModel != null) { mapping.Add(attributeModel, FieldInfo, FieldScope); } } } }
/// <summary> /// Gets the security type name of the specified attribute, and returns it. /// </summary> /// <param name="attributeModel">The attribute model.</param> /// <returns>The security type name of the specified attribute.</returns> private string GetAttributeTypeName(EntityAttributeModel attributeModel) { return(String.IsNullOrEmpty(attributeModel.FacebookPermissionScopeName) ? "Attribute" : "RestrictedAttribute"); }
private List <EntityModel> CreateDefaultEntities() { List <EntityModel> defaultEntList = new List <EntityModel>(); //Continue in attribute24 and relationship7 #region BlobFile_mb EntityModel blobFileEntity = new EntityModel(this); blobFileEntity.Name = "BlobFile_mb"; blobFileEntity.Attributes.Clear(); EntityAttributeModel attribute1 = new EntityAttributeModel(blobFileEntity); attribute1.Name = "blob_mb"; attribute1.AttributeType = AttributeType.BLOB; attribute1.AttributeInfo = new AttributeInfo(); blobFileEntity.Attributes.Add(attribute1); EntityRelationshipModel relationship1 = new EntityRelationshipModel(); relationship1.Name = "blobInfo_mb"; relationship1.InverseRelationshipName = "blobFile_mb"; relationship1.TargetTableName = "BlobInfo_mb"; relationship1.SupportMultipleRelationships = false; blobFileEntity.Relationships.Add(relationship1); EntityRelationshipModel relationship6 = new EntityRelationshipModel(); relationship6.Name = "blobInfoSmall_mb"; relationship6.InverseRelationshipName = "smallBlobFile_mb"; relationship6.TargetTableName = "BlobInfo_mb"; relationship6.SupportMultipleRelationships = false; blobFileEntity.Relationships.Add(relationship6); defaultEntList.Add(blobFileEntity); #endregion #region BlobInfo_mb EntityModel blobInfoEntity = new EntityModel(this); blobInfoEntity.Name = "BlobInfo_mb"; blobInfoEntity.Attributes.Clear(); EntityAttributeModel attribute2 = new EntityAttributeModel(blobInfoEntity); attribute2.Name = "blobStatus_mb"; attribute2.AttributeType = AttributeType.Integer16; attribute2.AttributeInfo = new AttributeInfoInteger(); blobInfoEntity.Attributes.Add(attribute2); EntityAttributeModel attribute3 = new EntityAttributeModel(blobInfoEntity); attribute3.Name = "errorMsg_mb"; attribute3.AttributeType = AttributeType.String; attribute3.AttributeInfo = new AttributeInfoString(); blobInfoEntity.Attributes.Add(attribute3); EntityAttributeModel attribute4 = new EntityAttributeModel(blobInfoEntity); attribute4.Name = "guid_mb"; attribute4.AttributeType = AttributeType.String; attribute4.AttributeInfo = new AttributeInfoString(); attribute4.AttributeInfo.IsIndexed = true; blobInfoEntity.Attributes.Add(attribute4); EntityAttributeModel attribute20 = new EntityAttributeModel(blobInfoEntity); attribute20.Name = "location_mb"; attribute20.AttributeType = AttributeType.String; attribute20.AttributeInfo = new AttributeInfoString(); blobInfoEntity.Attributes.Add(attribute20); EntityRelationshipModel relationship2 = new EntityRelationshipModel(); relationship2.Name = "blobFile_mb"; relationship2.InverseRelationshipName = "blobInfo_mb"; relationship2.TargetTableName = "BlobFile_mb"; relationship2.SupportMultipleRelationships = false; relationship2.DeletionRule = "Cascade"; blobInfoEntity.Relationships.Add(relationship2); EntityRelationshipModel relationship5 = new EntityRelationshipModel(); relationship5.Name = "smallBlobFile_mb"; relationship5.InverseRelationshipName = "blobInfoSmall_mb"; relationship5.TargetTableName = "BlobFile_mb"; relationship5.SupportMultipleRelationships = false; relationship5.DeletionRule = "Cascade"; blobInfoEntity.Relationships.Add(relationship5); defaultEntList.Add(blobInfoEntity); #endregion #region ConflictError_mb EntityModel conflictErrorEntity = new EntityModel(this); conflictErrorEntity.Name = "ConflictError_mb"; conflictErrorEntity.Attributes.Clear(); EntityAttributeModel attribute5 = new EntityAttributeModel(conflictErrorEntity); attribute5.Name = "entityGuid_mb"; attribute5.AttributeType = AttributeType.String; attribute5.AttributeInfo = new AttributeInfoString(); attribute5.AttributeInfo.IsIndexed = true; conflictErrorEntity.Attributes.Add(attribute5); EntityAttributeModel attribute6 = new EntityAttributeModel(conflictErrorEntity); attribute6.Name = "entityKind_mb"; attribute6.AttributeType = AttributeType.String; attribute6.AttributeInfo = new AttributeInfoString(); attribute6.AttributeInfo.IsIndexed = true; conflictErrorEntity.Attributes.Add(attribute6); EntityAttributeModel attribute7 = new EntityAttributeModel(conflictErrorEntity); attribute7.Name = "modifiedFields_mb"; attribute7.AttributeType = AttributeType.String; attribute7.AttributeInfo = new AttributeInfoString(); conflictErrorEntity.Attributes.Add(attribute7); defaultEntList.Add(conflictErrorEntity); #endregion #region DeviceNotification_mb EntityModel deviceNotificationEntity = new EntityModel(this); deviceNotificationEntity.Name = "DeviceNotification_mb"; deviceNotificationEntity.Attributes.Clear(); EntityAttributeModel attribute8 = new EntityAttributeModel(deviceNotificationEntity); attribute8.Name = "deviceId_mb"; attribute8.AttributeType = AttributeType.String; attribute8.AttributeInfo = new AttributeInfoString(); deviceNotificationEntity.Attributes.Add(attribute8); EntityAttributeModel attribute9 = new EntityAttributeModel(deviceNotificationEntity); attribute9.Name = "isNewToken_mb"; attribute9.AttributeType = AttributeType.Boolean; attribute9.AttributeInfo = new AttributeInfo(); deviceNotificationEntity.Attributes.Add(attribute9); EntityAttributeModel attribute10 = new EntityAttributeModel(deviceNotificationEntity); attribute10.Name = "token_mb"; attribute10.AttributeType = AttributeType.String; attribute10.AttributeInfo = new AttributeInfoString(); deviceNotificationEntity.Attributes.Add(attribute10); defaultEntList.Add(deviceNotificationEntity); #endregion #region DownloadSyncChunk_mb EntityModel downloadSyncChunkEntity = new EntityModel(this); downloadSyncChunkEntity.Name = "DownloadSyncChunk_mb"; downloadSyncChunkEntity.Attributes.Clear(); EntityAttributeModel attribute11 = new EntityAttributeModel(downloadSyncChunkEntity); attribute11.Name = "downloadId_mb"; attribute11.AttributeType = AttributeType.Integer64; attribute11.AttributeInfo = new AttributeInfoInteger(); attribute11.AttributeInfo.IsIndexed = true; downloadSyncChunkEntity.Attributes.Add(attribute11); EntityAttributeModel attribute12 = new EntityAttributeModel(downloadSyncChunkEntity); attribute12.Name = "guid_mb"; attribute12.AttributeType = AttributeType.String; attribute12.AttributeInfo = new AttributeInfoString(); attribute12.AttributeInfo.IsIndexed = true; downloadSyncChunkEntity.Attributes.Add(attribute12); EntityAttributeModel attribute13 = new EntityAttributeModel(downloadSyncChunkEntity); attribute13.Name = "jsonMessage_mb"; attribute13.AttributeType = AttributeType.BLOB; attribute13.AttributeInfo = new AttributeInfoString(); downloadSyncChunkEntity.Attributes.Add(attribute13); EntityAttributeModel attribute23 = new EntityAttributeModel(downloadSyncChunkEntity); attribute23.Name = "chunkOrder"; attribute23.AttributeType = AttributeType.Integer32; attribute23.AttributeInfo = new AttributeInfoInteger(); downloadSyncChunkEntity.Attributes.Add(attribute23); EntityRelationshipModel relationship3 = new EntityRelationshipModel(); relationship3.Name = "downloadSyncHeader_mb"; relationship3.InverseRelationshipName = "downloadSyncChunk_mb"; relationship3.TargetTableName = "DownloadSyncHeader_mb"; relationship3.SupportMultipleRelationships = false; downloadSyncChunkEntity.Relationships.Add(relationship3); defaultEntList.Add(downloadSyncChunkEntity); #endregion #region DownloadSyncHeader_mb EntityModel downloadSyncHeaderEntity = new EntityModel(this); downloadSyncHeaderEntity.Name = "DownloadSyncHeader_mb"; downloadSyncHeaderEntity.Attributes.Clear(); EntityAttributeModel attribute14 = new EntityAttributeModel(downloadSyncHeaderEntity); attribute14.Name = "downloadedEntities_mb"; attribute14.AttributeType = AttributeType.Integer32; attribute14.AttributeInfo = new AttributeInfoInteger(); downloadSyncHeaderEntity.Attributes.Add(attribute14); EntityAttributeModel attribute15 = new EntityAttributeModel(downloadSyncHeaderEntity); attribute15.Name = "downloadId_mb"; attribute15.AttributeType = AttributeType.Integer64; attribute15.AttributeInfo = new AttributeInfoInteger(); downloadSyncHeaderEntity.Attributes.Add(attribute15); EntityAttributeModel attribute16 = new EntityAttributeModel(downloadSyncHeaderEntity); attribute16.Name = "numRecs_mb"; attribute16.AttributeType = AttributeType.Integer32; attribute16.AttributeInfo = new AttributeInfoInteger(); downloadSyncHeaderEntity.Attributes.Add(attribute16); EntityAttributeModel attribute17 = new EntityAttributeModel(downloadSyncHeaderEntity); attribute17.Name = "sourceTable_mb"; attribute17.AttributeType = AttributeType.String; attribute17.AttributeInfo = new AttributeInfoString(); downloadSyncHeaderEntity.Attributes.Add(attribute17); EntityAttributeModel attribute18 = new EntityAttributeModel(downloadSyncHeaderEntity); attribute18.Name = "syncDate_mb"; attribute18.AttributeType = AttributeType.Double; attribute18.AttributeInfo = new AttributeInfoDouble(); downloadSyncHeaderEntity.Attributes.Add(attribute18); EntityAttributeModel attribute19 = new EntityAttributeModel(downloadSyncHeaderEntity); attribute19.Name = "syncOrder_mb"; attribute19.AttributeType = AttributeType.Integer32; attribute19.AttributeInfo = new AttributeInfoInteger(); downloadSyncHeaderEntity.Attributes.Add(attribute19); EntityAttributeModel attribute22 = new EntityAttributeModel(downloadSyncHeaderEntity); attribute22.Name = "guid_mb"; attribute22.AttributeType = AttributeType.String; attribute22.AttributeInfo = new AttributeInfoString(); attribute22.AttributeInfo.IsIndexed = true; downloadSyncHeaderEntity.Attributes.Add(attribute22); attribute22 = new EntityAttributeModel(downloadSyncHeaderEntity); attribute22.Name = "syncType_mb"; attribute22.AttributeType = AttributeType.Integer32; attribute22.AttributeInfo = new AttributeInfoInteger(); attribute22.AttributeInfo.IsIndexed = true; downloadSyncHeaderEntity.Attributes.Add(attribute22); EntityRelationshipModel relationship4 = new EntityRelationshipModel(); relationship4.Name = "downloadSyncChunk_mb"; relationship4.InverseRelationshipName = "downloadSyncHeader_mb"; relationship4.TargetTableName = "DownloadSyncChunk_mb"; relationship4.SupportMultipleRelationships = true; downloadSyncHeaderEntity.Relationships.Add(relationship4); defaultEntList.Add(downloadSyncHeaderEntity); #endregion #region LastSync_mb EntityModel lastSyncEntity = new EntityModel(this); lastSyncEntity.Name = "LastSync_mb"; lastSyncEntity.Attributes.Clear(); EntityAttributeModel attribute21 = new EntityAttributeModel(lastSyncEntity); attribute21.Name = "serverDate_mb"; attribute21.AttributeType = AttributeType.Double; attribute21.AttributeInfo = new AttributeInfoDouble(); lastSyncEntity.Attributes.Add(attribute21); defaultEntList.Add(lastSyncEntity); #endregion return(defaultEntList); }
/// <summary> /// Create a new dynamic entity strongly typed class base on a xsd document /// </summary> /// <param name="entityDefinition">Entity Definition to be parsed</param> /// <param name="timestamp">timestamp of the last version of the XSD definition</param> /// <returns>return the dynamic entity generate type base on the xsd.</returns> public static Type CreateTypeFromEntityDefinition(DatabaseModel ParentModel, EntityModel entityDefinition, DateTime timestamp) { lock (currentTypes) { string entityName = entityDefinition.Name; //System.Xml.Schema.XmlSchemaSet x; //x = new System.Xml.Schema.XmlSchemaSet(); entityName = entityName.Replace(".", "_"); Type currentType = DynamicEntityTypeManager.GetType(entityName); if (currentType == null) { if (moduleBuilder == null) { InitData(ParentModel); } TypeBuilder typeBuilder = GetTypeBuilder(entityName); Type[] constructorArgTypes = new Type[] { }; ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, constructorArgTypes); Type[] baseConstructorArgTypes = new Type[] { typeof(string) }; ILGenerator ilGenerator = constructorBuilder.GetILGenerator(); ConstructorInfo baseConstructor = typeof(DynamicEntityBase).GetConstructor(baseConstructorArgTypes); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldstr, entityDefinition.Name); ilGenerator.Emit(OpCodes.Call, baseConstructor); ilGenerator.Emit(OpCodes.Ret); // add copy constructor /* constructorArgTypes = new Type[] { typeof(DynamicEntityBase) }; * ConstructorBuilder constructorBuilder2 = typeBuilder.DefineConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, constructorArgTypes); * Type[] baseConstructorArgTypes2 = new Type[] { typeof(DynamicEntityBase) }; * ConstructorInfo baseConstructor2 = typeof(DynamicEntityBase).GetConstructor(baseConstructorArgTypes2); * ilGenerator = constructorBuilder2.GetILGenerator(); * ilGenerator.Emit(OpCodes.Ldarg_0); * ilGenerator.Emit(OpCodes.Ldarg_1); * ilGenerator.Emit(OpCodes.Call, baseConstructor2); * ilGenerator.Emit(OpCodes.Nop); * ilGenerator.Emit(OpCodes.Nop); * ilGenerator.Emit(OpCodes.Nop); * ilGenerator.Emit(OpCodes.Ret);*/ foreach (EntityAttributeModel element in entityDefinition.Attributes) { string propName = element.Name; if (propertNameRegex.IsMatch(propName, 0)) { // gets the type code of the property, and ensure that they don't have the namespace to basic schema definition Type propType = DynamicEntityTypeManager.GetClrTypeFromPropertyType(element.AttributeType); CreateProperty(typeBuilder, propName, propType, element.AttributeInfo.IsPrimaryKey, element.AttributeInfo.IsPrimaryKey, null); } else { throw new ArgumentException( @"Each property name must be alphanumeric and start with character."); } } // temporary type info for forward reference currentTypes[entityName] = new DynamicTypeInfo(entityName, timestamp, typeBuilder); foreach (EntityRelationshipModel relationship in entityDefinition.Relationships) { string propName = relationship.Name; if (propertNameRegex.IsMatch(propName, 0)) { // gets the type code of the property, and ensure that they don't have the namespace to basic schema definition Type relationshipType = DynamicEntityTypeManager.GetType(relationship.TargetTableName); EntityModel targetEntityDefinition = ParentModel.Entities.FirstOrDefault(entity => entity.Name == relationship.TargetTableName); bool isBuildChild = false; if (relationshipType == null) { if (relationship.TargetTableName == entityDefinition.Name) { // reference this same type being build relationshipType = typeBuilder; isBuildChild = false; } else { // create the type look for the model entity definition relationshipType = CreateTypeFromEntityDefinition(ParentModel, targetEntityDefinition, DateTime.UtcNow); isBuildChild = true; } } Type propType = null; List <CustomAttributeBuilder> additionalAttributes = new List <CustomAttributeBuilder>(); if (relationship.SupportMultipleRelationships) { propType = typeof(ICollection <>).MakeGenericType(relationshipType); if (!string.IsNullOrEmpty(relationship.InverseRelationshipName)) { EntityRelationshipModel inverseRelation = targetEntityDefinition.Relationships.FirstOrDefault(rel => rel.Name == relationship.InverseRelationshipName); ConstructorInfo attributeConstructor = null; CustomAttributeBuilder attributeBuilder = null; if (inverseRelation != null) { attributeConstructor = typeof(System.ComponentModel.DataAnnotations.Schema.InversePropertyAttribute).GetConstructor(new Type[] { typeof(string) }); attributeBuilder = new CustomAttributeBuilder(attributeConstructor, new object[] { relationship.InverseRelationshipName }, new FieldInfo[] { }, new object[] { }); additionalAttributes.Add(attributeBuilder); } } } else { propType = relationshipType; if (!string.IsNullOrEmpty(relationship.InverseRelationshipName)) { EntityRelationshipModel inverseRelation = targetEntityDefinition.Relationships.FirstOrDefault(rel => rel.Name == relationship.InverseRelationshipName); ConstructorInfo attributeConstructor = null; CustomAttributeBuilder attributeBuilder = null; if (inverseRelation != null) { attributeConstructor = typeof(System.ComponentModel.DataAnnotations.Schema.InversePropertyAttribute).GetConstructor(new Type[] { typeof(string) }); attributeBuilder = new CustomAttributeBuilder(attributeConstructor, new object[] { relationship.InverseRelationshipName }, new FieldInfo[] { }, new object[] { }); additionalAttributes.Add(attributeBuilder); } //create foreign key field EntityAttributeModel targetKey = targetEntityDefinition.Attributes.FirstOrDefault(a => a.AttributeInfo.IsPrimaryKey); if (targetKey != null) { string fkFieldName = relationship.Name + "_FK"; attributeConstructor = typeof(System.ComponentModel.DataAnnotations.Schema.ForeignKeyAttribute).GetConstructor(new Type[] { typeof(string) }); if (inverseRelation.SupportMultipleRelationships) { CreateProperty(typeBuilder, fkFieldName, DynamicEntityTypeManager.GetClrTypeFromPropertyType(targetKey.AttributeType), false, true, null); attributeBuilder = new CustomAttributeBuilder(attributeConstructor, new object[] { fkFieldName }, new FieldInfo[] { }, new object[] { }); } else { attributeBuilder = new CustomAttributeBuilder(attributeConstructor, new object[] { targetKey.Name }, new FieldInfo[] { }, new object[] { }); } additionalAttributes.Add(attributeBuilder); } } } if (propType == null) { throw new NullReferenceException(string.Format("The relationship {0} type can't be determinate", relationship.Name)); } CreateProperty(typeBuilder, propName, propType, false, !isBuildChild, additionalAttributes); } else { throw new ArgumentException( @"Each property name must be alphanumeric and start with character."); } } Type newType = typeBuilder.CreateType(); //currentTypes[resourceFriendlyName] = newType; currentTypes[entityName] = new DynamicTypeInfo(entityName, timestamp, newType); //assemblyBuilder.Save("BLTypeManagerTest.dll"); return(newType); } return(currentType); } }
/// <summary> /// Gets the security type name of the specified attribute, and returns it. /// </summary> /// <param name="attributeModel">The attribute model.</param> /// <returns>The security type name of the specified attribute.</returns> private string GetAttributeTypeName(EntityAttributeModel attributeModel) { return (String.IsNullOrEmpty(attributeModel.FacebookPermissionScopeName) ? "Attribute" : "RestrictedAttribute"); }