Exemplo n.º 1
0
        // execute batch write on a same partition of a same underlying table
        // on succeed, res is filled with exact number of table results, and return -1
        // otherwise, res only contain a single table result of error, and return the error index
        internal static int BatchWrite(IChainTable table, List <Tuple <TableOperationType, ITableEntity, string> > ops, out IList <TableResult> res,
                                       TableRequestOptions options = null, OperationContext context = null)
        {
            TableBatchOperation batch = new TableBatchOperation();

            foreach (var op in ops)
            {
                Assert.IsTrue(op.Item1 == TableOperationType.Insert || op.Item3 != null);
                if (op.Item3 != null)
                {
                    op.Item2.ETag = op.Item3;
                }
                batch.Add(TranslateWriteOp(op.Item1, op.Item2));
            }

            try
            {
                res = table.ExecuteBatch(batch);
                return(-1);
            }
            catch (ChainTableBatchException e)
            {
                res = new List <TableResult>();
                res.Add(new TableResult()
                {
                    Result = null, Etag = e.RequestInformation.Etag, HttpStatusCode = e.RequestInformation.HttpStatusCode
                });
                return(e.FailedOpIndex);
            }
        }