Пример #1
0
        /// <summary>
        /// method to send notification for each alert
        /// </summary>
        /// <param name="searchAlertBeo">Search Alert Business Entity</param>
        /// <param name="subject"></param>
        /// <param name="content"></param>
        /// <returns>Success status</returns>
        private void SendNotification(SearchAlertEntity searchAlertBeo, string subject, string content)
        {
            // Log message that notification is being sent.
            var notificationMessageBeo = new NotificationMessageBEO
            {
                CreatedBy = (m_UserBusinessEntity.DomainName.Equals(Constants.NA))
                    ? m_UserBusinessEntity.UserId
                    : m_UserBusinessEntity.DomainName + Constants.NA + m_UserBusinessEntity.UserId,
                NotificationId      = searchAlertBeo.NotificationId,
                NotificationSubject = HttpUtility.HtmlEncode(subject),
                NotificationBody    = content,
                CreatedByUserGuid   = m_UserBusinessEntity.UserGUID,
                CreatedByUserName   = (m_UserBusinessEntity.DomainName.Equals(Constants.NA))
                    ? m_UserBusinessEntity.UserId
                    : m_UserBusinessEntity.DomainName + Constants.NA + m_UserBusinessEntity.UserId
            };

            NotificationBO.SendNotificationMessage(notificationMessageBeo);
        }
