using System; using System.Threading; using CSLA.Security; namespace GZTW.AyaNova.BLL { /// /// Process a notification list and /// deliver appropriately /// public class GenProcessDeliveries { private GenProcessDeliveries() { // // TODO: Add constructor logic here // } /// /// Retrieve verifies and delivers all active user notifications /// public static void DeliverNotifications() { //case 1904 if (!AyaBizUtils.GlobalSettings.UseNotification) return; NotificationList nl=NotificationList.GetList(); //case 1904 - early exit, why not? if (nl.Count == 0) return; #region case 1382 smtp probing bool bSMTPCanDeliver = false; bool bHasSMTPDeliveriesToMake = false; //check if any smtp style deliveries //if so do a noop on the smtp server //if fails then skip all smtp style items foreach (NotificationList.NotificationListInfo info in nl) { if (info.DeliveryMethod == NotifyDeliveryMethods.SMS || info.DeliveryMethod == NotifyDeliveryMethods.SMTP) { bHasSMTPDeliveriesToMake = true; break; } } if (bHasSMTPDeliveriesToMake) { //probe the mail server bSMTPCanDeliver = GenSMTPMessageDelivery.ProbeSMTPServer; if (!bSMTPCanDeliver) { //If retry is false then allow the delivery attempt and subsequent removal //as that's the users choice if (!AyaBizUtils.GlobalSettings.SMTPRetry) bSMTPCanDeliver = true; } } #endregion case 1382 foreach (NotificationList.NotificationListInfo info in nl) { switch(info.DeliveryMethod) { case NotifyDeliveryMethods.SMS: { //case 1382 if (!bSMTPCanDeliver) continue; GenSMSMessageDelivery sms=new GenSMSMessageDelivery(); sms.FromAddress=GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPFrom; //Case 515 sms.Host = GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPHostPortionOnly; sms.Port = GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPPort; sms.Login=GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPAccount; sms.Password=GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPPassword; sms.Message=info.Message; sms.Subject="";//info.Subject; sms.ToAddress=info.Address; sms.Deliver(); LogAndRemoveEvent(info,sms.FailedDelivery,sms.Error); break; } case NotifyDeliveryMethods.SMTP: { //case 1382 if (!bSMTPCanDeliver) continue; GenSMTPMessageDelivery smtp=new GenSMTPMessageDelivery(); smtp.FromAddress=GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPFrom; //Case 515 smtp.Host = GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPHostPortionOnly; smtp.Port = GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPPort; smtp.Login=GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPAccount; smtp.Password=GZTW.AyaNova.BLL.AyaBizUtils.GlobalSettings.NotifySMTPPassword; smtp.Message=info.Message; smtp.Subject=info.Subject; smtp.ToAddress=info.Address; smtp.RootObjectID=info.RootObjectID; smtp.RootObjectType=info.RootObjectType; smtp.Deliver(); LogAndRemoveEvent(info,smtp.FailedDelivery,smtp.Error); break; } case NotifyDeliveryMethods.Memo: { GenMemoMessageDelivery m = new GenMemoMessageDelivery(); m.AyaNovaRecipientUserID=info.DeliverToUserID; m.Message=info.Message; m.Subject=info.Subject; m.RootObjectID=info.RootObjectID; m.RootObjectType=info.RootObjectType; m.Deliver(); LogAndRemoveEvent(info,m.FailedDelivery,m.Error); break; } case NotifyDeliveryMethods.PopUp: { GenPopUpMessageDelivery p = new GenPopUpMessageDelivery(); p.AyaNovaRecipientUserID=info.DeliverToUserID; p.Message=info.Message; p.Subject="";//info.Subject; p.RootObjectID=info.RootObjectID; p.RootObjectType=info.RootObjectType; p.Deliver(); LogAndRemoveEvent(info,p.FailedDelivery,p.Error); break; } }//End of switch //do nothing if not one of the above delivery formats } } /// /// Log and remove /// /// /// /// private static void LogAndRemoveEvent(NotificationList.NotificationListInfo info, bool failed, string error) { if(!failed) { //Remove the event NotifyEvent.RemoveDeliveredEvent(info.NotifyEventID); } //Log the delivery NotifyDeliveryLog.LogDelivery(info.RootObjectType, info.RootObjectID, info.EventType, info.DeliverToUserID, !failed, info.GuidValue, info.DeliveryMethod, error, DBUtil.CurrentWorkingDateTime); //case 1096 //Remove the event NotifyEvent.RemoveDeliveredEvent(info.NotifyEventID); } //================================= } }