/// <summary>
        /// Get image location
        /// </summary>
        /// <returns></returns>
        private string GetImageLocation()
        {
            var lawEvAdapter         = LawBO.GetLawAdapter(LawCaseId);
            var imageArchiveDirector = lawEvAdapter.GetImageArchiveDirectory();

            return(Path.Combine(imageArchiveDirector, "EVImages", string.Format("Job{0}", JobId)));
        }
        protected override bool Completed()
        {
            base.Completed();
            try
            {
                var lawSyncSummary = LawBO.GetLawSyncProcessSetJobSummary(MatterId, JobId);

                var jobSummaryKeyValuePairs = new EVKeyValuePairs();
                jobSummaryKeyValuePairs.Set("ImageFolder", SyncImage ? GetImageLocation() : "N/A");
                jobSummaryKeyValuePairs.Set("ImageSyncFailureCount",
                                            SyncImage ? lawSyncSummary.ImageSyncFailureCount.ToString(CultureInfo.InvariantCulture) : "N/A");
                jobSummaryKeyValuePairs.Set("MetadatSyncFailureCount",
                                            lawSyncSummary.MetadataSyncFailureCount.ToString(CultureInfo.InvariantCulture));
                jobSummaryKeyValuePairs.Set("TotalDocument",
                                            (lawSyncSummary.LawSyncSuceessCount + lawSyncSummary.LawSyncFailureCount).ToString(
                                                CultureInfo.InvariantCulture));


                JobMgmtBO.UpdateJobResult(JobId, lawSyncSummary.LawSyncSuceessCount, lawSyncSummary.LawSyncFailureCount,
                                          jobSummaryKeyValuePairs);
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
            }
            return(true);
        }
