public CommandResult Execute(ICommandInfo commandInfo) { var readInfo = commandInfo as ReadCommandInfo; if (readInfo == null) { return(CommandResult.Fail("CommandInfo does not implement ReadCommandInfo")); } if (readInfo.DataSource == null) { throw new ClientException("Invalid ReadCommand argument: Data source is not set."); } var genericRepository = _repositories.GetGenericRepository(readInfo.DataSource); ReadCommandResult result = _serverCommandsUtility.ExecuteReadCommand(readInfo, genericRepository); if (result.Records != null && !AlreadyFilteredByRowPermissions(readInfo)) { var valid = _serverCommandsUtility.CheckAllItemsWithinFilter(result.Records, RowPermissionsReadInfo.FilterName, genericRepository); if (!valid) { throw new UserException("You are not authorized to access some or all of the data requested.", "DataStructure:" + readInfo.DataSource + "."); } } return(new CommandResult { Data = _dataTypeProvider.CreateBasicData(result), Message = (result.Records != null ? result.Records.Length.ToString() : result.TotalCount.ToString()) + " row(s) found", Success = true }); }
public static QueryDataSourceCommandResult FromReadCommandResult(ReadCommandResult readCommandResult) { return(new QueryDataSourceCommandResult { Records = readCommandResult.Records, TotalRecords = readCommandResult.TotalCount.Value }); }
public static QueryDataSourceCommandResult FromReadCommandResult(ReadCommandResult readCommandResult) { return new QueryDataSourceCommandResult { Records = readCommandResult.Records, TotalRecords = readCommandResult.TotalCount.Value }; }
public CommandResult Execute(ICommandInfo commandInfo) { var info = (QueryDataSourceCommandInfo)commandInfo; var genericRepository = _repositories.GetGenericRepository(info.DataSource); var readCommandInfo = info.ToReadCommandInfo(); ReadCommandResult readCommandResult = _serverCommandsUtility.ExecuteReadCommand(readCommandInfo, genericRepository); var result = QueryDataSourceCommandResult.FromReadCommandResult(readCommandResult); return(new CommandResult { Data = _dataTypeProvider.CreateBasicData(result), Message = (result.Records != null ? result.Records.Length.ToString() : result.TotalRecords.ToString()) + " row(s) found", Success = true }); }
public ReadCommandResult ExecuteReadCommand(ReadCommandInfo commandInfo, GenericRepository <IEntity> genericRepository) { if (!commandInfo.ReadRecords && !commandInfo.ReadTotalCount) { throw new ClientException("Invalid ReadCommand argument: At least one of the properties ReadRecords or ReadTotalCount should be set to true."); } if (commandInfo.Top < 0) { throw new ClientException("Invalid ReadCommand argument: Top parameter must not be negative."); } if (commandInfo.Skip < 0) { throw new ClientException("Invalid ReadCommand argument: Skip parameter must not be negative."); } if (commandInfo.DataSource != genericRepository.EntityName) { throw new FrameworkException(string.Format( "Invalid ExecuteReadCommand arguments: The given ReadCommandInfo ('{0}') does not match the GenericRepository ('{1}').", commandInfo.DataSource, genericRepository.EntityName)); } AutoApplyFilters(commandInfo); ReadCommandResult result; var specificMethod = genericRepository.Reflection.RepositoryReadCommandMethod; if (specificMethod != null) { result = (ReadCommandResult)specificMethod.InvokeEx(genericRepository.EntityRepository, commandInfo); } else { bool pagingIsUsed = commandInfo.Top > 0 || commandInfo.Skip > 0; object filter = commandInfo.Filters != null && commandInfo.Filters.Any() ? (object)commandInfo.Filters : new FilterAll(); IEnumerable <IEntity> filtered = genericRepository.Read(filter, filter.GetType(), preferQuery: pagingIsUsed || !commandInfo.ReadRecords); IEntity[] resultRecords = null; int? totalCount = null; if (commandInfo.ReadRecords) { var sortedAndPaginated = GenericFilterHelper.SortAndPaginate(genericRepository.Reflection.AsQueryable(filtered), commandInfo); resultRecords = (IEntity[])genericRepository.Reflection.ToArrayOfEntity(sortedAndPaginated); } if (commandInfo.ReadTotalCount) { if (pagingIsUsed) { totalCount = SmartCount(filtered); } else { totalCount = resultRecords != null ? resultRecords.Length : SmartCount(filtered); } } result = new ReadCommandResult { Records = resultRecords, TotalCount = totalCount }; } return(result); }