private void GenerateContent() { try { var fileContent = Helpers.GetFileContent(new EmbeddedResourceName(_templateLocation + ".datasite-overview.htm")); fileContent = fileContent.Replace("$databasename$", _model.ProjectName); fileContent = fileContent.Replace("$pagetitle$", "Tables Documentation"); fileContent = fileContent.Replace("$time$", DateTime.Now.ToString("MMM dd yyyy HH:mm:ss")); #region Main { var tsb = new StringBuilder(); tsb.AppendLine("<table class=\"subItem-item\">"); tsb.AppendLine("<thead>"); tsb.AppendLine("<tr>"); tsb.AppendLine("<th>Type</th>"); tsb.AppendLine("<th>Count</th>"); tsb.AppendLine("</tr>"); tsb.AppendLine("</thead>"); tsb.AppendLine("<tbody>"); tsb.AppendLine("<tr>"); tsb.AppendLine("<td><a href=\"tables.html\">Tables</a></td>"); tsb.AppendLine("<td>" + _model.Database.Tables.Count(x => x.Generated) + "</td>"); tsb.AppendLine("</tr>"); tsb.AppendLine("<tr>"); tsb.AppendLine("<td><a href=\"views.html\">Views</a></td>"); tsb.AppendLine("<td>" + _model.Database.CustomViews.Count(x => x.Generated) + "</td>"); tsb.AppendLine("</tr>"); tsb.AppendLine("<tr>"); tsb.AppendLine("<td><a href=\"storedprocedures.html\">Stored Procedures</a></td>"); tsb.AppendLine("<td>" + _model.Database.CustomStoredProcedures.Count(x => x.Generated) + "</td>"); tsb.AppendLine("</tr>"); tsb.AppendLine("<tr>"); tsb.AppendLine("<td><a href=\"functions.html\">Functions</a></td>"); tsb.AppendLine("<td>" + _model.Database.Functions.Count(x => x.Generated) + "</td>"); tsb.AppendLine("</tr>"); tsb.AppendLine("</tbody>"); tsb.AppendLine("</table>"); fileContent = fileContent.Replace("$listtable$", tsb.ToString()); } #endregion #region Schemas { var schemas = _model.Database.Tables.Where(x => x.Generated).Select(x => x.GetSQLSchema()).ToList(); schemas.AddRange(_model.Database.CustomViews.Where(x => x.Generated).Select(x => x.GetSQLSchema()).ToList()); schemas.AddRange(_model.Database.CustomStoredProcedures.Where(x => x.Generated).Select(x => x.GetSQLSchema()).ToList()); schemas.AddRange(_model.Database.Functions.Where(x => x.Generated).Select(x => x.GetSQLSchema()).ToList()); var tsb = new StringBuilder(); tsb.AppendLine("<table class=\"subItem-item\">"); tsb.AppendLine("<thead>"); tsb.AppendLine("<tr>"); tsb.AppendLine("<th>Name</th>"); tsb.AppendLine("<th>Item Count</th>"); tsb.AppendLine("</tr>"); tsb.AppendLine("</thead>"); tsb.AppendLine("<tbody>"); foreach (var s in schemas.Distinct().OrderBy(x => x).ToList()) { tsb.AppendLine("<tr>"); tsb.AppendLine("<td>" + s + "</td>"); tsb.AppendLine("<td>" + schemas.Count(x => x == s) + "</td>"); tsb.AppendLine("</tr>"); } tsb.AppendLine("</tbody>"); tsb.AppendLine("</table>"); fileContent = fileContent.Replace("$schematable$", tsb.ToString()); } #endregion fileContent = fileContent.Replace("$footertext$", "Powered by nHydrate © " + DateTime.Now.Year); sb.Append(fileContent); } catch (Exception ex) { throw; } }
private void GenerateContent() { try { var fileContent = Helpers.GetFileContent(new EmbeddedResourceName(_templateLocation + ".datasite-view-template.htm")); fileContent = fileContent.Replace("$databasename$", _model.ProjectName); fileContent = fileContent.Replace("$objectname$", _item.GetSQLSchema() + "." + _item.Name); var description = _item.Description; if (string.IsNullOrEmpty(description)) description = "The " + _item.Name + " item"; fileContent = fileContent.Replace("$objectdescription$", description); fileContent = fileContent.Replace("$pagetitle$", "[" + _item.Name + "] Documentation"); fileContent = fileContent.Replace("$footertext$", "Powered by nHydrate © " + DateTime.Now.Year); #region Column Table var tsb = new StringBuilder(); tsb.AppendLine("<table class=\"subItem-item\">"); tsb.AppendLine("<thead>"); tsb.AppendLine("<tr>"); tsb.AppendLine("<th>Name</th>"); tsb.AppendLine("<th>Data type</th>"); tsb.AppendLine("<th>Length</th>"); tsb.AppendLine("<th>Allow Null</th>"); tsb.AppendLine("<th>Comment</th>"); tsb.AppendLine("</tr>"); tsb.AppendLine("</thead>"); tsb.AppendLine("<tbody>"); foreach (var subItem in _item.GeneratedColumns) { tsb.AppendLine("<tr class=\"" + (((_item.GeneratedColumns.IndexOf(subItem) % 2) == 1) ? "t-odd-color" : string.Empty) + "\">"); tsb.AppendLine("<td>" + subItem.Name + "</td>"); tsb.AppendLine("<td>" + subItem.DatabaseType + "</td>"); tsb.AppendLine("<td>" + subItem.GetLengthString() + "</td>"); tsb.AppendLine("<td>" + subItem.AllowNull.ToString() + "</td>"); tsb.AppendLine("<td class=\"description\">" + subItem.Description + "</td>"); tsb.AppendLine("</tr>"); } tsb.AppendLine("</tbody>"); tsb.AppendLine("</table>"); fileContent = fileContent.Replace("$columntable$", tsb.ToString()); #endregion #region SQL var sql = nHydrate.Core.SQLGeneration.SQLEmit.GetSqlCreateView(_item, true); var lines = sql.Replace("\r", string.Empty).Split('\n'); var newCode = new StringBuilder(); sql = string.Join("\r\n", lines.Where(x => !x.StartsWith("--MODELID")).ToList()); sql = nHydrate.Core.SQLGeneration.HtmlEmit.FormatHTMLSQL(sql); fileContent = fileContent.Replace("$sql$", sql); #endregion sb.Append(fileContent); } catch (Exception ex) { throw; } }