public Task <BatchUpdateResult <T> > BatchUpdateAsync(IEnumerable <T> objects, CancellationToken cancellationToken = default) { var path = GetRoute <T>("batch", "update"); var request = new BatchUpdateRequest(objects); return(_client.ExecuteAsync <BatchUpdateResult <T>, BatchUpdateRequest>(path, request, Method.POST, cancellationToken)); }
public async Task BatchUpdateListBlockItemsAsync(BatchUpdateRequest batchUpdateRequest) { using (var connection = await CreateNewConnectionAsync(batchUpdateRequest.TaskId).ConfigureAwait(false)) { var command = connection.CreateCommand(); var transaction = connection.BeginTransaction(); command.Connection = connection; command.Transaction = transaction; command.CommandTimeout = ConnectionStore.Instance.GetConnection(batchUpdateRequest.TaskId).QueryTimeoutSeconds;; try { var tableName = await CreateTemporaryTableAsync(command).ConfigureAwait(false); var dt = GenerateDataTable(batchUpdateRequest.ListBlockId, batchUpdateRequest.ListBlockItems); await BulkLoadInTransactionOperationAsync(dt, tableName, connection, transaction).ConfigureAwait(false); await PerformBulkUpdateAsync(command, tableName).ConfigureAwait(false); transaction.Commit(); } catch (SqlException sqlEx) { TryRollBack(transaction, sqlEx); } catch (Exception ex) { TryRollback(transaction, ex); } } }
protected void CommitUncommittedItems() { List <IListBlockItem <TItem> > listToCommit = null; lock (_uncommittedListSyncRoot) { if (_uncommittedItems != null && _uncommittedItems.Any()) { listToCommit = new List <IListBlockItem <TItem> >(_uncommittedItems); _uncommittedItems.Clear(); } } if (listToCommit != null && listToCommit.Any()) { var batchUpdateRequest = new BatchUpdateRequest() { TaskId = new TaskId(_applicationName, _taskName), ListBlockId = ListBlockId, ListBlockItems = Convert(listToCommit) }; Action <BatchUpdateRequest> actionRequest = _listBlockRepository.BatchUpdateListBlockItems; RetryService.InvokeWithRetry(actionRequest, batchUpdateRequest); } }
// STATUS [ August 3, 2019 ] : this works // BatchUpdateRequest // * Sets values in 1+ ranges of spreadsheet // * Caller must specify sheet ID, a valueInputOption, and 1+ ValueRanges // * Type is Google.Apis.Sheets.v4.SpreadsheetsResource+ValuesResource+BatchUpdateRequest // * See: https://bit.ly/2KBkBbt private BatchUpdateRequest CreateBatchUpdateRequest(BatchUpdateValuesRequest requestBody, string spreadSheetId) { BatchUpdateRequest request = _sheetsService.Spreadsheets.Values.BatchUpdate( requestBody, spreadSheetId ); return(request); }
// STATUS [ August 3, 2019 ] : this works /// <param name="data">todo: describe data parameter on WriteGoogleSheetColumnsAsync</param> /// <param name="sheetName">todo: describe sheetName parameter on WriteGoogleSheetColumnsAsync</param> /// <param name="range">todo: describe range parameter on WriteGoogleSheetColumnsAsync</param> /// <param name="jsonGroupName">todo: describe jsonGroupName parameter on WriteGoogleSheetColumnsAsync</param> /// <example> /// await _gSC.WriteGoogleSheetColumnsAsync(listOfLists, "YAHOO_TRENDS","A1:Z1000","CoreCalculator"); /// </example> public async Task <string> WriteGoogleSheetColumnsAsync(IList <IList <object> > data, string sheetName, string range, string jsonGroupName) { // _helpers.StartMethod(); ConnectToGoogle(); _spreadSheetId = SelectGoogleSheetToRead(jsonGroupName, "SpreadsheetId"); ValueRange dataValueRange = SetSheetDataValueRange(_columnsMajorDimension, sheetName, range, data); List <ValueRange> updateData = CreateValueRangeList(dataValueRange); BatchUpdateValuesRequest requestBody = CreateBatchUpdateValuesRequest(_userEnteredValueInputOption, updateData); BatchUpdateRequest request = CreateBatchUpdateRequest(requestBody, _spreadSheetId); BatchUpdateValuesResponse response = await CreateBatchUpdateValuesResponseAsync(request).ConfigureAwait(false); // PRINTERS // PrintRequestBodyData(requestBody); // PrintUpdateRangeDetails(sheetName, range, jsonGroupName, spreadsheetId); // LogSpreadsheetUpdateDetails(response); return(JsonConvert.SerializeObject(response)); }
public static void ShablonDuplicater(int shID, string title) { CopySheetToAnotherSpreadsheetRequest requestBody = new CopySheetToAnotherSpreadsheetRequest { DestinationSpreadsheetId = SpreadsheetId }; SpreadsheetsResource.SheetsResource.CopyToRequest request = service.Spreadsheets.Sheets.CopyTo(requestBody, SpreadsheetId, shID); SheetProperties response = request.Execute(); BatchUpdateSpreadsheetRequest requestBodyBU = new BatchUpdateSpreadsheetRequest(); IList <Request> LQReq = new List <Request>(); LQReq.Add(google_requests.RenamerSh(response.SheetId, title)); requestBodyBU.Requests = LQReq; BatchUpdateRequest BUrequest = service.Spreadsheets.BatchUpdate(requestBodyBU, SpreadsheetId); var resp2 = BUrequest.Execute(); newSheetId = response.SheetId ?? 0; }
internal async Task <bool> DeleteRow(string guid) { bool success; Cell deleteCell = await QueryGuidExists(guid); if (!deleteCell.Equals(Cell.InvalidCell)) { Request requestBody = new Request() { DeleteDimension = new DeleteDimensionRequest() { Range = new DimensionRange() { SheetId = 0, Dimension = "ROWS", StartIndex = deleteCell.Row - 1, EndIndex = deleteCell.Row } } }; List <Request> requestContainer = new List <Request>(); requestContainer.Add(requestBody); BatchUpdateSpreadsheetRequest deleteRequest = new BatchUpdateSpreadsheetRequest(); deleteRequest.Requests = requestContainer; BatchUpdateRequest deletion = new BatchUpdateRequest(SheetsService, deleteRequest, SpreadsheetId); await deletion.ExecuteAsync(); success = true; } else { success = false; } return(success); }
protected async Task CommitUncommittedItemsAsync() { List <IListBlockItem <TItem> > listToCommit = null; if (_uncommittedItems != null && _uncommittedItems.Any()) { listToCommit = new List <IListBlockItem <TItem> >(_uncommittedItems); _uncommittedItems.Clear(); } if (listToCommit != null && listToCommit.Any()) { var batchUpdateRequest = new BatchUpdateRequest() { TaskId = new TaskId(_applicationName, _taskName), ListBlockId = ListBlockId, ListBlockItems = Convert(listToCommit) }; Func <BatchUpdateRequest, Task> actionRequest = _listBlockRepository.BatchUpdateListBlockItemsAsync; await RetryService.InvokeWithRetryAsync(actionRequest, batchUpdateRequest).ConfigureAwait(false); } }
public static async System.Threading.Tasks.Task ReadEntriesAsync(Dictionary <string, object> dic) { int year = ((DateTime)dic["date"]).Year; int month = ((DateTime)dic["date"]).Month; dic["date"] = ((DateTime)dic["date"]).ToString("dd/MM/yyyy"); //string mont_nm = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(((DateTime)dic["date"]).Month); //string mont_nm = ((DateTime)dic["date"]).Month.ToString("MMMM", new CultureInfo("ru-RU")); string[] months = { "Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь" }; string mont_nm = months[month - 1].ToLower(); int sh_ID = 0; SheetExist(year); sh_ID = Googles.sheet_id; sheet = SheetName; var range = $"{sheet}!A:K"; //находить пустые строки при месяце //range A:A //IF row[0] == mont_nm то вставить строчку выше(если строчка выше пустая if предыдущий row[1] <> "", то получить ее номер, если нет новую) //заность данные туда. Получить координаты этой строчки (A + row.number, K + row.number) //ну и собстно поехали int inp_row = 0; int inp_row_mount = 0; SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(SpreadsheetId, range); var lol = service.Spreadsheets.Get(SpreadsheetId).Execute(); var response = request.Execute(); IList <IList <object> > values = response.Values; if (values != null && values.Count > 0) { foreach (var row in values) { if (row[0].ToString() == mont_nm.ToLower()) { inp_row = inp_row_mount = values.IndexOf(row) + 1; //Получаем индекс предыдущей строки (или нужен настоящей?) //проверка на пустую строку должна быть, если строка не пустая вставить строку а не апдейтить //тобишь если строка row.count > 1 break; } } //нашли строку, смотрим пустая она //если да пишем в нее IList <Request> LQReq = new List <Request>(); if (values[inp_row - 1].Count > 1) { if (values[inp_row][0].ToString().Length > 1) //если в следующей строке в месяце что-то написано { await InsertRowAsync(dic, inp_row + 1); Debug.WriteLine("RETURN HOME"); RB.fst_clm = 0; RB.sec_clm = 1; RB.fst_rw = inp_row - 1; RB.sec_rw = inp_row + 1; LQReq.Add(Merger(sh_ID)); Debug.WriteLine("MERGER"); } else { while (values[inp_row][0].ToString().Length == 0) { inp_row++; } await InsertRowAsync(dic, inp_row + 1); Debug.WriteLine("RETURN HOME"); RB.fst_clm = 0; RB.sec_clm = 1; RB.fst_rw = inp_row_mount - 1; RB.sec_rw = inp_row + 1; LQReq.Add(Merger(sh_ID)); Debug.WriteLine("MERGER"); } //foreach (Request item in google_requests.FormateRq(sh_ID, inp_row)) // { //LQReq.Add(item); //} BatchUpdateSpreadsheetRequest requestBody = new BatchUpdateSpreadsheetRequest(); requestBody.Requests = LQReq; BatchUpdateRequest BUrequest = service.Spreadsheets.BatchUpdate(requestBody, SpreadsheetId); BUrequest.Execute(); } else { //пустая, использовать существующий номер UpdateEntry(inp_row, dic); } } else { Debug.WriteLine("No data found."); } //sheetInfo = service.Spreadsheets.Get(SpreadsheetId).Execute(); sheetInfo = Googles.service.Spreadsheets.Get(Googles.SpreadsheetId).Execute(); Toast.MakeText(Android.App.Application.Context, "Запись прошла успешна", ToastLength.Long).Show(); }
public IActionResult UpdateMaterialBatch(Guid batchId, [FromBody] BatchUpdateRequest batchUpdateRequest) { if (batchUpdateRequest == null || batchUpdateRequest.ExpirationDate == null || batchUpdateRequest.StorageSiteId == null || batchUpdateRequest.StorageAreaId == null || batchUpdateRequest.CustomProps == null) { return(HandleBadRequest("Batch data missing for batch update.")); } // Validate batch number if (batchUpdateRequest.BatchNumber <= 0) { return(HandleBadRequest("The batch number must be greater than 0!")); } try { // Get material Material material = MaterialsService.GetMaterial(batchUpdateRequest.MaterialId); // Get storage location StorageSite site = LocationsService.GetStorageSite(batchUpdateRequest.StorageSiteId); StorageArea area = site.Areas.FirstOrDefault(a => a.Id == batchUpdateRequest.StorageAreaId); if (area == null) { throw new StorageAreaNotFoundException(site.Id, batchUpdateRequest.StorageAreaId); } StorageLocation storageLocation = new StorageLocation(site, area); // Proceed with creation and return new batch! MaterialBatch batch = InventoryService.UpdateMaterialBatch(batchId, material, batchUpdateRequest.ExpirationDate, storageLocation, batchUpdateRequest.BatchNumber, batchUpdateRequest.CustomProps); return(Ok(batch)); } catch (MaterialNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (StorageSiteNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (StorageAreaNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (ArgumentException exception) { return(HandleBadRequest(exception.Message)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }
// STATUS [ August 3, 2019 ] : this works // BatchUpdateValuesResponse // * "The response when updating a range of values in a spreadsheet" // * Type is Google.Apis.Sheets.v4.Data.BatchUpdateValuesResponse // * To do this async --> Data.BatchUpdateValuesResponse response = await request.ExecuteAsync(); // * See: https://bit.ly/2ZG0VJq private async static Task <BatchUpdateValuesResponse> CreateBatchUpdateValuesResponseAsync(BatchUpdateRequest request) { BatchUpdateValuesResponse response = await request.ExecuteAsync().ConfigureAwait(false); return(response); }
// STATUS [ August 3, 2019 ] : this works // BatchUpdateValuesResponse // * "The response when updating a range of values in a spreadsheet" // * Type is Google.Apis.Sheets.v4.Data.BatchUpdateValuesResponse // * To do this async --> Data.BatchUpdateValuesResponse response = await request.ExecuteAsync(); // * See: https://bit.ly/2ZG0VJq private static BatchUpdateValuesResponse CreateBatchUpdateValuesResponse(BatchUpdateRequest request) { BatchUpdateValuesResponse response = request.Execute(); return(response); }