コード例 #1
0
        public async Task <Tokens> LoginAsync(LoginInput input)
        {
            _logger.LogInformation("Login With Jwt Begin;");

            var user = await _userRepository
                       .Where(x => x.UserName == input.UserName || x.Email == input.UserName)
                       .ToOneAsync();

            if (user == null)
            {
                throw new NpsException("用户不存在", StatusCode.NotFound);
            }

            bool valid = EncryptHelper.Md5By32(input.Password) == user.Password;

            if (!valid)
            {
                throw new NpsException("请输入正确密码", StatusCode.ParameterError);
            }

            _logger.LogInformation($"用户{input.UserName},登录成功");

            Tokens tokens = await CreateTokenAsync(user);

            return(tokens);
        }
コード例 #2
0
ファイル: FreeSqlTest.cs プロジェクト: io2020/io_nps_server
        public async Task FreeSqlNavigateTest()
        {
            var servers = await _npsServerRepository.Where(x => 1 == 1).ToListAsync();

            var serversIncludeMany = await _npsServerRepository.Select.IncludeMany(x => x.NpsAppSecrets).ToListAsync();

            Check.NotNull(servers, nameof(NpsServer));

            var appSecrets = await _npsAppSecretRepository.Where(x => x.NpsServerId == servers[0].Id).ToListAsync();

            var appSecrets1 = await _npsAppSecretRepository.Where(x => x.NpsServer.Id == servers[0].Id).ToListAsync();

            var include = await _npsAppSecretRepository.Where(x => x.NpsServerId == servers[0].Id).Include(x => x.NpsServer).ToListAsync();

            var include1 = await _npsAppSecretRepository.Where(x => new List <long> {
                servers[0].Id
            }.Contains(x.NpsServer.Id)).ToListAsync();

            Assert.NotNull(servers);
            Assert.NotNull(serversIncludeMany);
            Assert.NotNull(appSecrets);
            Assert.NotNull(appSecrets1);
            Assert.NotNull(include);
            Assert.NotNull(include1);
        }
コード例 #3
0
        /// <summary>
        /// 检查是否更新NpsAppSecret、NpsServer、NpsClient
        /// </summary>
        /// <param name="npsAppSecret">NpsAppSecret</param>
        /// <returns>返回NpsAppSecret</returns>
        private async Task <NpsAppSecret> UpdateNpsClientOrNpsServerIfCheckNotNullAsync(NpsAppSecret npsAppSecret)
        {
            Check.NotNull(npsAppSecret, nameof(npsAppSecret));
            Check.NotNull(npsAppSecret.NpsClient, nameof(npsAppSecret.NpsClient));

            _logger.LogInformation($"检查是否更新NpsAppSecret、NpsServer、NpsClient,设备唯一识别编码:{npsAppSecret.DeviceUniqueId}");
            if (npsAppSecret.NpsClient.RemoteClientId == 0 || npsAppSecret.NpsServer == null || npsAppSecret.NpsServerId == 0)
            {
                var clientListOutput = await GetRemoteClientOutputAsync(npsAppSecret.AppSecret);

                if (clientListOutput == null || clientListOutput.Datas == null || clientListOutput.Datas.Count == 0)
                {
                    return(npsAppSecret);
                }

                //若本地数据库Nps客户端表中无远程Nps客户端Id,则将远程客户端信息回写
                if (npsAppSecret.NpsClient.RemoteClientId == 0)
                {
                    var remoteNpsClient = clientListOutput.Datas[0];

                    _npsClientRepository.Attach(npsAppSecret.NpsClient);
                    npsAppSecret.NpsClient.RemoteClientId     = remoteNpsClient.Id;
                    npsAppSecret.NpsClient.Status             = remoteNpsClient.Status;
                    npsAppSecret.NpsClient.IsConnect          = remoteNpsClient.IsConnect;
                    npsAppSecret.NpsClient.LastConnectAddress = remoteNpsClient.LastConnectAddress;
                    await _npsClientRepository.UpdateAsync(npsAppSecret.NpsClient);
                }

                //若该设备无对应的服务器信息,则将服务器写入本地数据库
                if (npsAppSecret.NpsServer == null)
                {
                    //先根据IP地址查询服务器是否存在
                    npsAppSecret.NpsServer = await _npsServerRepository.Where(x => x.ServerIPAddress == clientListOutput.ServerIPAddress).ToOneAsync();

                    if (npsAppSecret.NpsServer == null)
                    {
                        npsAppSecret.NpsServer = await _npsServerRepository.InsertAsync(new NpsServer
                        {
                            ServerIPAddress   = clientListOutput.ServerIPAddress,
                            ClientConnectPort = clientListOutput.ClientConnectPort.ToInt32OrDefault(0),
                            ProtocolType      = _protocolType
                        });
                    }
                }

                //若该设备无对应的服务器信息
                if (npsAppSecret.NpsServerId == 0)
                {
                    if (npsAppSecret?.NpsServer?.Id > 0)
                    {
                        //将服务器信息与设备应用密钥关联
                        _npsAppSecretRepository.Attach(npsAppSecret);
                        npsAppSecret.NpsServerId = npsAppSecret.NpsServer.Id;
                        await _npsAppSecretRepository.UpdateAsync(npsAppSecret);
                    }
                }
            }

            return(npsAppSecret);
        }
