Ejemplo n.º 1
0
        public static CrashReport Add(int crashIncidentId, string exceptionName,
                                      string exceptionMessage, string stackTrace, int?innerExceptionCrashReportId)
        {
            CrashReport result = null;

            string query = "INSERT INTO CrashReport (CrashReportCrashIncidentId, CrashReportExceptionName, CrashReportExceptionMessage, CrashReportExceptionStackTrace, CrashReportInnerExceptionCrashReportId) " +
                           "VALUES (@CrashReportCrashIncidentId, @CrashReportExceptionName, @CrashReportExceptionMessage, @CrashReportExceptionStackTrace, @CrashReportInnerExceptionCrashReportId);" +
                           "SELECT CAST(scope_identity() AS int)";

            using (SqlConnection conn = new SqlConnection(DatabaseHelper.ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportCrashIncidentId", SqlDbType.Int, crashIncidentId);
                    DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportExceptionName", SqlDbType.Text, exceptionName);
                    DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportExceptionMessage", SqlDbType.Text, exceptionMessage);
                    DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportExceptionStackTrace", SqlDbType.Text, stackTrace);
                    DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportInnerExceptionCrashReportId", SqlDbType.Int, innerExceptionCrashReportId);
                    conn.Open();
                    int id = (Int32)cmd.ExecuteScalar();
                    if (id > 0)
                    {
                        result = new CrashReport(id, crashIncidentId, exceptionName,
                                                 exceptionMessage, stackTrace, innerExceptionCrashReportId);
                    }
                }
                conn.Close();
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update an entry in the CrashReport table
        /// </summary>
        public static bool Update(CrashReport entry)
        {
            bool result = false;

            using (SqlConnection cn = new SqlConnection(DatabaseHelper.ConnectionString))
            {
                cn.Open();
                result = Update(cn, entry);
                cn.Close();
            }

            return(result);
        }
Ejemplo n.º 3
0
        private static CrashReport Get(SqlConnection cn, int id)
        {
            CrashReport   result = null;
            SqlCommand    cmd    = new SqlCommand("SELECT * FROM CrashReport WHERE CrashReportId=" + id, cn);
            SqlDataReader rdr    = cmd.ExecuteReader();

            if (rdr.Read())
            {
                result = BuildCrashReport(rdr);
            }
            rdr.Close();
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get an entry from the CrashReport table
        /// </summary>
        public static CrashReport Get(int id)
        {
            CrashReport result = null;

            using (SqlConnection cn = new SqlConnection(DatabaseHelper.ConnectionString))
            {
                cn.Open();
                result = Get(cn, id);
                cn.Close();
            }

            return(result);
        }
Ejemplo n.º 5
0
        public static CrashReport Add(int crashIncidentId, Exception ex)
        {
            if (ex.InnerException == null)
            {
                return(Add(crashIncidentId, ex.GetType().ToString(), ex.Message,
                           ex.StackTrace, null));
            }

            // Handle InnerException
            CrashReport innerCrashReport   = Add(crashIncidentId, ex.InnerException);
            CrashReport currentCrashReport = Add(crashIncidentId, ex.GetType().ToString(),
                                                 ex.Message, ex.StackTrace, innerCrashReport.Id);

            return(currentCrashReport);
        }
Ejemplo n.º 6
0
        private static bool Update(SqlConnection cn, CrashReport entry)
        {
            Int32 rowsAffected = 0;

            using (SqlCommand cmd = cn.CreateCommand())
            {
                cmd.CommandText = "UPDATE CrashReport SET CrashReportCrashIncidentId=@CrashReportCrashIncidentId,CrashReportExceptionName=@CrashReportExceptionName,CrashReportExceptionMessage=@CrashReportExceptionMessage,CrashReportExceptionStackTrace=@CrashReportExceptionStackTrace,CrashReportInnerExceptionCrashReportId=@CrashReportInnerExceptionCrashReportId WHERE CrashReportId=@CrashReportId";

                DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportId", SqlDbType.Int, entry.Id);
                DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportCrashIncidentId", SqlDbType.Int, entry.CrashIncidentId);
                DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportExceptionName", SqlDbType.Text, entry.ExceptionName);
                DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportExceptionMessage", SqlDbType.Text, entry.ExceptionMessage);
                DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportExceptionStackTrace", SqlDbType.Text, entry.StackTrace);
                DatabaseHelper.BuildSqlParameter(cmd, "@CrashReportInnerExceptionCrashReportId", SqlDbType.Int, entry.InnerExceptionCrashReportId);

                rowsAffected = cmd.ExecuteNonQuery();
            }
            return(rowsAffected != 0);
        }
Ejemplo n.º 7
0
 public bool Delete()
 {
     CrashReport.DeleteAll(Id);
     return(Delete(Id));
 }