예제 #1
0
        private WriteResponse[] ProcessRecordDeletesInBatchMode(BaseRef[] records, string methodName)
        {
            int batchSize        = Configuration.DeleteRequestSize;
            var beforeUploadArgs = new BeforeBatchDeleteEventArgs(methodName, records.Length, batchSize);

            var beforeUploadHandler = GetBeforeDeleteHandler();
            var afterUploadHandler  = GetAfterDeleteHandler();

            if (records.Length <= batchSize)
            {
                beforeUploadHandler(beforeUploadArgs.UpdateData(records, 1));
                var result = InvokeService <WriteResponse[]>(records, methodName);
                afterUploadHandler(new AfterBatchUploadEventArgs(beforeUploadArgs, result).UpdateData(0));
                return(result);
            }

            List <WriteResponse> responses = new List <WriteResponse>(records.Length);
            var afterUploadArgs            = new AfterBatchUploadEventArgs(null, responses);

            BaseRef[] batch         = new BaseRef[batchSize];
            int       leftOverCount = 0;
            int       batchNumber   = 1;
            int       responseStartIndex;

            for (int i = 0; i < records.Length; i++)
            {
                if (i != 0 && (i % Configuration.DeleteRequestSize == 0))
                {
                    beforeUploadHandler(beforeUploadArgs.UpdateData(batch, batchNumber));
                    responseStartIndex = responses.Count;
                    ProcessDeleteBatch(batch, responses, methodName);
                    afterUploadHandler(afterUploadArgs.UpdateData(responseStartIndex));
                    ++batchNumber;

                    leftOverCount = 0;
                    batch         = new BaseRef[Configuration.DeleteRequestSize];
                }
                batch[i % Configuration.DeleteRequestSize] = records[i];
                ++leftOverCount;
            }

            BaseRef[] leftOvers = new BaseRef[leftOverCount];
            Array.Copy(batch, leftOvers, leftOverCount);

            beforeUploadHandler(beforeUploadArgs.UpdateData(leftOvers, batchNumber));
            responseStartIndex = responses.Count;
            ProcessDeleteBatch(leftOvers, responses, methodName);
            afterUploadHandler(afterUploadArgs.UpdateData(responseStartIndex));
            return(responses.ToArray());
        }
예제 #2
0
        private WriteResponse[] BatchInvoke(Record[] records, string methodName, int batchSize)
        {
            if (_log.IsDebugEnabled)
            {
                _log.Debug(string.Format("Executing {0} in batch mode: {1} records, {2} batch size", methodName, records.Length, batchSize));
            }

            var beforeUploadArgs = new BeforeBatchUploadEventArgs(methodName, records.Length, batchSize);

            var beforeUploadHandler = GetBeforeUploadHandler();
            var afterUploadHandler  = GetAfterUploadHandler();

            var responses       = new List <WriteResponse>(records.Length);
            var afterUploadArgs = new AfterBatchUploadEventArgs(beforeUploadArgs, responses);

            Record[] batch         = new Record[batchSize];
            int      leftOverCount = 0;
            int      batchNumber   = 1;
            int      responseStartIndex;

            for (int i = 0; i < records.Length; i++)
            {
                if (i != 0 && (i % batchSize == 0))
                {
                    beforeUploadHandler(beforeUploadArgs.UpdateData(batch, batchNumber));
                    responseStartIndex = responses.Count;
                    ProcessBatch(batch, responses, methodName);
                    afterUploadHandler(afterUploadArgs.UpdateData(responseStartIndex));
                    ++batchNumber;

                    leftOverCount = 0;
                    batch         = new Record[batchSize];
                }
                batch[i % batchSize] = records[i];
                ++leftOverCount;
            }

            Record[] leftOvers = new Record[leftOverCount];
            Array.Copy(batch, leftOvers, leftOverCount);

            beforeUploadHandler(beforeUploadArgs.UpdateData(leftOvers, batchNumber));
            responseStartIndex = responses.Count;
            ProcessBatch(leftOvers, responses, methodName);
            afterUploadHandler(afterUploadArgs.UpdateData(responseStartIndex));
            return(responses.ToArray());
        }