コード例 #4
0
        /// <summary>
        /// 根据服务器IP查询服务器信息
        /// </summary>
        /// <param name="serverIPAddress">服务器IP地址</param>
        /// <returns>返回服务器信息</returns>
        public async Task <NpsServerSearchOutput> GetAsync(string serverIPAddress)
        {
            var server = await _npsServerRepository
                         .Where(x => x.ServerIPAddress == serverIPAddress)
                         .ToOneAsync <NpsServerSearchOutput>();

            return(server);
        }
コード例 #5
0
        /// <summary>
        /// 分页查询所有已开通服务列表
        /// </summary>
        /// <param name="input">查询服务参数</param>
        /// <returns>分页返回查询结果</returns>
        public async Task <List <NpsClientOpenedOutput> > SearchAsync(PagingInput <NpsClientSearchInput> input)
        {
            var outputs = new List <NpsClientOpenedOutput>();

            var npsAppSecrets = await _npsAppSecretRepository
                                .Where(x => x.CreateUserId == CurrentUser.UserId)
                                .WhereIf(input.Filter?.DeviceUniqueId.IsNotNullOrEmpty() ?? false, x => x.DeviceUniqueId == input.Filter.DeviceUniqueId)
                                .WhereCascade(x => x.IsDeleted == false)
                                .Include(x => x.NpsServer)
                                .Include(x => x.NpsClient)
                                .ToListAsync();

            if (npsAppSecrets.Count == 0)
            {
                return(outputs);
            }

            var npsClientIds = npsAppSecrets.Select(x => x.NpsClient?.Id ?? 0).ToList();

            var npsChannels = await _npsChannelRepository
                              .Where(x => x.IsDeleted == false)
                              .Where(x => npsClientIds.Contains(x.NpsClientId))
                              .WhereIf(input.Filter?.SearchPorts.IsNotNull() ?? false, x => input.Filter.SearchPorts.Contains(x.DeviceAddress))
                              .ToListAsync();

            if (npsChannels.Count == 0)
            {
                return(outputs);
            }

            npsAppSecrets.ForEach(npsAppSecret =>
            {
                if (npsAppSecret.NpsClient != null)
                {
                    npsAppSecret.NpsClient.NpsChannels = npsChannels.Where(x => x.NpsClientId == npsAppSecret.NpsClient?.Id).ToList();
                }
            });

            npsAppSecrets.ForEach(npsAppSecret =>
            {
                var npsClientOpenedOutput = Mapper.Map <NpsClientOpenedOutput>(npsAppSecret);
                outputs.Add(npsClientOpenedOutput);
            });
            return(outputs);
        }