private string GetMessageDef(string templateName)
        {
            NotificationDef def = null;

            if (_messageDefs != null)
            {
                def = _messageDefs[templateName];
            }

            string contents = string.Empty;

            // Can use configurable template in folder.
            if (def != null)
            {
                bool useEmbeddedFile = false;
                if (!string.IsNullOrEmpty(_settings.TemplateFolderPath))
                {
                    string templatefilePath = Path.Combine(_settings.TemplateFolderPath, templateName);
                    if (File.Exists(templatefilePath))
                    {
                        contents = File.ReadAllText(templatefilePath);
                    }
                    else
                    {
                        useEmbeddedFile = true;
                    }
                }
                if (useEmbeddedFile)
                {
                    // Now get and replace values.
                    contents = NotificationUtils.GetInternalNotificationTemplate(def.FileName);
                }
            }
            return(contents);
        }
 /// <summary>
 /// Default the message templates to the internal ones provided by commonlibrary.net.
 /// </summary>
 public NotificationDefinitions()
 {
     _defs["WelcomeNewUser"]  = new NotificationDef("WelcomeNewUser", "Notifications.Templates.welcome.html", "welcome.html", true, "CommonLibrary", false);
     _defs["ForgotPassword"]  = new NotificationDef("ForgotPassword", "Notifications.Templates.password_reminder.html", "password_reminder.html", true, "CommonLibrary", false);
     _defs["SendWebSitePost"] = new NotificationDef("SendWebSitePost", "Notifications.Templates.sendtofriend_post.html", "sendtofriend_post.html", true, "CommonLibrary", false);
     _defs["SendWebSite"]     = new NotificationDef("SendWebSite", "Notifications.Templates.sendtofriend_site.html", "sendtofriend_site.html", true, "CommonLibrary", false);
     _defs["SubmitFeedback"]  = new NotificationDef("SubmitFeedback", "Notifications.Templates.feedback.html", "feedback.html", true, "CommonLibrary", false);
 }
Пример #3
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);
            }
        }