Пример #1
0
        private static void PostAlert(eXAlert model)
        {
            const string appKeyName           = "@key";
            const string appZoneName          = "@zone";
            const string appInstanceName      = "@instance";
            const string titleParamName       = "@title";
            const string sourceParamName      = "@source";
            const string importanceParamName  = "@importance";
            const string urgencyParamName     = "@urgency";
            const string xmlDataParamName     = "@xmldata";
            const string dispositionParamName = "@disposition";
            const string createdAtParamName   = "@createdat";

            try
            {
                using (SqlConnection cn = new SqlConnection(cnString))
                {
                    cn.Open();
                    using (SqlCommand cmd = cn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        string sql = "insert into [log].[alert] ([appkey],[appzone],[appinstance],[title],[source],[importance],[urgency],[xmldata],[disposition],[createdat]) values ( " +
                                     appKeyName + "," + appZoneName + "," + appInstanceName + "," + titleParamName + "," + sourceParamName + "," + importanceParamName + "," +
                                     urgencyParamName + "," + xmlDataParamName + "," + dispositionParamName + "," + createdAtParamName + ")";
                        cmd.Parameters.AddWithValue(appKeyName, model.ApplicationKey);
                        cmd.Parameters.AddWithValue(appZoneName, model.Zone);
                        string appinstance;
                        if (model.Items.TryGet <string>("app.context.instance", out appinstance))
                        {
                            cmd.Parameters.AddWithValue(appInstanceName, appinstance);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue(appInstanceName, "none");
                        }

                        cmd.Parameters.AddWithValue(titleParamName, model.Title);
                        cmd.Parameters.AddWithValue(sourceParamName, !String.IsNullOrWhiteSpace(model.Source) ? model.Source : "none");
                        cmd.Parameters.AddWithValue(importanceParamName, model.Importance);
                        cmd.Parameters.AddWithValue(urgencyParamName, model.Urgency);
                        var xml = GenericSerializer.DbParamFromItem(model);
                        cmd.Parameters.AddWithValue(XmlDataParamName, xml);
                        cmd.Parameters.AddWithValue(dispositionParamName, "none");
                        cmd.Parameters.AddWithValue(createdAtParamName, DateTime.Now);

                        cmd.CommandText = sql;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                IEventWriter writer = new EventLogWriter();
                string       m      = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                var          props  = eXtensibleConfig.GetProperties();
                props.Add("location", "SqlServerEventWriter.line.105");
                writer.WriteError(m, SeverityType.Critical, "EventWriter", props);
            }
        }
Пример #2
0
        public static void PostAlert(List <TypedItem> properties)
        {
            eXAlert model = new eXAlert(properties);

            if (eXtensibleConfig.HandleAlerts)
            {
                HandleAlert(model);
            }
            PostAlert(model);
        }
Пример #3
0
 protected abstract void Execute(eXAlert alert, AlertInterest interest);
Пример #4
0
 private static void HandleAlert(eXAlert model)
 {
 }
Пример #5
0
 void IAlertPublisher.Execute(eXAlert alert, AlertInterest interest)
 {
     Execute(alert, interest);
 }