/// <summary> /// Get simple Html string of a single class object with only new lines /// </summary> /// <param name="Class">Any entity object , can be null.</param> /// <param name="additionalStylesWithTable"></param> /// <param name="additionalStylesWithRow"></param> /// <param name="additionalStylesWithCell"></param> /// <returns> /// Returns property and value string combination, returns empty string if class is null or doesn't have any valid /// properties to display. /// </returns> public static string AsHtmlTable(object Class, string additionalStylesWithTable = "", string additionalStylesWithRow = "", string additionalStylesWithCell = "") { if (Class != null) { var properties = Class.GetType() .GetProperties(TypeOfPropertise) .Where(p => p.Name != "EntityKey" && p.Name != "EntityState") .ToList(); var sb = new StringBuilder(properties.Count * 3 + 20); var styles = CssStyle.GetCommonStyles("#74DA74", "black", null, "8px 20px 16px", "4px"); var styles2 = CssStyle.GetCommonStyles(null, null, null, null, null, "bolder"); sb.Append("<table "); sb.Append("style='" + styles + additionalStylesWithTable + "'>"); sb.Append("<thead>"); //sb.Append(HtmlHelperExtension.GetTag("caption", "Entity Title : " + anyObject.ToString())); sb.Append("<tr "); sb.Append("style='" + styles2 + additionalStylesWithRow + "'>"); sb.Append(HtmlHelperExtension.GetTag("td", "", additionalStylesWithCell)); sb.Append(HtmlHelperExtension.GetTag("td", "", additionalStylesWithCell)); sb.Append(HtmlHelperExtension.GetTag("td", "", additionalStylesWithCell)); //sb.Append(HtmlHelperExtension.GetTag("td", "Properties")); //sb.Append(HtmlHelperExtension.GetTag("td", "")); //sb.Append(HtmlHelperExtension.GetTag("td", "Values")); sb.Append("</tr>"); sb.Append("</thead>"); sb.Append("<tbody>"); foreach (var prop in properties) { var val = prop.GetValue(Class, null); sb.Append("<tr "); sb.Append("style='" + additionalStylesWithRow + "'>"); if (TypeChecker.IsPrimitiveOrGuid(val)) { sb.Append(HtmlHelperExtension.GetTag("td", prop.Name, additionalStylesWithCell)); sb.Append(":"); sb.Append(HtmlHelperExtension.GetTag("td", val.ToString(), additionalStylesWithCell)); } sb.Append("</tr>"); } sb.Append("</tbody>"); sb.Append("</table>"); var output = sb.ToString(); sb = null; GC.Collect(); return(output); } return(""); }
/// <summary> /// </summary> /// <param name="ex"></param> /// <param name="subject"></param> /// <param name="body"></param> /// <param name="method"></param> /// <param name="entitySingleObject"></param> public void GenerateErrorBody(Exception ex, ref string subject, ref string body, string method = "", object entitySingleObject = null) { var isUserExist = HttpContext.Current != null && HttpContext.Current.User.Identity.IsAuthenticated; var sb = new StringBuilder(30); if (body == null) { body = ""; } sb.Append(GetErrorMsgHtml(ex, method)); if (string.IsNullOrEmpty(subject)) { subject = string.Format("[{0}] [Error] on [{1}] method at {2}", Config.ApplicationName, method, DateTime.UtcNow); } if (isUserExist) { sb.Append("<hr />"); var loggedUserStyle = CssStyle.GetCommonStyles("Green", "White", "0 0 5px 0", "8px", "3px", "bolder"); sb.Append(HtmlHelperExtension.GetTag("div", "Logged in user : "******"<hr/>"); sb.Append(HtmlHelperExtension.GetTag("h3", "Entity Title : " + entitySingleObject)); try { var entityString = EntityToString.GetHtmlOfSingleClassAsTable(entitySingleObject); sb.Append(entityString); } catch (Exception ex2) { sb.Append("<div style='color:red'> Error Can't Read Entity: " + ex2.Message + "</div>"); } } sb.Append("<hr />"); sb.Append("<div style='background-color:#FFFFD1" + Config.CommonStyles + "> Stack Trace: " + ex.StackTrace + "</div>"); body = sb.ToString(); }