internal async Task <bool> Commit(bool enableTimeAudit = false, int sleepTime = 0) { bool result = true; DateTime startTime = DateTime.Now; Ekin.Clarizen.Bulk.Execute bulkService = await ClarizenAPI.CommitBulkService(_isBulkTransactional, _batch, _includeRequestsInResponse, _timeout); if (bulkService.IsCalledSuccessfully) { foreach (Response res in bulkService.Data.Responses) { if (res.StatusCode != 200) { Logs.AddError("Ekin.Clarizen.BulkOperations", "CommitBulkService", "Bulk item failed. Error: " + ((Error)res.Body).Formatted, _includeRequestsInResponse ? res.Request : null); result = false; } } } else { Logs.AddError("Ekin.Clarizen.BulkOperations", "CommitBulkService", "Bulk service failed. Error: " + bulkService.Error); result = false; } DateTime endTime = DateTime.Now; if (enableTimeAudit) { Logs.AddAudit("Ekin.Clarizen.BulkOperations", "CommitBulkService", string.Format("Bulk API call completed in {0:0.00}s", (endTime - startTime).TotalSeconds)); } if (sleepTime > 0) { await Task.Delay(sleepTime * 1000); } return(result); }
internal async Task <Tuple <List <T>, bool> > Commit <T>(bool enableTimeAudit = false, int sleepTime = 0) { List <T> result = new List <T> { }; DateTime startTime = DateTime.Now; bool hasErrors = false; Ekin.Clarizen.Bulk.Execute bulkService = await ClarizenAPI.CommitBulkService(_isBulkTransactional, _batch, _includeRequestsInResponse, _timeout); if (bulkService.IsCalledSuccessfully) { foreach (Response res in bulkService.Data.Responses) { if (res.StatusCode != 200) { Logs.AddError("Ekin.Clarizen.BulkOperations", "CommitBulkServiceAndGetData", "Bulk item failed. Error: " + ((Error)res.Body).Formatted, _includeRequestsInResponse ? res.Request : null); hasErrors = true; } else { try { if (res.Body is T) { result.Add((T)res.Body); } else { result.Add(default(T)); } } catch (Exception ex) { Logs.AddError("Ekin.Clarizen.BulkOperations", "CommitBulkServiceAndGetData", string.Format("Item returned from Clarizen API could not be parsed to type {0}. Error: {1}", typeof(T), ex.Message)); hasErrors = true; } } } } else { Logs.AddError("Ekin.Clarizen.BulkOperations", "CommitBulkServiceAndGetData", "Bulk service failed. Error: " + bulkService.Error); hasErrors = true; } DateTime endTime = DateTime.Now; if (enableTimeAudit) { Logs.AddAudit("Ekin.Clarizen.BulkOperations", "CommitBulkServiceAndGetData", string.Format("Bulk API call completed in {0:0.00}s", (endTime - startTime).TotalSeconds)); } if (sleepTime > 0) { await Task.Delay(sleepTime * 1000); } if (hasErrors) { return(new Tuple <List <T>, bool>(null, true)); } else { return(new Tuple <List <T>, bool>(result, false)); } }