/// <summary> /// This is the overridden DoAtomicWork method. /// </summary> /// <param name="task">print Job Task</param> /// <param name="jobParameters">Email Job Parameters</param> /// <returns>If Atomic work was successful</returns> protected override bool DoAtomicWork(BaseJobTaskBusinessEntity task, BaseJobBEO jobParameters) { bool success = true; bool isSendPerformed = false; SendEmailServiceRequestBEO request = null; if (task != null) { bool isMailSent = false; try { request = (SendEmailServiceRequestBEO)XmlUtility.DeserializeObject(jobParameters.BootParameters, typeof(SendEmailServiceRequestBEO)); string emailDocumentConfigurations = GetEmailDocumentConfigurations(); success = SendEmailBO.CreateTemperaryFolder(jobParameters.JobId.ToString(CultureInfo.InvariantCulture), request.RequestedBy.UserId, request.Documents[task.TaskNumber - 1], emailDocumentConfigurations); if (task.TaskNumber == request.Documents.Count) { isSendPerformed = true; //Compress the temporary folder SendEmailBO.CompressFolder(jobParameters.JobId.ToString(CultureInfo.InvariantCulture), emailDocumentConfigurations); //Construct Zip folder isMailSent = SendEmailBO.ComposeAndSendEmail(jobParameters.JobId.ToString(CultureInfo.InvariantCulture), request, emailDocumentConfigurations); //Send Notification on success/failure of email job SendEmailBO.SendNotification(jobParameters.JobId.ToString(CultureInfo.InvariantCulture), isMailSent); } EvLog.WriteEntry(Constants.JobTypeName + Constants.Hyphen + jobParameters.JobId.ToString(CultureInfo.InvariantCulture), Constants.Event_Job_DoAtomicWork_Success + Constants.ForTaskNumber + task.TaskNumber, EventLogEntryType.Information); } catch (Exception exp) { exp.Trace(); isMailSent = false; //Send Notification on success/failure of email job if (isSendPerformed) { SendEmailBO.SendNotification(jobParameters.JobId.ToString(CultureInfo.InvariantCulture), isMailSent); } //Update Delivery Status to Failed DeliveryOptionsBO.UpdateDeliveryStatus(jobParameters.JobId.ToString(CultureInfo.InvariantCulture), (short)PrintToFileServiceStateBEO.Failed); EvLog.WriteEntry(Constants.JobTypeName + Constants.Hyphen + jobParameters.JobId.ToString(CultureInfo.InvariantCulture), Constants.Event_Job_DoAtomicWork_Failed + Constants.ForTaskNumber + task.TaskNumber + Constants.Colon + exp.Message, EventLogEntryType.Error); if (request != null && request.Documents.Count > 0) { DocumentIdentifierBEO documentIdentifier = request.Documents[task.TaskNumber - 1]; TaskLogInfo.TaskKey = SendEmailBO.GetDcnFieldValue(documentIdentifier.MatterId, documentIdentifier.CollectionId, documentIdentifier.DocumentId); } TaskLogInfo.AddParameters(Constants.Event_Job_DoAtomicWork_Failed + Constants.Colon + exp.Message); if (task.TaskNumber == request.Documents.Count && !isSendPerformed) { EVJobException jobException = new EVJobException(ErrorCodes.ProblemInDoAtomicWork, exp, TaskLogInfo); throw (jobException); } else { EVTaskException taskException = new EVTaskException(ErrorCodes.ProblemInDoAtomicWork, exp, TaskLogInfo); throw (taskException); } } } return(success); }
/// <summary> /// Logs the exception message into database.. /// </summary> /// <param name="logInfo">Log information</param> /// <param name="exp">exception received</param> /// <param name="category">To identify the job or task to log the message</param> /// <param name="errocode">error code</param> /// <param name="taskKey">taskKey</param> private static void LogException(LogInfo logInfo, Exception exp, LogCategory category, string errorCode, string taskKey) { if (category == LogCategory.Job) { var jobException = new EVJobException(errorCode, exp, logInfo); throw (jobException); } logInfo.TaskKey = taskKey; var taskException = new EVTaskException(errorCode, exp, logInfo); throw (taskException); }
/// <summary> /// Handles the exception. /// </summary> /// <param name="category">The category.</param> /// <param name="customMessage">The custom message.</param> /// <param name="ex">The ex.</param> /// <param name="errorCode">Error Code</param> private void HandleException(LogCategory category, string customMessage, Exception ex, string errorCode) { if (category == LogCategory.Job) { JobLogInfo.AddParameters(customMessage); EVJobException jobException = new EVJobException(errorCode, ex, JobLogInfo); throw (jobException); } TaskLogInfo.AddParameters(customMessage); EVTaskException taskException = new EVTaskException(errorCode, ex, TaskLogInfo); throw (taskException); }
/// <summary> /// Handles the exception. /// </summary> /// <param name="category">The category.</param> /// <param name="ex">The ex.</param> /// <param name="taskKey">string</param> /// <param name="errorCode">Error Code</param> private void HandleException(LogCategory category, Exception ex, string taskKey, string errorCode) { if (category == LogCategory.Job) { JobLogInfo.AddParameters(ex.Message); var jobException = new EVJobException(errorCode, ex, JobLogInfo); throw jobException; } TaskLogInfo.AddParameters(ex.Message); TaskLogInfo.TaskKey = taskKey; var taskException = new EVTaskException(errorCode, ex, TaskLogInfo); throw taskException; }
/// <summary> /// Logs the exception message into database.. /// </summary> /// <param name="logMsg">LogInfo</param> /// <param name="exp">exception received</param> /// <param name="category">To identify the job or task to log the message</param> /// <param name="taskKey">Key to identify the Task, need for task log only</param> /// <param name="errorCode">string</param> private static void LogException(LogInfo logMsg, Exception exp, LogCategory category, string taskKey, string errorCode) { if (category == LogCategory.Job) { EVJobException jobException = new EVJobException(errorCode, exp, logMsg); throw (jobException); } else { logMsg.TaskKey = taskKey; EVTaskException jobException = new EVTaskException(errorCode, exp, logMsg); throw (jobException); } }
/// <summary> /// Logs the exception message. /// </summary> /// <param name="jobId">Job Identifier</param> /// <param name="exp">exception received</param> /// <param name="msg">message to be logged</param> /// <param name="category">To identify the job or task to log the message</param> /// <param name="taskKey">Key value pair to identify the Task, need for task log only</param> /// <param name="errorCode">string</param> private void LogException(int jobId, Exception exp, string msg, LogCategory category, string taskKey, string errorCode) { if (category == LogCategory.Job) { JobLogInfo.AddParameters(jobId + msg); var jobException = new EVJobException(errorCode, exp, JobLogInfo); throw (jobException); } TaskLogInfo.AddParameters(jobId + msg); TaskLogInfo.TaskKey = taskKey; var taskException = new EVTaskException(errorCode, exp, TaskLogInfo); throw (taskException); }
/// <summary> /// Logs the exception message into database.. /// </summary> /// <param name="logInfo">Log information</param> /// <param name="exp">exception received</param> /// <param name="category">To identify the job or task to log the message</param> /// <param name="errorCode"> </param> /// <param name="taskKey">taskKey</param> private static void LogException(LogInfo logInfo, Exception exp, LogCategory category, string errorCode, string taskKey) { switch (category) { case LogCategory.Job: { EVJobException jobException = new EVJobException(errorCode, exp, logInfo); throw (jobException); } default: { logInfo.TaskKey = taskKey; EVTaskException taskException = new EVTaskException(errorCode, exp, logInfo); throw (taskException); } } }
/// <summary> /// Does atomic 1)Gets DCB document 2) Generate xml 3) Update xml file to database. /// </summary> /// <param name="task">ConvertDCBLinkTaskBusinessEntityObject</param> /// <param name="jobParameters">Job business entity</param> /// <returns></returns> protected override bool DoAtomicWork(ConvertDCBLinkTaskBusinessEntityObject task, BaseJobBEO jobParameters) { bool StatusFlag = true;// Function return status. try { EvLog.WriteEntry(Constants.JobTypeName + " - " + jobParameters.JobRunId.ToString(CultureInfo.InvariantCulture), Constants.Event_Job_DoAtomicWork_Start, EventLogEntryType.Information); // Perform Atomic Task DCBLinkCollectionBEO dcbLinks = new DCBLinkCollectionBEO(); DCBLinkBEO dcbLink; ReviewerSearchResults searchResults = null; if (_documentCount > 0) { DocumentQueryEntity documentQueryEntity = GetDocumentQueryEntity(task.DatasetId.ToString(CultureInfo.InvariantCulture), _query, _documentCount.ToString(CultureInfo.InvariantCulture)); documentQueryEntity.TransactionName = "ConvertDCBLinksToCaseMap - DoAtomicWork"; searchResults = JobSearchHandler.GetSearchResults(documentQueryEntity); } List <DCBLinkBEO> linkList = new List <DCBLinkBEO>(); string uuid = string.Empty; int count = 0; foreach (DocumentResult document in searchResults.ResultDocuments) { dcbLink = new DCBLinkBEO(); DocumentIdentifierBEO docIdentifier = new DocumentIdentifierBEO(document.MatterID.ToString(CultureInfo.InvariantCulture), document.CollectionID, document.DocumentID); if (count == 0) { uuid = docIdentifier.UniqueIdentifier.Replace(docIdentifier.DocumentId, string.Empty); } dcbLink.NewDocumentId = docIdentifier.DocumentId; List <FieldResult> fieldValues = document.Fields.Where(f => System.String.Compare(f.Name, EVSystemFields.DcbId, System.StringComparison.OrdinalIgnoreCase) == 0).ToList(); dcbLink.OldDocumentId = fieldValues.Any() ? fieldValues.First().Value.Replace("[", "(").Replace("]", ")") : string.Empty; linkList.Add(dcbLink); dcbLink.CollectionId = docIdentifier.CollectionId; dcbLink.DCN = docIdentifier.DCN; if (docIdentifier.MatterId != null) { dcbLink.MatterId = long.Parse(docIdentifier.MatterId); } count++; } linkList.SafeForEach(l => dcbLinks.Links.Add(l)); dcbLinks.UrlApplicationLink = task.LinkBackUrl; string xml = DocumentFactBusinessObject.GenerateDcbLinksXml(dcbLinks, uuid); UTF8Encoding encoding = new UTF8Encoding(); byte[] content = encoding.GetBytes(xml); StringBuilder nameBuilder = new StringBuilder(); nameBuilder.Append(Constants.TaskName); nameBuilder.Append(Constants.OnDate); nameBuilder.Append(startedTime.ConvertToUserTime()); string requestName = nameBuilder.ToString(); nameBuilder = new StringBuilder(); nameBuilder.Append(Constants.TaskName); _requestDescription = nameBuilder.ToString(); string fileType = ApplicationConfigurationManager.GetValue(Constants.FileType); _conversionId = CaseMapDAO.SaveConversionResults(jobParameters.JobRunId, requestName, _requestDescription, content, fileType, _createdByUserGuid); StatusFlag = true; EvLog.WriteEntry(Constants.JobTypeName + " - " + jobParameters.JobRunId.ToString(CultureInfo.InvariantCulture), Constants.Event_Job_DoAtomicWork_Success, EventLogEntryType.Information); TaskLogInfo.AddParameters(Constants.DataSetName, task.DatasetName); } catch (EVTaskException ex) { _isJobFailed = true; EvLog.WriteEntry(Constants.JobTypeName + MethodInfo.GetCurrentMethod().Name, ex.Message, EventLogEntryType.Error); throw; } catch (Exception ex) { _isJobFailed = true; // Handle exception in Generate Tasks EvLog.WriteEntry(Constants.JobTypeName + MethodInfo.GetCurrentMethod().Name, ex.Message, EventLogEntryType.Error); EVTaskException jobException = new EVTaskException(ErrorCodes.DoAtomicError, ex); TaskLogInfo.StackTrace = ex.Message + Constants.LineBreak + ex.StackTrace; TaskLogInfo.AddParameters(Constants.DataSetId, task.DatasetId.ToString(CultureInfo.InvariantCulture)); TaskLogInfo.AddParameters(Constants.DataSetName, task.DatasetName); TaskLogInfo.TaskKey = Constants.DataSetName + ":" + task.DatasetName; jobException.LogMessge = TaskLogInfo; throw (jobException); } return(StatusFlag); }
/// <summary> /// Atomic work 1) Search 2) Notify 3) Update task details back to database. /// </summary> /// <param name="task"></param> /// <param name="jobParameters"></param> /// <returns></returns> protected override bool DoAtomicWork(SearchAlertsTaskBEO task, SearchAlertsJobBEO jobParameters) { var statusFlag = Constants.FAILURE; // Function return status. var queryTostore = string.Empty; DocumentQueryEntity searchBizEntityObj = null; try { //Get Previous Run Details var prevAlertRunDetails = m_Helper.GetPreviousAlertRunDetails(task.SearchAlert.AlertId); if (prevAlertRunDetails.Count > 0 && prevAlertRunDetails.Count == 7) { m_AlertLastRunTimestamp = Convert.ToDateTime(prevAlertRunDetails[0]); m_LastResultCount = Convert.ToInt32(prevAlertRunDetails[1]); m_ManualAlertNextRunDate = Convert.ToDateTime(prevAlertRunDetails[2]); var searchQuery = prevAlertRunDetails[3]; if (!string.IsNullOrEmpty(searchQuery)) { searchBizEntityObj = (DocumentQueryEntity) XmlUtility.DeserializeObject(searchQuery, typeof(DocumentQueryEntity)); if (searchBizEntityObj != null) { m_PrevSearchQuery = HttpUtility.HtmlDecode( (searchBizEntityObj.QueryObject.DisplayQuery.Split(new[] { Constants.ThreeTilde }, StringSplitOptions.None))[0]); } } var createdBy = prevAlertRunDetails[6]; //the below block of code is required to pass the user details who has actually created or updated the alert so that search can use the same // to check various business rules. var adminUserSession = EVSessionManager.Get <UserSessionBEO>(Constants.UserSessionInfo); var currentAlertUser = UserBO.GetUserUsingGuid(createdBy); if (currentAlertUser != null) { SetContext(adminUserSession, currentAlertUser, true); } var originalQuery = HttpUtility.HtmlDecode(task.SearchAlert.DocumentQuery.QueryObject.DisplayQuery); var generatedQuery = PopulateQuery(task, originalQuery, currentAlertUser.Timezone); //now modify the query in order to distinguish between all results and new results. This will be used in the UI. queryTostore = originalQuery + Constants.QUERY_DELIMETER + generatedQuery.Item3; // 1st time both will be the same so execute search only once. if (generatedQuery.Item1) { // Get only the all doc result count. This will be executed only for 1st time. m_AllResultCount = GetAlertResultCount(searchBizEntityObj, originalQuery); m_NewResultCount = m_AllResultCount; } else { // Get the new result count m_NewResultCount = GetAlertResultCount(searchBizEntityObj, generatedQuery.Item2); // Get the all docs result count m_AllResultCount = GetAlertResultCount(searchBizEntityObj, originalQuery); } ConstructNotificationMessage(task, originalQuery, searchBizEntityObj); statusFlag = Constants.SUCCESS; } } catch (EVException ex) { HandleEVException(ex, MethodBase.GetCurrentMethod().Name, task); statusFlag = Constants.FAILURE; var taskException = new EVTaskException(ex.GetErrorCode(), ex, TaskLogInfo); throw (taskException); } catch (Exception ex) { // Handle exception in initialize LogMessage(ex.Message, MethodBase.GetCurrentMethod().Name, EventLogEntryType.Error, task); statusFlag = Constants.FAILURE; var taskException = new EVTaskException(ErrorCodes.ProblemInDoAtomicWork, ex, TaskLogInfo); throw (taskException); } finally { try { task.SearchAlert.ActualOccurrenceCount = task.SearchAlert.ActualOccurrenceCount + 1; task.SearchAlert.DocumentQuery.QueryObject.QueryList.Clear(); task.SearchAlert.DocumentQuery.QueryObject.QueryList.AddRange(new List <Query> { new Query { SearchQuery = queryTostore, Precedence = 1 } }); // 3. Update alert details back to database m_Helper.UpdateAlertPostNotification(task.SearchAlert.ActualOccurrenceCount, DateTime.UtcNow, m_NewResultCount, m_AllResultCount, m_ManualAlertNextRunDate != DateTime.MinValue ? m_ManualAlertNextRunDate : m_Helper.CalculateNextRunTimeStampForAlert( task.SearchAlert.Duration, task.SearchAlert.NextRunDate), task.SearchAlert.AlertId, task.SearchAlert.NotificationId, jobParameters.JobRunId, XmlUtility.SerializeObject(task.SearchAlert.DocumentQuery)); } catch (EVException ex) { HandleEVException(ex, MethodBase.GetCurrentMethod().Name, task); statusFlag = Constants.FAILURE; } catch (Exception ex) { // Handle exception in initialize LogMessage(Constants.FAILED_MESSAGE + ex.Message, MethodBase.GetCurrentMethod().Name, EventLogEntryType.Error, task); statusFlag = Constants.FAILURE; } } return(statusFlag); // function return status. }