public async Task WriteOneAsync(T entity, TableInsertMode mode = TableInsertMode.Insert)
        {
            // Create the TableOperation that inserts the customer entity.
            TableOperation op;

            switch (mode)
            {
            case TableInsertMode.Insert:
                op = TableOperation.InsertOrReplace(entity);
                break;

            case TableInsertMode.InsertOrMerge:
                op = TableOperation.InsertOrMerge(entity);
                break;

            case TableInsertMode.InsertOrReplace:
                op = TableOperation.InsertOrReplace(entity);
                break;

            default:
                throw new InvalidOperationException("Unsupported insert mode: " + mode.ToString());
            }

            // Execute the insert operation.
            await _table.ExecuteAsync(op);
        }
 public async Task WriteOneAsync(T entity, TableInsertMode mode)
 {
     lock (_lock)
     {
         WriteOneWorker(entity);
     }
 }
        public async Task WriteOneAsync(T entity, TableInsertMode mode)
        {
            await Task.Yield();

            lock (_lock)
            {
                WriteOneWorker(entity);
            }
        }
 // $$$ - Respect insert mode
 public async Task WriteBatchAsync(T[] entities, TableInsertMode mode)
 {
     lock (_lock)
     {
         foreach (var entity in entities)
         {
             WriteOneWorker(entity);
         }
     }
 }
        // All must have the same partition key
        public async Task WriteBatchAsync(T[] entities, TableInsertMode mode = TableInsertMode.Insert)
        {
            if (entities.Length == 0)
            {
                return; // nothing to write.
            }
            string partitionKey = entities[0].PartitionKey;

            const int BatchSize = 99;

            TableBatchOperation batchOperation = new TableBatchOperation();

            foreach (var entity in entities)
            {
                if (entity.PartitionKey != partitionKey)
                {
                    throw new InvalidOperationException("All entities in a batch must have same partition key");
                }

                ValidateRowKey(entity.RowKey);

                switch (mode)
                {
                case TableInsertMode.Insert:
                    batchOperation.Insert(entity);
                    break;

                case TableInsertMode.InsertOrMerge:
                    batchOperation.InsertOrMerge(entity);
                    break;

                case TableInsertMode.InsertOrReplace:
                    batchOperation.InsertOrReplace(entity);
                    break;

                default:
                    throw new InvalidOperationException("Unsupported insert mode: " + mode.ToString());
                }

                if (batchOperation.Count == BatchSize)
                {
                    // Flush
                    await _table.ExecuteBatchAsync(batchOperation);

                    batchOperation = new TableBatchOperation();
                }
            }

            if (batchOperation.Count > 0)
            {
                await _table.ExecuteBatchAsync(batchOperation);
            }
        }