public async Task <BatchGetValuesResponse> BatchGetAsync(List <string> ranges) { BatchGetRequest request = _service.Spreadsheets.Values.BatchGet(SheetId()); request.Ranges = ranges; return(await request.ExecuteAsync()); }
/// <summary> /// Batch-get multiple trees and multiple nodes. /// </summary> /// <param name="trees">The identifying data for the trees to get.</param> /// <param name="nodes">The identifying data for the nodes to get.</param> /// <returns>Does not return anything.</returns> private async Task BatchGet(TreeIdentity[] trees, TreeNodeIdentity[] nodes) { var batchGetRequest = new BatchGetRequest { Trees = trees, // Optional Nodes = nodes, // Optional }; Console.WriteLine($"Batch-getting {batchGetRequest.Trees?.Length} trees and {batchGetRequest.Nodes?.Length} nodes..."); var batchGetResponse = await this.orgClient.BatchGetAsync(batchGetRequest).ConfigureAwait(false); if (batchGetResponse.Responses != null) { Console.WriteLine($"Batch-got {batchGetResponse.Responses.Trees.Count} trees:"); this.PrintTrees(batchGetResponse.Responses.Trees); Console.WriteLine($"Batch-got {batchGetResponse.Responses.Nodes.Count} nodes:"); this.PrintNodes(batchGetResponse.Responses.Nodes); Console.WriteLine(); } if (batchGetResponse.Errors != null) { if (batchGetResponse.Errors.Trees != null) { Console.WriteLine("Tree errors:"); foreach (var treeError in batchGetResponse.Errors.Trees) { Console.WriteLine($"{treeError.Code} {treeError.Message}"); if (treeError.Item != null) { Console.WriteLine($" ForestId={treeError.Item.ForestId}, TreeId={treeError.Item.TreeId}"); } } Console.WriteLine(); } if (batchGetResponse.Errors.Nodes != null) { Console.WriteLine("Node errors:"); foreach (var nodeError in batchGetResponse.Errors.Nodes) { Console.WriteLine($"{nodeError.Code} {nodeError.Message}"); if (nodeError.Item != null) { Console.WriteLine($" ForestId={nodeError.Item.ForestId}, TreeId={nodeError.Item.TreeId}, NodeId={nodeError.Item.NodeId}"); } } Console.WriteLine(); } } }
/// <summary> /// Using the set of <c>Query</c> objects, executes a batch query on the Google Sheets API and stores the returned values in the <c>Query</c>'s Data attributes. /// </summary> /// <param name="service"></param> /// <param name="workbookID"></param> /// <param name="queries">The set of queries to be executed. All are expected to have the same <c>Orientation</c> value as <paramref name="dimension"/>.</param> /// <returns></returns> /// <exception cref="GoogleSheetsQueryFailedException"></exception> private void ExecuteBatchQuery(SheetsService service, string workbookID, MajorDimensionEnum dimension, IList <Query> queries) { try { if (queries.Count == 0) { return; } BatchGetRequest request = service.Spreadsheets.Values.BatchGet(workbookID); request.Ranges = queries.Select(q => q.ToString()).ToList(); request.MajorDimension = dimension; BatchGetValuesResponse response = request.Execute(); int i = 0; foreach (Query query in queries) { if (response.ValueRanges.ElementAtOrDefault(i).Values == null) { if (query.AllowNullData) { query.Data = new List <IList <object> >(); } else { throw new GoogleSheetsQueryReturnedNullException(query.Sheet); } } else { query.Data = response.ValueRanges.ElementAtOrDefault(i).Values; } i++; } } catch (Exception ex) { throw new GoogleSheetsQueryFailedException(string.Join(", ", queries.Select(q => q.Sheet)), ex); } }
/// <summary> /// Batch-get multiple libraries, definitions and PSets. /// </summary> /// <param name="libraries">The identifying data for the libraries to get.</param> /// <param name="definitions">The identifying data for the definitions to get.</param> /// <param name="psets">The identifying data for the PSets to get.</param> /// <returns>Does not return anything.</returns> private async Task BatchGet(LibraryIdentity[] libraries, DefinitionIdentity[] definitions, PSetIdentity[] psets) { var batchGetRequest = new BatchGetRequest { Libraries = libraries, // Optional Definitions = definitions, // Optional PSets = psets, // Optional }; Console.WriteLine($"Batch-getting {batchGetRequest.Libraries?.Count} libraries, {batchGetRequest.Definitions.Count} definitions and {batchGetRequest.PSets?.Count} PSets..."); var batchGetResponse = await this.psetClient.BatchGetAsync(batchGetRequest).ConfigureAwait(false); if (batchGetResponse.Responses != null) { Console.WriteLine($"Batch-got {batchGetResponse.Responses.Libraries.Count} libraries:"); this.PrintLibraries(batchGetResponse.Responses.Libraries); Console.WriteLine($"Batch-got {batchGetResponse.Responses.Definitions.Count} definitions:"); this.PrintDefinitions(batchGetResponse.Responses.Definitions); Console.WriteLine($"Batch-got {batchGetResponse.Responses.PSets.Count} PSets:"); this.PrintPSets(batchGetResponse.Responses.PSets); Console.WriteLine(); } if (batchGetResponse.Errors != null) { if (batchGetResponse.Errors.Libraries != null) { Console.WriteLine("Library errors:"); foreach (var libraryError in batchGetResponse.Errors.Libraries) { Console.WriteLine($"{libraryError.Code} {libraryError.Message}"); if (libraryError.Item != null) { Console.WriteLine($" LibraryId={libraryError.Item.LibraryId}"); } } Console.WriteLine(); } if (batchGetResponse.Errors.Definitions != null) { Console.WriteLine("Definition errors:"); foreach (var definitionError in batchGetResponse.Errors.Definitions) { Console.WriteLine($"{definitionError.Code} {definitionError.Message}"); if (definitionError.Item != null) { Console.WriteLine($" LibraryId={definitionError.Item.LibraryId}, DefinitionId={definitionError.Item.DefinitionId}"); } } Console.WriteLine(); } if (batchGetResponse.Errors.PSets != null) { Console.WriteLine("PSet errors:"); foreach (var psetError in batchGetResponse.Errors.PSets) { Console.WriteLine($"{psetError.Code} {psetError.Message}"); if (psetError.Item != null) { Console.WriteLine($" LibraryId={psetError.Item.LibraryId}, DefinitionId={psetError.Item.DefinitionId}, Link={psetError.Item.Link}"); } } Console.WriteLine(); } } }