/// <summary>Adds one row to the converter. Once BatchSize is reached, data is written to the server. If you have /// no more data to add, call Flush to push the remaining data to the server.</summary> /// <param name="record">A record to send to the server. </param> /// <remarks> I used object here rather than T so that I can use the interface when dynamically creating BulkCopyHelper.BulkCopyHelper of T via /// reflection (see CreateBasedOnType below).</remarks> public async Task AddRow(T record) { if (record == null) { throw new ArgumentNullException("Please do not pass null records to the AddRow method!"); } if (_initialized == false) { throw new ArgumentException("Please call initialize before calling AddRow."); } CtoDService.AddRow((T)record); if (CtoDService.Count % BatchSize == 0) { await Flush(); } }
/// <summary>Flushes any remaining records to the server. Call this once you are done adding rows so that the last records in the queue /// can be flushed to the server. It's OK to call this method if there is nothing in the queue.</summary> public async Task Flush() { if (_initialized == false) { throw new ArgumentException("Please call initialize before calling flush."); } // Is there anything to save? if (CtoDService.Count == 0) { return; } // WRITE to SERVER! await _bulkCopy.WriteToServerAsync(CtoDService.Table); TotalWrittenCount += CtoDService.Count; CtoDService.Clear(); }