Beispiel #1
0
        public void Notify(List<Common.Models.NotificationDetails> notificationDetails)
        {
            eZeeFlowTraceListener traceListener = new eZeeFlowTraceListener();
            DataStorageHelper objStorageHelper = new DataStorageHelper();
            try
            {
                foreach (var nd in notificationDetails)
                {
                    if (!string.IsNullOrEmpty(nd.NotificationMode))
                    {
                        if (nd.NotificationMode == eZeeFlow.Notification.Gateway.Constants.HTTPRequest)
                        {
                            nd.RecipientDetails = PostFileUploadedSuccessUri;
                            var tenantId = nd.TenantID.ToString();

                            ProcessedFileDetail objFileDetail = new ProcessedFileDetail();
                            objFileDetail.FileId = nd.FileID.ToString();
                            objFileDetail.FileUrl = nd.FileURI;

                            HttpWebRequest httpWebRequest = WebRequest.Create(PostFileUploadedSuccessUri) as HttpWebRequest;
                            httpWebRequest.ContentType = "text/json";
                            httpWebRequest.Method = "POST";
                            string serializedObj = JsonConvert.SerializeObject(objFileDetail).Replace(@"\", "-");

                            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                            {
                                streamWriter.Write(serializedObj);
                            }

                            string response = new StreamReader(httpWebRequest.GetResponse().GetResponseStream()).ReadToEnd();

                            traceListener.WriteLog(Categories.Info, "Eventing - HTTP Notification", response, string.Empty, tenantId);

                        }
                    }
                }

                GatewayFactory objGF = new GatewayFactory();
                objGF.WriteNotificationToStorage(notificationDetails, true, Constants.HTTPRequest);

                //// TODO: Though we send out multiple notifications, there is a single column for the status -- db structure needs to be updated to support granular tracking.
                var isNotificationUpdated = objGF.UpdateNotificationStatus(notificationDetails, true);

            }
            catch (Exception ex)
            {
                traceListener.WriteLog(Categories.Error, "Eventing", ex.Message.ToString(), ex.StackTrace.ToString());
            }
        }
        /// <summary>
        /// Sends a mail
        /// </summary>
        public void Notify(List<NotificationDetails> notificationDetails)
        {
            eZeeFlowTraceListener traceListener = new eZeeFlowTraceListener();
            try
            {
                var mail = new MailMessage();
                var subject = string.Empty;
                var body = string.Empty;
                if (!string.IsNullOrEmpty(_smtpMailFrom)) mail.From = new MailAddress(_smtpMailFrom);
                foreach (var notificationDetail in notificationDetails)
                {
                    if (!string.IsNullOrEmpty(notificationDetail.NotificationMode))
                    {
                        if (notificationDetail.NotificationMode == eZeeFlow.Notification.Gateway.Constants.EMail)
                        {
                            mail.To.Add(new MailAddress(notificationDetail.RecipientDetails));
                        }
                    }
                }

                mail.Subject = GetSubjectForMail(notificationDetails);
                mail.Body = CreateMailBody(notificationDetails);

                var client = new SmtpClient(_smtpGatewayUrl, _smtpGatewayPort);
                client.UseDefaultCredentials = false;
                client.EnableSsl = true;
                var credential = new System.Net.NetworkCredential(_smtpUserName, _smtpPassword);
                client.Credentials = credential;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Send(mail);
                GatewayFactory objGF = new GatewayFactory();
                objGF.WriteNotificationToStorage(notificationDetails, true, Constants.EMail);

                //// TODO: Though we send out multiple notifications, there is a single column for the status -- db structure needs to be updated to support granular tracking.

                var isNotificationUpdated = objGF.UpdateNotificationStatus(notificationDetails, true);

                if (!string.IsNullOrEmpty(_messageToLog))
                {
                    traceListener.WriteLog(Categories.Error, "Eventing", "[Notification] Message is empty.");
                }
                mail.Dispose();
            }
            catch (Exception ex)
            {
                traceListener.WriteLog(Categories.Error, "Eventing", ex.Message.ToString(), ex.StackTrace.ToString());
            }
        }