public async Task ExecuteRemoteTasks(string vaultId, Device remoteDevice, bool primaryAccountOnly) { _dataProtectionService.Validate(); var vault = await _hardwareVaultService.GetVaultByIdAsync(vaultId); if (vault == null) { throw new HESException(HESCode.HardwareVaultNotFound); } // Tasks query var query = _hardwareVaultTaskService .TaskQuery() .Include(t => t.HardwareVault) .Include(t => t.Account) .Where(t => t.HardwareVaultId == vaultId); if (primaryAccountOnly) { query = query.Where(x => x.AccountId == vault.Employee.PrimaryAccountId || x.Operation == TaskOperation.Primary); } query = query.OrderBy(x => x.CreatedAt).AsNoTracking(); var tasks = await query.ToListAsync(); while (tasks.Any()) { foreach (var task in tasks) { task.Password = _dataProtectionService.Decrypt(task.Password); task.OtpSecret = _dataProtectionService.Decrypt(task.OtpSecret); await ExecuteRemoteTask(remoteDevice, task); await TaskCompleted(task.Id); } tasks = await query.ToListAsync(); } await _hardwareVaultService.UpdateNeedSyncAsync(vault, false); await _synchronizationService.HardwareVaultStateChanged(vault.Id); }
public async Task <int> GetHardwareVaultTasksCount() { return(await _hardwareVaultTaskService.TaskQuery().CountAsync()); }