// ---------------------------------------------------------------------------------------- /// <!-- SimpleTestTable --> /// <summary> /// Returns a simple two column thre row table for testing various Data methods /// </summary> /// <returns></returns> private static RichDataTable SimpleTestTable() { RichDataTable rt = new RichDataTable(); rt.Add("Name", typeof(string)); rt.Add("Age", typeof(int)); int row; row = rt.Add(); rt.Rows[row]["Name"] = "Fred"; rt.Rows[row]["Age"] = 26; row = rt.Add(); rt.Rows[row]["Name"] = "Jon"; rt.Rows[row]["Age"] = 48; row = rt.Add(); rt.Rows[row]["Name"] = "Melinda"; rt.Rows[row]["Age"] = 26; return(rt); }
// ---------------------------------------------------------------------------------------- /// <!-- RichDataTable_Add_test --> /// <summary> /// /// </summary> public void RichDataTable_Add_test() { Assert.ThingsAbout("RichDataTable", "Add"); RichDataTable rt = SimpleTestTable(); RichDataTable rt2 = rt.Clone(); Assert.That(rt2.Columns[1].ColumnName, Is.equal_to, rt.Columns[1].ColumnName); rt2.Add(1, rt); // _CopyRowToTable(1, rt2); rt2.Add(0, rt); // _CopyRowToTable(0, rt2); int age1 = rt.IntValue(1, 1, 1); int age2 = rt2.IntValue(0, 1, 2); Assert.That(age2, Is.equal_to, age1); string name1 = rt.StrValue(0, 0, "a"); string name2 = rt2.StrValue(1, 0, "b"); Assert.That(name2, Is.equal_to, name1); _result += Assert.Conclusion; }
// ---------------------------------------------------------------------------------------- /// <!-- NameSourceList --> /// <summary> /// /// </summary> /// <returns></returns> public static RichDataTable NameSourceList() { RichDataTable source = new RichDataTable("DsmCodeSource", "Id"); source.Add("Id", typeof(string)); source.Add("Source", typeof(string)); source.Add("Id", "DSM4", "Source", "Official DSM4"); source.Add("Id", "DSMV", "Source", "Official DSMV"); source.Add("Id", "Both DSM4 & DSMV", "Source", "Both DSM4 & DSMV"); source.Add("Id", "Alternate", "Source", "Alternate"); source.Add("Id", "BHAS App Input", "Source", "BHAS App Input"); source.Add("Id", "Unknown", "Source", "Unknown"); return(source); }
// ---------------------------------------------------------------------------------------- /// <!-- AddSsnFinal4 --> /// <summary> /// Adds a column to the table contining the final N digits of the SSN /// </summary> /// <param name="table">the table to change</param> /// <param name="columnFrom">the current ssn column</param> /// <param name="columnTo">the (new) column to put the ssn final 4 in</param> /// <returns></returns> public static RichDataTable AddSsnFinalN(RichDataTable table, int num, string columnFrom, string columnTo) { table.Add(columnTo, typeof(string)); for (int row = 0; row < table.Count; ++row) { if (num > 0) { string str = table.StrValue(row, columnFrom, ""); //string lastX = Regex.Replace(str, "^.*(.{" + num + "})$", "$1"); string lastX = __.LastNChars(num, str); table.Rows[row][columnTo] = lastX; } } return(table); }
// ---------------------------------------------------------------------------------------- /// <!-- UnpackErrorMessages --> /// <summary> /// Extracts the messages, sources and types from an exception /// </summary> /// <param name="ex"></param> /// <returns></returns> /// <remarks> /// Moved from GlobalConstants /// /// beta code /// </remarks> public static string Unpack(Exception ex) { string err = ""; if (ex != null) { Exception e = ex; // ---------------------------------------------------------------------- // Interpretation header // ---------------------------------------------------------------------- Type exType = ex.GetType(); // Start by saying 'you did nothing wrong' in case this ever reaches a user //string intro = "You did nothing wrong, "; string intro = ""; string cr = "\r\n"; switch (exType.Name) { case "ActivationException": err = intro + "the program or data has experienced an anomaly masked by a web configuration problem:"; err += cr + " ---> " + ex.Message; break; case "SqlException": err = intro + "an internal sql command has experienced an anomaly when run on the database:"; err += cr + " ---> " + ex.Message; break; default: err = intro + "anomaly message: " + ex.Message; break; } // ---------------------------------------------------------------------- // Standard header // ---------------------------------------------------------------------- err += cr; int width = 120; // ---------------------------------------------------------------------- // Unpack the exception and inner exception messages // ---------------------------------------------------------------------- string delim = ""; while (ex != null) { RichDataTable dt = new RichDataTable(ex, "Exception", false, ""); dt.Add(ex); exType = ex.GetType(); err += cr + "+-" + "---------------------------------------".PadRight(width - 3, '-') + "+"; err += cr + "| " + ("Exception Type: " + exType.Name).PadRight(width - 3) + "|"; err += cr + "| " + dt.PrettyFormatRow(0, width - 3, "|\r\n| ") + "|"; err += cr + "+-" + "---------------------------------------".PadRight(width - 3, '-') + "+"; delim = cr + cr + " <--" + cr + cr; ex = ex.InnerException; } // ---------------------------------------------------------------------- // Add a nice footer (stacktrace) // ---------------------------------------------------------------------- err += cr + "|".PadRight(width - 1) + "|"; err += cr + "|".PadRight(width - 1) + "|"; err += cr + "|Stack Trace:".PadRight(width - 1) + "|"; err += cr + __.PrettyPrintStackTrace(e.StackTrace, width); } return(err); }