//-------------------------------------------------------------- //Method to send email notifications //-------------------------------------------------------------- public override void SendLogNotifications() { try { lockNotif.AcquireWriterLock( WriterLockTimeout ); XmlDocument xmlPendingNotificationsDoc = new XmlDocument(); try { xmlPendingNotificationsDoc.Load( GetFilePath( PendingNotificationsFile ) ); } catch( FileNotFoundException ) { //file not found return; } ArrayList arrLogTypeInfo; XMLLoggingProvider x = new XMLLoggingProvider(); arrLogTypeInfo = x.GetLogTypeConfigInfo(); PurgeLogBuffer(); int a; for( a = 0; a <= arrLogTypeInfo.Count - 1; a++ ) { LogTypeConfigInfo objLogTypeInfo; objLogTypeInfo = (LogTypeConfigInfo)arrLogTypeInfo[a]; if( objLogTypeInfo.EmailNotificationIsActive ) { XmlNodeList xmlPendingNotifications = xmlPendingNotificationsDoc.DocumentElement.SelectNodes( "log[@NotificationLogTypeKey='" + objLogTypeInfo.LogTypeKey + "' and @LogTypePortalID='" + objLogTypeInfo.LogTypePortalID + "' and number(@LogCreateDateNum) > " + DateToNum( objLogTypeInfo.StartDateTime ).ToString() + "]" ); if( xmlPendingNotifications.Count >= objLogTypeInfo.NotificationThreshold ) { //we have notifications to send out XmlNode xmlPendingNotification; XmlDocument xmlOut = new XmlDocument(); xmlOut.LoadXml( "<notification></notification>" ); foreach( XmlNode tempLoopVar_xmlPendingNotification in xmlPendingNotifications ) { xmlPendingNotification = tempLoopVar_xmlPendingNotification; XmlNode tmpNode; tmpNode = xmlOut.ImportNode( xmlPendingNotification, true ); xmlOut.DocumentElement.AppendChild( tmpNode ); //Remove the node from the list of pending notifications xmlPendingNotificationsDoc.DocumentElement.RemoveChild( xmlPendingNotification ); } bool NotificationFailed = false; string errSendNotif; errSendNotif = Mail.Mail.SendMail( objLogTypeInfo.MailFromAddress, objLogTypeInfo.MailToAddress, "", "Log Notification", xmlOut.OuterXml, "", "", "", "", "", "" ); if( !String.IsNullOrEmpty(errSendNotif) ) { //notification failed to send NotificationFailed = true; } EventLogController objEventLogController = new EventLogController(); if( NotificationFailed ) { //Notification failed, log it LogInfo objEventLogInfo = new LogInfo(); objEventLogInfo.LogTypeKey = EventLogController.EventLogType.LOG_NOTIFICATION_FAILURE.ToString(); objEventLogInfo.AddProperty( "Log Notification Failed: ", errSendNotif ); objEventLogController.AddLog( objEventLogInfo ); //need to reload the xml doc because //we removed xml nodes above xmlPendingNotificationsDoc.Load( GetFilePath( PendingNotificationsFile ) ); if( xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationFailure"] == null ) { XmlAttribute xmlNotificationFailed; xmlNotificationFailed = xmlPendingNotificationsDoc.CreateAttribute( "LastNotificationFailure" ); xmlNotificationFailed.Value = DateTime.Now.ToString(); xmlPendingNotificationsDoc.DocumentElement.Attributes.Append( xmlNotificationFailed ); } else { xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationFailure"].Value = DateTime.Now.ToString(); } xmlPendingNotificationsDoc.Save( GetFilePath( PendingNotificationsFile ) ); } else { //Notification succeeded. //Save the updated pending notifications file //so we remove the notifications that have been completed. if( xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationFailure"] != null ) { xmlPendingNotificationsDoc.DocumentElement.Attributes.Remove( xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationFailure"] ); } if( xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationSuccess"] == null ) { XmlAttribute xmlNotificationSucceeded; xmlNotificationSucceeded = xmlPendingNotificationsDoc.CreateAttribute( "LastNotificationSuccess" ); xmlNotificationSucceeded.Value = DateTime.Now.ToString(); xmlPendingNotificationsDoc.DocumentElement.Attributes.Append( xmlNotificationSucceeded ); } else { xmlPendingNotificationsDoc.DocumentElement.Attributes["LastNotificationSuccess"].Value = DateTime.Now.ToString(); } xmlPendingNotificationsDoc.Save( GetFilePath( PendingNotificationsFile ) ); } } } } x.DeleteOldPendingNotifications(); } catch( Exception exc ) { Exceptions.Exceptions.LogException( exc ); } finally { lockNotif.ReleaseWriterLock(); } }