/// <summary>
        /// Construct Log Data
        /// </summary>
        /// <param name="correlationId">The correlation identifier.</param>
        /// <param name="success">if set to <c>true</c> [success].</param>
        /// <param name="dcn">The DCN.</param>
        /// <param name="isErrorInNative">if set to <c>true</c> [is error in native].</param>
        /// <param name="isErrorInText">if set to <c>true</c> [is error in text].</param>
        /// <param name="isErrorInImage">if set to <c>true</c> [is error in image].</param>
        /// <param name="message">The message.</param>
        /// <returns>ExportFileCopyLogInfo</returns>
        public JobWorkerLog <ExportFileCopyLogInfo> ConstructLog(string correlationId, bool success, string dcn, bool isErrorInNative, bool isErrorInText, bool isErrorInImage, string message)
        {
            var metadataLog = new JobWorkerLog <ExportFileCopyLogInfo>
            {
                JobRunId         = (!string.IsNullOrEmpty(PipelineId)) ? Convert.ToInt64(PipelineId) : 0,
                CorrelationId    = (!string.IsNullOrEmpty(correlationId)) ? Convert.ToInt64(correlationId) : 0,
                WorkerInstanceId = WorkerId,
                WorkerRoleType   = Constants.ExportFileCopyWorkerRoleType,
                Success          = success,
                CreatedBy        = _createdBy,
                IsMessage        = false,
                LogInfo          =
                    new ExportFileCopyLogInfo
                {
                    DCN                 = dcn,
                    IsErrorInField      = false,
                    IsErrorInNativeFile = isErrorInNative,
                    IsErrorInImageFile  = isErrorInImage,
                    IsErrorInTextFile   = isErrorInText,
                    Information         = (!string.IsNullOrEmpty(message) ? (message) : string.Empty)
                }
            };

            return(metadataLog);
        }
