Пример #1
0
        public void PrepareNotification(NotificationType notificationType, Hashtable templateParams)
        {
            string templateFolder = HttpContext.Current.Server.MapPath("~/templates/notifications");
            string BaseTemplate   = System.IO.File.ReadAllText(templateFolder + "\\BaseTemplate.htm");

            MessageBody = BaseTemplate;

            var notificationSettings = Settings.FirstOrDefault(s => s.NotificationType == notificationType);

            if (notificationSettings != null)
            {
                //load message template and replace template placeholder keys with param values
                string messageTemplate = System.IO.File.ReadAllText(templateFolder + "\\" + notificationSettings.TemplateFile);
                this.Subject = notificationSettings.Subject;
                MessageBody  = MessageBody.Replace("{MessageBody}", messageTemplate);

                if (templateParams != null)
                {
                    foreach (string key in templateParams.Keys)
                    {
                        if (templateParams[key] != null)
                        {
                            Subject     = Subject.Replace("{" + key + "}", templateParams[key].ToString());
                            MessageBody = MessageBody.Replace("{" + key + "}", templateParams[key].ToString());
                        }
                    }
                }
            }
            else
            {
                MessageBody = MessageBody.Replace("{MessageBody}", "");
            }
        }
Пример #2
0
        internal override string GetPowerShellCommand()
        {
            // [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('Your_Desired_Message','Your_Desired_Title');
            var sb = new System.Text.StringBuilder("[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('");

            sb.Append(MessageBody.Replace("'", "''"));
            if (Title != null)
            {
                sb.Append("','");
                sb.Append(Title.Replace("'", "''"));
            }
            sb.Append("'); ");
            return(sb.ToString());
        }