Example #1
0
            private long BatchBytesSize()
            {
                long entityBytes = 0;

                EntitiesToBatch.ForEach(ent => entityBytes += ent.EntityByteSize);
                return(entityBytes);
            }
Example #2
0
            public void GroupEntitiesIntoBatches()
            {
                BatchList.Clear();
                EntitiesToBatch.ForEach(ent => ent.IsInBatch = false);
                const int maxBatchCount = 100;
                const int maxBatchSize  = 4194304;
                var       qtyRemaining  = EntitiesToBatch.Count;

                while (qtyRemaining > 0)
                {
                    var batch            = new TableBatchOperation();
                    var currentBatchQty  = 0;
                    var currentBatchSize = 0;
                    foreach (var entityBatchPair in EntitiesToBatch.Where(etb => !etb.IsInBatch).Select(e => e))
                    {
                        var newSize = currentBatchSize + entityBatchPair.EntityByteSize;
                        if (newSize <= maxBatchSize && currentBatchQty < maxBatchCount)
                        {
                            AddOperationToBatch(ref batch, entityBatchPair.TableEntity, _operationName);
                            currentBatchQty++;
                            currentBatchSize += entityBatchPair.EntityByteSize;
                            qtyRemaining--;
                            entityBatchPair.IsInBatch = true;
                        }
                    }
                    BatchList.Add(batch);
                }
            }