private bool IsNotified(MonitorItem Item, string Key, string RuntimeValue, string Message, out NotifiedMonitorItem Notified)
        {
            Notified = null;
            var key = Item.ToString() + ", " + Key + ", " + RuntimeValue;

            if (!notifiedAlerts.ContainsKey(key))
            {
                Notified = new NotifiedMonitorItem {
                    Server = Item.Server, CurrentValue = Message, CreatedDate = DateTime.Now
                };
                notifiedAlerts.Add(key, Notified);
                if (Settings.Instance.LogHistory)
                {
                    Settings.Instance.NotifiedAlerts.Add(Notified);
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
        private void ShowAlert(MonitorItem Item, string Key, string CurrentValue)
        {
            string message = Settings.Instance.AlertTemplate;

            if (string.IsNullOrEmpty(message))
            {
                message = Settings.DefaultTemplate;
            }
            string type   = string.Empty;
            string action = string.Empty;

            switch (Item.AlertType)
            {
            case AlertTypes.SQL:
                action = CurrentValue;
                switch (Item.CondictionType)
                {
                case 0:
                    type = "SQL executes: ";
                    break;

                case 1:
                    type = "SQL lasts: ";
                    break;

                case 2:
                    type = "SQL blocked: ";
                    break;

                default:
                    break;
                }
                break;

            case AlertTypes.Server:
                break;

            //case AlertTypes.CPU:
            //    message = string.Format("CPU usage is now {0}, higher than {1}", CurrentValue, Item.CondictionValue);
            //    break;
            //case AlertTypes.Memory:
            //    message = string.Format("Available memory is now {0}, lower than {1}", CurrentValue, Item.CondictionValue);
            //    break;
            //case AlertTypes.Diskspace:
            //    break;
            default:
                break;
            }
            if (!string.IsNullOrEmpty(message))
            {
                var fullMessage = message.Replace("#Type#", type);
                fullMessage = fullMessage.Replace("#Action#", action);
                fullMessage = fullMessage.Replace("#Server#", Item.Server);
                fullMessage = fullMessage.Replace("#Now#", DateTime.Now.ToString());
                NotifiedMonitorItem notified;
                if (!IsNotified(Item, Key, type + action, fullMessage, out notified))
                {
                    if (Alert != null)
                    {
                        Alert(this, new AlertEventArgs(Item, notified, fullMessage));
                    }
                }
            }
        }
 public AlertEventArgs(MonitorItem Item, NotifiedMonitorItem Notification, string Message)
     : base(Message, false)
 {
     this.Item         = Item;
     this.Notification = Notification;
 }