public async Task Update(IAccessPermissionCollection accessPermissions) { // NOTE: this is temporary quick solution // Normally it should be replaced with an implementation of partial updates based on MS Sync Framework var biometricInfo = await _listUsersBiometricRequest.Request(ListCommand.WithoutParameters); var biometricInfoMap = biometricInfo.Users.ToDictionary(x => x.UserName); Func <string, UserHash> getHash = x => { var hash = biometricInfoMap.ContainsKey(x) ? biometricInfoMap[x].BiometricHash : null; return(new UserHash(x, hash)); }; // add user permissions var accessRights = await _listAccessRightsRequest.Request(ListCommand.WithoutParameters); foreach (var userAccessRights in accessRights.UserAccessRights) { var userName = userAccessRights.UserName; var userHash = getHash(userName); userAccessRights.PermanentAccessRules.ForEach( rule => { var permission = new PermanentUserAccess(rule.AccessPointId, userHash); accessPermissions.AddOrUpdatePermission(permission); }); userAccessRights.ScheduledAccessRules.ForEach( rule => { var permission = new ScheduledUserAccess(rule.AccessPointId, userHash, WeeklySchedule.Convert(rule.WeeklySchedule)); accessPermissions.AddOrUpdatePermission(permission); }); } // add user group permissions foreach (var groupRights in accessRights.UserGroupAccessRights) { var groupName = groupRights.UserGroupName; var usersInGroupResult = await _listUsersInGroupRequest.Request(ListCommand.ListUsersInGroup(groupName)); var userHashes = usersInGroupResult.Users.Select(x => getHash(x.UserName)).ToArray(); groupRights.PermanentAccessRules.ForEach( rule => { var permission = new PermanentGroupAccess(rule.AccessPointId, groupName, userHashes); accessPermissions.AddOrUpdatePermission(permission); }); groupRights.ScheduledAccessRules.ForEach( rule => { var permission = new ScheduledGroupAccess(rule.AccessPointId, groupName, userHashes, WeeklySchedule.Convert(rule.WeeklySchedule)); accessPermissions.AddOrUpdatePermission(permission); }); } }
/// <summary> /// Lists the users and biometric hash codes in the current group. /// </summary> /// <returns></returns> protected async Task <Tuple <string[], string[]> > ListUsersInGroup() { var usersInGroupResult = await _listUsersInGroupRequest.Request(ListCommand.ListUsersInGroup(GroupName)); var userNames = usersInGroupResult.Users.Select(x => x.UserName).ToArray(); var userHashes = new string[userNames.Length]; for (var i = 0; i < userNames.Length; i++) { userHashes[i] = FindUserHash(userNames[i]); } return(Tuple.Create(userNames, userHashes)); }