Пример #2
0
        internal void SendNotifications(ActiveJob job, Director.JobStatus jobStatus, string notificationMessage)
        {
            if (DebugMode)
            {
                return;
            }
            try
            {
                if (null != job)
                {
                    JobBusinessEntity jobDetails = null;
                    var jobBusinessEntity        = JobMgmtBO.GetJobDetails(job.JobId.ToString());
                    var userName = jobBusinessEntity.CreatedBy;
                    jobDetails = job.BusinessEntity;
                    var userBusinessEntity = UserBO.GetUser(userName);

                    #region Construct the notification message object

                    NotificationMessageBEO notificationMessageBeo = null;
                    try
                    {
                        notificationMessageBeo = new NotificationMessageBEO
                        {
                            NotificationId    = job.Beo.JobNotificationId,
                            CreatedByUserGuid = userBusinessEntity.UserGUID,
                            CreatedByUserName =
                                (userBusinessEntity.DomainName.Equals(@"N/A"))
                                                                 ? userBusinessEntity.UserId
                                                                 : userBusinessEntity.DomainName + @"\" +
                                userBusinessEntity.UserId,
                            SubscriptionTypeName = jobDetails.TypeName,
                            FolderId             = jobDetails.FolderID
                        };
                    }
                    catch
                    {
                        Tracer.Error("Unable to construct notification message for Job Id: {0}", job.JobId);
                    }

                    #endregion

                    #region Call Notification API

                    if (null != jobDetails && null != notificationMessageBeo &&
                        ((0 != notificationMessageBeo.NotificationId ||
                          !string.IsNullOrEmpty(notificationMessageBeo.SubscriptionTypeName)) &&
                         !string.IsNullOrEmpty(notificationMessageBeo.CreatedByUserGuid)))
                    {
                        #region Construct notification message

                        var message = new StringBuilder();
                        message.Append(string.IsNullOrEmpty(jobDetails.TypeName) ? string.Empty : " Type: ");
                        message.Append(jobDetails.Visibility
                                           ? jobDetails.TypeName
                                           : jobDetails.TypeName.Replace("Job", "Task"));
                        message.Append("<br/>");
                        message.Append(jobDetails.Name);
                        if (job.Beo != null)
                        {
                            message.Append(" Instance: ");
                            message.Append(job.Beo.JobRunId);
                        }
                        message.Append("<br/>");
                        message.Append("Folder: ");
                        message.Append(jobDetails.FolderName);
                        message.Append(" ");
                        message.Append("<br/>");
                        message.Append("Status: ");
                        message.Append(notificationMessage);

                        #region Job type specific custom message

                        try
                        {
                            switch (job.JobTypeId)
                            {
                            case 14:     // Load File Job custom message as per FSD.
                            {
                                var stream         = new StringReader(job.Beo.BootParameters);
                                var xmlStream      = new XmlSerializer(typeof(ImportBEO));
                                var bootParameters = xmlStream.Deserialize(stream) as ImportBEO;
                                stream.Close();

                                if (null != bootParameters &&
                                    string.IsNullOrEmpty(bootParameters.NotificationMessage))
                                {
                                    if (bootParameters.IsAppend)
                                    {
                                        if (jobStatus == Director.JobStatus.Completed)
                                        {
                                            message.Append(NotificationMessageCustomLoadFileAppendSuccessMessage);
                                            message.Append(jobDetails.FolderName);
                                            message.Append(NotificationMessageCustomLoadFileAppendMessagePart2);
                                            message.Append(job.JobId.ToString());
                                        }
                                        else
                                        {
                                            message.Append(NotificationMessageCustomLoadFileAppendFailureMessage);
                                            message.Append(jobDetails.FolderName);
                                            message.Append(NotificationMessageCustomLoadFileAppendMessagePart2);
                                            message.Append(job.JobId.ToString());
                                        }
                                    }
                                    else
                                    {
                                        if (jobStatus == Director.JobStatus.Completed)
                                        {
                                            message.Append(
                                                NotificationMessageCustomLoadFileOverlaySuccessMessagePart1);
                                            message.Append(jobDetails.FolderName);
                                            message.Append(
                                                NotificationMessageCustomLoadFileOverlaySuccessMessagePart2);
                                            message.Append(job.JobId.ToString());
                                        }
                                        else
                                        {
                                            message.Append(
                                                NotificationMessageCustomLoadFileOverlayFailureMessagePart1);
                                            message.Append(jobDetails.FolderName);
                                            message.Append(
                                                NotificationMessageCustomLoadFileOverlayFailureMessagePart2);
                                            message.Append(job.JobId.ToString());
                                            message.Append(
                                                NotificationMessageCustomLoadFileOverlayFailureMessagePart3);
                                        }
                                    }
                                }
                            }
                                notificationMessageBeo.SendDefaultMessage = (jobStatus ==
                                                                             Director.JobStatus.Completed);
                                break;

                            case 16:     // Reviewer bulk tag job custom message as per FSD.
                                ConstructBulkTagNotification(job, jobStatus, notificationMessageBeo, jobBusinessEntity, notificationMessage);
                                break;

                            case 38:
                                message.Append(jobStatus == Director.JobStatus.Completed
                                                       ? ConstructNotificationMessageForConversionResultsExport(job)
                                                       : NotificationMessageCustomConversionResultsExportError);
                                break;

                            case 54:
                                if (jobStatus == Director.JobStatus.Completed)
                                {
                                    message.Append(ConstructNotificationMessageForExportAnalysisSetDocuments(job));
                                }
                                break;

                            case BillingReportJobTypeId:

                                message.Append(ConstructBillingReportNotificationMessage(job, jobStatus));
                                break;
                            }
                        }
                        catch
                        {
                            Tracer.Error("Unable to set custom notification message for Job Id:{0}", job.JobId);
                        }

                        #endregion

                        if (job.JobTypeId != 16)
                        {
                            notificationMessageBeo.NotificationSubject = message.ToString().Replace("<br/>", "  ");
                            notificationMessageBeo.NotificationBody    = message.ToString();
                        }


                        #endregion

                        #region Send notification message by invoking notifications API

                        try
                        {
                            if (!string.IsNullOrEmpty(notificationMessageBeo.NotificationBody))
                            {
                                NotificationBO.SendNotificationMessage(notificationMessageBeo);
                            }
                        }
                        catch
                        {
                            Tracer.Error("Unable to send notification message for Job Id: {0}", job.JobId);
                        }

                        #endregion
                        if (job.JobTypeId == 14 || job.JobTypeId == 16) // Load File Import
                        {
                            return;                                     //For Load File Import- Custom message will be sent by default notification message.
                        }
                        if (jobStatus == Director.JobStatus.Completed && job.Beo.JobNotificationId > 0)
                        {
                            var customNotify = new NotificationMessageBEO
                            {
                                NotificationId     = job.Beo.JobNotificationId,
                                SendDefaultMessage = true,
                                CreatedByUserGuid  = userBusinessEntity.UserGUID
                            };

                            NotificationBO.SendNotificationMessage(customNotify);
                        }
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                ex.AddUsrMsg("Unable to send notification message.").Trace().Swallow();
            }
        }