Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        private void InitializeEntities()
        {
            Entity userEntity     = ProjectUtilities.FindByEntityType(_project, EntityType.User);
            Entity claimEntity    = ProjectUtilities.FindByEntityType(_project, EntityType.Claim);
            Entity loginEntity    = ProjectUtilities.FindByEntityType(_project, EntityType.Login);
            Entity roleEntity     = ProjectUtilities.FindByEntityType(_project, EntityType.Role);
            Entity userRoleEntity = ProjectUtilities.FindByEntityType(_project, EntityType.UserRole);
            var    entity         = userEntity ?? claimEntity ?? loginEntity ?? roleEntity ?? userRoleEntity;

            Property emailProperty       = userEntity == null ? null : ProjectUtilities.FindByPropertyType(userEntity, PropertyType.Email);
            Property phoneNumberProperty = userEntity == null ? null : ProjectUtilities.FindByPropertyType(userEntity, PropertyType.PhoneNumber);

            foreach (Namespace ns in _project.AllNamespaces)
            {
                comboBoxNamespace.Items.Add(ns.FullName);
            }

            // Set namespace
            if (entity != null)
            {
                comboBoxNamespace.Text = entity.Namespace;
            }
            else
            {
                comboBoxNamespace.Text = _project.DefaultNamespace;
            }

            // initialize checkbox
            checkBoxClaims.Checked         = claimEntity != null;
            checkBoxExternalLogins.Checked = loginEntity != null;
            checkBoxRole.Checked           = roleEntity != null;
            //checkBoxUserRole.Checked = userRoleEntity != null;
            checkBoxEmailUnique.Checked       = emailProperty != null && emailProperty.IsUnique;
            checkBoxPhoneNumberUnique.Checked = phoneNumberProperty != null && phoneNumberProperty.IsUnique;
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        public override void Initialize(Project project, Producer producer)
        {
            base.Initialize(project, producer);

            _codeDomProducer = project.Producers.GetProducerInstance <CodeDomProducer>();
            if (_codeDomProducer == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(EditorTargetDirectory))
            {
                EditorTargetDirectory = _codeDomProducer.EditorTargetDirectory;
            }

            _codeDomProducer.CodeDomProduction += CodeDomProducer_CodeDomProduction;


            Entity userEntity = ProjectUtilities.FindByEntityType(project, EntityType.User);

            if (userEntity != null)
            {
                _identityUser = new IdentityUser(userEntity);
            }

            Entity roleEntity = ProjectUtilities.FindByEntityType(project, EntityType.Role);

            if (roleEntity != null)
            {
                _identityRole = new IdentityRole(roleEntity);
            }

            Entity loginEntity = ProjectUtilities.FindByEntityType(project, EntityType.Login);

            if (loginEntity != null)
            {
                _identityLogin = new IdentityLogin(loginEntity);
            }

            Entity claimEntity = ProjectUtilities.FindByEntityType(project, EntityType.Claim);

            if (claimEntity != null)
            {
                _identityClaim = new IdentityClaim(claimEntity);
            }

            if (_identityUser != null)
            {
                _userStoreProducer = new UserStoreProducer(_codeDomProducer, this, _identityUser, _identityRole, _identityLogin, _identityClaim);
            }

            if (_identityRole != null)
            {
                _roleStoreProducer = new RoleStoreProducer(_codeDomProducer, this, _identityRole);
            }
        }
Esempio n. 6
0
        //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";
        }
Esempio n. 8
0
        private Property GetOrCreateProperty(Entity entity, TypeProperty typeProperty)
        {
            Property property = entity.Properties.Find(typeProperty.CanonicalName, StringComparison.OrdinalIgnoreCase);

            if (property == null)
            {
                property = ProjectUtilities.FindByPropertyType(entity, typeProperty.IdentityPropertyType);
                if (property != null)
                {
                    property.Name = typeProperty.CanonicalName;
                }
            }

            if (property == null)
            {
                property          = new Property();
                property.Name     = typeProperty.CanonicalName;
                property.TypeName = typeProperty.ExpectedType;
                if (typeProperty.ExpectedUIType != UIType.Unspecified)
                {
                    property.UIType = typeProperty.ExpectedUIType;
                }

                property.IsNullable = typeProperty.Nullable;

                if (!property.IsNullable && (
                        property.ClrFullTypeName == typeof(int).FullName ||
                        property.ClrFullTypeName == typeof(uint).FullName ||
                        property.ClrFullTypeName == typeof(short).FullName ||
                        property.ClrFullTypeName == typeof(ushort).FullName ||
                        property.ClrFullTypeName == typeof(long).FullName ||
                        property.ClrFullTypeName == typeof(ulong).FullName ||
                        property.ClrFullTypeName == typeof(byte).FullName ||
                        property.ClrFullTypeName == typeof(sbyte).FullName ||
                        property.ClrFullTypeName == typeof(float).FullName ||
                        property.ClrFullTypeName == typeof(decimal).FullName ||
                        property.ClrFullTypeName == typeof(double).FullName ||
                        property.ClrFullTypeName == typeof(DateTime).FullName ||
                        property.ClrFullTypeName == typeof(TimeSpan).FullName ||
                        property.ClrFullTypeName == typeof(DateTimeOffset).FullName ||
                        property.ClrFullTypeName == typeof(Guid).FullName ||
                        property.ClrFullTypeName == typeof(bool).FullName))
                {
                    property.MustUsePersistenceDefaultValue = false;
                }

                property.SetAttributeValue("", "propertyType", Constants.NamespaceUri, typeProperty.IdentityPropertyType);
                entity.Properties.Add(property);
            }

            return(property);
        }