Example #2
0
        /// <summary>
        /// Construct log
        /// </summary>
        public void ConstructLog(int lawDocumentId, int documentCorrelationId, string documentControlNumber, string message)
        {
            var sbErrorMessage = new StringBuilder();

            sbErrorMessage.Append(message);
            sbErrorMessage.Append(Constants.MessageDCN);
            sbErrorMessage.Append(documentControlNumber);
            sbErrorMessage.Append(Constants.MessageLawDocumentId);
            sbErrorMessage.Append(lawDocumentId);
            var lawSyncLog = new JobWorkerLog <LawSyncLogInfo>
            {
                JobRunId         = Convert.ToInt64(PipelineId),
                CorrelationId    = documentCorrelationId,
                WorkerInstanceId = WorkerId,
                WorkerRoleType   = Constants.LawSyncReProcessStartupWorkerRoleType,
                ErrorCode        = (int)LawSyncErrorCode.DocumentNotAvailble,
                Success          = false,
                CreatedBy        = _lawSyncJobParameter.CreatedBy,
                IsMessage        = false,
                LogInfo          = new LawSyncLogInfo
                {
                    LawDocumentId           = lawDocumentId,
                    DocumentControlNumber   = documentControlNumber,
                    Information             = sbErrorMessage.ToString(),
                    IsFailureInSyncMetadata = true
                }
            };

            _logInfoList.Add(lawSyncLog);
        }
        private void LogMessage(Object documentDetail, bool success, string message)
        {
            const string roleId = "CE73BFB1-94FB-4953-8AF8-B53BE828AD11";

            if (documentDetail is ProductionDocumentDetail)
            {
                var doc       = (ProductionDocumentDetail)documentDetail;
                var log       = new List <JobWorkerLog <ProductionParserLogInfo> >();
                var parserLog = new JobWorkerLog <ProductionParserLogInfo>
                {
                    JobRunId =
                        (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                    CorrelationId    = doc.CorrelationId,
                    WorkerRoleType   = roleId,
                    WorkerInstanceId = WorkerId,
                    IsMessage        = false,
                    Success          = success,
                    CreatedBy        = doc.CreatedBy,
                    LogInfo          =
                        new ProductionParserLogInfo
                    {
                        Information = message,
                        BatesNumber = doc.AllBates,
                        DatasetName = doc.OriginalDatasetName,
                        DCN         = doc.DCNNumber,
                        ProductionDocumentNumber = doc.DocumentProductionNumber,
                        ProductionName           = doc.Profile.ProfileName
                    }
                };

                log.Add(parserLog);
                SendLog(log);
            }
        }
        /// <summary>
        /// Construct Log Message and Call Log pipe
        /// </summary>
        private void LogMessage(DocumentResult document, bool success, string message)
        {
            var log    = new List <JobWorkerLog <LogInfo> >();
            var taskId = Convert.ToInt32(document.DocumentControlNumber.Replace(_mDataSet.DCNPrefix, string.Empty));
            // form the paser lof entity
            var parserLog = new JobWorkerLog <LogInfo>
            {
                JobRunId =

                    (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                CorrelationId    = taskId,
                WorkerRoleType   = "PrintValidationWorker",
                WorkerInstanceId = WorkerId,
                IsMessage        = false,
                Success          = success, //!string.IsNullOrEmpty(documentDetail.DocumentProductionNumber) && success,
                CreatedBy        = bulkPrintServiceRequestBEO.RequestedBy.UserId,
                LogInfo          =
                    new LogInfo
                {
                    TaskKey = document.DocumentControlNumber,
                    IsError = !success
                }
            };

            parserLog.LogInfo.AddParameters(Constants.DCN, document.DocumentControlNumber);
            parserLog.LogInfo.AddParameters(message, mappedPrinter.PrinterDetails.Name);
            log.Add(parserLog);
            SendLog(log);
        }
Example #5
0
        /// <summary>
        ///     Construct Near Duplication Log Info for Document
        /// </summary>
        private JobWorkerLog <NearDuplicationLogInfo> ConstructNearDuplicationLogInfoForDocument(bool isErrorInDatabase,
                                                                                                 bool isErrorInSearchEngine,
                                                                                                 DocumentMasterEntity documentInfo)
        {
            string documentControlNumber = documentInfo.DocumentTitle;
            var    nearDuplicationLog    = new JobWorkerLog <NearDuplicationLogInfo>
            {
                JobRunId =
                    (!string.IsNullOrEmpty(PipelineId))
                        ? Convert.ToInt64(PipelineId)
                        : 0,
                CorrelationId    = Convert.ToInt32(documentControlNumber.Replace(_dataset.DCNPrefix, string.Empty)),
                WorkerInstanceId = WorkerId,
                WorkerRoleType   = Constants.NearDuplicationEvUpdateWorkerRoleType,
                Success          = false,
                CreatedBy        = _jobParameter.CreatedBy,
                IsMessage        = false,
                LogInfo          = new NearDuplicationLogInfo
                {
                    DocumentControlNumber     = documentControlNumber,
                    IsFailureInDatabaseUpdate = isErrorInDatabase,
                    IsFailureInSearchUpdate   = isErrorInSearchEngine,
                    Information =
                        string.Format(
                            Constants.
                            NearDuplicationEvUpdateWorkerFailureMessage,
                            documentControlNumber)
                }
            };

            return(nearDuplicationLog);
        }
Example #6
0
 private void LogMessage(bool success, string information)
 {
     try
     {
         var log      = new List <JobWorkerLog <BaseWorkerProcessLogInfo> >();
         var logEntry = new JobWorkerLog <BaseWorkerProcessLogInfo>();
         logEntry.JobRunId            = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
         logEntry.CorrelationId       = 0;
         logEntry.WorkerRoleType      = "8781617C-FE8A-4726-A8B6-D63D36120A0C";
         logEntry.WorkerInstanceId    = WorkerId;
         logEntry.IsMessage           = false;
         logEntry.Success             = success;
         logEntry.CreatedBy           = "N/A";
         logEntry.LogInfo             = new BaseWorkerProcessLogInfo();
         logEntry.LogInfo.Information = information;
         if (!success)
         {
             logEntry.LogInfo.Message = information;
         }
         log.Add(logEntry);
         SendLog(log);
     }
     catch (Exception ex)
     {
         Tracer.Error("Conversion Reprocess Startup Worker: " + ex.Message);
     }
 }
Example #7
0
        public ProductionWorkerLogBEO ConstructProductionWorkerLog <T>(JobWorkerLog <T> log)
        {
            ProductionWorkerLogBEO workerLog = new ProductionWorkerLogBEO();

            workerLog.JobRunId         = Convert.ToInt32(log.JobRunId);
            workerLog.CorrelationId    = log.CorrelationId;
            workerLog.WorkerInstanceId = log.WorkerInstanceId;
            workerLog.WorkerRoleType   = log.WorkerRoleType;
            workerLog.IsError          = !log.Success;
            workerLog.CreatedBy        = log.CreatedBy;
            if (log is JobWorkerLog <ProductionParserLogInfo> )
            {
                var documentParserLog = log as JobWorkerLog <ProductionParserLogInfo>;
                workerLog.DCN         = documentParserLog.LogInfo.DCN;
                workerLog.DatasetName = documentParserLog.LogInfo.DatasetName;
                workerLog.BatesNumber = documentParserLog.LogInfo.BatesNumber;
                workerLog.ProductionDocumentNumber = documentParserLog.LogInfo.ProductionDocumentNumber;
                workerLog.ProductionName           = documentParserLog.LogInfo.ProductionName;
                workerLog.LogDescription           = documentParserLog.LogInfo.Information;
            }
            else if (log is JobWorkerLog <ProductionParserLogInfo> )
            {
                var productionParserLog = log as JobWorkerLog <ProductionParserLogInfo>;
                workerLog.LogDescription = productionParserLog.LogInfo.Information;
            }

            return(workerLog);
        }
Example #8
0
        private void LogMessage(ProductionDocumentDetail documentDetail, bool success, string message, bool isMessage)
        {
            const string roleId    = "prod0fc6-113e-4217-9863-ec58c3f7yz89";
            var          log       = new List <JobWorkerLog <ProductionParserLogInfo> >();
            var          parserLog = new JobWorkerLog <ProductionParserLogInfo>
            {
                JobRunId =
                    (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                CorrelationId    = documentDetail.CorrelationId,
                WorkerRoleType   = roleId,
                WorkerInstanceId = WorkerId,
                IsMessage        = isMessage,
                Success          = success,
                CreatedBy        = documentDetail.CreatedBy,
                LogInfo          =
                    new ProductionParserLogInfo
                {
                    Information = message,
                    BatesNumber = documentDetail.AllBates,
                    DatasetName = documentDetail.OriginalDatasetName,
                    DCN         = documentDetail.DCNNumber,
                    ProductionDocumentNumber = documentDetail.DocumentProductionNumber,
                    ProductionName           = documentDetail.Profile.ProfileName
                }
            };

            log.Add(parserLog);
            SendLog(log);
        }
Example #9
0
        /// <summary>
        /// Construct Log Data
        /// </summary>
        public JobWorkerLog <ExportMetadataLogInfo> ConstructLog(string correlationId, bool success, string dcn, bool isErrorInDocument, bool isErrorInTag, string message)
        {
            var metadataLog = new JobWorkerLog <ExportMetadataLogInfo>
            {
                JobRunId         = (!string.IsNullOrEmpty(PipelineId)) ? Convert.ToInt64(PipelineId) : 0,
                CorrelationId    = (!string.IsNullOrEmpty(correlationId)) ? Convert.ToInt64(correlationId) : 0,
                WorkerInstanceId = WorkerId,
                WorkerRoleType   = Constants.ExportMetadataWorkerRoleType,
                Success          = success,
                CreatedBy        = "NA",
                IsMessage        = false,
                LogInfo          = new ExportMetadataLogInfo {
                    DCN = dcn
                }
            };

            if (isErrorInDocument)
            {
                metadataLog.LogInfo.IsErrorInField      = true;
                metadataLog.LogInfo.IsErrorInNativeFile = true;
                metadataLog.LogInfo.IsErrorInImageFile  = true;
                metadataLog.LogInfo.IsErrorInTextFile   = true;
            }
            if (isErrorInTag)
            {
                metadataLog.LogInfo.IsErrorInTag = true;
            }
            if (!success)
            {
                metadataLog.LogInfo.Information = (!string.IsNullOrEmpty(message) ? (message + ". DCN:" + dcn) : string.Empty);
            }
            return(metadataLog);
        }
Example #10
0
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 private void LogMessage(bool status, string information, string createdBy, string reviewsetName)
 {
     try
     {
         var log       = new List <JobWorkerLog <ReviewsetLogInfo> >();
         var parserLog = new JobWorkerLog <ReviewsetLogInfo>
         {
             JobRunId =
                 (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
             CorrelationId    = 0,
             WorkerRoleType   = Constants.ReviewsetVaultUpdateRoleID,
             WorkerInstanceId = WorkerId,
             IsMessage        = false,
             Success          = status,
             CreatedBy        = createdBy,
             LogInfo          = new ReviewsetLogInfo {
                 Information = information, ReviewsetName = reviewsetName
             }
         };
         // TaskId
         log.Add(parserLog);
         SendLog(log);
     }
     catch (Exception exception)
     {
         Tracer.Info("ReviewsetVaultUpdateWorker : LogMessage : Exception details: {0}", exception);
     }
 }
        public void ConstructLog(string documentControlNumber, string message)
        {
            var nearDuplicationLog = new JobWorkerLog <NearDuplicationLogInfo>
            {
                JobRunId =
                    (!string.IsNullOrEmpty(PipelineId))
                                                     ? Convert.ToInt64(PipelineId)
                                                     : 0,
                CorrelationId = (!string.IsNullOrEmpty(documentControlNumber)
                                                                     ? Convert.ToInt32(
                                     documentControlNumber.Replace(_dataset.DCNPrefix, string.Empty))        //To get dcn prefix number to log document related failures in Job
                                                                     : new Random().Next(1000000, 10000000)  //To get random number to log common failures in Job
                                 ),
                WorkerInstanceId = WorkerId,
                WorkerRoleType   = Constants.NearDuplicationStartupWorkerRoleType,
                Success          = string.IsNullOrEmpty(documentControlNumber),
                CreatedBy        = _jobParameter.CreatedBy,
                IsMessage        = string.IsNullOrEmpty(documentControlNumber),
                LogInfo          = new NearDuplicationLogInfo
                {
                    DocumentControlNumber = documentControlNumber,
                    IsMissingText         = !string.IsNullOrEmpty(documentControlNumber),
                    Information           = (message + documentControlNumber)
                }
            };

            _logInfoList.Add(nearDuplicationLog);
        }
        private List <JobWorkerLog <ExportLoadFileWritterLogInfo> > WriteLoadFiles()
        {
            var fileWriterLogList = new List <JobWorkerLog <ExportLoadFileWritterLogInfo> >();

            #region Construct Data

            Parallel.ForEach(exportDocumentCollection.Documents,
                             new ParallelOptions {
                MaxDegreeOfParallelism = _maxParallelThread
            },
                             (doc) =>
            {
                var loadFileDataRow    = string.Empty;
                var textHelperFileRow  = string.Empty;
                var imageHelperFileRow = string.Empty;
                JobWorkerLog <ExportLoadFileWritterLogInfo> fileWriterLog = null;

                ConstructAllData(doc, out loadFileDataRow, out textHelperFileRow, out imageHelperFileRow,
                                 out fileWriterLog);

                lock (loadFileSortOrderCollection)
                {
                    if (!string.IsNullOrEmpty(loadFileDataRow))
                    {
                        if (!loadFileSortOrderCollection.Keys.Contains(doc.DCN.Trim()))
                        {
                            loadFileSortOrderCollection.Add(doc.DCN.Trim(), loadFileDataRow);
                        }
                    }
                    if (!string.IsNullOrEmpty(textHelperFileRow))
                    {
                        if (!textFileSortOrderCollection.Keys.Contains(doc.DCN.Trim()))
                        {
                            textFileSortOrderCollection.Add(doc.DCN.Trim(), textHelperFileRow);
                        }
                    }
                    if (!string.IsNullOrEmpty(imageHelperFileRow))
                    {
                        if (!imageFileSortOrderCollection.Keys.Contains(doc.DCN.Trim()))
                        {
                            imageFileSortOrderCollection.Add(doc.DCN.Trim(), imageHelperFileRow);
                        }
                    }
                    if (fileWriterLog != null)
                    {
                        fileWriterLogList.Add(fileWriterLog);
                    }
                }
            });

            #endregion

            IncreaseProcessedDocumentsCount(exportDocumentCollection.Documents.Count());

            return(fileWriterLogList);
        }
Example #13
0
        /// <summary>
        /// Reports the errors.
        /// </summary>
        /// <param name="logPipe"></param>
        /// <param name="errorDocumentDetails">The error document details.</param>
        /// <param name="pipelineId">The pipeline identifier.</param>
        /// <param name="workerId">The worker identifier.</param>
        /// <param name="workerRoleTypeId"></param>
        /// <returns></returns>
        internal static IEnumerable <JobWorkerLog <ProductionParserLogInfo> > SendProductionLogs(Pipe logPipe, IEnumerable <ProductionDocumentDetail> errorDocumentDetails, string pipelineId, string workerId, string workerRoleTypeId)
        {
            if (errorDocumentDetails == null)
            {
                return(null);
            }
            var productionParserLogInfos = new List <JobWorkerLog <ProductionParserLogInfo> >();

            try
            {
                var jobRunId = Convert.ToInt64(pipelineId);
                foreach (var errorDocument in errorDocumentDetails)
                {
                    var parserLog = new JobWorkerLog <ProductionParserLogInfo>
                    {
                        JobRunId         = jobRunId,
                        CorrelationId    = errorDocument.CorrelationId,
                        WorkerRoleType   = workerRoleTypeId,
                        WorkerInstanceId = workerId,
                        IsMessage        = false,
                        Success          = false,
                        CreatedBy        = errorDocument.CreatedBy,
                        LogInfo          =
                            new ProductionParserLogInfo
                        {
                            Information = errorDocument.ErrorMessage,
                            BatesNumber = errorDocument.AllBates,
                            DatasetName = errorDocument.OriginalDatasetName,
                            DCN         = errorDocument.DCNNumber,
                            ProductionDocumentNumber = errorDocument.DocumentProductionNumber,
                            ProductionName           = errorDocument.Profile.ProfileName
                        }
                    };
                    productionParserLogInfos.Add(parserLog);
                    if (logPipe == null)
                    {
                        Trace.TraceError("log pipe is empty");
                    }
                    logPipe.Open();
                    var message = new PipeMessageEnvelope()
                    {
                        Body = productionParserLogInfos
                    };
                    logPipe.Send(message);
                }
            }
            catch (Exception exception)
            {
                var dcns = String.Join(",", errorDocumentDetails.Select(errorDoc => errorDoc.DCNNumber));
                exception.AddDbgMsg("Failed to send documents to Redact-It and failed in reporting errors");
                exception.AddDbgMsg(string.Format("Document Control Numbers:{0}", dcns));
                exception.Trace().Swallow();
            }
            return(productionParserLogInfos);
        }
        /// <summary>
        /// Reports the errors.
        /// </summary>
        /// <param name="logPipe"></param>
        /// <param name="errorDocumentDetails">The error document details.</param>
        /// <param name="pipelineId">The pipeline identifier.</param>
        /// <param name="workerId">The worker identifier.</param>
        /// <param name="workerRoleTypeId"></param>
        /// <returns></returns>
        internal static IEnumerable<JobWorkerLog<ProductionParserLogInfo>> SendProductionLogs(Pipe logPipe, IEnumerable<ProductionDocumentDetail> errorDocumentDetails, string pipelineId, string workerId, string workerRoleTypeId)
        {
            if(errorDocumentDetails==null) return null;
             var productionParserLogInfos = new List<JobWorkerLog<ProductionParserLogInfo>>();
            try
            {
               
                var jobRunId = Convert.ToInt64(pipelineId);
                foreach (var errorDocument in errorDocumentDetails)
                {


                    var parserLog = new JobWorkerLog<ProductionParserLogInfo>
                    {
                        JobRunId =jobRunId,
                        CorrelationId = errorDocument.CorrelationId,
                        WorkerRoleType = workerRoleTypeId,
                        WorkerInstanceId = workerId,
                        IsMessage = false,
                        Success = false,
                        CreatedBy = errorDocument.CreatedBy,
                        LogInfo =
                            new ProductionParserLogInfo
                            {
                                Information = errorDocument.ErrorMessage,
                                BatesNumber = errorDocument.AllBates,
                                DatasetName = errorDocument.OriginalDatasetName,
                                DCN = errorDocument.DCNNumber,
                                ProductionDocumentNumber = errorDocument.DocumentProductionNumber,
                                ProductionName = errorDocument.Profile.ProfileName
                            }
                    };
                  productionParserLogInfos.Add(parserLog);
                  if (logPipe == null) 
                      Trace.TraceError("log pipe is empty");
                  logPipe.Open();
                  var message = new PipeMessageEnvelope()
                  {
                      Body = productionParserLogInfos
                  };
                  logPipe.Send(message);
                }
              
            }
            catch (Exception exception)
            {
                var dcns = String.Join(",", errorDocumentDetails.Select(errorDoc => errorDoc.DCNNumber));
                exception.AddDbgMsg("Failed to send documents to Redact-It and failed in reporting errors");
                exception.AddDbgMsg(string.Format("Document Control Numbers:{0}", dcns));
                exception.Trace().Swallow();
            }
            return productionParserLogInfos;
        }
Example #15
0
        /// <summary>
        /// Gets the law documents based on filter tags it includes mapped fields and tags
        /// </summary>
        /// <param name="correlationId"></param>
        /// <param name="documentCtrlNbr"></param>
        /// <param name="rawDocument"></param>
        /// <param name="logs"></param>
        /// <returns></returns>
        public List <DocumentDetail> GetDocuments(string correlationId, string documentCtrlNbr,
                                                  RVWDocumentBEO rawDocument,
                                                  out JobWorkerLog <LawImportLogInfo> logs)
        {
            var documentDetailList = new List <DocumentDetail>();
            var document           = ConsturctDocument(correlationId, rawDocument, out logs);

            if (_jobParams.ImportOptions == ImportOptionsBEO.AppendNew)
            {
                // Assign DCN
                document.DocumentControlNumber = documentCtrlNbr;
                //1) Construct Native Set
                var nativeSetDocument = GetNativeDocument(document);
                var doc = new DocumentDetail
                {
                    CorrelationId     = correlationId,
                    docType           = DocumentsetType.NativeSet,
                    document          = nativeSetDocument,
                    ConversationIndex = document.ConversationIndex,
                    IsNewDocument     = true
                };
                //Add Native Document
                documentDetailList.Add(doc);

                //2) Construct Image Set
                if (_jobParams.IsImportImages && !string.IsNullOrEmpty(_jobParams.ImageSetId))
                {
                    var imageSetDocument = GetImageDocuments(document, _jobParams.ImageSetId);
                    var docImg           = new DocumentDetail
                    {
                        CorrelationId = correlationId,
                        docType       = DocumentsetType.ImageSet,
                        document      = imageSetDocument,
                        IsNewDocument = true
                    };
                    //Add Image Document
                    documentDetailList.Add(docImg);
                }
            }
            else
            {
                GetOverlayDocuments(document, documentDetailList, correlationId);
            }

            return(documentDetailList);
        }
        /// <summary>
        /// Gets the law documents based on filter tags it includes mapped fields and tags
        /// </summary>
        /// <param name="correlationId"></param>
        /// <param name="documentCtrlNbr"></param>
        /// <param name="rawDocument"></param>
        /// <param name="logs"></param>
        /// <returns></returns>
        public List<DocumentDetail> GetDocuments(string correlationId, string documentCtrlNbr,
                                                 RVWDocumentBEO rawDocument,
                                                 out JobWorkerLog<LawImportLogInfo> logs)
        {
            var documentDetailList = new List<DocumentDetail>();
            var document = ConsturctDocument(correlationId, rawDocument, out logs);
            if (_jobParams.ImportOptions == ImportOptionsBEO.AppendNew)
            {
                // Assign DCN
                document.DocumentControlNumber = documentCtrlNbr;
                //1) Construct Native Set
                var nativeSetDocument = GetNativeDocument(document);
                var doc = new DocumentDetail
                    {
                        CorrelationId = correlationId,
                        docType = DocumentsetType.NativeSet,
                        document = nativeSetDocument,
                        ConversationIndex = document.ConversationIndex,
                        IsNewDocument = true
                    };
                //Add Native Document
                documentDetailList.Add(doc);

                //2) Construct Image Set                       
                if (_jobParams.IsImportImages && !string.IsNullOrEmpty(_jobParams.ImageSetId))
                {
                    var imageSetDocument = GetImageDocuments(document, _jobParams.ImageSetId);
                    var docImg = new DocumentDetail
                        {
                            CorrelationId = correlationId,
                            docType = DocumentsetType.ImageSet,
                            document = imageSetDocument,
                            IsNewDocument = true
                        };
                    //Add Image Document
                    documentDetailList.Add(docImg);
                }
            }
            else
            {
                GetOverlayDocuments(document, documentDetailList, correlationId);
            }

            return documentDetailList;
        }
Example #17
0
        public ExportWorkerLogBEO ConstructExportWorkerLog <T>(JobWorkerLog <T> log)
        {
            ExportWorkerLogBEO workerLog = new ExportWorkerLogBEO();

            workerLog.JobRunId         = log.JobRunId;
            workerLog.CorrelationId    = log.CorrelationId;
            workerLog.WorkerInstanceId = log.WorkerInstanceId;
            workerLog.WorkerRoleType   = log.WorkerRoleType;
            workerLog.IsError          = !log.Success;
            workerLog.IsWarning        = log.IsMessage;
            workerLog.CreatedBy        = log.CreatedBy;
            if (log is JobWorkerLog <ExportMetadataLogInfo> )
            {
                var documentLog = log as JobWorkerLog <ExportMetadataLogInfo>;
                workerLog.IsErrorInField      = documentLog.LogInfo.IsErrorInField;
                workerLog.IsErrorInNativeFile = documentLog.LogInfo.IsErrorInNativeFile;
                workerLog.IsErrorInImageFile  = documentLog.LogInfo.IsErrorInImageFile;
                workerLog.IsErrorInTextFile   = documentLog.LogInfo.IsErrorInTextFile;
                workerLog.IsErrorInTag        = documentLog.LogInfo.IsErrorInTag;
                workerLog.IsErrorInComments   = documentLog.LogInfo.IsErrorInComments;
                workerLog.LogDescription      = documentLog.LogInfo.Information;
            }
            else if (log is JobWorkerLog <ExportFileCopyLogInfo> )
            {
                var documentLog = log as JobWorkerLog <ExportFileCopyLogInfo>;
                workerLog.IsErrorInNativeFile = documentLog.LogInfo.IsErrorInNativeFile;
                workerLog.IsErrorInImageFile  = documentLog.LogInfo.IsErrorInImageFile;
                workerLog.IsErrorInTextFile   = documentLog.LogInfo.IsErrorInTextFile;
                workerLog.LogDescription      = documentLog.LogInfo.Information;
            }
            else if (log is JobWorkerLog <ExportLoadFileWritterLogInfo> )
            {
                var documentLog = log as JobWorkerLog <ExportLoadFileWritterLogInfo>;
                workerLog.IsErrorInNativeFile = documentLog.LogInfo.IsErrorInNativeFile;
                workerLog.IsErrorInImageFile  = documentLog.LogInfo.IsErrorInImageFile;
                workerLog.IsErrorInTextFile   = documentLog.LogInfo.IsErrorInTextFile;
                workerLog.LogDescription      = documentLog.LogInfo.Information;
            }
            else if (log is JobWorkerLog <ExportStartupLogInfo> )
            {
                var documentLog = log as JobWorkerLog <ExportStartupLogInfo>;
                workerLog.LogDescription = documentLog.LogInfo.Information;
            }
            return(workerLog);
        }
Example #18
0
        private static string GetDateFiedlValue(Field dcbField, JobWorkerLog <DcbParserLogInfo> dcbParserLogEntry)
        {
            string   strDateTime = dcbField.Value;
            DateTime dt;
            bool     success = DateTime.TryParseExact(strDateTime, Constants.DateFormatType3, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);

            if (success)
            {
                return(dt.ToString(Constants.EVDateTimeFormat));
            }

            string errorMessage = String.Format("Cannot parse string \"{0}\" as date/time format \"{1}\"", strDateTime, Constants.DateFormatType3);

            Tracer.Error(errorMessage);
            dcbParserLogEntry.Success         = false;
            dcbParserLogEntry.LogInfo.Message = errorMessage;
            return(String.Empty);
        }
Example #19
0
        public JobWorkerLogBEO ConstructLawSyncWorkerLog(JobWorkerLog <LawSyncLogInfo> log)
        {
            var workerLog = new JobWorkerLogBEO
            {
                JobRunId            = log.JobRunId,
                CorrelationId       = log.CorrelationId,
                WorkerInstanceId    = log.WorkerInstanceId,
                WorkerRoleType      = log.WorkerRoleType,
                IsError             = !log.Success,
                ErrorCode           = log.ErrorCode,
                IsWarning           = log.IsMessage,
                CreatedBy           = log.CreatedBy,
                CrossReferenceField = log.LogInfo.LawDocumentId.ToString(CultureInfo.InvariantCulture),
                LogDescription      = log.LogInfo.Information
            };

            return(workerLog);
        }
        /// <summary>
        /// Construct Log Message and Call Log pipe
        /// </summary>
        private void LogMessage(bool status, string information)
        {
            var log       = new List <JobWorkerLog <EdLoaderParserLogInfo> >();
            var parserLog = new JobWorkerLog <EdLoaderParserLogInfo>();

            parserLog.JobRunId            = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
            parserLog.CorrelationId       = 0; // TaskId
            parserLog.WorkerRoleType      = "d279b1fd-dd38-4afd-a6fb-22527dfbc7aa";
            parserLog.WorkerInstanceId    = WorkerId;
            parserLog.IsMessage           = false;
            parserLog.Success             = status;
            parserLog.CreatedBy           = (!string.IsNullOrEmpty(profileBEO.CreatedBy) ? profileBEO.CreatedBy : "N/A");
            parserLog.LogInfo             = new EdLoaderParserLogInfo();
            parserLog.LogInfo.Information = information;
            parserLog.LogInfo.Message     = information;
            log.Add(parserLog);
            SendLog(log);
        }
Example #21
0
        private void LogMessage(bool status, string information)
        {
            List <JobWorkerLog <DcbParserLogInfo> > log       = new List <JobWorkerLog <DcbParserLogInfo> >();
            JobWorkerLog <DcbParserLogInfo>         parserLog = new JobWorkerLog <DcbParserLogInfo>();

            parserLog.JobRunId            = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
            parserLog.CorrelationId       = 0;// TaskId
            parserLog.WorkerRoleType      = "6d7f04b0-f323-4f51-b6ba-959afb818e17";
            parserLog.WorkerInstanceId    = WorkerId;
            parserLog.IsMessage           = false;
            parserLog.Success             = status;
            parserLog.CreatedBy           = (!string.IsNullOrEmpty(ProfileBEO.CreatedBy) ? ProfileBEO.CreatedBy : "N/A");
            parserLog.LogInfo             = new DcbParserLogInfo();
            parserLog.LogInfo.Information = information;
            parserLog.LogInfo.Message     = information;
            log.Add(parserLog);
            SendLog(log);
        }
Example #22
0
        public RVWDocumentBEO ConsturctDocument(string correlationId, RVWDocumentBEO document,
                                                out JobWorkerLog <LawImportLogInfo> logs)
        {
            int importedImagesCount;

            document.CollectionId      = _jobParams.CollectionId;
            document.MatterId          = _jobParams.MatterId;
            document.CreatedBy         = _jobParams.CreatedBy;
            document.ImportDescription = _jobParams.ImportDetail;
            bool isMissingContent;

            SetFamilyRelationshipIds(document);

            #region Native File

            var missingNativeFile = GetMissingNativeFiles(document);

            #endregion

            #region Image File

            var missingImageFiles = GetMissingImageFiles(document, out importedImagesCount);

            #endregion

            #region Text File (Content File)
            if (_jobParams != null)
            {
                if (!_datasetDetails.DatasetFieldList.Any(f => f.FieldType.DataTypeId == 2000 && f.Name == _jobParams.FieldNameToPopulateText))
                {
                    document.CustomFieldToPopulateText = _jobParams.FieldNameToPopulateText;
                }
            }
            var missingContentFiles = GetMissingContentFiles(document, out isMissingContent);

            #endregion

            logs = ConstructLog(correlationId, document.DocumentId,
                                missingNativeFile, missingImageFiles, isMissingContent, missingContentFiles,
                                importedImagesCount, document.DocumentControlNumber,
                                document.CrossReferenceFieldValue);

            return(document);
        }
        /// <summary>
        /// Copy document files(Native, Text & Image)
        /// </summary>
        private ExportDocumentDetail CopyFiles(ExportDocumentDetail documentDetail, out JobWorkerLog <ExportFileCopyLogInfo> fileCopyLog)
        {
            var sucess       = true;
            var message      = string.Empty;
            var errorBuilder = new StringBuilder();

            try
            {
                string messageInNativeFile;
                var    isErrorInNative = !(CopyNativeFiles(documentDetail, out messageInNativeFile));

                string messageInTextFile;
                var    isErrorInText = !(CopyTextFiles(documentDetail, out messageInTextFile));

                string messageInImageFile = string.Empty;
                bool   isErrorInImage     = false;

                if (_includeImages) //Copy the image file only when the include image option selected
                {
                    isErrorInImage = !(CopyImageFiles(documentDetail, out messageInImageFile));
                }

                if (isErrorInNative || isErrorInText || isErrorInImage)
                {
                    sucess = false;
                    errorBuilder.Append(Constants.ExportDCNMessage);
                    errorBuilder.Append(documentDetail.DCN);
                    errorBuilder.Append(Constants.ExportBreak);
                    errorBuilder.Append(messageInNativeFile);
                    errorBuilder.Append(messageInTextFile);
                    errorBuilder.Append(messageInImageFile);
                    message = errorBuilder.ToString();
                }

                fileCopyLog = ConstructLog(documentDetail.CorrelationId, sucess, documentDetail.DCN, isErrorInNative, isErrorInText, isErrorInImage, message);
            }
            catch (Exception ex)
            {
                ex.AddUsrMsg("Failed to copy document files for job run id:{0}", PipelineId).Trace().Swallow();
                fileCopyLog = ConstructLog(documentDetail.CorrelationId, false, documentDetail.DCN, true, true, true, Constants.ExportFileCopyErrorMessage);
            }
            return(documentDetail);
        }
        public void ConstructLog(int lawDocumentId, int documentCorrelationId, string documentControlNumber, string message, string heartBeatFilePath = null, string imageFolderPath = null)
        {
            var sbErrorMessage = new StringBuilder();

            sbErrorMessage.Append(message);
            sbErrorMessage.Append(Constants.MessageSpace);
            sbErrorMessage.Append(Constants.MessageDCN);
            sbErrorMessage.Append(documentControlNumber);
            sbErrorMessage.Append(Constants.MessageLawDocumentId);
            sbErrorMessage.Append(lawDocumentId);
            if (!string.IsNullOrEmpty(heartBeatFilePath))
            {
                sbErrorMessage.Append(Constants.MessageSpace);
                sbErrorMessage.Append(Constants.MessageHeartbeatFile);
                sbErrorMessage.Append(heartBeatFilePath);
            }
            if (!string.IsNullOrEmpty(imageFolderPath))
            {
                sbErrorMessage.Append(Constants.MessageSpace);
                sbErrorMessage.Append(Constants.MessageVolume);
                sbErrorMessage.Append(imageFolderPath);
            }
            var lawSyncLog = new JobWorkerLog <LawSyncLogInfo>
            {
                JobRunId         = Convert.ToInt64(PipelineId),
                CorrelationId    = documentCorrelationId,
                WorkerInstanceId = WorkerId,
                WorkerRoleType   = Constants.LawSyncImageUpdateWorkerRoleType,
                ErrorCode        = (int)LawSyncErrorCode.ImageConversionFailure,
                Success          = false,
                CreatedBy        = _jobParameter.CreatedBy,
                LogInfo          = new LawSyncLogInfo
                {
                    LawDocumentId              = lawDocumentId,
                    DocumentControlNumber      = documentControlNumber,
                    Information                = sbErrorMessage.ToString(),
                    IsFailureInImageConversion = true
                }
            };

            _logInfoList.Add(lawSyncLog);
        }
Example #25
0
        public ReviewsetLogBEO ConstructReviewsetWorkerLog <T>(JobWorkerLog <T> log)
        {
            ReviewsetLogBEO workerLog = new ReviewsetLogBEO();

            workerLog.JobRunId         = Convert.ToInt32(log.JobRunId);
            workerLog.TaskId           = log.CorrelationId;
            workerLog.WorkerInstanceId = log.WorkerInstanceId;
            workerLog.WorkerRoleType   = log.WorkerRoleType;
            workerLog.IsError          = !log.Success;
            workerLog.CreatedBy        = log.CreatedBy;
            if (log is JobWorkerLog <ReviewsetLogInfo> )
            {
                var documentParserLog = log as JobWorkerLog <ReviewsetLogInfo>;
                workerLog.ReviewsetId    = documentParserLog.LogInfo.ReviewsetID;
                workerLog.ReviewsetName  = documentParserLog.LogInfo.ReviewsetName;
                workerLog.LogDescription = documentParserLog.LogInfo.Information;
            }

            return(workerLog);
        }
Example #26
0
        public PrintWorkerLogBusinessEntity ConstructPrintWorkerLog <T>(JobWorkerLog <T> log)
        {
            PrintWorkerLogBusinessEntity workerLog = new PrintWorkerLogBusinessEntity();

            workerLog.JobRunId         = Convert.ToInt32(log.JobRunId);
            workerLog.CorrelationId    = log.CorrelationId;
            workerLog.WorkerInstanceId = log.WorkerInstanceId;
            workerLog.WorkerRoleType   = log.WorkerRoleType;
            workerLog.IsError          = !log.Success;
            workerLog.CreatedBy        = log.CreatedBy;
            if (log is JobWorkerLog <PrintLogInfo> )
            {
                var documentParserLog = log as JobWorkerLog <PrintLogInfo>;
                workerLog.Dcn            = documentParserLog.LogInfo.DCN;
                workerLog.DatasetName    = documentParserLog.LogInfo.DatasetName;
                workerLog.PrintJobName   = documentParserLog.LogInfo.PrintJobName;
                workerLog.LogDescription = documentParserLog.LogInfo.Information;
            }
            return(workerLog);
        }
        /// <summary>
        /// Construct Log Message and Call Log pipe
        /// </summary>
        private void LogMessage(bool status, string information)
        {
            var log       = new List <JobWorkerLog <ExportStartupLogInfo> >();
            var parserLog = new JobWorkerLog <ExportStartupLogInfo>
            {
                JobRunId         = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                CorrelationId    = 0,
                WorkerRoleType   = Constants.ExportStartupWorkerRoleType,
                WorkerInstanceId = WorkerId,
                IsMessage        = false,
                Success          = status,
                CreatedBy        = _createdBy,
                LogInfo          = new ExportStartupLogInfo {
                    Information = information
                }
            };

            log.Add(parserLog);
            SendLog(log);
        }
        /// <summary>
        /// Construct Log Message and Call Log pipe
        /// </summary>
        internal void LogMessage(bool status, string information)
        {
            var log       = new List <JobWorkerLog <LoadFileParserLogInfo> >();
            var parserLog = new JobWorkerLog <LoadFileParserLogInfo>();

            parserLog.JobRunId            = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
            parserLog.CorrelationId       = 0; // TaskId
            parserLog.WorkerRoleType      = Constants.LoadFileParserWorkerRoleType;
            parserLog.WorkerInstanceId    = WorkerId;
            parserLog.IsMessage           = false;
            parserLog.Success             = status;
            parserLog.CreatedBy           = (!string.IsNullOrEmpty(m_Parameters.CreatedBy) ? m_Parameters.CreatedBy : "N/A");
            parserLog.LogInfo             = new LoadFileParserLogInfo();
            parserLog.LogInfo.Information = information;
            if (!status)
            {
                parserLog.LogInfo.Message = "Unhandled Exception:" + information;
            }
            log.Add(parserLog);
            SendLog(log);
        }
        private void LogMessage(bool success, string information)
        {
            List <JobWorkerLog <BaseWorkerProcessLogInfo> > log      = new List <JobWorkerLog <BaseWorkerProcessLogInfo> >();
            JobWorkerLog <BaseWorkerProcessLogInfo>         logEntry = new JobWorkerLog <BaseWorkerProcessLogInfo>();

            logEntry.JobRunId            = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
            logEntry.CorrelationId       = 0;// TaskId
            logEntry.WorkerRoleType      = "051c994f-a843-428f-92e9-1958b87f0015";
            logEntry.WorkerInstanceId    = WorkerId;
            logEntry.IsMessage           = false;
            logEntry.Success             = success;
            logEntry.CreatedBy           = "N/A";
            logEntry.LogInfo             = new BaseWorkerProcessLogInfo();
            logEntry.LogInfo.Information = information;
            if (!success)
            {
                logEntry.LogInfo.Message = information;
            }
            log.Add(logEntry);
            SendLog(log);
        }
Example #30
0
        /// <summary>
        /// Construct Log Message and Call Log pipe
        /// </summary>
        internal void LogMessage(bool status, string information)
        {
            List <JobWorkerLog <LoadFileDocumentParserLogInfo> > log       = new List <JobWorkerLog <LoadFileDocumentParserLogInfo> >();
            JobWorkerLog <LoadFileDocumentParserLogInfo>         parserLog = new JobWorkerLog <LoadFileDocumentParserLogInfo>();

            parserLog.JobRunId            = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
            parserLog.CorrelationId       = 0;// TaskId
            parserLog.WorkerRoleType      = Constants.LoadFileRecordParserWorkerRoleType;
            parserLog.WorkerInstanceId    = WorkerId;
            parserLog.IsMessage           = false;
            parserLog.Success             = status;
            parserLog.CreatedBy           = (!string.IsNullOrEmpty(_jobParameter.CreatedBy) ? _jobParameter.CreatedBy : "N/A");
            parserLog.LogInfo             = new LoadFileDocumentParserLogInfo();
            parserLog.LogInfo.Information = information;
            if (!status)
            {
                parserLog.LogInfo.Message = information;
            }
            log.Add(parserLog);
            SendLog(log);
        }
Example #31
0
        public void ConstructLog(string message)
        {
            var logInfoList = new List <JobWorkerLog <LawSyncLogInfo> >();
            var lawSyncLog  = new JobWorkerLog <LawSyncLogInfo>
            {
                JobRunId         = (!string.IsNullOrEmpty(PipelineId)) ? Convert.ToInt64(PipelineId) : 0,
                CorrelationId    = 0,
                WorkerInstanceId = WorkerId,
                WorkerRoleType   = Constants.LawSyncReProcessStartupWorkerRoleType,
                Success          = false,
                CreatedBy        = _lawSyncJobParameter.CreatedBy,
                IsMessage        = false,
                LogInfo          = new LawSyncLogInfo
                {
                    Information = message
                }
            };

            logInfoList.Add(lawSyncLog);
            SendLogPipe(logInfoList);
        }
Example #32
0
        /// <summary>
        /// Construct Log Message and Call Log pipe
        /// </summary>
        internal void LogMessage(bool status, string information, bool isMessage)
        {
            List <JobWorkerLog <EDocsExtractionLogInfo> > edocsExtarctionLogs = new List <JobWorkerLog <EDocsExtractionLogInfo> >();
            JobWorkerLog <EDocsExtractionLogInfo>         extracionLog        = new JobWorkerLog <EDocsExtractionLogInfo>()
            {
                JobRunId         = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                CorrelationId    = 0 /* TaskId*/,
                WorkerRoleType   = Constants.EDOCSExtractionRoleType,
                WorkerInstanceId = WorkerId,
                IsMessage        = isMessage,
                Success          = status,
                CreatedBy        = (!string.IsNullOrEmpty(m_Parameters.CreatedBy) ? m_Parameters.CreatedBy : "N/A"),
                LogInfo          = new EDocsExtractionLogInfo()
            };

            extracionLog.LogInfo.Information          = information;
            extracionLog.LogInfo.Message              = information;
            extracionLog.LogInfo.DatasetExtractedPath = m_Parameters.DatasetDetails.CompressedFileExtractionLocation;
            edocsExtarctionLogs.Add(extracionLog);
            SendLog(edocsExtarctionLogs);
        }
 /// <summary>
 /// Construct Log Data
 /// </summary>       
 public JobWorkerLog<ExportMetadataLogInfo> ConstructLog(string correlationId, bool success, string dcn, bool isErrorInDocument, bool isErrorInTag, string message)
 {
     var metadataLog = new JobWorkerLog<ExportMetadataLogInfo>
     {
         JobRunId = (!string.IsNullOrEmpty(PipelineId)) ? Convert.ToInt64(PipelineId) : 0,
         CorrelationId = (!string.IsNullOrEmpty(correlationId)) ? Convert.ToInt64(correlationId) : 0,
         WorkerInstanceId = WorkerId,
         WorkerRoleType = Constants.ExportMetadataWorkerRoleType,
         Success = success,
         CreatedBy = "NA",
         IsMessage = false,
         LogInfo = new ExportMetadataLogInfo { DCN = dcn }
     };
     if (isErrorInDocument)
     {
         metadataLog.LogInfo.IsErrorInField = true;
         metadataLog.LogInfo.IsErrorInNativeFile = true;
         metadataLog.LogInfo.IsErrorInImageFile = true;
         metadataLog.LogInfo.IsErrorInTextFile = true;
     }
     if (isErrorInTag)
     {
         metadataLog.LogInfo.IsErrorInTag = true;
     }
     if (!success)
     {
         metadataLog.LogInfo.Information = (!string.IsNullOrEmpty(message) ? (message + ". DCN:" + dcn) : string.Empty);
     }
     return metadataLog;
 }
        /// <summary>
        /// Construct document based on search 
        /// </summary>      
        public List<DocumentDetail> ConstructDocumentFromSearch(DocumentDetail docDetail, List<DocumentResult> bulkSearchresult,
            out string existingThreadConstraint, out JobWorkerLog<OverlaySearchLogInfo> overlayLog)
        {
            List<DocumentDetail> documentDetailList = new List<DocumentDetail>();
            existingThreadConstraint = string.Empty;
            #region Overlay
            string searchQuery = string.Empty;
            bool isExactMatch = false;
            bool isNoMatch = false;
            bool isNewRecord = false;
            string searchMessage = string.Empty;
            bool isImportDocument = true;
            bool isNewImageSet = true;
            string overlayField;
            string nonMatchingOverlayDCN = string.Empty;
            List<DocumentResult> documentResult = null;
            var misMatchedFields = new List<string>();
            var misMatchedFieldsMessage = new List<string>();
            string dcn = string.Empty;
            //Filter document from bulk Search Result
            if (bulkSearchresult != null && bulkSearchresult.Count > 0)
                documentResult = DocumentMatchFromBulkSearchResult(docDetail, bulkSearchresult);
            if (documentResult != null)
            {
                if (documentResult.Count == 1)
                {
                    isExactMatch = true;
                    searchMessage = Constants.MessageMatchRecord;
                }
                else
                {
                    isNoMatch = true;
                    #region Log
                    searchMessage = (documentResult.Count == 0) ? Constants.MessageNoMatchRecord : Constants.MessageMoreThanOneRecord;
                    //Return more than one record
                    foreach (var result in documentResult)
                    {
                        if (result.Fields == null || !result.Fields.Any()) continue;
                        var dcnField = result.Fields.FirstOrDefault(f => f.DataTypeId.Equals(Constants.DCNFieldType));
                        if (dcnField != null)
                        {
                            nonMatchingOverlayDCN = !string.IsNullOrEmpty(nonMatchingOverlayDCN) ? string.Format("{0},{1}", nonMatchingOverlayDCN, dcnField.Value) : dcnField.Value;

                        }
                    }

                    if (!string.IsNullOrEmpty(nonMatchingOverlayDCN))
                        nonMatchingOverlayDCN = " DCN:" + nonMatchingOverlayDCN;
                    else
                        searchMessage = Constants.MessageNoMatchRecord;

                    #endregion
                }
            }
            else
            {
                //No Match Found
                isNoMatch = true;
            }

            #region Log
            if (docDetail.OverlayMatchingField != null)
                searchQuery = ConstructSearchQuery(docDetail.OverlayMatchingField);
            overlayField = searchQuery.Replace(Constants.SearchAndCondition.Trim(), ",");
            #endregion
            if (isExactMatch)
            {
                UpdateDocumentForExactMatch(docDetail, ref existingThreadConstraint, ref isNewRecord, ref isNewImageSet, documentResult, misMatchedFields, misMatchedFieldsMessage);
                var dcnField = documentResult.First().Fields.FirstOrDefault(f => f.DataTypeId == Constants.DCNFieldType);
                if (dcnField != null)
                {
                    if (docDetail.document != null) docDetail.document.DocumentControlNumber = dcnField.Value;
                    dcn = dcnField.Value;
                }
            }
            else if (m_JobParameter.IsOverlayReplaceAndAppend)
            {
                //Insert as new record for non matching record
                isNewRecord = true;
            }
            else
            {
                // Not applicable for Insert/Update
                isImportDocument = false;
                isNewRecord = false;
            }

            #endregion

            #region Construct Documents
            if (isImportDocument)
            {
                var docdetails = ConstructNativeImageSet(isNewRecord, isNewImageSet, docDetail, misMatchedFields, misMatchedFieldsMessage);
                if (docdetails != null && docdetails.Count > 0)
                {
                    documentDetailList.AddRange(docdetails);
                }
            }
            if (string.IsNullOrEmpty(dcn))
                dcn = docDetail.document.DocumentControlNumber;
            //3) Construct Log          
            overlayLog = ConstructLog(docDetail.CorrelationId, true, isExactMatch, isNoMatch, isImportDocument, searchMessage, overlayField, nonMatchingOverlayDCN, docDetail.document.DocumentId, dcn, isNewRecord, docDetail.document.CrossReferenceFieldValue, misMatchedFields, misMatchedFieldsMessage);
            #endregion
            return documentDetailList;
        }
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 private void LogMessage(ProductionDocumentDetail documentDetail, bool success, string message)
 {
     try
     {
         var log = new List<JobWorkerLog<ProductionParserLogInfo>>();
         var parserLog = new JobWorkerLog<ProductionParserLogInfo>
                             {
                                 JobRunId =
                                     (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                                 CorrelationId = documentDetail.CorrelationId,
                                 WorkerRoleType = Constants.ProductionPreProcessRoleId,
                                 WorkerInstanceId = WorkerId,
                                 IsMessage = false,
                                 Success = success, //!string.IsNullOrEmpty(documentDetail.DocumentProductionNumber) && success,
                                 CreatedBy = documentDetail.CreatedBy,
                                 LogInfo =
                                     new ProductionParserLogInfo
                                         {
                                             Information = message, //string.IsNullOrEmpty(documentDetail.DocumentProductionNumber) ? "Unable to produce this document" : message,
                                             BatesNumber = documentDetail.AllBates,
                                             DatasetName = documentDetail.OriginalDatasetName,
                                             DCN = documentDetail.DCNNumber,
                                             ProductionDocumentNumber = documentDetail.DocumentProductionNumber,
                                             ProductionName = documentDetail.Profile.ProfileName
                                         }
                             };
         // TaskId
         log.Add(parserLog);
         SendLog(log);
     }
     catch (Exception exception)
     {
         Tracer.Error("Production Preprocess Worker: Unable to log message. Exception details: {0}", exception);
         throw;
     }
 }
 public void ConstructLog(int lawDocumentId, int documentCorrelationId, string documentControlNumber, string message)
 {
     var sbErrorMessage = new StringBuilder();
     sbErrorMessage.Append(message);
     sbErrorMessage.Append(Constants.MessageDCN);
     sbErrorMessage.Append(documentControlNumber);
     sbErrorMessage.Append(Constants.MessageLawDocumentId);
     sbErrorMessage.Append(lawDocumentId);
     var lawSyncLog = new JobWorkerLog<LawSyncLogInfo>
     {
         JobRunId = Convert.ToInt64(PipelineId),
         CorrelationId = documentCorrelationId,
         WorkerInstanceId = WorkerId,
         WorkerRoleType = Constants.LawSyncUpdateWorkerRoleType,
         ErrorCode = (int)LawSyncErrorCode.MetadataSyncFail,
         Success = false,
         CreatedBy = _jobParameter.CreatedBy,
         IsMessage = false,
         LogInfo = new LawSyncLogInfo
         {
             LawDocumentId = lawDocumentId,
             DocumentControlNumber = documentControlNumber,
             Information = sbErrorMessage.ToString(),
             IsFailureInSyncMetadata = true
         }
     };
     _logInfoList.Add(lawSyncLog);
 }
        private void LogMessage(bool status, string information)
        {
            var parserLog = new JobWorkerLog<ReviewsetLogInfo>
            {
                JobRunId =
                    (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                CorrelationId = 0,
                WorkerRoleType = Constants.ReviewsetStartupRoleID,
                WorkerInstanceId = WorkerId,
                IsMessage = false,
                Success = status,
                CreatedBy = _bootObject.JobScheduleCreatedBy,
                LogInfo = new ReviewsetLogInfo { Information = information }
            };

            var log = new List<JobWorkerLog<ReviewsetLogInfo>>();
            log.Add(parserLog);
            SendLog(log);
        }
        protected override void ProcessMessage(PipeMessageEnvelope envelope)
        {
            if (null == envelope || null == envelope.Body)
            {
                return;
            }

            try
            {
                DcbSlice dcbSlice = (DcbSlice)envelope.Body;

                OpenDCB(dcbSlice.DcbCredentials);

                ImageSetId = dcbSlice.ImageSetId;

                FamiliesInfo familiesInfo = DcbOpticonJobBEO.IsImportFamilies ? new FamiliesInfo() : null;

                var documentDetailList = new List<DocumentDetail>();
                var dcbParserLogEntries = new List<JobWorkerLog<DcbParserLogInfo>>();
                int lastDocumentInTheBatch = dcbSlice.FirstDocument + dcbSlice.NumberOfDocuments - 1;
                for (int currentDocumentNumber = dcbSlice.FirstDocument;
                     currentDocumentNumber <= lastDocumentInTheBatch;
                     currentDocumentNumber++)
                {
                    JobWorkerLog<DcbParserLogInfo> dcbParserLogEntry =
                        new JobWorkerLog<DcbParserLogInfo>()
                            {
                                JobRunId = long.Parse(PipelineId),
                                WorkerInstanceId = WorkerId,
                                CorrelationId = currentDocumentNumber + 1, // CorrId is the same as TaskId and it is 1 based.
                                // This magic GUID is set in [EVMaster].[dbo].[EV_JOB_WorkerRoleType] to identify DcbParcer for Log Worker
                                WorkerRoleType = "e754adb7-23c8-44cc-8d4c-12f33aef41b6",
                                Success = true,
                                CreatedBy = ProfileBEO.CreatedBy,
                                IsMessage = false,
                                LogInfo = new DcbParserLogInfo()
                            };

                    FetchDocumentFromDCB(currentDocumentNumber, documentDetailList, familiesInfo, dcbParserLogEntry);

                    dcbParserLogEntries.Add(dcbParserLogEntry);
                }

                if (0 == dcbSlice.FirstDocument)
                {
                    DcbDatabaseTags dcbDatabaseTags = FetchDatabaseLevelTags();
                    if (null != dcbDatabaseTags)
                    {
                        if (null == documentDetailList[0].DcbTags)
                        {
                            documentDetailList[0].DcbTags = new List<DcbTags>();
                        }
                        documentDetailList[0].DcbTags.Add(dcbDatabaseTags);
                    }
                }

                if (DcbOpticonJobBEO.IsImportFamilies)
                {
                    SendRelationshipsInfo(familiesInfo.FamilyInfoList);
                }

                Send(documentDetailList);
                SendLog(dcbParserLogEntries);
            }
            catch (ArgumentOutOfRangeException exRange)
            {
                exRange.AddUsrMsg(Constants.ExportPathFull);
                ReportToDirector(exRange);
                exRange.Trace();
                LogMessage(false, Constants.ExportPathFull);
                throw;
            }
            catch (Exception ex)
            {
                ReportToDirector(ex);
                ex.Trace().Swallow();
                LogMessage(false, "DcbParser failed to process document. Error: " + ex.ToUserString());
            }
        }
 /// <summary>
 ///     Construct Near Duplication Log Info for Document
 /// </summary>
 private JobWorkerLog<NearDuplicationLogInfo> ConstructNearDuplicationLogInfoForDocument(bool isErrorInDatabase,
     bool isErrorInSearchEngine,
     DocumentMasterEntity documentInfo)
 {
     string documentControlNumber = documentInfo.DocumentTitle;
     var nearDuplicationLog = new JobWorkerLog<NearDuplicationLogInfo>
     {
         JobRunId =
             (!string.IsNullOrEmpty(PipelineId))
                 ? Convert.ToInt64(PipelineId)
                 : 0,
         CorrelationId = Convert.ToInt32(documentControlNumber.Replace(_dataset.DCNPrefix, string.Empty)),
         WorkerInstanceId = WorkerId,
         WorkerRoleType = Constants.NearDuplicationEvUpdateWorkerRoleType,
         Success = false,
         CreatedBy = _jobParameter.CreatedBy,
         IsMessage = false,
         LogInfo = new NearDuplicationLogInfo
         {
             DocumentControlNumber = documentControlNumber,
             IsFailureInDatabaseUpdate = isErrorInDatabase,
             IsFailureInSearchUpdate = isErrorInSearchEngine,
             Information =
                 string.Format(
                     Constants.
                         NearDuplicationEvUpdateWorkerFailureMessage,
                     documentControlNumber)
         }
     };
     return nearDuplicationLog;
 }
        private static string GetDateFiedlValue(Field dcbField, JobWorkerLog<DcbParserLogInfo> dcbParserLogEntry)
        {
            string strDateTime = dcbField.Value;
            DateTime dt;
            bool success = DateTime.TryParseExact(strDateTime, Constants.DateFormatType3, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
            if (success)
            {
                return dt.ToString(Constants.EVDateTimeFormat);    
            }

            string errorMessage = String.Format("Cannot parse string \"{0}\" as date/time format \"{1}\"", strDateTime, Constants.DateFormatType3);
            Tracer.Error(errorMessage);
            dcbParserLogEntry.Success = false;
            dcbParserLogEntry.LogInfo.Message = errorMessage;
            return String.Empty;
        }
        private bool DumpTextToFile(RVWDocumentBEO rVwDocumentBEO, string contentText, JobWorkerLog<DcbParserLogInfo> dcbParserLogEntry)
        {
            TextFileFolder.ShouldNotBe(null);
            if (string.IsNullOrEmpty(contentText)) return true;

            string filePath = Path.Combine(TextFileFolder, rVwDocumentBEO.DocumentId + Constants.FileExtension);
            File.AppendAllText(filePath, contentText);

            if (rVwDocumentBEO.DocumentBinary == null) { rVwDocumentBEO.DocumentBinary = new RVWDocumentBinaryBEO(); }
            RVWExternalFileBEO textFile = new RVWExternalFileBEO
            {
                Type = TEXT_FILE_TYPE,
                Path = filePath
            };
            rVwDocumentBEO.DocumentBinary.FileList.Add(textFile);
            return true;
        }
        private void LogMessage(ProductionDocumentDetail documentDetail, bool success, string message, bool isMessage)
        {
            const string roleId = "prod0fc6-113e-4217-9863-ec58c3f7yz89";
            var log = new List<JobWorkerLog<ProductionParserLogInfo>>();
            var parserLog = new JobWorkerLog<ProductionParserLogInfo>
            {
                JobRunId =
                    (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                CorrelationId = documentDetail.CorrelationId,
                WorkerRoleType = roleId,
                WorkerInstanceId = WorkerId,
                IsMessage = isMessage,
                Success = success,
                CreatedBy = documentDetail.CreatedBy,
                LogInfo =
                    new ProductionParserLogInfo
                    {
                        Information = message,
                        BatesNumber = documentDetail.AllBates,
                        DatasetName = documentDetail.OriginalDatasetName,
                        DCN = documentDetail.DCNNumber,
                        ProductionDocumentNumber = documentDetail.DocumentProductionNumber,
                        ProductionName = documentDetail.Profile.ProfileName
                    }
            };

            log.Add(parserLog);
            SendLog(log);
        }
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 private void LogMessage(bool status, string information)
 {
     var log = new List<JobWorkerLog<EdLoaderParserLogInfo>>();
     var parserLog = new JobWorkerLog<EdLoaderParserLogInfo>();
     parserLog.JobRunId = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
     parserLog.CorrelationId = 0; // TaskId
     parserLog.WorkerRoleType = "d279b1fd-dd38-4afd-a6fb-22527dfbc7aa";
     parserLog.WorkerInstanceId = WorkerId;
     parserLog.IsMessage = false;
     parserLog.Success = status;
     parserLog.CreatedBy = (!string.IsNullOrEmpty(profileBEO.CreatedBy) ? profileBEO.CreatedBy : "N/A");
     parserLog.LogInfo = new EdLoaderParserLogInfo();
     parserLog.LogInfo.Information = information;
     parserLog.LogInfo.Message = information;
     log.Add(parserLog);
     SendLog(log);
 }
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 private void LogMessage(bool status, string information)
 {
     try
     {
         string createdBy = string.Empty;
         if (_mBootParameters != null)
         {
             createdBy = _mBootParameters.CreatedBy;
         }
         var log = new List<JobWorkerLog<ProductionParserLogInfo>>();
         var parserLog = new JobWorkerLog<ProductionParserLogInfo>
         {
             JobRunId =
                 (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
             CorrelationId = 0,
             WorkerRoleType = Infrastructure.Jobs.Constants.ProductionStartupRoleId,
             WorkerInstanceId = WorkerId,
             IsMessage = false,
             Success = status,
             CreatedBy = createdBy,
             LogInfo = new ProductionParserLogInfo { Information = information }
         };
         // TaskId
         log.Add(parserLog);
         SendLog(log);
     }
     catch (Exception ex)
     {
         Tracer.Error("ProdcutionStartupWorker" + ex.Message);
     }
 }
 /// <summary>
 /// Construct and Send Log
 /// </summary>
 /// <param name="message"></param>
 public void ConstructAndSendLog(string message)
 {
      var logInfoList=new List<JobWorkerLog<NearDuplicationLogInfo>>();
     var nearDuplicationLog = new JobWorkerLog<NearDuplicationLogInfo>
     {
         JobRunId =
             (!string.IsNullOrEmpty(PipelineId))
                 ? Convert.ToInt64(PipelineId)
                 : 0,
         CorrelationId = 1,
         WorkerInstanceId = WorkerId,
         WorkerRoleType = Constants.NearDuplicationPorcessingWorkerRoleType,
         Success = false,
         CreatedBy = _jobParameter.CreatedBy,
         IsMessage = false,
         LogInfo = new NearDuplicationLogInfo
         {
             Information = message
         }
     };
     logInfoList.Add(nearDuplicationLog);
     SendLogPipe(logInfoList);
 }
 /// <summary>
 /// Logs document count in job log
 /// </summary>
 /// <param name="documentDetail"></param>
 /// <param name="success"></param>
 /// <param name="message"></param>
 private void LogMessage(ProductionDocumentDetail documentDetail, bool success, string message)
 {
     try
     {
         var log = new List<JobWorkerLog<ProductionParserLogInfo>>();
         var parserLog = new JobWorkerLog<ProductionParserLogInfo>
         {
             JobRunId =
                 (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
             CorrelationId = documentDetail.CorrelationId,
             WorkerRoleType = "prod0fc6-113e-4217-9863-ec58c3f7sw89",
             WorkerInstanceId = WorkerId,
             IsMessage = false,
             Success = success, //!string.IsNullOrEmpty(documentDetail.DocumentProductionNumber) && success,
             CreatedBy = documentDetail.CreatedBy,
             LogInfo =
                 new ProductionParserLogInfo
                 {
                     Information = message, //string.IsNullOrEmpty(documentDetail.DocumentProductionNumber) ? "Unable to produce this document" : message,
                     BatesNumber = documentDetail.AllBates,
                     DatasetName = documentDetail.OriginalDatasetName,
                     DCN = documentDetail.DCNNumber,
                     ProductionDocumentNumber = documentDetail.DocumentProductionNumber,
                     ProductionName = documentDetail.Profile.ProfileName
                 }
         };
         // TaskId
         log.Add(parserLog);
         SendLog(log);
     }
     catch (Exception ex)
     {
         ex.AddDbgMsg("Unable to log production documents");
         ex.Trace().Swallow();
     }
 }
 /// <summary>
 /// This method constructs the log message to send
 /// </summary>
 /// <param name="status">bool</param>
 /// <param name="information">string</param>
 /// <param name="createdBy">string</param>
 /// <returns>List<JobWorkerLog<ReviewsetLogInfo>></returns>
 private List<JobWorkerLog<ReviewsetLogInfo>> ConstructLogMessage(bool status, string information, string createdBy)
 {
     var log = new List<JobWorkerLog<ReviewsetLogInfo>>();
     var parserLog = new JobWorkerLog<ReviewsetLogInfo>
     {
         JobRunId =
             (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
         CorrelationId = 0,
         WorkerRoleType = Constants.SearchIndexUpdateWorkerRoleId,
         WorkerInstanceId = WorkerId,
         IsMessage = false,
         Success = status,
         CreatedBy = createdBy,
         LogInfo = new ReviewsetLogInfo { Information = information }
     };
     // TaskId
     log.Add(parserLog);
     return log;
 }
        /// <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;
        }
 public void LogMessage(string message)
 {
     var logInfoList = new List<JobWorkerLog<LawSyncLogInfo>>();
     var lawSyncLog = new JobWorkerLog<LawSyncLogInfo>
     {
         JobRunId = (!string.IsNullOrEmpty(PipelineId)) ? Convert.ToInt64(PipelineId) : 0,
         CorrelationId = 0,
         WorkerInstanceId = WorkerId,
         WorkerRoleType = Constants.LawSyncUpdateWorkerRoleType,
         Success = false,
         CreatedBy = _jobParameter.CreatedBy,
         IsMessage = false,
         LogInfo = new LawSyncLogInfo
         {
             Information = message
         }
     };
     logInfoList.Add(lawSyncLog);
     SendLogPipe(logInfoList);
 }
        /// <summary>
        /// Construct Log Message and Call Log pipe
        /// </summary>
        private void LogMessage(DocumentResult document, bool success, string message)
        {
            var log = new List<JobWorkerLog<LogInfo>>();
            var taskId = Convert.ToInt32(document.DocumentControlNumber.Replace(_mDataSet.DCNPrefix, string.Empty));
            // form the paser lof entity
            var parserLog = new JobWorkerLog<LogInfo>
            {
                JobRunId =

                    (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
                CorrelationId = taskId,
                WorkerRoleType = "PrintValidationWorker",
                WorkerInstanceId = WorkerId,
                IsMessage = false,
                Success = success, //!string.IsNullOrEmpty(documentDetail.DocumentProductionNumber) && success,
                CreatedBy = bulkPrintServiceRequestBEO.RequestedBy.UserId,
                LogInfo =
                    new LogInfo
                    {
                        TaskKey = document.DocumentControlNumber,
                        IsError = !success

                    }

            };
            parserLog.LogInfo.AddParameters(Constants.DCN, document.DocumentControlNumber);
            parserLog.LogInfo.AddParameters(message, mappedPrinter.PrinterDetails.Name);
            log.Add(parserLog);
            SendLog(log);
        }
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 internal void LogMessage(bool status, string information)
 {
     var log = new List<JobWorkerLog<LawImportLogInfo>>();
     var lawLog = new JobWorkerLog<LawImportLogInfo>
     {
         JobRunId = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
         CorrelationId = 0,
         WorkerRoleType = Constants.LawImportStartupWorkerRoleType,
         WorkerInstanceId = WorkerId,
         IsMessage = false,
         Success = status,
         CreatedBy = (!string.IsNullOrEmpty(_jobParams.CreatedBy) ? _jobParams.CreatedBy : "N/A"),
         LogInfo = new LawImportLogInfo {Information = information}
     };
     if (!status)
         lawLog.LogInfo.Message = information;
     log.Add(lawLog);
     SendLog(log);
 }
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 internal void LogMessage(bool status, string information, bool isMessage)
 {
     List<JobWorkerLog<EDocsExtractionLogInfo>> edocsExtarctionLogs = new List<JobWorkerLog<EDocsExtractionLogInfo>>();
     JobWorkerLog<EDocsExtractionLogInfo> extracionLog = new JobWorkerLog<EDocsExtractionLogInfo>()
     {
         JobRunId = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
         CorrelationId = 0 /* TaskId*/,
         WorkerRoleType = Constants.EDOCSExtractionRoleType,
         WorkerInstanceId = WorkerId,
         IsMessage = isMessage,
         Success = status,
         CreatedBy = (!string.IsNullOrEmpty(m_Parameters.CreatedBy) ? m_Parameters.CreatedBy : "N/A"),
         LogInfo = new EDocsExtractionLogInfo()
     };
     extracionLog.LogInfo.Information = information;
     extracionLog.LogInfo.Message = information;
     extracionLog.LogInfo.DatasetExtractedPath = m_Parameters.DatasetDetails.CompressedFileExtractionLocation;
     edocsExtarctionLogs.Add(extracionLog);
     SendLog(edocsExtarctionLogs);
 }
        /// <summary>
        /// Construct Log Data
        /// </summary>       
        private JobWorkerLog<OverlaySearchLogInfo> ConstructLog(string correlationId, bool success, bool isExactMatch, bool isNoMatch, bool overlayAction, string searchMessage, string overlayField, string nonMatchOverlayDCN, string overlayDocumentIdPair, string documentCtrlNbr, bool isAppend, string crossReferenceValue, List<string> misMatchedFields, List<string> misMatchedFieldsMessage)
        {
            var overlayLog = new JobWorkerLog<OverlaySearchLogInfo>();
            overlayLog.CorrelationId = (!string.IsNullOrEmpty(correlationId)) ? Convert.ToInt64(correlationId) : 0;
            overlayLog.JobRunId = (!string.IsNullOrEmpty(m_JobRunId)) ? Convert.ToInt64(m_JobRunId) : 0;
            overlayLog.WorkerInstanceId = m_WorkerInstanceId;
            overlayLog.Success = success;
            overlayLog.WorkerRoleType = Constants.OverlayWorkerRoleType; //Need to Add Role Type
            overlayLog.CreatedBy = m_JobParameter.CreatedBy;
            overlayLog.IsMessage = false;
            overlayLog.LogInfo = new OverlaySearchLogInfo();
            overlayLog.LogInfo.DCN = !string.IsNullOrEmpty(documentCtrlNbr) ? documentCtrlNbr : string.Empty;
            overlayLog.LogInfo.Message = string.Empty;
            if (success)
            {
                if (isExactMatch)
                    overlayLog.LogInfo.OverlayDocumentId = overlayDocumentIdPair;
                overlayLog.LogInfo.IsDocumentUpdated = isExactMatch;
                overlayLog.LogInfo.IsNoMatch = isNoMatch;
                overlayLog.LogInfo.OverlayFieldInfo = overlayField;
                overlayLog.LogInfo.SearchMessage = searchMessage;
                overlayLog.LogInfo.Information = Constants.OverlaySuccessMessage;
                if (isNoMatch)
                {
                    overlayLog.LogInfo.NonMatchOverlayDCN = nonMatchOverlayDCN;
                    overlayLog.IsMessage = true;
                    overlayLog.LogInfo.CrossReferenceField = crossReferenceValue;
                    overlayLog.LogInfo.Message = !String.IsNullOrEmpty(nonMatchOverlayDCN)
                        ? Constants.MessageMoreThanOneRecord : Constants.MessageNoMatchRecord;
                    overlayLog.LogInfo.Information = !String.IsNullOrEmpty(nonMatchOverlayDCN)
                        ? Constants.ErrorMessageSearchNoMatch + nonMatchOverlayDCN
                        : Constants.ErrorMessageSearchNoMatch;
                }
                if (!overlayAction)
                    overlayLog.LogInfo.Information += Constants.OverlayNoActionMessage;
                overlayLog.LogInfo.IsDocumentAdded = isAppend; //Overlay Non matching record inserted into dataset
            }
            else
            {
                overlayLog.LogInfo.Information = Constants.OverlayFailureMessage;
                overlayLog.LogInfo.CrossReferenceField = crossReferenceValue;
                overlayLog.LogInfo.Message = Constants.MsgDocumentSearch;
            }

            if (misMatchedFields != null && misMatchedFields.Count > 0)
            {
                overlayLog.IsMessage = true;
                if (!string.IsNullOrEmpty(documentCtrlNbr))
                {
                    overlayLog.LogInfo.Information += string.Format(Constants.MisMatchedFieldMessage, documentCtrlNbr);
                }
                overlayLog.LogInfo.CrossReferenceField = crossReferenceValue;
                misMatchedFields.ForEach(x => overlayLog.LogInfo.Information += x);
                if (misMatchedFieldsMessage != null)
                {
                    misMatchedFieldsMessage.ForEach(
                        x =>
                        overlayLog.LogInfo.Message =
                        overlayLog.LogInfo.Message.Contains(x)
                            ? overlayLog.LogInfo.Message
                            : overlayLog.LogInfo.Message + x);
                }
            }
            return overlayLog;
        }
        public RVWDocumentBEO ConsturctDocument(string correlationId, RVWDocumentBEO document,
                                                out JobWorkerLog<LawImportLogInfo> logs)
        {
            int importedImagesCount;
            document.CollectionId = _jobParams.CollectionId;
            document.MatterId = _jobParams.MatterId;
            document.CreatedBy = _jobParams.CreatedBy;
            document.ImportDescription = _jobParams.ImportDetail;
            bool isMissingContent;

            SetFamilyRelationshipIds(document);

            #region Native File

            var missingNativeFile = GetMissingNativeFiles(document);

            #endregion

            #region Image File

            var missingImageFiles = GetMissingImageFiles(document, out importedImagesCount);

            #endregion

            #region Text File (Content File)
            if (_jobParams != null)
            {
                if (!_datasetDetails.DatasetFieldList.Any(f => f.FieldType.DataTypeId == 2000 && f.Name == _jobParams.FieldNameToPopulateText))
                {
                    document.CustomFieldToPopulateText = _jobParams.FieldNameToPopulateText;
                }
            }
            var missingContentFiles = GetMissingContentFiles(document, out isMissingContent);

            #endregion

            logs = ConstructLog(correlationId, document.DocumentId,
                                missingNativeFile, missingImageFiles, isMissingContent, missingContentFiles,
                                importedImagesCount, document.DocumentControlNumber,
                                document.CrossReferenceFieldValue);

            return document;
        }
        private ExportDocumentDetail ConstructDocumentData(ExportDocumentCollection exportDocumentCollection,
            string documentId, string correlationId, out JobWorkerLog<ExportMetadataLogInfo> metadataLog)
        {
            var exportDocument = new ExportDocumentDetail();
            try
            {
                exportDocument.DocumentId = documentId;
                exportDocument.CorrelationId = correlationId;
                bool isError;
                bool isErrorInTag = false;
              
                var document = DocumentBO.GetDocumentDataForExportJob(matterId, _dataset.CollectionId, documentId, out isError);
                if (document != null)
                {
                     exportDocument.DCN = document.DocumentControlNumber;

                    if (!String.IsNullOrEmpty(exportDocumentCollection.ExportOption.FieldForTextFileName))
                    {
                        var textFieldId = DocumentBO.GetFieldIdByNameForExportJob(_dataset,
                            exportDocumentCollection.ExportOption.FieldForTextFileName, false);
                        exportDocument.TextFileName = DocumentBO.GetFieldValueForExportJob(matterId,
                            _dataset.CollectionId, documentId, textFieldId);
                    }

                    if (!String.IsNullOrEmpty(exportDocumentCollection.ExportOption.FieldForNativeFileName))
                    {
                        var nativeFieldId = DocumentBO.GetFieldIdByNameForExportJob(_dataset,
                            exportDocumentCollection.ExportOption.FieldForNativeFileName, false);
                        exportDocument.NativeFileName = DocumentBO.GetFieldValueForExportJob(matterId,
                            _dataset.CollectionId, documentId, nativeFieldId);
                    }

                    #region "Recreate family group"
                    //2)Attachment Range
                    if (_beginsEnds != null)
                    {
                        Tuple<string, string> beginEnd;
                        _beginsEnds.TryGetValue(document.Id.ToString(), out beginEnd);
                        if (beginEnd != null)
                        {
                            exportDocument.BeginDoc = beginEnd.Item1;
                            exportDocument.EndDoc = beginEnd.Item2;
                        }
                    }
                    #endregion

                    //3) File Path (Native File & Text)
                    if (document.DocumentBinary.FileList != null)
                    {
                        if (exportDocumentCollection.ExportOption.IsNative)
                        {
                            //Get the tag name to check the tag exists for the document. If exists then export the native files.
                            string tagNameToIncludeNative = exportDocumentCollection.ExportOption.IncludeNativeTagName;
                            if (!string.IsNullOrEmpty(tagNameToIncludeNative)) //If "Include native for tagged document only" option is selected
                            {
                                //Check whether the document tagged with the selected tag. If yes, set the IsNativeTagExists property as true and get all native files to export out.
                                exportDocument.IsNativeTagExists = CheckTagExistsToIncludeNative(document.CollectionId, document.DocumentId, tagNameToIncludeNative);
                                if (exportDocument.IsNativeTagExists) //If document tagged then get the native files list to export.
                                    exportDocument.NativeFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.NativeFileTypeId).ToList());
                            }
                            else //If "Include native for tagged document only" option not selected, get native files to export out.
                            {
                                exportDocument.NativeFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.NativeFileTypeId).ToList());
                            }
                        }
                        if (exportDocumentCollection.ExportOption.IsText)
                        {
                            if (exportDocumentCollection.ExportOption.IsTextFieldToExportSelected && !string.IsNullOrEmpty(exportDocumentCollection.ExportOption.TextFieldToExport))
                            {
                                var fileList = new List<ExportFileInformation>
                                {
                                    new ExportFileInformation()
                                    {
                                        IsTextFieldExportEnabled = true
                                    }
                                };
                                exportDocument.TextFiles = fileList;
                            }
                            else
                            {
                                if (exportDocumentCollection.ExportOption.IsProduction && !string.IsNullOrEmpty(exportDocumentCollection.ExportOption.ProductionSetCollectionId))
                                {
                                    string[] lstOfProductionSets = exportDocumentCollection.ExportOption.ProductionSetCollectionId.Split(',');
                                    foreach (string productionSetId in lstOfProductionSets)
                                    {
                                        var productionDocumentData = GetDocumentData(documentId, productionSetId, out isError);
                                        if (exportDocumentCollection.ExportOption.TextOption1 == Constants.ScrubbedText) //If Text Prority 1 is Printed/Scrubbed text
                                        {
                                            //Get the scrubbed text files for one or more productions...
                                            if (exportDocument.TextFiles == null)
                                            {
                                                //Get the scrubbed text files for the first time....
                                                exportDocument.TextFiles = GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList());
                                            }
                                            else
                                            {
                                                //Appnd to existing text files in case user chooses more than one production 
                                                exportDocument.TextFiles.AddRange(GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList()));
                                            }
                                            if ((exportDocument.TextFiles == null || exportDocument.TextFiles.Count == 0 || !File.Exists(exportDocument.TextFiles.FirstOrDefault().SourceFilePath)) && exportDocumentCollection.ExportOption.TextOption2 == Constants.ExtractedText) //If scrubbed text not exists for this document then get the Extracted text
                                            {
                                                exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                                exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath);
                                            }
                                            else
                                                exportDocument.TextFiles.ForEach(s => s.IsScrubbedText = true);
                                        }
                                        else //Else If Text Prority 1 is Extracted text
                                        {
                                            //Get the extracted text files
                                            exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                            exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath); //Remove the querystring
                                            if ((exportDocument.TextFiles == null || exportDocument.TextFiles.Count == 0 || !File.Exists(exportDocument.TextFiles.FirstOrDefault().SourceFilePath)) && exportDocumentCollection.ExportOption.TextOption2 == Constants.ScrubbedText) //If extracted text not exists for this document then get the Scrubbed text if exists
                                            {
                                                exportDocument.TextFiles = GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList());
                                                exportDocument.TextFiles.ForEach(s => s.IsScrubbedText = true);
                                            }
                                        }
                                    }

                                }
                                else
                                {
                                    exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                    exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath); //Remove the querystring
                                }
                            }
                        }
                    }
                    //2.1) File Path (Images for Imageset or Production Set)
                    exportDocument.ImageFiles = new List<ExportFileInformation>();
                }
                //3) Tag
                if (exportDocumentCollection.ExportOption.IsTag && exportDocumentCollection.ExportOption.TagList != null && exportDocumentCollection.ExportOption.TagList.Count > 0)
                {
                    var tag = GetDocumentTags(documentId, out isErrorInTag);
                    if (tag != null && tag.Count > 0)
                    {
                        exportDocument.Tags = tag.Where(t => exportDocumentCollection.ExportOption.TagList.Contains(t.TagId.ToString(CultureInfo.InvariantCulture)) && t.Status).ToList();
                    }
                }

                #region Log
                metadataLog = ConstructLog(correlationId, (!isError), (!string.IsNullOrEmpty(exportDocument.DCN) ? exportDocument.DCN : string.Empty), isError, isErrorInTag, string.Empty);
                #endregion
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                metadataLog = ConstructLog(correlationId, false, string.Empty, true, true, "Error in get Metadata.");
            }
            return exportDocument;
        }
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 private void LogMessage(bool status, string information)
 {
     var log = new List<JobWorkerLog<DcbParserLogInfo>>();
     var parserLog = new JobWorkerLog<DcbParserLogInfo>();
     parserLog.JobRunId = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
     parserLog.CorrelationId = 0; // TaskId
     parserLog.WorkerRoleType = "6d7f04b0-f323-4f51-b6ba-959afb818e17";
     parserLog.WorkerInstanceId = WorkerId;
     parserLog.IsMessage = false;
     parserLog.Success = status;
     parserLog.CreatedBy = (!string.IsNullOrEmpty(ProfileBEO.CreatedBy) ? ProfileBEO.CreatedBy : "N/A");
     parserLog.LogInfo = new DcbParserLogInfo();
     parserLog.LogInfo.Information = information;
     parserLog.LogInfo.Message = information;
     log.Add(parserLog);
     SendLog(log);
 }
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 private void LogMessage(bool status, string information, string createdBy, string reviewsetName)
 {
     try
     {
         var log = new List<JobWorkerLog<ReviewsetLogInfo>>();
         var parserLog = new JobWorkerLog<ReviewsetLogInfo>
         {
             JobRunId =
                 (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0,
             CorrelationId = 0,
             WorkerRoleType = Constants.ReviewsetSearchRoleId,
             WorkerInstanceId = WorkerId,
             IsMessage = false,
             Success = status,
             CreatedBy = createdBy,
             LogInfo = new ReviewsetLogInfo { Information = information, ReviewsetName = reviewsetName }
         };
         // TaskId
         log.Add(parserLog);
         SendLog(log);
     }
     catch (Exception exception)
     {
         Tracer.Info("SearchWorker : LogMessage : Exception details: {0}", exception);
     }
 }
        /// <summary>
        /// Construct Log Data
        /// </summary>       
        private JobWorkerLog<LawImportLogInfo> ConstructLog(string correlationId, string docId,
                                                            string missingNativeFile, List<string> missingImageFiles,
                                                            bool isMissingContent,
                                                            IEnumerable<string> missingContentFiles,
                                                            Int32 importedImagesCount, string documentCtrlNbr,
                                                            string crossReferenceFieldValue)
        {
            try
            {
                docId.ShouldNotBe(null);
                var log = new JobWorkerLog<LawImportLogInfo>
                    {
                        JobRunId = (!string.IsNullOrEmpty(_jobRunId)) ? Convert.ToInt64(_jobRunId) : 0,
                        CorrelationId = (!string.IsNullOrEmpty(correlationId)) ? Convert.ToInt64(correlationId) : 0,
                        WorkerInstanceId = _workerInstanceId,
                        WorkerRoleType = Constants.LawImportStartupWorkerRoleType,
                        Success = true,
                        CreatedBy = _jobParams.CreatedBy,
                        IsMessage = false,
                        LogInfo = new LawImportLogInfo()
                    };
                if (log.LogInfo.Message == null)
                    log.LogInfo.Message = string.Empty;

                log.LogInfo.Information = Constants.RecordParserSuccessMessage;
                if (null != missingNativeFile || missingImageFiles.Count > 0 || isMissingContent)
                {
                    log.Success = false;
                    log.LogInfo.Information = !string.IsNullOrEmpty(documentCtrlNbr)
                                                  ? string.Format(Constants.MissingFileMessage, documentCtrlNbr)
                                                  : Constants.MissingFiles;
                }

                if (null != missingNativeFile)
                {
                    log.LogInfo.Information += Constants.MissingNativeFileMessage + missingNativeFile;
                    log.LogInfo.Message = log.LogInfo.Message.Contains(Constants.MsgMissingNativeFiles)
                                              ? log.LogInfo.Message
                                              : log.LogInfo.Message + Constants.MsgMissingNativeFiles;
                    log.LogInfo.CrossReferenceField = crossReferenceFieldValue;
                }

                foreach (var missingImageFile in missingImageFiles)
                {
                    log.LogInfo.Information += Constants.MissingImageFileMessage + missingImageFile;
                    log.LogInfo.Message = log.LogInfo.Message.Contains(Constants.MsgMissingImage)
                                              ? log.LogInfo.Message
                                              : log.LogInfo.Message + Constants.MsgMissingImage;
                    log.LogInfo.CrossReferenceField = crossReferenceFieldValue;
                }

                foreach (var missingContentFile in missingContentFiles)
                {
                    log.LogInfo.Information += Constants.MissingContentFileMessage + missingContentFile;
                    log.LogInfo.Message = log.LogInfo.Message.Contains(Constants.MsgMissingContentFile)
                                              ? log.LogInfo.Message
                                              : log.LogInfo.Message + Constants.MsgMissingContentFile;
                    log.LogInfo.CrossReferenceField = crossReferenceFieldValue;
                }

                log.LogInfo.IsMissingImage = missingImageFiles.Count > 0;
                log.LogInfo.IsMissingNative = null != missingNativeFile;
                log.LogInfo.IsMissingText = isMissingContent;
                log.LogInfo.AddedDocument = 1;
                log.LogInfo.AddedImages = importedImagesCount;
                log.LogInfo.DocumentId = docId;
                log.LogInfo.DCN = documentCtrlNbr;
                return log;
            }
            catch (Exception ex)
            {
                throw new Exception(Constants.ErrorConstrcutLogData + ex.Message);
            }
        }
        protected void FetchDocumentFromDCB(int documentNumber,
            List<DocumentDetail> documentDetailList, FamiliesInfo familiesInfo, JobWorkerLog<DcbParserLogInfo> dcbParserLogEntry)
        {
            #region Precondition asserts
            documentDetailList.ShouldNotBe(null);
            dcbParserLogEntry.ShouldNotBe(null);
            #endregion
            RVWDocumentBEO evDocument = new RVWDocumentBEO();
            try
            {
                //Get the document from DcbFacade
                Document currentDcbDocument = DcbFacade.GetDocument(documentNumber);

                //Throw exception if GetDocument fails
                currentDcbDocument.ShouldNotBe(null);

                //Create the target EV document
                evDocument.DocumentId = Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                dcbParserLogEntry.LogInfo.DocumentId = evDocument.DocumentId;
                evDocument.CollectionId = DcbOpticonJobBEO.TargetDatasetId;
                evDocument.MatterId = DcbOpticonJobBEO.MatterId;

                //Add the fields required for casemap
                RVWDocumentFieldBEO evDocumentAccessionNumField = new RVWDocumentFieldBEO
                                                   {
                                                       FieldId = Convert.ToInt32(DcbOpticonJobBEO.SysDocId),
                                                       FieldName = EVSystemFields.DcbId,
                                                       IsSystemField = true,
                                                       IsRequired = true,
                                                       FieldValue = Convert.ToString(currentDcbDocument.UUID, CultureInfo.InvariantCulture)
                                                   };
                evDocument.FieldList.Add(evDocumentAccessionNumField);
                evDocument.FieldList.Add(_evDocumentSysImportTypeField);

                //Set the fields from field mapping except content field
                foreach (FieldMapBEO fieldMap in DcbOpticonJobBEO.FieldMappings)
                {
                    Field dcbField = currentDcbDocument.FieldItems.Find(o => (o.Code == fieldMap.SourceFieldID));

                    //Profile fieldmapping has duplicates
                    RVWDocumentFieldBEO evDocumentFieldBEO = evDocument.FieldList.Find(o => o.FieldId.Equals(fieldMap.DatasetFieldID));
                    if ((null != dcbField) && (evDocumentFieldBEO == null) && (fieldMap.DatasetFieldID != _contentFieldId))
                    {
                        RVWDocumentFieldBEO evDocuemtnField = new RVWDocumentFieldBEO
                                                                  {
                                                                      FieldId = fieldMap.DatasetFieldID,
                                                                      FieldName = fieldMap.DatasetFieldName
                                                                  };


                        FieldBEO evfieldDef = _dataset.DatasetFieldList.Find(o => o.ID == evDocuemtnField.FieldId);
                        evDocuemtnField.FieldValue = evfieldDef.FieldType.DataTypeId == Constants.DateDataType
                                                         ? GetDateFiedlValue(dcbField, dcbParserLogEntry)
                                                         : Regex.Replace(dcbField.Value, "\r\n", "\n");
                        evDocument.FieldList.Add(evDocuemtnField);
                    }
                }

                //Separate logic for content
                StringBuilder sbContent = new StringBuilder();
                if (DcbOpticonJobBEO.ContentFields != null)
                {
                    foreach (string contentfield in DcbOpticonJobBEO.ContentFields.Field)
                    {
                        Field dcbContentField = currentDcbDocument.FieldItems.Find(o => (o.Name.Equals(contentfield)));
                        if (null != dcbContentField)
                        {
                            sbContent.Append(dcbContentField.Value);
                        }
                    }
                }
                string text = sbContent.ToString().Replace("\r\n", "\n");
                //evDocument.DocumentBinary.Content = Regex.Replace(sbContent.ToString(), "\r\n", "\n");

                if (!DumpTextToFile(evDocument, text, dcbParserLogEntry))
                {
                    return;
                }

                //Set the native file path if selected
                evDocument.NativeFilePath = GetNativeFilePath(currentDcbDocument);

                if (!String.IsNullOrEmpty(evDocument.NativeFilePath) && File.Exists(evDocument.NativeFilePath))
                {
                    FileInfo fileInfo = new FileInfo(evDocument.NativeFilePath);
                    //Tracer.Trace("DcbParcer located native document {0} for DocumentId = {1} and the file length is {2}",
                    //    evDocument.NativeFilePath, evDocument.DocumentId, fileInfo.Length);
                    if (fileInfo.Length > 0)
                    {
                        evDocument.FileSize = (int)Math.Ceiling(fileInfo.Length / 1024.0);
                    }
                    else
                    {
                        evDocument.FileSize = 0;
                    }

                    evDocument.MD5HashValue = DocumentHashHelper.GetMD5HashValue(evDocument.NativeFilePath);
                    evDocument.SHAHashValue = DocumentHashHelper.GetSHAHashValue(evDocument.NativeFilePath);
                }

                //Set the MIME type
                string extn = string.Empty;
                string newExtn = string.Empty;
                extn = Path.GetExtension(evDocument.NativeFilePath);
                if (!String.IsNullOrEmpty(extn))
                    newExtn = extn.Remove(0, 1);
                evDocument.MimeType = GetMimeType(newExtn);
                evDocument.FileExtension = extn;

                string createdByGuid = String.Empty;
                if (null != ProfileBEO && null != ProfileBEO.CreatedBy)
                {
                    createdByGuid = ProfileBEO.CreatedBy;
                }
                evDocument.CreatedBy = createdByGuid;
                evDocument.ModifiedBy = createdByGuid;

                if (File.Exists(evDocument.NativeFilePath))
                {
                    //Calculating size of file in KB
                    FileInfo fileInfo = new FileInfo(evDocument.NativeFilePath);
                    evDocument.FileSize = (int)Math.Ceiling(fileInfo.Length / Constants.KBConversionConstant);

                    if (evDocument.DocumentBinary == null) { evDocument.DocumentBinary = new RVWDocumentBinaryBEO(); }
                    RVWExternalFileBEO nativeFile = new RVWExternalFileBEO
                    {
                        Type = NATIVE_FILE_TYPE,
                        Path = evDocument.NativeFilePath
                    };
                    evDocument.DocumentBinary.FileList.Add(nativeFile);
                }

                DocumentDetail documentDetail = new DocumentDetail
                                                    {
                                                        // CorrId is the same as TaskId and it is 1 based.
                                                        CorrelationId = checked(documentNumber + 1).ToString(CultureInfo.InvariantCulture),
                                                        IsNewDocument = true,
                                                        docType = DocumentsetType.NativeSet,
                                                        document = evDocument
                                                    };
                documentDetailList.Add(documentDetail);

                //Add Tags
                if (DcbOpticonJobBEO.IncludeTags && null != currentDcbDocument.TagItems && currentDcbDocument.TagItems.Count > 0)
                {
                    if (null == documentDetail.DcbTags)
                    {
                        documentDetail.DcbTags = new List<DcbTags>();
                    }
                    DcbDocumentTags dcbDocumentTags = new DcbDocumentTags
                                                          {
                        compositeTagNames = currentDcbDocument.TagItems,
                        DatasetId = DcbOpticonJobBEO.TargetDatasetId,
                        MatterId = DcbOpticonJobBEO.MatterId,
                        DocumentId = evDocument.DocumentId
                    };
                    documentDetail.DcbTags.Add(dcbDocumentTags);
                }

                // Add notes
                AddComments(documentDetail, evDocument, currentDcbDocument);

                //Add Images
                if (DcbOpticonJobBEO.ImportImages)
                {
                    RVWDocumentBEO images = ImportDocumentImages(evDocument.DocumentId, currentDcbDocument);
                    if (null != images)
                    {
                        DocumentDetail imageDocumentDetail = new DocumentDetail
                                                                 {
                                                                     // CorrId is the same as TaskId and it is 1 based.
                                                                     CorrelationId = checked(documentNumber + 1).ToString(CultureInfo.InvariantCulture),
                                                                     IsNewDocument = true,
                                                                     docType = DocumentsetType.ImageSet,
                                                                     document = images
                                                                 };
                        documentDetailList.Add(imageDocumentDetail);
                        dcbParserLogEntry.LogInfo.AddedImages = images.DocumentBinary.FileList.Count;
                    }

                    //Add Redlines
                    //ImportDocumentRedlines();
                }

                //Add Document Relation
                if (DcbOpticonJobBEO.IsImportFamilies)
                {
                    ImportDocumentRelationship(evDocument.DocumentId, currentDcbDocument, familiesInfo);
                }
                #region Postcondition asserts
                documentDetailList.ShouldNotBe(null);
                #endregion
            }
            catch (Exception ex)
            {
                //TaskLogInfo.AddParameters(Constants.ErrorDoAtomicWork + "<br/>" + ex.Message);
                //TaskLogInfo.StackTrace = ex.Source + "<br/>" + ex.Message + "<br/>" + ex.StackTrace;
                //TaskLogInfo.IsError = true;

                ex.Trace().Swallow();
                dcbParserLogEntry.Success = false;
                if (ex.ToUserString().Contains(Constants.DiskFullErrorMessage))
                {
                    dcbParserLogEntry.LogInfo.Message = "There is not enough space on the disk";
                    throw;
                }
                else
                {
                    dcbParserLogEntry.LogInfo.Message = ex.ToUserString();
                }
            }
        }
 /// <summary>
 /// Construct Log Message and Call Log pipe
 /// </summary>
 internal void LogMessage(bool status, string information)
 {
     List<JobWorkerLog<LoadFileDocumentParserLogInfo>> log = new List<JobWorkerLog<LoadFileDocumentParserLogInfo>>();
     JobWorkerLog<LoadFileDocumentParserLogInfo> parserLog = new JobWorkerLog<LoadFileDocumentParserLogInfo>();
     parserLog.JobRunId = (!String.IsNullOrEmpty(PipelineId)) ? Convert.ToUInt32(PipelineId) : 0;
     parserLog.CorrelationId = 0;// TaskId
     parserLog.WorkerRoleType = Constants.LoadFileRecordParserWorkerRoleType;
     parserLog.WorkerInstanceId = WorkerId;
     parserLog.IsMessage = false;
     parserLog.Success = status;
     parserLog.CreatedBy = (!string.IsNullOrEmpty(_jobParameter.CreatedBy) ? _jobParameter.CreatedBy : "N/A");
     parserLog.LogInfo = new LoadFileDocumentParserLogInfo();
     parserLog.LogInfo.Information = information;
     if (!status)
         parserLog.LogInfo.Message = information;
     log.Add(parserLog);
     SendLog(log);
 }