// August 17, 2019: Not yet implemented but should be private string MajorDimensionString(MajorDimensionEnum dimension) { string dimensionType; switch (dimension) { case MajorDimensionEnum.ROWS: dimensionType = _rowsMajorDimension; return(dimensionType); case MajorDimensionEnum.COLUMNS: dimensionType = _columnsMajorDimension; return(dimensionType); default: throw new Exception("Unexpected Case"); } throw new Exception("GoogleSheetsConnector > MajorDimensionString > ERROR: 'Dimension Enum Type not found'"); }
/// <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); } }