Exemple #1
0
        public UserDto CheckUser(string userName, string password)
        {
            _logger.LogInformation("CheckUser: username:{0}", userName);
            if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(password))
            {
                return(null);
            }

            //get from indexs,get radom id to get url for balanced solrcloud
            var readindex  = _indexReadFactory.CreateIndex <UserIndexs, IUserIndexsIndexRead>(Guid.NewGuid().ToString(), "authcore1");
            var userindexs = readindex.FirstOrDefault(new List <KeyValuePair <string, string> >(2)
            {
                new KeyValuePair <string, string>("name", userName), new KeyValuePair <string, string>("keywords", password)
            });
            UserIndex userindex = null;

            if (userindexs == null)
            {
                userindex = _userrepositoryread.CheckUserIndex(userName, password);
                if (userindex != null)//write to indexs
                {
                    var writeuserindexs = Mapper.Map <UserIndexs>(userindex);
                    var writeindex      = _indexFactory.CreateIndex <UserIndexs, IUserIndexsIndex>(writeuserindexs.Id.ToString(), "authcore1");
                    writeindex.Insert(writeuserindexs);
                }
            }
            else
            {
                userindex = Mapper.Map <UserIndex>(userindexs);
            }

            var user = _repositoryReadFactory.CreateRepository <User, IUserRepositoryRead>(userindex.UserId.ToString()).CheckUser(userName, password);//

            return(Mapper.Map <UserDto>(user));
        }
        private void InsertIndex(UserIndex bodys)
        {
            var userindexs = Mapper.Map <UserIndexs>(bodys);
            var objindex   = _indexFactory.CreateIndex <UserIndexs, IUserIndexsIndex>(userindexs.Id.ToString(), "authcore1");

            objindex.Insert(userindexs);
        }
Exemple #3
0
 private void DeleteIndex(List <Guid> ids)
 {
     ids.ForEach(id => {
         if (!default(Guid).Equals(id))
         {
             var objindex = _indexFactory.CreateIndex <UserIndexs, IUserIndexsIndex>(id.ToString(), "authcore1");
             objindex.Delete(id);
         }
     });
 }
Exemple #4
0
        /// <summary>
        ///     Creates a new index.
        /// </summary>
        /// <typeparam name="TKey"> The type of the index key. </typeparam>
        /// <param name="indexFactory"> The index factory. </param>
        /// <param name="keyInfo"> The definition of the index key. </param>
        /// <returns> The index. </returns>
        public IIndex <TEntity, TKey> CreateIndex <TKey>(
            IIndexFactory indexFactory,
            IKeyInfo <TEntity, TKey> keyInfo)
        {
            var index = indexFactory.CreateIndex(this, keyInfo);

            this.indexes.Add(index);
            this.OnIndexChanged();

            return(index);
        }
Exemple #5
0
        /// <summary>
        ///     Creates a new index.
        /// </summary>
        /// <typeparam name="TKey">
        ///     The type of the index key.
        /// </typeparam>
        /// <param name="indexFactory">
        ///     The index factory.
        /// </param>
        /// <param name="keySelector">
        ///     The expression representing the definition of the index key.
        /// </param>
        /// <returns>
        ///     The index.
        /// </returns>
        public IIndex <TEntity, TKey> CreateIndex <TKey>(
            IIndexFactory indexFactory,
            Expression <Func <TEntity, TKey> > keySelector)
        {
            var keyFactory = new ModularKeyInfoFactory(this.Database);
            var key        = keyFactory.Create(keySelector);
            var index      = indexFactory.CreateIndex(this, key);

            this.indexes.Add(index);
            this.OnIndexChanged();

            return(index);
        }
        private void UpdateUserRole(user_update_userroles_normal msg)
        {
            UserRoleMsg bodys = ByteConvertHelper.Bytes2Object <UserRoleMsg>(msg.MessageBodyByte);

            if (bodys == null)
            {
                return;
            }
            List <UserRole>           userRoles    = new List <UserRole>();
            Dictionary <Guid, string> userRoleStrs = new Dictionary <Guid, string>(bodys.userIds.Count);

            bodys.userIds.ForEach(uid => {
                StringBuilder roleStrs = new StringBuilder();
                bodys?.roleIds.ForEach(rid => { userRoles.Add(new UserRole()
                    {
                        UserId = uid, RoleId = rid
                    }); roleStrs.Append(rid).Append(","); });
                roleStrs.Remove(roleStrs.Length - 1, 1);
                userRoleStrs.Add(uid, roleStrs.ToString());
            });

            lock (normalLocker)
            {
                bodys.userIds.ForEach(id => {
                    var up = _repository.CreateRepository <User, IUserRepository>(id.ToString());
                    up.Execute(() =>
                    {
                        //get from indexs
                        var readindex = _indexReadFactory.CreateIndex <UserIndexs, IUserIndexsIndexRead>(id.ToString(), "authcore1");
                        var userindex = readindex.FirstOrDefault(new List <KeyValuePair <string, string> >(1)
                        {
                            new KeyValuePair <string, string>("id", id.ToString())
                        });
                        if (userindex != null)
                        {
                            userindex.roles = userRoleStrs[id];
                            //update indexs
                            var objindex = _indexFactory.CreateIndex <UserIndexs, IUserIndexsIndex>(id.ToString(), "authcore1");
                            objindex.Insert(userindex);
                        }

                        // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction
                        up.RemoveUserRoles(id);
                        up.UnitOfWork.SaveChange();
                        up.BatchAddUserRoles(userRoles);
                        up.UnitOfWork.SaveChange();
                    });
                });
            }
        }