public async Task NpsClientDeleteTestAsync() { Thread.CurrentPrincipal = new ClaimsPrincipal ( new ClaimsIdentity ( new List <Claim> { new Claim(ClaimTypes.NameIdentifier, "117084294703656960") } ) ); var input = new NpsClientDeleteInput { DeviceUniqueId = "AAAAAAAAAA", DeletePorts = new List <string> { "1111", "2222", "3333" } }; var deleteResult = await _npsClientService.DeleteAsync(input); Assert.NotNull(deleteResult); }
public async Task <IExecuteResult> DeleteAsync(NpsClientDeleteInput input) { return(ExecuteResult.Ok(await _npsClientService.DeleteAsync(input))); }
/// <summary> /// 设备端口删除服务 /// </summary> /// <param name="input">删除服务参数</param> /// <returns>返回删除结果</returns> public async Task <List <NpsClientDeletedOutput> > DeleteAsync(NpsClientDeleteInput input) { var deletedOutputs = new List <NpsClientDeletedOutput>(); //查询设备对应的应用密钥信息 var npsAppSecret = await _npsAppSecretRepository .Where(x => x.DeviceUniqueId == input.DeviceUniqueId) .Where(x => x.CreateUserId == CurrentUser.UserId) .WhereCascade(x => x.IsDeleted == false) .Include(x => x.NpsServer) .Include(x => x.NpsClient) .ToOneAsync(); if (npsAppSecret == null || npsAppSecret.NpsClient == null) { throw new NpsException("删除失败,查询不存在", StatusCode.NotFound); } //查询需要删除的隧道列表 var npsChannels = await _npsChannelRepository .Where(x => x.NpsClientId == npsAppSecret.NpsClient.Id) .Where(x => input.DeletePorts.Contains(x.DeviceAddress)) .ToListAsync(); if (npsChannels.Count == 0) { throw new NpsException("删除失败,查询不存在", StatusCode.NotFound); } var deletedChannels = new List <NpsChannel>(); var baseAuthInput = await BeforeRequestNpsApiAsync(); for (int index = 0; index < npsChannels.Count; index++) { var npsChannel = npsChannels[index]; var deletedOutput = new NpsClientDeletedOutput { DeviceAddress = npsChannel.DeviceAddress }; //向远程服务发送删除指令 var remoteApiResult = await _npsApi.DeleteChannelAsync(new ChannelIdInput { AuthKey = baseAuthInput.AuthKey, Timestamp = baseAuthInput.Timestamp, Id = npsChannel.RemoteChannelId }); deletedOutput.RemoteStatus = remoteApiResult.Status; deletedOutput.RemoteMessage = remoteApiResult.Message; deletedOutputs.Add(deletedOutput); if (remoteApiResult.Status == 1) {//远程服务器删除成功后,删除至删除集合列表,统一删除 deletedChannels.Add(npsChannel); } } if (deletedChannels.Count > 0) { await _npsChannelRepository.DeleteAsync(deletedChannels); } return(deletedOutputs); }