private void BindEmailTemplateFields()
    {
        EmailNotificationManager objemailnot = new EmailNotificationManager();
        string strtabbindtemplate            = "";

        try
        {
            Array tabname = Enum.GetValues(typeof(EmailNotificationManager.EmailTemplate));
            strtabbindtemplate += "<div class='tab-content'>";
            foreach (EmailNotificationManager.EmailTemplate tab in tabname)
            {
                DataTable dtcontent = new DataTable();
                objemailnot.EmailType = Convert.ToInt32(((int)tab).ToString());

                dtcontent = objemailnot.SelectSingleItem();
                if (dtcontent.Rows.Count > 0)
                {
                    if (((int)tab) == 1)
                    {
                        strtabbindtemplate += "<div class='active tab-pane' id=" + tab.ToString() + ">";
                        strtabbindtemplate += "<div class='form-group'>";
                        strtabbindtemplate += "<label for='inputName' class='col-sm-1 control-label'>Subject :</label>";
                        strtabbindtemplate += "<div class='col-sm-6'>";
                        strtabbindtemplate += "<input type='text' class='form-control' id='txtsubject" + ((int)tab).ToString() + "' maxlength='100' name='txtsubject" + ((int)tab).ToString() + "' value='" + dtcontent.Rows[0]["EmailSubject"].ToString() + "'/>";
                        strtabbindtemplate += "</div>";
                        strtabbindtemplate += "</div>";
                        strtabbindtemplate += "<div class='form-group'>";
                        strtabbindtemplate += "<div class='col-sm-9'>";
                        strtabbindtemplate += "<textarea class='form-control ckeditor' id='txtdescription" + ((int)tab).ToString() + "'  maxlength='500' name='txtdescription" + ((int)tab).ToString() + "' >" + dtcontent.Rows[0]["EmailBody"].ToString() + "</textarea>";
                        strtabbindtemplate += "</div>";
                        strtabbindtemplate += "</div>";
                        strtabbindtemplate += "</div>";
                    }
                    else
                    {
                        strtabbindtemplate += "<div class='tab-pane' id=" + tab.ToString() + ">";
                        strtabbindtemplate += "<div class='form-group'>";
                        strtabbindtemplate += "<label for='inputName' class='col-sm-1 control-label'>Subject :</label>";
                        strtabbindtemplate += "<div class='col-sm-6'>";
                        strtabbindtemplate += "<input type='text' class='form-control' id='txtsubject" + ((int)tab).ToString() + "' maxlength='100' name='txtsubject" + ((int)tab).ToString() + "' value='" + dtcontent.Rows[0]["EmailSubject"].ToString() + "'/>";
                        strtabbindtemplate += "</div>";
                        strtabbindtemplate += "</div>";
                        strtabbindtemplate += "<div class='form-group'>";
                        strtabbindtemplate += "<div class='col-sm-9'>";
                        strtabbindtemplate += "<textarea class='form-control ckeditor' id='txtdescription" + ((int)tab).ToString() + "'  maxlength='500' name='txtdescription" + ((int)tab).ToString() + "' >" + dtcontent.Rows[0]["EmailBody"].ToString() + "</textarea>";
                        strtabbindtemplate += "</div>";
                        strtabbindtemplate += "</div>";
                        strtabbindtemplate += "</div>";
                    }
                }
            }
            strtabbindtemplate += "</div>";

            ltrtabbinddata.Text = strtabbindtemplate.ToString();
        }
        catch (Exception ex) { throw ex; }
    }
 public NotificationHelper(
     MessageManager messageManager,
     EmailNotificationManager emailNotificationManager,
     UserManager userManager,
     AlertNotificationManager alertNotificationManager,
     RequestManager requestManager,
     AlertTypeManager alertTypeManager)
 {
     _messageManager           = messageManager;
     _emailNotificationManager = emailNotificationManager;
     _userManager = userManager;
     _alertNotificationManager = alertNotificationManager;
     _alertTypeManager         = alertTypeManager;
     _requestManager           = requestManager;
 }
    protected void btnconfirmemailnotification_Click(object sender, EventArgs e)
    {
        EmailNotificationManager objemailnotification = new EmailNotificationManager();

        try
        {
            Array tabname = Enum.GetValues(typeof(EmailNotificationManager.EmailTemplate));
            foreach (EmailNotificationManager.EmailTemplate tab in tabname)
            {
                objemailnotification.EmailType    = Convert.ToInt32(((int)tab));
                objemailnotification.FromEmail    = Convert.ToString(txtfromemail.Text);
                objemailnotification.EmailSubject = Convert.ToString(Request.Form["txtsubject" + ((int)tab)]);
                objemailnotification.EmailBody    = Convert.ToString(Request.Form["txtdescription" + ((int)tab)]);
                objemailnotification.UpdateItem();
            }
            //Response.Redirect("setup.aspx");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Email notification updated successfully');", true);
        }
        catch (Exception ex) { throw ex; }
        finally { }
    }
