コード例 #1
0
        private void AppendFullTemplate(StringBuilder sb)
        {
            try
            {
                sb.Append(nHydrate.Core.SQLGeneration.SQLEmit.GetSqlCreateView(_currentView, true));

                if (!string.IsNullOrEmpty(_model.Database.GrantExecUser))
                {
                    _grantSB.AppendFormat("GRANT ALL ON [" + _currentView.GetSQLSchema() + "].[{0}] TO [{1}]", _currentView.DatabaseName, _model.Database.GrantExecUser).AppendLine();
                    _grantSB.AppendLine("--MODELID: " + _currentView.Key);
                    _grantSB.AppendLine("GO");
                    _grantSB.AppendLine();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #2
0
        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;
            }
        }