private void CheckDevice(LoginDataContract selectedLogin) { try { if (DeviceCollection == null || !DeviceCollection.Any()) { return; } foreach (var selectedDevice in DeviceCollection) { selectedDevice.Selected = selectedDevice.DeviceTaken = false; } using (var policySetService = _ppsClientViewModel.ServiceProxy.GetPpsChannelFactory <ILoginDevicesService>()) { var channel = policySetService.CreateChannel(); if (selectedLogin == null) { return; } var result = channel.GetLoginDevices(null); if (result == null) { throw new Exception("Ошибка вызова службы"); } if (!result.BoolRes || result.SomeResult == null) { throw new Exception(result.ErrorRes); } var selectedDevices = result.SomeResult.Where(x => x.LoginId == selectedLogin.LoginId); foreach (var selectedDevice in DeviceCollection) { var findInLoginDevice = selectedDevices.FirstOrDefault(x => x.DeviceId == selectedDevice.DeviceId); selectedDevice.Selected = findInLoginDevice != null; var loginDevice = result.SomeResult.FirstOrDefault(x => x.DeviceId == selectedDevice.DeviceId); selectedDevice.NeedUpdateDevice = loginDevice != null && findInLoginDevice != null && (findInLoginDevice.NeedUpdateDevice ?? false); } if (_loginIdAndDeviceIdDct == null || !_loginIdAndDeviceIdDct.Any()) { return; } var devLst = new List <long>(); foreach ( var devId in _loginIdAndDeviceIdDct.Where(x => x.Key != selectedLogin.LoginId) .SelectMany(set => set.Value.Where(devId => !devLst.Contains(devId)))) { devLst.Add(devId); } foreach (var selectedDevice in DeviceCollection) { selectedDevice.DeviceTaken = devLst.Any(x => x == selectedDevice.DeviceId); selectedDevice.OnDeviceSelected += selectedDevice_OnDeviceSelected; } } } catch (Exception ex) { _ppsClientViewModel.WriteLogMessage(string.Concat("Не удалось выбрать устройства пользователя - ", ex.Message)); } }