/// <summary>
        /// Creating logs to send logging worker. 
        /// </summary>
        /// <param name="originalDocuments"></param>
        /// <param name="failedDocuments"></param>
        /// <param name="bulkTagRecord"></param>
        private List<JobWorkerLog<TagLogInfo>> CreateLogs(List<BulkDocumentInfoBEO> originalDocuments, 
            IEnumerable<KeyValuePair<string, string>> failedDocuments, 
            BulkTagRecord bulkTagRecord)
        {
            var jobWorkerLogs = new List<JobWorkerLog<TagLogInfo>>();
            foreach (var failedDocument in failedDocuments)
            {
                var documentLog = originalDocuments.Find(d => d.DocumentId == failedDocument.Key);
                if (null == documentLog) continue;

                var logInfo = new TagLogInfo
                {
                    Information = string.Format("{0} : {1}",documentLog.DCN , failedDocument.Value),
                    IsFailureInDatabaseUpdate = false,
                    IsFailureInSearchUpdate = true,
                    DocumentControlNumber = documentLog.DCN,
                    DocumentId = failedDocument.Key,                    
                };

                var jobWorkerLog = new JobWorkerLog<TagLogInfo>
                {
                    JobRunId = Convert.ToInt32(PipelineId),
                    WorkerInstanceId = WorkerId,
                    WorkerRoleType = WorkerRoletype,
                    Success = false,
                    IsMessage = false,
                    LogInfo = logInfo
                };
                jobWorkerLogs.Add(jobWorkerLog);
                if (!bulkTagRecord.Notification.DocumentsFailed.Exists(d => d == failedDocument.Key))
                {
                    bulkTagRecord.Notification.DocumentsFailed.Add(failedDocument.Key);
                }
            }
            return jobWorkerLogs;
        }
        /// <summary>
        /// Helper method to update the tag log in database
        /// </summary>
        /// <param name="bulkTagRecord"></param>
        private void UpdateTagStatistics(BulkTagRecord bulkTagRecord)
        {
            var taglog = new TagLogBEO
                                       {
                                           DatasetId = Convert.ToInt32(bulkTagRecord.DatasetId),
                                           JobId = WorkAssignment.JobId,
                                           AlreadyTag = _documentsAlreadyTagged,
                                           FailedTag = _documentsFailed,
                                           DocumentTag = _documentsTagged
                                       };

            RVWTagBO.UpdateTagLog(taglog);
        }
 private void Send(BulkTagRecord bulkTagRecord)
 {
     var message = new PipeMessageEnvelope()
     {
         Body = bulkTagRecord
     };
     if (null != OutputDataPipe)
     {
         OutputDataPipe.Send(message);
         IncreaseProcessedDocumentsCount(bulkTagRecord.Documents.Count);
     }
 }
        /// <summary>
        /// This method groups the results into batches and send
        /// </summary>
        /// <param name="documents"></param>
        private void GroupDocumentsAndSend(List<BulkDocumentInfoBEO> documents)
        {
            documents = GatherFamiliesAndDuplicates(documents);

            // Construct the record object for the successive worker, with the boot param
            var bulkTagRecord = new BulkTagRecord
            {
                BinderId = _mBootObject.BinderId,
                CollectionId = _mBootObject.TagDetails.CollectionId,
                MatterId = _mBootObject.TagDetails.MatterId,
                DatasetId = _mBootObject.TagDetails.DatasetId,
                ReviewSetId = _mBootObject.DocumentListDetails.SearchContext.ReviewSetId,
                NumberOfOriginalDocuments = _mTotalDocumentCount,
                CreatedByUserGuid = _mBootObject.JobScheduleCreatedBy
            };

            // Fill the tag details in record object
            var tagRecord = new TagRecord
            {
                Id = _mBootObject.TagDetails.Id,
                ParentId = _mBootObject.TagDetails.ParentTagId,
                Name = _mBootObject.TagDetails.Name,
                TagDisplayName = _mBootObject.TagDetails.TagDisplayName,
                IsOperationTagging = _mBootObject.IsOperationTagging,
                IsTagAllDuplicates = _mBootObject.IsTagAllDuplicates,
                IsTagAllFamily = _mBootObject.IsTagAllFamily
            };

            tagRecord.TagBehaviors.AddRange(_mBootObject.TagDetails.TagBehaviors);

            bulkTagRecord.SearchContext = _mSearchContext;
            bulkTagRecord.TagDetails = tagRecord;

            // Determine # of batches for documents to be sent
            var documentsCopy = new List<BulkDocumentInfoBEO>(documents);
            var noOfBatches = (documentsCopy.Count % _mWindowSize == 0)
                ? (documents.Count / _mWindowSize)
                : (documents.Count / _mWindowSize) + 1;
            bulkTagRecord.NumberOfBatches = noOfBatches;

            Tracer.Info(string.Format("Total batch of document(s) determined : {0}", noOfBatches));
            var processedDocCount = 0;
            for (var i = 0; i < noOfBatches; i++)
            {
                // Group documents and send it to next worker
                bulkTagRecord.Documents = documentsCopy.Skip(processedDocCount).Take(_mWindowSize).ToList();
                processedDocCount += _mWindowSize;
                Send(bulkTagRecord);
            }
        }