Ejemplo n.º 1
0
        /// <summary>
        /// Processes the notification message. Either just sends the data or transforms the
        /// data and then sends it.
        /// </summary>
        /// <param name="currentMessage"></param>
        public void Process(NotificationMessage currentMessage)
        {
            try
            {
                string messageBody = string.Empty;

                // Currently the templates are hardcoded to get the files from this assembly.
                NotificationDef def = _messageDefs[currentMessage.MessageTemplateId];
                if (def.IsAssemblyEmbedded && def.AssemblyName == "CommonLibrary")
                {
                    // Now get and replace values.
                    messageBody = NotificationUtils.GetInternalNotificationTemplate(def.FileName);
                    messageBody = StringHelpers.Substitute(currentMessage.Values, messageBody);

                    // Now replace using the global notification substitution settings.
                    messageBody = StringHelpers.Substitute(_settings.Settings, messageBody);
                }

                /*
                 * if (currentMessage.PerformTransform)
                 * {
                 *  string xslFilePath = _xmlDirectoryLocation + "\\Xsl\\" + currentMessage.XslFilePath + ".xsl";
                 *  string xml = XmlSerializerUtil.XmlSerialize(currentMessage.Adaptor);
                 *  messageBody = XmlUtils.TransformXml(xml, xslFilePath);
                 *  currentMessage.Body = messageBody;
                 * }
                 * else
                 * {
                 *  messageBody = currentMessage.Body;
                 * }
                 */
                // Output the transform to debug file.
                if (_settings.DebugOutputMessageToFile)
                {
                    OutputContent(currentMessage, messageBody);
                }

                // Send the notification if enabled.
                if (_settings.EnableNotifications)
                {
                    // Notify
                    _emailService.Send(currentMessage);
                }
                else if (_settings.DebugSleepIfNotEnabled)
                {
                    Thread.Sleep(_settings.DebugSleepTimeIfNotEnabled);
                    if (_settings.LogMessage)
                    {
                        Logger.Info("Notifications are not enabled. Simulating single email notification by sleeping.");
                    }
                }
            }
            catch (Exception ex)
            {
                string error = string.Empty;
                if (currentMessage != null)
                {
                    error = currentMessage.To + " " + currentMessage.MessageTemplateId;
                }
                Logger.Error("Unable to send notification : " + error, ex);
            }
        }