Пример #1
0
        public UserStoreProducer(
            CodeDomBaseProducer codeDomBaseProducer,
            AspNetIdentityProducer aspNetIdentityProducer,
            ProjectMessages projectMessages,
            IdentityUser identityUser,
            IdentityRole identityRole,
            IdentityUserLogin identityUserLogin,
            IdentityUserClaim identityUserClaim)
            : base(codeDomBaseProducer)
        {
            if (aspNetIdentityProducer == null)
            {
                throw new ArgumentNullException("aspNetIdentityProducer");
            }
            if (identityUser == null)
            {
                throw new ArgumentNullException("identityUser");
            }

            _aspNetIdentityProducer = aspNetIdentityProducer;
            _projectMessages        = projectMessages;
            _identityUser           = identityUser;
            _identityRole           = identityRole;
            _identityUserLogin      = identityUserLogin;
            _identityUserClaim      = identityUserClaim;
        }
 public UserStoreProducer(
     AspNetIdentityProducer aspNetIdentityProducer,
     CodeDomBaseProducer codeDomBaseProducer,
     ProjectMessages projectMessages,
     IdentityUser identityUser,
     IdentityRole identityRole,
     IdentityUserLogin identityUserLogin,
     IdentityUserClaim identityUserClaim)
     : base(aspNetIdentityProducer, codeDomBaseProducer)
 {
     _projectMessages = projectMessages;
     _identityUser = identityUser;
     _identityRole = identityRole;
     _identityUserLogin = identityUserLogin;
     _identityUserClaim = identityUserClaim;
 }
        private void buttonOk_Click(object sender, EventArgs e)
        {
            Entity userEntity = CreateUserEntity();
            Entity roleEntity = null;
            //Entity userRoleEntity = null;
            Entity loginsEntity = null;
            Entity claimsEntity = null;
            Entity roleClaimEntity = null;

            if (checkBoxRole.Checked)
            {
                roleEntity = CreateRoleEntity();
            }

            //if (checkBoxUserRole.Checked)
            //{
            //    userRoleEntity = CreateUserRoleEntity();
            //    AddRelation(userEntity, PropertyType.Roles, userRoleEntity, PropertyType.User, RelationType.ManyToOne);
            //    AddRelation(roleEntity, PropertyType.RoleUsers, userRoleEntity, PropertyType.Role, RelationType.ManyToOne);
            //}
            //else
            //{
            AddRelation(userEntity, PropertyType.UserRoles, roleEntity, PropertyType.RoleUsers, RelationType.ManyToMany);
            //}

            if (checkBoxClaims.Checked)
            {
                claimsEntity = CreateUserClaimsEntity();
                AddRelation(userEntity, PropertyType.UserClaims, claimsEntity, PropertyType.UserClaimUser, RelationType.ManyToOne);
            }

            if (checkBoxExternalLogins.Checked)
            {
                loginsEntity = CreateUserLoginsEntity();
                AddRelation(userEntity, PropertyType.UserLogins, loginsEntity, PropertyType.UserLoginUser, RelationType.ManyToOne);
            }

            if (checkBoxRoleClaim.Checked)
            {
                roleClaimEntity = CreateRoleClaimEntity();
                AddRelation(roleEntity, PropertyType.RoleClaims, roleClaimEntity, PropertyType.RoleClaimRole, RelationType.ManyToOne);
            }

            CreateUserMethods(userEntity, loginsEntity);

            SetCollectionMode(userEntity);
            SetCollectionMode(roleEntity);
            //SetCollectionMode(userRoleEntity);
            SetCollectionMode(loginsEntity);
            SetCollectionMode(claimsEntity);
            SetCollectionMode(roleClaimEntity);

            if (_aspNetIdentityProducer.MustCreateMessages)
            {
                ProjectMessages messages = new ProjectMessages(_project);
                if (messages.RoleNotFoundMessage == null)
                {
                    var message = new Message
                    {
                        EditorName = "RoleNotFound",
                        Class = MessageClass._default.ToString(),
                        CultureName = ConvertUtilities.ToCultureInfo(_aspNetIdentityProducer.MessagesCulture, _project.Culture).Name,
                        Value = IdentityRole.RoleNotFoundMessage,
                        AddToRuntimeResourceFile = true
                    };
                    message.SetAttributeValue("", "messageType", Constants.NamespaceUri, ProjectMessageType.RoleNotFound);
                    _project.Messages.Add(message);
                }
            }

            this.Close();
        }
