public async Task <ActionResult <List <AppEntranceDto> > > GetAll(ClientPlatform clientPlatform, string clientId = Client.DefaultId) { try { var input = new GetAppEntrancesInput { ClientId = clientId, UserRoles = GetUserRoles().ToList(), ClientPlatform = clientPlatform, }; return(await _workbenchAppService.GetAppEntrancesAsync(input)); } catch (Exception ex) { return(BadRequest(LogError(_logger, ex))); } }
public async Task <List <AppEntranceDto> > GetAppEntrancesAsync(GetAppEntrancesInput input) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (string.IsNullOrEmpty(input.ClientId)) { throw new ArgumentNullException(nameof(input.ClientId)); } var dictClients = await StateManager.GetOrAddAsync <IReliableDictionary2 <string, Client> >(Service.DictionaryName_Client); var dictAppEntrances = await StateManager.GetOrAddAsync <IReliableDictionary2 <Guid, AppEntrance> >(Service.DictionaryName_AppEntrance); var token = CancellationToken.None; var result = new List <AppEntranceDto>(); using (var tx = StateManager.CreateTransaction()) { var clientWrap = await dictClients.TryGetValueAsync(tx, input.ClientId); if (!clientWrap.HasValue) { throw new ArgumentOutOfRangeException("没有clientId的数据", nameof(input.ClientId)); } var client = clientWrap.Value; var enumerator = (await dictAppEntrances.CreateEnumerableAsync(tx, o => client.AppEntranceIds.Contains(o), EnumerationMode.Unordered)).GetAsyncEnumerator(); while (await enumerator.MoveNextAsync(token)) { var item = enumerator.Current.Value; if (item.NeedRoles?.Length > 0) { //without any roles then continue if (input.UserRoles == null || input.UserRoles.Count == 0) { continue; } var hasNeedRole = true; foreach (var role in item.NeedRoles) { //without this role then break hasNeedRole = input.UserRoles.Contains(role); if (!hasNeedRole) { break; } } if (!hasNeedRole) { continue; } } var dto = CheckPlatformThenAdd(input.ClientPlatform, result, item); } } return(result); }