private static ConfigValidationMessage[] testAllDependencies() { List <CmsDependencyMessage> dMsgs = new List <CmsDependencyMessage>(); CmsDependency[] dependencies; try { dependencies = CmsDependencyUtils.GatherAllDependencies(); } catch (Exception ex) { string innerMsg = ""; if (ex.InnerException != null) { innerMsg = "# " + ex.InnerException.Message + " Source:" + ex.InnerException.Source; } dMsgs.Add(CmsDependencyMessage.Error("Exception when Gathering Dependencies: " + ex.Message + " " + innerMsg)); dependencies = new CmsDependency[0]; } foreach (CmsDependency d in dependencies) { try { dMsgs.AddRange(d.ValidateDependency()); } catch (Exception ex) { dMsgs.Add(CmsDependencyMessage.Error("Exception in " + d.GetType().FullName + ".ValidateDependency(): " + ex.Message)); } } return(CmsDependencyMessage.ToConfigValidationMessages(dMsgs.ToArray())); }
protected void b_ValidateConfig_Click(object sender, EventArgs e) { StringBuilder html = new StringBuilder(); if (!connectionStringMatches()) { html.Append("<p style=\"color: red;\">You entered an incorrect Connection String.</p>"); } else { CmsDependencyMessage[] msgs = setupPage.VerifyConfig(); CmsDependencyMessage[] errorMessages = CmsDependencyMessage.GetAllMessagesByLevel(CmsDependencyMessage.MessageLevel.Error, msgs); if (errorMessages.Length == 0) { html.Append("<p style=\"color: green;\">Configuration has been validated without errors</p>"); } else { html.Append("<div style=\"color: red;\">The following errors were found in your configuration: </div>"); html.Append("<ul>"); foreach (CmsDependencyMessage m in errorMessages) { html.Append("<li>" + m.Message + "</li>"); } html.Append("</ul>"); } } ph_ValidationErrors.Controls.Clear(); ph_ValidationErrors.Controls.Add(new LiteralControl(html.ToString())); }
public override void RunBackgroundTask() { string techEmail = CmsConfig.getConfigValue("TechnicalAdministratorEmail", ""); string smtpServer = CmsConfig.getConfigValue("smtpServer", ""); if (techEmail.IndexOf("@") < 1 || smtpServer.Trim() == "") { return; // don't run anything if there's no email address or smtp server defined. } CmsDependencyMessage[] msgs = setupPage.VerifyConfig(); CmsDependencyMessage[] errorMessages = CmsDependencyMessage.GetAllMessagesByLevel(CmsDependencyMessage.MessageLevel.Error, msgs); if (errorMessages.Length > 0) // only email errors { StringBuilder msgBody = new StringBuilder(); string subject = "HatCMS site errors"; msgBody.Append("<div style=\"color: red;\">"); string siteName = CmsConfig.getConfigValue("SiteName", ""); if (siteName != "") { msgBody.Append("The following errors were found in the " + siteName + ":"); subject = siteName + " Errors"; } else { msgBody.Append("The following errors were found in your configuration:"); } msgBody.Append("</div>"); msgBody.Append("<ul>"); foreach (CmsDependencyMessage m in errorMessages) { msgBody.Append("<li>" + m.Message + "</li>"); } msgBody.Append("</ul>"); MailMessage msg = new MailMessage(techEmail, techEmail, subject, msgBody.ToString()); msg.IsBodyHtml = true; SmtpClient smtpclient = new SmtpClient(smtpServer); smtpclient.Send(msg); } }
protected void b_verifyConfig_Click(object sender, System.EventArgs e) { CmsDependencyMessage[] messages = VerifyConfig(); CmsDependencyMessage[] errorMessages = CmsDependencyMessage.GetAllMessagesByLevel(CmsDependencyMessage.MessageLevel.Error, messages); if (errorMessages.Length == 0) { l_msg.Text = "<div style=\"color: green;\">Configuration has been validated without errors</div>"; } else { StringBuilder msg = new StringBuilder(); msg.Append("<div style=\"color: red;\">Errors found in the configuration: </div>"); msg.Append("<ul>"); foreach (CmsDependencyMessage m in errorMessages) { msg.Append("<li>" + m.Message + "</li>"); } msg.Append("</ul>"); l_msg.Text = msg.ToString(); } }
public override string Render() { StringBuilder html = new StringBuilder(); CmsDependencyMessage[] msgs = setupPage.VerifyConfig(); CmsDependencyMessage[] errorMessages = CmsDependencyMessage.GetAllMessagesByLevel(CmsDependencyMessage.MessageLevel.Error, msgs); if (errorMessages.Length == 0) { html.Append("<p style=\"color: green;\">Configuration has been validated without errors</p>"); } else { html.Append("<div style=\"color: red;\">The following errors were found in your configuration: </div>"); html.Append("<ul>"); foreach (CmsDependencyMessage m in errorMessages) { html.Append("<li>" + m.Message + "</li>"); } html.Append("</ul>"); } return(html.ToString()); }