Пример #1
0
        /// <summary>
        /// Loads the HTML-template for the warning mail and generates the mail
        /// Template tags: [%WSName%], [%Date%], [%PluginName%], [%Indicator%], [%Value%]
        /// </summary>
        /// <returns>String containing the HTML-Email-Message</returns>
        private string GenerateWarningMail(int monitoredSystemID, DateTime criticalValueReceived,
                                           string pluginName, string indicator, string criticalValue)
        {
            string template = "";

            //instantiate the WarningMailParser
            parser.ClearTags();

            using (var dataContext = DataContextFactory.CreateReadOnlyDataContext())
            {
                StreamReader reader = null;
                try
                {
                    string name = PrecompiledQueries.GetMonitoredSystemNameByID(dataContext, monitoredSystemID);
                    parser.AddTag("[%WSName%]", name);
                    parser.AddTag("[%Date%]", criticalValueReceived.ToString());
                    parser.AddTag("[%PluginName%]", pluginName);
                    parser.AddTag("[%Indicator%]", indicator);
                    parser.AddTag("[%Value%]", criticalValue);

                    //load the warning mail template
                    reader = new StreamReader(TemplatePath);

                    template = reader.ReadToEnd();
                }
                catch (Exception e)
                {
                    //logging
                    StringBuilder messageEx1 = new StringBuilder();
                    messageEx1.Append("Mailer_GenerateWarningMail: ");
                    messageEx1.Append("Can't load warning mail template. " + e.ToString());
                    Logger.Instance.WriteEntry(messageEx1.ToString(), LogType.Exception);
                }
                finally
                {
                    reader.Close();
                }

                //Parese template string
                return(parser.ParseTemplateString(template));
            }
        }