Esempio n. 9
0
        public static void AddRelation(Entity fromEntity, PropertyType fromPropertyType, Entity toEntity, PropertyType toPropertyType, RelationType relationType)
        {
            if (fromEntity == null || toEntity == null)
            {
                return;
            }

            Property fromProperty = ProjectUtilities.FindByPropertyType(fromEntity, fromPropertyType);
            Property toProperty   = ProjectUtilities.FindByPropertyType(toEntity, toPropertyType);

            if (fromProperty == null || toProperty == null)
            {
                return;
            }

            switch (relationType)
            {
            case RelationType.OneToOne:
                fromProperty.TypeName = toEntity.ClrFullTypeName;
                toProperty.TypeName   = fromEntity.ClrFullTypeName;
                break;

            case RelationType.OneToMany:
                fromProperty.TypeName = toEntity.ClrFullTypeName;
                toProperty.TypeName   = fromEntity.Set.ClrFullTypeName;
                break;

            case RelationType.ManyToOne:
                fromProperty.TypeName = toEntity.Set.ClrFullTypeName;
                toProperty.TypeName   = fromEntity.ClrFullTypeName;
                break;

            case RelationType.ManyToMany:
                fromProperty.TypeName = toEntity.Set.ClrFullTypeName;
                toProperty.TypeName   = fromEntity.Set.ClrFullTypeName;
                break;
            }

            fromProperty.SetRelation(toProperty, relationType);

            switch (relationType)
            {
            case RelationType.OneToMany:
                toProperty.CascadeDelete = CascadeType.Before;
                break;

            case RelationType.ManyToOne:
                fromProperty.CascadeDelete = CascadeType.Before;
                break;
            }
        }
Esempio n. 10
0
        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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        private Entity GetOrCreateEntity(EntityType entityType, string entityName, string @namespace)
        {
            Entity entity = _project.Entities.Find(entityName);

            if (entity == null)
            {
                entity = ProjectUtilities.FindByEntityType(_project, entityType);
                if (entity != null)
                {
                    entity.Name = entityName; // Rename
                }
            }

            if (entity == null)
            {
                entity           = new Entity();
                entity.Name      = entityName;
                entity.Namespace = @namespace;
                entity.SetAttributeValue("", "entityType", Constants.NamespaceUri, entityType);
                _project.Entities.Add(entity);
            }

            return(entity);
        }
Esempio n. 17
0
        public override void Initialize(Project project, Producer producer)
        {
            base.Initialize(project, producer);

            if (InputProducer == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(EditorTargetDirectory))
            {
                EditorTargetDirectory = InputProducer.EditorTargetDirectory;
            }

            InputProducer.CodeDomProduction += CodeDomProducer_CodeDomProduction;


            Entity userEntity = ProjectUtilities.FindByEntityType(project, EntityType.User);

            if (userEntity != null)
            {
                _identityUser = new IdentityUser(userEntity);
            }

            Entity roleEntity = ProjectUtilities.FindByEntityType(project, EntityType.Role);

            if (roleEntity != null)
            {
                _identityRole = new IdentityRole(roleEntity);
            }

            Entity loginEntity = ProjectUtilities.FindByEntityType(project, EntityType.UserLogin);

            if (loginEntity != null)
            {
                _identityUserLogin = new IdentityUserLogin(loginEntity);
            }

            Entity claimEntity = ProjectUtilities.FindByEntityType(project, EntityType.UserClaim);

            if (claimEntity != null)
            {
                _identityUserClaim = new IdentityUserClaim(claimEntity);
            }

            Entity roleClaimEntity = ProjectUtilities.FindByEntityType(project, EntityType.RoleClaim);

            if (roleClaimEntity != null)
            {
                _identityRoleClaim = new IdentityRoleClaim(roleClaimEntity);
            }

            ProjectMessages projectMessages = new ProjectMessages(project);

            if (TargetVersion == AspNetIdentityVersion.Version1 || TargetVersion == AspNetIdentityVersion.Version2)
            {
                if (_identityUser != null)
                {
                    _userStoreProducer = new UserStoreProducer(InputProducer, this, projectMessages, _identityUser, _identityRole, _identityUserLogin, _identityUserClaim);
                }

                if (_identityRole != null)
                {
                    _roleStoreProducer = new RoleStoreProducer(InputProducer, this, _identityRole);
                }
            }
            else if (TargetVersion == AspNetIdentityVersion.Version3)
            {
                if (_identityUser != null)
                {
                    _userStore3Producer = new UserStore3Producer(InputProducer, this, projectMessages, _identityUser, _identityRole, _identityUserLogin, _identityUserClaim);
                }

                if (_identityRole != null)
                {
                    _roleStore3Producer = new RoleStore3Producer(InputProducer, this, _identityRole, _identityRoleClaim);
                }
            }
        }