public static async Task <List <ServerConfiguration> > GetAsync(string serverName, int wsdlPort) { Queries.QueryServiceClient queryClient = EndPoint.GetQueryClient(serverName, wsdlPort); Queries.QueryMetadata query = ServerConfiguration.Query(); Queries.PositionBasedPaging paging = new Queries.PositionBasedPaging(); paging.StartingPosition = 1; paging.NumberOfRecordsToFetch = 100; Queries.ExecuteQueryRequest request = new Queries.ExecuteQueryRequest(query, paging); Task <Queries.ExecuteQueryResponse> queryTask = queryClient.ExecuteQueryAsync(request); await queryTask; List <ServerConfiguration> configs = null; if (queryTask.Result != null) { configs = ServerConfiguration.RowsToConfigs(queryTask.Result.ExecuteQueryResult); // Get tasks for fetching batch configuration for each server var tasks = from server in configs select BatchConfiguration.GetAsync(server.ServerId, serverName, wsdlPort); // Await all batch configuration calls to return List <BatchConfiguration>[] batches = await Task.WhenAll(tasks); // Assign each batch configuration to its respective server foreach (var server in configs) { var batchConfig = from b in batches where b[0].ServerId == server.ServerId select b; if (batchConfig != null && batchConfig.Count() > 0) { server.BatchConfigurations = batchConfig.First().ToList(); } } } return(configs); }
public static async Task <List <BatchConfiguration> > GetAsync(string serverId, string serverName, int wsdlPort) { Queries.QueryServiceClient queryClient = EndPoint.GetQueryClient(serverName, wsdlPort); Queries.QueryMetadata query = BatchConfiguration.Query(serverId); Queries.Paging paging = new Queries.PositionBasedPaging(); (paging as Queries.PositionBasedPaging).StartingPosition = 1; (paging as Queries.PositionBasedPaging).NumberOfRecordsToFetch = 100; Queries.ExecuteQueryRequest request = new Queries.ExecuteQueryRequest(query, paging); Task <Queries.ExecuteQueryResponse> queryTask = queryClient.ExecuteQueryAsync(request); await queryTask; List <BatchConfiguration> configs = null; if (queryTask.Result != null) { configs = BatchConfiguration.RowsToConfigs(queryTask.Result.ExecuteQueryResult); } return(configs); }