Пример #4
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);
                }
            }
        }
        public override void Initialize(Project project, Producer producer)
        {
            base.Initialize(project, producer);

            if (InputProducer == null)
                return;

            if (Utilities.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 (_identityUser != null)
            {
                _userStoreProducer = new UserStoreProducer(this, InputProducer, projectMessages, _identityUser, _identityRole, _identityUserLogin, _identityUserClaim);
            }

            if (_identityRole != null)
            {
                _roleStoreProducer = new RoleStoreProducer(this, InputProducer, _identityRole, _identityRoleClaim);
            }
        }
Пример #6
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            Entity userEntity = CreateUserEntity();
            Entity roleEntity = null;
            //Entity userRoleEntity = null;
            Entity loginsEntity    = null;
            Entity claimsEntity    = null;
            Entity roleClaimEntity = null;

            if (checkBoxRole.Checked)
            {
                roleEntity = CreateRoleEntity();
            }

            //if (checkBoxUserRole.Checked)
            //{
            //    userRoleEntity = CreateUserRoleEntity();
            //    AddRelation(userEntity, PropertyType.Roles, userRoleEntity, PropertyType.User, RelationType.ManyToOne);
            //    AddRelation(roleEntity, PropertyType.RoleUsers, userRoleEntity, PropertyType.Role, RelationType.ManyToOne);
            //}
            //else
            //{
            AddRelation(userEntity, PropertyType.UserRoles, roleEntity, PropertyType.RoleUsers, RelationType.ManyToMany);
            //}

            if (checkBoxClaims.Checked)
            {
                claimsEntity = CreateUserClaimsEntity();
                AddRelation(userEntity, PropertyType.UserClaims, claimsEntity, PropertyType.UserClaimUser, RelationType.ManyToOne);
            }

            if (checkBoxExternalLogins.Checked)
            {
                loginsEntity = CreateUserLoginsEntity();
                AddRelation(userEntity, PropertyType.UserLogins, loginsEntity, PropertyType.UserLoginUser, RelationType.ManyToOne);
            }

            if (checkBoxRoleClaim.Checked)
            {
                roleClaimEntity = CreateRoleClaimEntity();
                AddRelation(roleEntity, PropertyType.RoleClaims, roleClaimEntity, PropertyType.RoleClaimRole, RelationType.ManyToOne);
            }

            CreateUserMethods(userEntity, loginsEntity);

            SetCollectionMode(userEntity);
            SetCollectionMode(roleEntity);
            //SetCollectionMode(userRoleEntity);
            SetCollectionMode(loginsEntity);
            SetCollectionMode(claimsEntity);
            SetCollectionMode(roleClaimEntity);

            if (_aspNetIdentityProducer.MustCreateMessages)
            {
                ProjectMessages messages = new ProjectMessages(_project);
                if (messages.RoleNotFoundMessage == null)
                {
                    var message = new Message
                    {
                        EditorName  = "RoleNotFound",
                        Class       = MessageClass._default.ToString(),
                        CultureName = ConvertUtilities.ToCultureInfo(_aspNetIdentityProducer.MessagesCulture, _project.Culture).Name,
                        Value       = IdentityRole.RoleNotFoundMessage,
                        AddToRuntimeResourceFile = true
                    };
                    message.SetAttributeValue("", "messageType", Constants.NamespaceUri, ProjectMessageType.RoleNotFound);
                    _project.Messages.Add(message);
                }
            }

            this.Close();
        }