Example #4
0
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            var emailSenderService = _serviceProvider.GetRequiredService <EmailSenderService>();
            var settingsService    = _serviceProvider.GetRequiredService <SettingsService>();

            var notificationManager = EmailNotificationManager.GetNewManager(settingsService);

            while (!cancellationToken.IsCancellationRequested)
            {
                var notifications = await notificationManager.GetNotSentNotificationAsync();

                var emailNotifications = notifications.ToList();
                if (emailNotifications.Any())
                {
                    foreach (var notification in emailNotifications)
                    {
                        await notificationManager.ProcessingNotificationAsync(notification);

                        var emailsTo = notification.EmailsTo.Split(',', StringSplitOptions.RemoveEmptyEntries);
                        foreach (var emailTo in emailsTo)
                        {
                            try
                            {
                                await emailSenderService.SendEmailAsync(emailTo, notification.Subject, notification.Body);
                            }
                            catch (Exception e)
                            {
                                Log.Logger.Error(e, e.Message);
                            }
                        }

                        await notificationManager.CompleatedNotificationAsync(notification);
                    }
                }
                await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
            }
        }
        public MainForm()
        {
            InitializeComponent();

            // check if the OpenHardwareMonitorLib assembly has the correct version
            if (Assembly.GetAssembly(typeof(Computer)).GetName().Version !=
                Assembly.GetExecutingAssembly().GetName().Version)
            {
                MessageBox.Show(
                    "The version of the file OpenHardwareMonitorLib.dll is incompatible.",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(0);
            }

            this.settings = new PersistentSettings();
            this.settings.Load(Path.ChangeExtension(
                                   Application.ExecutablePath, ".config"));

            this.unitManager       = new UnitManager(settings);
            this.sensorTextManager = new SensorTextManager(this.unitManager);

            // make sure the buffers used for double buffering are not disposed
            // after each draw call
            BufferedGraphicsManager.Current.MaximumBuffer =
                Screen.PrimaryScreen.Bounds.Size;

            // set the DockStyle here, to avoid conflicts with the MainMenu
            this.splitContainer.Dock = DockStyle.Fill;

            this.Font     = SystemFonts.MessageBoxFont;
            treeView.Font = SystemFonts.MessageBoxFont;

            plotPanel      = new PlotPanel(settings, unitManager);
            plotPanel.Font = SystemFonts.MessageBoxFont;
            plotPanel.Dock = DockStyle.Fill;

            nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
            nodeTextBoxText.DrawText          += nodeTextBoxText_DrawText;
            nodeTextBoxValue.DrawText         += nodeTextBoxText_DrawText;
            nodeTextBoxMin.DrawText           += nodeTextBoxText_DrawText;
            nodeTextBoxMax.DrawText           += nodeTextBoxText_DrawText;
            nodeTextBoxText.EditorShowing     += nodeTextBoxText_EditorShowing;

            foreach (TreeColumn column in treeView.Columns)
            {
                column.Width = Math.Max(20, Math.Min(400,
                                                     settings.GetValue("treeView.Columns." + column.Header + ".Width",
                                                                       column.Width)));
            }

            treeModel  = new TreeModel();
            root       = new Node(System.Environment.MachineName);
            root.Image = Utilities.EmbeddedResources.GetImage("computer.png");

            treeModel.Nodes.Add(root);
            treeView.Model = treeModel;

            this.computer = new Computer(settings);

            systemTray = new SystemTray(computer, settings, unitManager);
            systemTray.HideShowCommand += hideShowClick;
            systemTray.ExitCommand     += exitClick;

            int p = (int)Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128)) // Unix
            {
                treeView.RowHeight           = Math.Max(treeView.RowHeight, 18);
                splitContainer.BorderStyle   = BorderStyle.None;
                splitContainer.Border3DStyle = Border3DStyle.Adjust;
                splitContainer.SplitterWidth = 4;
                treeView.BorderStyle         = BorderStyle.Fixed3D;
                plotPanel.BorderStyle        = BorderStyle.Fixed3D;
                gadgetMenuItem.Visible       = false;
                minCloseMenuItem.Visible     = false;
                minTrayMenuItem.Visible      = false;
                startMinMenuItem.Visible     = false;
            }
            else // Windows
            {
                treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18);

                gadget = new SensorGadget(computer, settings, unitManager);
                gadget.HideShowCommand += hideShowClick;

                wmiProvider = new WmiProvider(computer);
            }

            plotColorPalette     = new Color[13];
            plotColorPalette[0]  = Color.Blue;
            plotColorPalette[1]  = Color.OrangeRed;
            plotColorPalette[2]  = Color.Green;
            plotColorPalette[3]  = Color.LightSeaGreen;
            plotColorPalette[4]  = Color.Goldenrod;
            plotColorPalette[5]  = Color.DarkViolet;
            plotColorPalette[6]  = Color.YellowGreen;
            plotColorPalette[7]  = Color.SaddleBrown;
            plotColorPalette[8]  = Color.RoyalBlue;
            plotColorPalette[9]  = Color.DeepPink;
            plotColorPalette[10] = Color.MediumSeaGreen;
            plotColorPalette[11] = Color.Olive;
            plotColorPalette[12] = Color.Firebrick;

            computer.HardwareAdded   += new HardwareEventHandler(HardwareAdded);
            computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);

            computer.Open();

            timer.Enabled = true;

            showHiddenSensors = new UserOption("hiddenMenuItem", false,
                                               hiddenMenuItem, settings);
            showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
                treeModel.ForceVisible = showHiddenSensors.Value;
            };

            showValue = new UserOption("valueMenuItem", true, valueMenuItem,
                                       settings);
            showValue.Changed += delegate(object sender, EventArgs e) {
                treeView.Columns[1].IsVisible = showValue.Value;
            };

            showMin          = new UserOption("minMenuItem", false, minMenuItem, settings);
            showMin.Changed += delegate(object sender, EventArgs e) {
                treeView.Columns[2].IsVisible = showMin.Value;
            };

            showMax          = new UserOption("maxMenuItem", true, maxMenuItem, settings);
            showMax.Changed += delegate(object sender, EventArgs e) {
                treeView.Columns[3].IsVisible = showMax.Value;
            };

            startMinimized = new UserOption("startMinMenuItem", false,
                                            startMinMenuItem, settings);

            minimizeToTray = new UserOption("minTrayMenuItem", true,
                                            minTrayMenuItem, settings);
            minimizeToTray.Changed += delegate(object sender, EventArgs e) {
                systemTray.IsMainIconEnabled = minimizeToTray.Value;
            };

            minimizeOnClose = new UserOption("minCloseMenuItem", false,
                                             minCloseMenuItem, settings);

            autoStart = new UserOption(null, startupManager.Startup,
                                       startupMenuItem, settings);
            autoStart.Changed += delegate(object sender, EventArgs e) {
                try {
                    startupManager.Startup = autoStart.Value;
                } catch (InvalidOperationException) {
                    MessageBox.Show("Updating the auto-startup option failed.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    autoStart.Value = startupManager.Startup;
                }
            };

            readMainboardSensors = new UserOption("mainboardMenuItem", true,
                                                  mainboardMenuItem, settings);
            readMainboardSensors.Changed += delegate(object sender, EventArgs e) {
                computer.MainboardEnabled = readMainboardSensors.Value;
            };

            readCpuSensors = new UserOption("cpuMenuItem", true,
                                            cpuMenuItem, settings);
            readCpuSensors.Changed += delegate(object sender, EventArgs e) {
                computer.CPUEnabled = readCpuSensors.Value;
            };

            readRamSensors = new UserOption("ramMenuItem", true,
                                            ramMenuItem, settings);
            readRamSensors.Changed += delegate(object sender, EventArgs e) {
                computer.RAMEnabled = readRamSensors.Value;
            };

            readGpuSensors = new UserOption("gpuMenuItem", true,
                                            gpuMenuItem, settings);
            readGpuSensors.Changed += delegate(object sender, EventArgs e) {
                computer.GPUEnabled = readGpuSensors.Value;
            };

            readFanControllersSensors = new UserOption("fanControllerMenuItem", true,
                                                       fanControllerMenuItem, settings);
            readFanControllersSensors.Changed += delegate(object sender, EventArgs e) {
                computer.FanControllerEnabled = readFanControllersSensors.Value;
            };

            readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem,
                                            settings);
            readHddSensors.Changed += delegate(object sender, EventArgs e) {
                computer.HDDEnabled = readHddSensors.Value;
            };

            showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
                                        settings);
            showGadget.Changed += delegate(object sender, EventArgs e) {
                if (gadget != null)
                {
                    gadget.Visible = showGadget.Value;
                }
            };

            celsiusMenuItem.Checked =
                unitManager.TemperatureUnit == TemperatureUnit.Celsius;
            fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked;

            server = new HttpServer(root, this.settings.GetValue("listenerPort", 8085));
            if (server.PlatformNotSupported)
            {
                webMenuItemSeparator.Visible = false;
                webMenuItem.Visible          = false;
            }

            runWebServer = new UserOption("runWebServerMenuItem", false,
                                          runWebServerMenuItem, settings);
            runWebServer.Changed += delegate(object sender, EventArgs e) {
                if (runWebServer.Value)
                {
                    server.StartHTTPListener();
                }
                else
                {
                    server.StopHTTPListener();
                }
            };

            List <IChecker> checkers = new List <IChecker>()
            {
                new GPULoadChecker(this.settings, this.computer),
                new GPUTemperatureChecker(this.settings, this.computer),
                new CPULoadChecker(this.settings, this.computer),
                new CPUTemperatureChecker(this.settings, this.computer),
                new MemoryUsageChecker(this.settings, this.computer)
            };

            this.emailNotificationManager = new EmailNotificationManager(this.computer, this.sensorTextManager, this.settings, checkers);

            logger = new Logger(computer);

            logSensors = new UserOption("logSensorsMenuItem", false, logSensorsMenuItem,
                                        settings);

            loggingInterval = new UserRadioGroup("loggingInterval", 0,
                                                 new[] { log1sMenuItem, log2sMenuItem, log5sMenuItem, log10sMenuItem,
                                                         log30sMenuItem, log1minMenuItem, log2minMenuItem, log5minMenuItem,
                                                         log10minMenuItem, log30minMenuItem, log1hMenuItem, log2hMenuItem,
                                                         log6hMenuItem },
                                                 settings);
            loggingInterval.Changed += (sender, e) => {
                switch (loggingInterval.Value)
                {
                case 0: logger.LoggingInterval = new TimeSpan(0, 0, 1); break;

                case 1: logger.LoggingInterval = new TimeSpan(0, 0, 2); break;

                case 2: logger.LoggingInterval = new TimeSpan(0, 0, 5); break;

                case 3: logger.LoggingInterval = new TimeSpan(0, 0, 10); break;

                case 4: logger.LoggingInterval = new TimeSpan(0, 0, 30); break;

                case 5: logger.LoggingInterval = new TimeSpan(0, 1, 0); break;

                case 6: logger.LoggingInterval = new TimeSpan(0, 2, 0); break;

                case 7: logger.LoggingInterval = new TimeSpan(0, 5, 0); break;

                case 8: logger.LoggingInterval = new TimeSpan(0, 10, 0); break;

                case 9: logger.LoggingInterval = new TimeSpan(0, 30, 0); break;

                case 10: logger.LoggingInterval = new TimeSpan(1, 0, 0); break;

                case 11: logger.LoggingInterval = new TimeSpan(2, 0, 0); break;

                case 12: logger.LoggingInterval = new TimeSpan(6, 0, 0); break;
                }
            };

            InitializePlotForm();

            startupMenuItem.Visible = startupManager.IsAvailable;

            if (startMinMenuItem.Checked)
            {
                if (!minTrayMenuItem.Checked)
                {
                    WindowState = FormWindowState.Minimized;
                    Show();
                }
            }
            else
            {
                Show();
            }

            // Create a handle, otherwise calling Close() does not fire FormClosed
            IntPtr handle = Handle;

            // Make sure the settings are saved when the user logs off
            Microsoft.Win32.SystemEvents.SessionEnded += delegate {
                computer.Close();
                SaveConfiguration();
                if (runWebServer.Value)
                {
                    server.Quit();
                }
            };
        }