public static string Dump(LogPriority logPriority, LogReport report, int count = 1000)
        {
            string sql =
                $"SELECT TOP {count} created, priority, tag, msg FROM SysLog WHERE Priority >= @priority ORDER BY created DESC";

            using (var q = new SqlStatement(sql, Config.Settings.ConnectionString))
            {
                q.AddParameter("@Priority", logPriority);
                using (var reader = q.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        Environment.ExitCode = 1;
                    }
                    var r = LogReporter.Write(reader, report);
                    return(r);
                }
            }
        }
Beispiel #2
0
 private static Task ReadTask(string sql)
 {
     using (var sqlCommand = new SqlStatement(sql, Config.Settings.ConnectionString))
         using (var reader = sqlCommand.ExecuteReader())
         {
             while (reader.Read())
             {
                 var id      = (int)reader[0];
                 var action  = (string)reader[1];
                 var payload = (string)reader[2];
                 var task    = CreateTask(action, id, payload);
                 task.Created = (DateTime)reader[3];
                 if (task != Task.Failed)
                 {
                     return(task);
                 }
             }
             return(Task.Idle);
         }
 }
Beispiel #3
0
        private static string QueryToHtml(string tableName, int maxCount = 1000)
        {
            var rows = new HtmlWriter();

            using (SqlStatement cmd = SqlServer.Query(tableName, maxCount))
                using (SqlDataReader r = cmd.ExecuteReader())
                {
                    if (!r.HasRows)
                    {
                        rows.Tag("h3", tableName + ": Empty");
                        return(rows.ToString());
                    }

                    var headers = new HtmlWriter();
                    for (int i = 0; i < r.FieldCount; i++)
                    {
                        headers.Tag("th", r.GetName(i));
                    }
                    rows.TagRaw("tr", headers.ToString());

                    while (r.Read())
                    {
                        var row = new HtmlWriter();
                        for (int i = 0; i < r.FieldCount; i++)
                        {
                            row.Tag("TD", r[i].ToString().Replace("\r\n", "<br />"));
                        }
                        rows.TagRaw("tr", row.ToString());
                    }
                }

            var html  = new HtmlWriter();
            int count = SqlServer.QueryRecordCount(tableName);

            html.Tag("h3", tableName + " (rows 1-" + Math.Min(maxCount, count) + " of " + count + ")");
            html.TagRaw("table", rows.ToString());
            return(html.ToString());
        }