Esempio n. 3
0
        private void UpdateDocumentsMetadatasInLaw(LawSyncDocumentCollection lawDocumentsList)
        {
            try
            {
                var lawEvAdapter          = LawBO.GetLawAdapter(_jobParameter.LawCaseId);
                var lawDocumentUpdateList = new List <LawDocumentBEO>();
                var metadatNameList       = new List <string>();
                if (_jobParameter.MappingFields != null && _jobParameter.MappingFields.Any())
                {
                    metadatNameList.AddRange(_jobParameter.MappingFields.Select(fields => fields.Name).ToList());
                }
                if (_jobParameter.MappingTags != null && _jobParameter.MappingTags.Any())
                {
                    metadatNameList.AddRange(_jobParameter.MappingTags.Select(tags => tags.Name).ToList());
                }
                metadatNameList.Add(_jobParameter.LawSyncTagName);

                foreach (var document in lawDocumentsList.Documents.Where(d => !d.IsErrorOnGetMetadata))
                {
                    var lawDocumentUpdate = new LawDocumentBEO
                    {
                        LawDocId     = document.LawDocumentId,
                        LawMetadatas = document.MetadataList
                    };
                    lawDocumentUpdateList.Add(lawDocumentUpdate);
                }

                if (lawDocumentUpdateList.Any())
                {
                    lawEvAdapter.UpdateLawMetadata(lawDocumentUpdateList, metadatNameList);

                    foreach (var document in lawDocumentsList.Documents.Where(d => !d.IsErrorOnGetMetadata))
                    {
                        _documentProcessStateList.Add(GetDocumentProcessStateInformation(document, (int)LawSyncProcessState.Completed));
                    }
                }
            }
            catch (Exception ex)
            {
                //Construct Log
                foreach (var document in lawDocumentsList.Documents)
                {
                    ConstructLog(document.LawDocumentId, document.CorrelationId, document.DocumentControlNumber,
                                 Constants.LawSyncFailureinSyncMetadataMessage);
                    _documentProcessStateList.Add(GetDocumentProcessStateInformation(document, (int)LawSyncProcessState.Failed));
                    document.IsErrorOnSyncMetadata = true;
                }
                ex.Trace().Swallow();
                ReportToDirector(ex);
            }
        }
        protected override void ProcessMessage(PipeMessageEnvelope message)
        {
            try
            {
                if (message.Body == null)
                {
                    return;
                }
                var lawDocumentsList = (LawSyncDocumentCollection)message.Body;
                if (_jobParameter == null)
                {
                    if (lawDocumentsList.IsLawSyncReprocessJob)
                    {
                        _jobParameter = lawDocumentsList.OrginalJobParameter;
                    }
                    else
                    {
                        _jobParameter = (LawSyncBEO)XmlUtility.DeserializeObject(BootParameters, typeof(LawSyncBEO));
                    }
                }
                _datasetCollectionId      = lawDocumentsList.DatasetCollectionId;
                _lawSyncJobId             = lawDocumentsList.LawSynJobId;
                _logInfoList              = new List <JobWorkerLog <LawSyncLogInfo> >();
                _documentProcessStateList = new List <DocumentConversionLogBeo>();

                _lawEvAdapter          = LawBO.GetLawAdapter(_jobParameter.LawCaseId);
                _imageArchiveDirectory = _lawEvAdapter.GetImageArchiveDirectory();

                var lawImagingDocuments = lawDocumentsList.Documents.Where(d => d.IsImaging).ToList();
                if (_jobParameter.IsProduceImage && lawImagingDocuments.Any())
                {
                    _logInfoList = new List <JobWorkerLog <LawSyncLogInfo> >();
                    ProcessDocumentImages(lawDocumentsList);
                }

                if (_logInfoList.Any())
                {
                    SendLogPipe(_logInfoList);
                }
                if (_documentProcessStateList.Any())
                {
                    UpdateDcoumentProcessState(_documentProcessStateList);
                }
            }
            catch (Exception ex)
            {
                ReportToDirector(ex);
                ex.Trace().Swallow();
                LogMessage(Constants.LawSyncFailureinSyncImageMessage + ex.ToUserString());
            }
        }
        /// <summary>
        /// To generate message and pass to the next worker with collection of documents in a batch
        /// </summary>
        /// <returns></returns>
        protected override bool GenerateMessage()
        {
            try
            {
                OutputDataPipe.ShouldNotBe(null);
                if (_jobParams == null)
                {
                    _jobParams = GetJobParams(BootParameters);
                }
                var documents =
                    LawBO.GetDocuments(_jobParams.LawCaseId, _selectedFields, _selectedTags, _jobParams.TagFilters);

                if (documents != null)
                {
                    var localDocumentList = new List <RVWDocumentBEO>();
                    foreach (var doc in documents)
                    {
                        doc.DocumentId = GetDocumentId();
                        //Setting the Cross Reference field with LAW DocID by default
                        doc.CrossReferenceFieldValue = doc.LawDocumentId.ToString(CultureInfo.InvariantCulture);
                        localDocumentList.Add(doc);
                        if (localDocumentList.Count % _batchSize != 0)
                        {
                            continue;
                        }
                        ProcessMessage(localDocumentList);
                        localDocumentList.Clear();
                    }

                    //Sending remaining documents for process
                    if (localDocumentList.Any())
                    {
                        ProcessMessage(localDocumentList);
                    }
                }
            }
            catch (Exception ex)
            {
                LogMessage(false, ex.ToUserString());
                ReportToDirector(ex.ToUserString());
                throw;
            }

            LogMessage(true, Constants.ParserSuccessMessage);
            return(true);
        }
        /// <summary>
        /// Worker begin work event
        /// </summary>
        protected override void BeginWork()
        {
            try
            {
                base.BeginWork();
                _jobParams = GetJobParams(BootParameters);
                _jobParams.ShouldNotBe(null);
                _jobParams.FolderId.ShouldBeGreaterThan(0);

                _datasetDetails = DataSetBO.GetDataSetDetailForDataSetId(_jobParams.FolderId);
                var matterDetails =
                    MatterDAO.GetMatterDetails(_jobParams.MatterId.ToString(CultureInfo.InvariantCulture));
                matterDetails.ShouldNotBe(null);
                _datasetDetails.Matter = matterDetails;
                var searchServerDetails = ServerDAO.GetSearchServer(matterDetails.SearchServer.Id);
                searchServerDetails.ShouldNotBe(null);
                _datasetDetails.Matter.SearchServer = searchServerDetails;

                if (!LawBO.TestServerConnection(_jobParams.LawCaseId))
                {
                    ReportToDirector("Failed to connect Law server. Please see application log for details.");
                }

                if (EVHttpContext.CurrentContext == null)
                {
                    // Moq the session
                    MockSession(_jobParams.CreatedBy);
                }

                //Create fields for selected law fields
                CreateSelectedLawFields();

                //Create tags for selected law tags
                CreateSelectedLawTags();

                //Law import batch size for documents
                _batchSize = GetMessageBatchSize();
            }
            catch (Exception ex)
            {
                //Send log infor to Log worker
                LogMessage(false, ex.ToUserString());
                ReportToDirector(ex.ToUserString());
                throw;
            }
        }
        public static string GetJobImageFolder(long jobId, long caseId)
        {
            string imageArchiveDirectory;

            #region "debug"

            /*
             * var lawCase = LawBO.GetLawCaseDetails(caseId);
             * if (lawCase != null)
             * {
             *  if (!string.IsNullOrEmpty(lawCase.ImageArchiveDirectory))
             *  {
             *      imageArchiveDirectory = lawCase.ImageArchiveDirectory;
             *  }
             *  else
             *  {
             *      //It will be replaced by API
             *      imageArchiveDirectory = Path.Combine(lawCase.CaseDirectory, Constants.LawImageArchiveFolderName);
             *      Directory.CreateDirectory(imageArchiveDirectory);
             *  }
             * }
             */
            #endregion

            var lawEvAdapter = LawBO.GetLawAdapter(caseId);
            lawEvAdapter.CreateImageArchiveFolder();
            imageArchiveDirectory = lawEvAdapter.GetImageArchiveDirectory();

            //1) Create EvImages Folder
            var evImagesFolderPath = Path.Combine(imageArchiveDirectory, Constants.LawEVImagesFolderName);
            if (!Directory.Exists(evImagesFolderPath))
            {
                Directory.CreateDirectory(evImagesFolderPath);
            }

            //2) Create Job Folder
            var jobImageFolder = Path.Combine(evImagesFolderPath, string.Format("{0}{1}", "Job", jobId));
            if (!Directory.Exists(jobImageFolder))
            {
                Directory.CreateDirectory(jobImageFolder);
            }
            return(jobImageFolder);
        }
        /// <summary>
        /// Create metadata in Law case
        /// </summary>
        private bool CreateMetaDataFieldsInLawCase()
        {
            try
            {
                //1) Fields
                var lawEvAdapter = LawBO.GetLawAdapter(_jobParameter.LawCaseId);
                if (_jobParameter.MappingFields != null && _jobParameter.MappingFields.Any())
                {
                    foreach (var field in _jobParameter.MappingFields.Where(field => !string.IsNullOrEmpty(field.Name)))
                    {
                        lawEvAdapter.CreateField(field.Name, field.FieldType);
                    }
                }

                //2) Tag
                if (_jobParameter.MappingTags != null && _jobParameter.MappingTags.Any())
                {
                    foreach (var tag in _jobParameter.MappingTags.Where(tag => !string.IsNullOrEmpty(tag.Name)))
                    {
                        lawEvAdapter.CreateTag(tag.Name);
                    }
                }
                //3) create special Tag
                if (!string.IsNullOrEmpty(_jobParameter.LawSyncTagName))
                {
                    lawEvAdapter.CreateTag(_jobParameter.LawSyncTagName);
                }
                return(true);
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                ReportToDirector(ex);
            }
            return(false);
        }