Example #1
0
    private void generateMessage(string message,
                                 string title = "",
                                 enumPageMessageTypes messageType = enumPageMessageTypes.INFO,
                                 bool sendEmail = false)
    {
        string friendlymessage = "Sorry for the inconvenience, but the application has encountered an unknown error. It doesn't appear to have affected your data, but our technical staff have been automatically notified and will be looking into this with the utmost urgency.  Thank you for your patience.";
        string jsFunction      = string.Empty;
        string platform        = ConfigurationManager.AppSettings["PlatformName"].ToUpper().Trim();
        bool   inTestMode      = (ConfigurationManager.AppSettings["TestMode"] == "on");

        message = message.Trim();

        if (string.IsNullOrEmpty(message))
        {
            return;
        }

        var emailMgr = new Emailer(ConfigurationManager.AppSettings["SMTPServer"],
                                   int.Parse(ConfigurationManager.AppSettings["MailPort"]),
                                   ConfigurationManager.AppSettings["notificationemailaddress"],
                                   new NetworkCredential(ConfigurationManager.AppSettings["MailUserId"], ConfigurationManager.AppSettings["MailPassword"]));

        emailMgr.isSecure = bool.Parse(ConfigurationManager.AppSettings["SendSecureMail"]);

        if ((emailMgr != null) && (sendEmail) && (messageType != enumPageMessageTypes.INFO))
        {
            emailMgr.priority = EmailConstants.enumMailPriority.High;

            emailMgr.Send(
                ((!string.IsNullOrEmpty(platform)) ? "[" + platform + "]" : string.Empty) + title,
                message,
                ConfigurationManager.AppSettings["notificationemailaddress"]
                );
        }

        message = message.Replace("\r\n", "<br />").Trim();

        if (messageType == enumPageMessageTypes.INFO)
        {
            jsFunction = string.Format("showInfoPopup(\"{0}\");", message);
        }
        else
        {
            if (!inTestMode && (messageType == enumPageMessageTypes.ERROR)) //means we are in Prod, so show friendly message
            {
                message = friendlymessage;
            }

            jsFunction = string.Format("showErrorPopup(\"{0}\", \"{1}\");", title, message);
        }

        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ShowMessage", "$(document).ready(function() { " + jsFunction + " });", true);
    }
Example #2
0
 protected void writeMessage(string message, enumPageMessageTypes messageType = enumPageMessageTypes.INFO)
 {
     this.generateMessage(message, string.Empty, messageType);
 }