Esempio n. 1
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());
        }
Esempio n. 2
0
        private WriteResponse[] DirectInvoke(Record[] records, string methodName, int batchSize)
        {
            var beforeUploadArgs = new BeforeBatchUploadEventArgs(methodName, records.Length, batchSize);

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

            beforeUploadHandler(beforeUploadArgs.UpdateData(records, 1));
            var results = InvokeService <WriteResponse[]>(records, methodName);

            afterUploadHandler(new AfterBatchUploadEventArgs(beforeUploadArgs, results).UpdateData(0));
            return(results);
        }