public IdentityRole(Entity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Entity = entity; KeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleKey); NameProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleName) ?? ProjectUtilities.FindNameProperty(entity); UsersProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleUsers); ClaimsProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleClaims); LoadByKeyMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadRoleByKey); if (LoadByKeyMethod != null) { LoadByKeyMethodName = LoadByKeyMethod.Name; } else if (KeyProperty != null && Entity.LoadByKeyMethod != null) { LoadByKeyMethodName = Entity.LoadByKeyMethod.Name; } else { LoadByKeyMethodName = "LoadByEntityKey"; } LoadByNameMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadRoleByName) ?? Entity.LoadByCollectionKeyMethod; LoadAllMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadAllRoles) ?? Entity.LoadAllMethod; }
public IdentityRoleClaim(Entity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Entity = entity; KeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleClaimKey); ValueProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleClaimClaimValue); TypeProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleClaimClaimType); ValueTypeProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleClaimClaimValueType); IssuerProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleClaimClaimIssuer); OriginalIssuerProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleClaimClaimOriginalIssuer); RoleProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.RoleClaimRole); LoadByRoleMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadRoleClaimsByRole); if (LoadByRoleMethod == null && RoleProperty != null && RoleProperty.ProjectEntity != null) { LoadByRoleMethod = entity.LoadMethods.FirstOrDefault( method => method.Parameters.Count == 1 && method.Parameters[0].ClrFullTypeName == RoleProperty.ProjectEntity.ClrFullTypeName); } }
private void CreateUserMethods(Entity userEntity, Entity loginEntity) { if (userEntity == null) { throw new ArgumentNullException("userEntity"); } // LoadByUserLoginInfo if (loginEntity != null) { var loginsProperty = ProjectUtilities.FindByPropertyType(userEntity, PropertyType.UserLogins); var providerKeyProperty = ProjectUtilities.FindByPropertyType(loginEntity, PropertyType.UserLoginProviderKey); var providerNameProperty = ProjectUtilities.FindByPropertyType(loginEntity, PropertyType.UserLoginProviderName); if (loginsProperty != null && providerKeyProperty != null) { Method loadByProviderKeyMethod = ProjectUtilities.FindByMethodType(userEntity, MethodType.LoadUserByUserLoginInfo); if (loadByProviderKeyMethod == null) { loadByProviderKeyMethod = new Method(); loadByProviderKeyMethod.Name = "LoadByUserLoginInfo"; loadByProviderKeyMethod.SetAttributeValue("", "methodType", Constants.NamespaceUri, MethodType.LoadUserByUserLoginInfo); userEntity.Methods.Add(loadByProviderKeyMethod); Body body = new Body(); if (providerNameProperty != null) { body.Text = string.Format("LOADONE(string providerKey, string providerName) WHERE {0}.{1} = @providerKey AND {0}.{2} = @providerName", loginsProperty.Name, providerKeyProperty.Name, providerNameProperty.Name); } else { body.Text = string.Format("LOADONE(string providerKey) WHERE {0}.{1} = @providerKey", loginsProperty.Name, providerKeyProperty.Name); } loadByProviderKeyMethod.Bodies.Add(body); } } } // LoadUserByEmail var emailProperty = ProjectUtilities.FindByPropertyType(userEntity, PropertyType.UserEmail); if (emailProperty != null && !emailProperty.IsCollectionKey) { Method loadByEmailMethod = ProjectUtilities.FindByMethodType(userEntity, MethodType.LoadUserByEmail); if (loadByEmailMethod == null) { loadByEmailMethod = new Method(); loadByEmailMethod.Name = "LoadByEmail"; loadByEmailMethod.SetAttributeValue("", "methodType", Constants.NamespaceUri, MethodType.LoadUserByEmail); userEntity.Methods.Add(loadByEmailMethod); Body body = new Body(); body.Text = string.Format("LOADONE({0}) WHERE {0} = @{0}", emailProperty.Name); loadByEmailMethod.Bodies.Add(body); } } }
//private Entity CreateUserRoleEntity() //{ // Entity entity = GetOrCreateEntity(EntityType.UserRole, textBoxUserRoleEntityName.Text, comboBoxNamespace.Text); // foreach (var typeProperty in TypeProperty.UserRoleProperties) // { // if (!MustGenerate(EntityType.User, typeProperty)) // continue; // Property property = GetOrCreateProperty(entity, typeProperty); // property.IsKey = true; // } // return entity; //} private Entity CreateUserClaimsEntity() { Entity entity = GetOrCreateEntity(EntityType.UserClaim, textBoxClaimsEntityName.Text, comboBoxNamespace.Text); foreach (var typeProperty in TypeProperty.ClaimsProperties) { if (!MustGenerate(EntityType.UserClaim, typeProperty)) { continue; } Property property = GetOrCreateProperty(entity, typeProperty); if (typeProperty.IdentityPropertyType == PropertyType.UserClaimKey) { property.IsKey = true; } } Method deleteMethod = ProjectUtilities.FindByMethodType(entity, MethodType.DeleteUserClaimsByClaim); if (deleteMethod == null) { deleteMethod = new Method(); deleteMethod.Name = "DeleteByClaim"; deleteMethod.SetAttributeValue("", "methodType", Constants.NamespaceUri, MethodType.DeleteUserClaimsByClaim); entity.Methods.Add(deleteMethod); Body body = new Body(); string typePropertyName = ProjectUtilities.FindByPropertyType(entity, PropertyType.UserClaimType).Name; string valuePropertyName = ProjectUtilities.FindByPropertyType(entity, PropertyType.UserClaimValue).Name; body.Text = string.Format("DELETE({0}, {1}) WHERE {0} = @{0} AND {1} = @{1}", typePropertyName, valuePropertyName); deleteMethod.Bodies.Add(body); } Method loadMethod = ProjectUtilities.FindByMethodType(entity, MethodType.LoadUserClaimsByClaim); if (loadMethod == null) { deleteMethod = new Method(); deleteMethod.Name = "LoadByClaim"; deleteMethod.SetAttributeValue("", "methodType", Constants.NamespaceUri, MethodType.LoadUserClaimsByClaim); entity.Methods.Add(deleteMethod); Body body = new Body(); string typePropertyName = ProjectUtilities.FindByPropertyType(entity, PropertyType.UserClaimType).Name; string valuePropertyName = ProjectUtilities.FindByPropertyType(entity, PropertyType.UserClaimValue).Name; body.Text = string.Format("LOAD({0}, {1}) WHERE {0} = @{0} AND {1} = @{1}", typePropertyName, valuePropertyName); deleteMethod.Bodies.Add(body); } return(entity); }
public IdentityUser(Entity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Entity = entity; KeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserKey); UserNameProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserName) ?? ProjectUtilities.FindNameProperty(entity); NormalizedUserNameProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserNormalizedName) ?? UserNameProperty; CreationDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserCreationDate); EmailProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserEmail); EmailConfirmedProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserEmailConfirmed); PhoneNumberProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserPhoneNumber); PhoneNumberConfirmedProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserPhoneNumberConfirmed); PasswordProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserPassword); LastPasswordChangeDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLastPasswordChangeDate); FailedPasswordAttemptCountProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserFailedPasswordAttemptCount); FailedPasswordAttemptWindowStartProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserFailedPasswordAttemptWindowStart); LockoutEnabledProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLockoutEnabled); LockoutEndDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLockoutEndDate); LastProfileUpdateDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLastProfileUpdateDate); TwoFactorEnabledProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserTwoFactorEnabled); SecurityStampProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserSecurityStamp); RolesProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserRoles); ClaimsProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaims); LoginsProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserLogins); LoadByKeyMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByKey); if (LoadByKeyMethod != null) { LoadByKeyMethodName = LoadByKeyMethod.Name; } else if (KeyProperty != null && Entity.LoadByKeyMethod != null) { LoadByKeyMethod = Entity.LoadByKeyMethod; LoadByKeyMethodName = Entity.LoadByKeyMethod.Name; } else { LoadByKeyMethodName = "LoadByEntityKey"; } LoadByUserNameMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByUserName) ?? Entity.LoadByCollectionKeyMethod; LoadByEmailMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByEmail) ?? Entity.Methods.Find("LoadByEmail", StringComparison.OrdinalIgnoreCase) ?? (EmailProperty != null && EmailProperty.IsCollectionKey ? Entity.LoadByCollectionKeyMethod : null); LoadByUserLoginInfoMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByUserLoginInfo); LoadAllMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadAllUsers) ?? Entity.LoadAllMethod; DeleteMethodName = ProjectUtilities.FindByMethodType(Entity, MethodType.DeleteUser)?.Name ?? Entity.GetAttributeValue("deleteMethodName", Constants.NamespaceUri, (string)null) ?? "Delete"; }
private Entity CreateLoginsEntity() { Entity entity = GetOrCreateEntity(EntityType.UserLogin, textBoxUserLoginsEntityName.Text, comboBoxNamespace.Text); foreach (var typeProperty in TypeProperty.UserLoginProperties) { if (!MustGenerate(EntityType.UserLogin, typeProperty)) { continue; } Property property = GetOrCreateProperty(entity, typeProperty); if (typeProperty.IdentityPropertyType == PropertyType.UserLoginProviderKey || typeProperty.IdentityPropertyType == PropertyType.UserLoginProviderName || typeProperty.IdentityPropertyType == PropertyType.UserLoginUser) { property.AddUniqueConstraintName("ASP.NET_Identity"); } } Method deleteMethod = ProjectUtilities.FindByMethodType(entity, MethodType.DeleteUserLoginByUserLoginInfo); if (deleteMethod == null) { deleteMethod = new Method(); deleteMethod.Name = "DeleteByUserLoginInfo"; deleteMethod.SetAttributeValue("", "methodType", Constants.NamespaceUri, MethodType.DeleteUserLoginByUserLoginInfo); entity.Methods.Add(deleteMethod); Body body = new Body(); string userPropertyName = ProjectUtilities.FindByPropertyType(entity, PropertyType.UserLoginUser).Name; string providerKeyPropertyName = ProjectUtilities.FindByPropertyType(entity, PropertyType.UserLoginProviderKey).Name; Property userLoginProviderNameProperty = ProjectUtilities.FindByPropertyType(entity, PropertyType.UserLoginProviderName); string providerNamePropertyName = userLoginProviderNameProperty != null ? userLoginProviderNameProperty.Name : null; if (providerNamePropertyName != null) { body.Text = string.Format("DELETE({0}, {1}, {2}) WHERE {0} = @{0} AND {1} = @{1} AND {2} = @{2}", userPropertyName, providerKeyPropertyName, providerNamePropertyName); } else { body.Text = string.Format("DELETE({0}, {1}) WHERE {0} = @{0} AND {1} = @{1}", userPropertyName, providerKeyPropertyName); } deleteMethod.Bodies.Add(body); } return(entity); }
public IdentityUser(Entity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Entity = entity; KeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserKey); UserNameProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserName) ?? ProjectUtilities.FindNameProperty(entity); CreationDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.CreationDate); EmailProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.Email); EmailConfirmedProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.EmailConfirmed); PhoneNumberProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.PhoneNumber); PhoneNumberConfirmedProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.PhoneNumberConfirmed); PasswordProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.Password); LastPasswordChangeDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.LastPasswordChangeDate); FailedPasswordAttemptCountProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.FailedPasswordAttemptCount); FailedPasswordAttemptWindowStartProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.FailedPasswordAttemptWindowStart); LockoutEnabledProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.LockoutEnabled); LockoutEndDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.LockoutEndDate); LastProfileUpdateDateProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.LastProfileUpdateDate); TwoFactorEnabledProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.TwoFactorEnabled); SecurityStampProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.SecurityStamp); RolesProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.Roles); ClaimsProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.Claims); LoginsProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.Logins); LoadByKeyMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByKey); if (LoadByKeyMethod != null) { LoadByKeyMethodName = LoadByKeyMethod.Name; } else if (KeyProperty != null && Entity.LoadByKeyMethod != null) { LoadByKeyMethodName = Entity.LoadByKeyMethod.Name; } else { LoadByKeyMethodName = "LoadByEntityKey"; } LoadByUserNameMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByUserName) ?? Entity.LoadByCollectionKeyMethod; LoadByEmailMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByEmail); LoadByProviderKeyMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserByProviderKey); LoadAllMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadAll) ?? Entity.LoadAllMethod; }
public IdentityLogin(Entity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Entity = entity; KeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.LoginKey); ProviderKeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.LoginProviderKey); ProviderNameProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.LoginProviderName); UserProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.User); DeleteByUserAndProviderKeyMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.DeleteLogin); }
public IdentityClaim(Entity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Entity = entity; KeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.ClaimsKey); TypeProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.ClaimsType); ValueProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.ClaimsValue); ValueTypeProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.ClaimsValueType); IssuerProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.ClaimsIssuer); OriginalIssuerProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.ClaimsOriginalIssuer); UserProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.User); DeleteClaimMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.DeleteClaim); }
public IdentityUserClaim(Entity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Entity = entity; KeyProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaimKey); TypeProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaimType); ValueProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaimValue); ValueTypeProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaimValueType); IssuerProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaimIssuer); OriginalIssuerProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaimOriginalIssuer); UserProperty = ProjectUtilities.FindByPropertyType(Entity, PropertyType.UserClaimUser); DeleteClaimsMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.DeleteUserClaimsByClaim); LoadClaimsMethod = ProjectUtilities.FindByMethodType(Entity, MethodType.LoadUserClaimsByClaim); }
private Entity CreateLoginsEntity() { Entity entity = GetOrCreateEntity(EntityType.Login, textBoxExternalLoginsEntityName.Text, comboBoxNamespace.Text); foreach (var typeProperty in TypeProperty.ExternalLoginProperties) { if (!MustGenerate(EntityType.Login, typeProperty)) { continue; } Property property = GetOrCreateProperty(entity, typeProperty); if (typeProperty.IdentityPropertyType == PropertyType.UserKey) { property.IsKey = true; } } Method deleteMethod = ProjectUtilities.FindByMethodType(entity, MethodType.DeleteClaim); if (deleteMethod == null) { deleteMethod = new Method(); deleteMethod.Name = "DeleteByUserAndProviderKey"; deleteMethod.SetAttributeValue("", "methodType", Constants.NamespaceUri, MethodType.DeleteLogin); entity.Methods.Add(deleteMethod); Body body = new Body(); string userPropertyName = ProjectUtilities.FindByPropertyType(entity, PropertyType.User).Name; string providerKeyPropertyName = ProjectUtilities.FindByPropertyType(entity, PropertyType.LoginProviderKey).Name; body.Text = string.Format("DELETE({0}, {1}) WHERE {0} = @{0} AND {1} = @{1}", userPropertyName, providerKeyPropertyName); deleteMethod.Bodies.Add(body); } return(entity); }