v1.2.4
This commit is contained in:
@@ -60,44 +60,49 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Core Database connection.
|
||||
ISacsDatabase db = SaxGlobals.App.GetCoreDatabase(SessionContext);
|
||||
|
||||
// Database table row counts.
|
||||
Dictionary<String, int> tableRowCounts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
String query =
|
||||
"SELECT QUOTENAME(SCHEMA_NAME(sOBJ.schema_id)) + '.' + QUOTENAME(sOBJ.name) AS[TableName], SUM(sPTN.Rows) AS[RowCount] " +
|
||||
"FROM sys.objects AS sOBJ " +
|
||||
"INNER JOIN sys.partitions AS sPTN ON sOBJ.object_id = sPTN.object_id " +
|
||||
"WHERE sOBJ.type = 'U' AND sOBJ.is_ms_shipped = 0x0 AND index_id< 2 /*Index Id: 0:Heap,1:Clustered*/ " +
|
||||
"GROUP BY sOBJ.schema_id, sOBJ.name";
|
||||
using (DbResultSet dbResultSet = DbResultSet_DataReader.ExecuteQuery(db, query))
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsDisposable> disposableItems = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
while (dbResultSet != null && dbResultSet.NextRecord())
|
||||
|
||||
// Core Database connection.
|
||||
ISacsDatabase db = SaxGlobals.App.GetCoreDatabase(SessionContext);
|
||||
|
||||
// Database table row counts.
|
||||
Dictionary<String, int> tableRowCounts = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
String query =
|
||||
"SELECT QUOTENAME(SCHEMA_NAME(sOBJ.schema_id)) + '.' + QUOTENAME(sOBJ.name) As [TableName], SUM(sPTN.Rows) As [RowCount] " +
|
||||
"FROM sys.objects AS sOBJ " +
|
||||
"INNER JOIN sys.partitions AS sPTN ON sOBJ.object_id = sPTN.object_id " +
|
||||
"WHERE sOBJ.type = 'U' AND sOBJ.is_ms_shipped = 0x0 AND index_id< 2 /*Index Id: 0:Heap,1:Clustered*/ " +
|
||||
"GROUP BY sOBJ.schema_id, sOBJ.name";
|
||||
using (DbResultSet dbResultSet = DbResultSet_DataReader.ExecuteQuery(db, query))
|
||||
{
|
||||
tableRowCounts.Add(dbResultSet.GetRecordValues().GetValue("TableName").ToString(), (int)dbResultSet.GetRecordValues().GetValue("RowCount").AsLong());
|
||||
while (dbResultSet != null && dbResultSet.NextRecord())
|
||||
{
|
||||
tableRowCounts.Add(dbResultSet.GetRecordValues().GetValue("TableName").ToString(), (int)dbResultSet.GetRecordValues().GetValue("RowCount").AsLong());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Core database tables.
|
||||
List<DbDfnTable> tableDfns = db.GetTableDfns();
|
||||
foreach (DbDfnTable tableDfn in tableDfns.OrderBy(item => item.Name))
|
||||
{
|
||||
// Filter by table name.
|
||||
if (!StringUtil.IsEmpty(model.DatabaseFilter.Table) && !tableDfn.Name.ContainsCI(model.DatabaseFilter.Table))
|
||||
continue;
|
||||
// Core database tables.
|
||||
List<DbDfnTable> tableDfns = db.GetTableDfns();
|
||||
foreach (DbDfnTable tableDfn in tableDfns.OrderBy(item => item.Name))
|
||||
{
|
||||
// Filter by table name.
|
||||
if (!StringUtil.IsEmpty(model.DatabaseFilter.Search) && !tableDfn.Name.ContainsCI(model.DatabaseFilter.Search))
|
||||
continue;
|
||||
|
||||
DatabaseTableData tableData = new DatabaseTableData();
|
||||
tableData.SchemaName = tableDfn.Schema;
|
||||
tableData.TableName = tableDfn.Name;
|
||||
tableData.QualifiedName = tableDfn.QualifiedName;
|
||||
tableData.ColumnCount = tableDfn.ColumnCount;
|
||||
tableData.IndexCount = tableDfn.IndexCount;
|
||||
DatabaseTableData tableData = new DatabaseTableData();
|
||||
tableData.SchemaName = tableDfn.Schema;
|
||||
tableData.TableName = tableDfn.Name;
|
||||
tableData.QualifiedName = tableDfn.QualifiedName;
|
||||
tableData.ColumnCount = tableDfn.ColumnCount;
|
||||
tableData.IndexCount = tableDfn.IndexCount;
|
||||
|
||||
// Row count.
|
||||
tableData.RowCount = tableRowCounts.GetValueOrDefault(tableDfn.QuotedQualifiedName, 0);
|
||||
// Row count.
|
||||
tableData.RowCount = tableRowCounts.GetValueOrDefault(tableDfn.QuotedQualifiedName, 0);
|
||||
|
||||
responseData.Tables.Add(tableData);
|
||||
responseData.Tables.Add(tableData);
|
||||
}
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
@@ -127,9 +132,9 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("System/Ajax/ValidateDatabaseSchema")]
|
||||
public IActionResult Ajax_ValidateDatabaseSchema(Model_Sport model)
|
||||
public IActionResult Ajax_ValidateDatabaseSchema(Model_System model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetDatabaseTables";
|
||||
String fn = GetType().Name + ".Ajax_ValidateDatabaseSchema";
|
||||
String messageTitle = Localiser["system.caption.database"];
|
||||
AjaxResponse_ValidateDatabaseSchema responseData = new AjaxResponse_ValidateDatabaseSchema(model);
|
||||
|
||||
@@ -137,42 +142,47 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Core Database connection.
|
||||
ISacsDatabase db = SaxGlobals.App.GetCoreDatabase(SessionContext);
|
||||
|
||||
// Retrieve XML database schema definition.
|
||||
var assembly = typeof(SaxSystem_Dbas).GetTypeInfo().Assembly;
|
||||
String xmlSchema = SacsResourceHelper.GetManifestResourceAsText(assembly, "", "SaxDbDfn_Core.xml");
|
||||
if (StringUtil.IsEmpty(xmlSchema))
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to extract XML schema definition."));
|
||||
|
||||
// Extract schema from XML definition.
|
||||
SaDbProcess_ConvertDbSchema.Config cfgSchemaConvert = new SaDbProcess_ConvertDbSchema.Config();
|
||||
SaDbProcess_ConvertDbSchema procSchemaConvert = new SaDbProcess_ConvertDbSchema(cfgSchemaConvert);
|
||||
List<DbDfnTable> tables = procSchemaConvert.ConvertXmlToTables(xmlSchema);
|
||||
if (procSchemaConvert.HasProcessError())
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to convert XML schema: " + procSchemaConvert.GetProcessError()));
|
||||
|
||||
SaDbProcess_CompareDatabaseSchemas.Config cfgSchemaCompare = new SaDbProcess_CompareDatabaseSchemas.Config(tables, db);
|
||||
cfgSchemaCompare.HideIdenticalObjects = true;
|
||||
cfgSchemaCompare.IgnorePosition = true;
|
||||
SaDbProcess_CompareDatabaseSchemas procSchemaCompare = new SaDbProcess_CompareDatabaseSchemas(cfgSchemaCompare);
|
||||
procSchemaCompare.ProcessNotifier = this;
|
||||
procSchemaCompare.RunProcess();
|
||||
|
||||
List<SaDbProcess_CompareDatabaseSchemas.SchemaComparisonItem> schemaComparisonItems = procSchemaCompare.GetSchemaComparisonItems();
|
||||
foreach (SaDbProcess_CompareDatabaseSchemas.SchemaComparisonItem schemaComparisonItem in schemaComparisonItems)
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsDisposable> disposableItems = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
DbSchemaItemResponseData item = new DbSchemaItemResponseData()
|
||||
|
||||
// Core Database connection.
|
||||
ISacsDatabase db = SaxGlobals.App.GetCoreDatabase(SessionContext);
|
||||
|
||||
// Retrieve XML database schema definition.
|
||||
var assembly = typeof(SaxSystem_Dbas).GetTypeInfo().Assembly;
|
||||
String xmlSchema = SacsResourceHelper.GetManifestResourceAsText(assembly, "", "SaxDbDfn_Core.xml");
|
||||
if (StringUtil.IsEmpty(xmlSchema))
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to extract XML schema definition."));
|
||||
|
||||
// Extract schema from XML definition.
|
||||
SaDbProcess_ConvertDbSchema.Config cfgSchemaConvert = new SaDbProcess_ConvertDbSchema.Config();
|
||||
SaDbProcess_ConvertDbSchema procSchemaConvert = new SaDbProcess_ConvertDbSchema(cfgSchemaConvert);
|
||||
List<DbDfnTable> tables = procSchemaConvert.ConvertXmlToTables(xmlSchema);
|
||||
if (procSchemaConvert.HasProcessError())
|
||||
return Json(responseData.SetMessage(messageTitle, "Failed to convert XML schema: " + procSchemaConvert.GetProcessError()));
|
||||
|
||||
SaDbProcess_CompareDatabaseSchemas.Config cfgSchemaCompare = new SaDbProcess_CompareDatabaseSchemas.Config(tables, db);
|
||||
cfgSchemaCompare.HideIdenticalObjects = true;
|
||||
cfgSchemaCompare.IgnorePosition = true;
|
||||
SaDbProcess_CompareDatabaseSchemas procSchemaCompare = new SaDbProcess_CompareDatabaseSchemas(cfgSchemaCompare);
|
||||
procSchemaCompare.ProcessNotifier = this;
|
||||
procSchemaCompare.RunProcess();
|
||||
|
||||
List<SaDbProcess_CompareDatabaseSchemas.SchemaComparisonItem> schemaComparisonItems = procSchemaCompare.GetSchemaComparisonItems();
|
||||
foreach (SaDbProcess_CompareDatabaseSchemas.SchemaComparisonItem schemaComparisonItem in schemaComparisonItems)
|
||||
{
|
||||
Id = schemaComparisonItem.Id,
|
||||
TableName = schemaComparisonItem.TableName,
|
||||
ColumnName = schemaComparisonItem.ColumnName,
|
||||
ColumnPosition = schemaComparisonItem.ColumnPosition,
|
||||
IndexName = schemaComparisonItem.IndexName,
|
||||
Comment = schemaComparisonItem.Comment
|
||||
};
|
||||
responseData.Items.Add(item);
|
||||
DbSchemaItemResponseData item = new DbSchemaItemResponseData()
|
||||
{
|
||||
Id = schemaComparisonItem.Id,
|
||||
TableName = schemaComparisonItem.TableName,
|
||||
ColumnName = schemaComparisonItem.ColumnName,
|
||||
ColumnPosition = schemaComparisonItem.ColumnPosition,
|
||||
IndexName = schemaComparisonItem.IndexName,
|
||||
Comment = schemaComparisonItem.Comment
|
||||
};
|
||||
responseData.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
@@ -193,6 +203,194 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Database Table ajax request.
|
||||
//-------------------------------------------------------------------
|
||||
private class AjaxResponseData_Table
|
||||
{
|
||||
public AjaxResponseData_Table(DbDfnTable tableDfn)
|
||||
{
|
||||
Schema = tableDfn.Schema;
|
||||
Name = tableDfn.Name;
|
||||
if (!StringUtil.IsEmpty(tableDfn.Remarks))
|
||||
Remarks = tableDfn.Remarks;
|
||||
foreach (DbDfnColumn columnDfn in tableDfn.Columns)
|
||||
Columns.Add(new AjaxResponseData_Column(columnDfn));
|
||||
foreach (DbDfnIndex indexDfn in tableDfn.Indices)
|
||||
Indices.Add(new AjaxResponseData_Index(indexDfn));
|
||||
}
|
||||
public String Schema { get; }
|
||||
public String Name { get; }
|
||||
public String QualifiedName { get { return (!StringUtil.IsEmpty(Schema) ? Schema + "." : "") + Name; } }
|
||||
public String QuotedQualifiedName { get { return (!StringUtil.IsEmpty(Schema) ? "[" + Schema + "]." : "") + "[" + Name + "]"; } }
|
||||
public String Remarks { get; set; } = String.Empty;
|
||||
public List<AjaxResponse_Data.ItemLabelValue> Properties { get; } = new List<AjaxResponse_Data.ItemLabelValue>();
|
||||
public List<AjaxResponseData_Column> Columns { get; } = new List<AjaxResponseData_Column>();
|
||||
public List<AjaxResponseData_Index> Indices { get; } = new List<AjaxResponseData_Index>();
|
||||
}
|
||||
private class AjaxResponseData_Column
|
||||
{
|
||||
public int Pos { get; }
|
||||
public String Name { get; }
|
||||
public String Format { get; }
|
||||
public String DataTypeName { get; }
|
||||
public short? DataTypeNative { get; }
|
||||
public String DataTypeNameNative { get; }
|
||||
public bool? IsIdentity { get; }
|
||||
public long? Size { get; }
|
||||
public long? BufferLen { get; }
|
||||
public short? DecimalDigits { get; }
|
||||
public bool? Nullable { get; }
|
||||
public bool? IsNullable { get; }
|
||||
public String Remarks { get; }
|
||||
public AjaxResponseData_Column(DbDfnColumn columnDfn)
|
||||
{
|
||||
Pos = columnDfn.Pos;
|
||||
Name = columnDfn.Name;
|
||||
Format = columnDfn.GetFormat();
|
||||
if (!StringUtil.IsEmpty(columnDfn.DataTypeName))
|
||||
DataTypeName = columnDfn.DataTypeName;
|
||||
if (columnDfn.DataTypeNative > 0)
|
||||
DataTypeNative = columnDfn.DataTypeNative;
|
||||
if (!StringUtil.IsEmpty(columnDfn.DataTypeNameNative))
|
||||
DataTypeNameNative = columnDfn.DataTypeNameNative;
|
||||
if (columnDfn.IsIdentity)
|
||||
IsIdentity = columnDfn.IsIdentity;
|
||||
if (columnDfn.Size > 0)
|
||||
Size = columnDfn.Size;
|
||||
if (columnDfn.BufferLen > 0)
|
||||
BufferLen = columnDfn.BufferLen;
|
||||
if (columnDfn.DecimalDigits > 0)
|
||||
DecimalDigits = columnDfn.DecimalDigits;
|
||||
if (columnDfn.Nullable == DbColumnNullable.Nullable)
|
||||
Nullable = true;
|
||||
if (columnDfn.IsNullable)
|
||||
IsNullable = columnDfn.IsNullable;
|
||||
if (!StringUtil.IsEmpty(columnDfn.Remarks))
|
||||
Remarks = columnDfn.Remarks;
|
||||
}
|
||||
}
|
||||
private class AjaxResponseData_Index
|
||||
{
|
||||
public String Name { get; }
|
||||
public int? IndexType { get; }
|
||||
public bool? Unique { get; }
|
||||
public bool? Primary { get; }
|
||||
public bool? Clustered { get; }
|
||||
public bool? Nullable { get; }
|
||||
public int? Pages { get; }
|
||||
public int? UniqueValues { get; }
|
||||
public List<AjaxResponseData_IndexColumn> Columns { get; } = new List<AjaxResponseData_IndexColumn>();
|
||||
public AjaxResponseData_Index(DbDfnIndex indexDfn)
|
||||
{
|
||||
Name = indexDfn.Name;
|
||||
if (indexDfn.IndexType > 0)
|
||||
IndexType = indexDfn.IndexType;
|
||||
if (indexDfn.Unique)
|
||||
Unique = indexDfn.Unique;
|
||||
if (indexDfn.Primary)
|
||||
Primary = indexDfn.Primary;
|
||||
if (indexDfn.Clustered)
|
||||
Clustered = indexDfn.Clustered;
|
||||
if (indexDfn.Nullable)
|
||||
Nullable = indexDfn.Nullable;
|
||||
if (indexDfn.Pages > 0)
|
||||
Pages = indexDfn.Pages;
|
||||
if (indexDfn.UniqueValues > 0)
|
||||
UniqueValues = indexDfn.UniqueValues;
|
||||
foreach (DbDfnIndexColumn indexColumnDfn in indexDfn.Columns)
|
||||
Columns.Add(new AjaxResponseData_IndexColumn(indexColumnDfn));
|
||||
}
|
||||
}
|
||||
private class AjaxResponseData_IndexColumn
|
||||
{
|
||||
public short Seq { get; }
|
||||
public String Name { get; }
|
||||
public bool? Desc { get; }
|
||||
public AjaxResponseData_IndexColumn(DbDfnIndexColumn indexColumnDfn)
|
||||
{
|
||||
Seq = indexColumnDfn.Seq;
|
||||
Name = indexColumnDfn.Name;
|
||||
if (!indexColumnDfn.Ascend)
|
||||
Desc = true;
|
||||
}
|
||||
}
|
||||
private class AjaxResponse_DatabaseTable : AjaxResponse_Data
|
||||
{
|
||||
// Construction.
|
||||
public AjaxResponse_DatabaseTable(SaxModel_Admin model) : base(model) { }
|
||||
// Database table.
|
||||
public String PopupTitle { get; set; }
|
||||
public AjaxResponseData_Table Table { get; set; }
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("System/Ajax/GetDatabaseTable")]
|
||||
public IActionResult Ajax_GetDatabaseTable(Model_System model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetDatabaseTable";
|
||||
String messageTitle = Localiser["system.caption.database"];
|
||||
AjaxResponse_DatabaseTable responseData = new AjaxResponse_DatabaseTable(model);
|
||||
|
||||
// Validate session.
|
||||
if (!ValidUserSession)
|
||||
return GetAjaxResult_InvalidSession(responseData);
|
||||
|
||||
// Record disposable items as they are created so all can be disposed when needed.
|
||||
using (DisposableCollection<SacsDisposable> disposableItems = new DisposableCollection<SacsDisposable>())
|
||||
{
|
||||
|
||||
// Parameters.
|
||||
if (StringUtil.IsEmpty(model.DatabaseTable.Name))
|
||||
return Json(responseData.SetMessage(messageTitle, "Table name must be supplied."));
|
||||
|
||||
// Core Database connection.
|
||||
ISacsDatabase db = SaxGlobals.App.GetCoreDatabase(SessionContext);
|
||||
|
||||
// Table definition.
|
||||
DbDfnTable tableDfn = db.GetTableDfn(model.DatabaseTable.Name, true);
|
||||
if (tableDfn == null)
|
||||
return Json(responseData.SetMessage(messageTitle, "Invalid Table name supplied."));
|
||||
|
||||
// Populate table response.
|
||||
responseData.Table = new AjaxResponseData_Table(tableDfn);
|
||||
responseData.PopupTitle = Localiser["label.table"] + ": " + tableDfn.Name;
|
||||
|
||||
// Database sizing.
|
||||
String query = "Exec sp_SpaceUsed [" + tableDfn.QualifiedName + "];";
|
||||
using (DbResultSet dbResultSet = DbResultSet_DataReader.ExecuteQuery(db, query))
|
||||
{
|
||||
if (dbResultSet != null && dbResultSet.NextRecord())
|
||||
{
|
||||
// Row count.
|
||||
long rows = StringUtil.ToLong(dbResultSet.GetRecordValues().GetValue("rows").ToString());
|
||||
if (rows > 0)
|
||||
responseData.Table.Properties.Add(new AjaxResponse_Data.ItemLabelValue() { Label = "Rows", Value = rows.ToString() });
|
||||
// Reserved space.
|
||||
String reserved = dbResultSet.GetRecordValues().GetValue("reserved").AsString();
|
||||
if (!StringUtil.IsEmpty(reserved))
|
||||
responseData.Table.Properties.Add(new AjaxResponse_Data.ItemLabelValue() { Label = "Reserved", Value = reserved });
|
||||
// Data space.
|
||||
String data = dbResultSet.GetRecordValues().GetValue("data").AsString();
|
||||
if (!StringUtil.IsEmpty(data))
|
||||
responseData.Table.Properties.Add(new AjaxResponse_Data.ItemLabelValue() { Label = "Data", Value = data });
|
||||
// Index space.
|
||||
String index = dbResultSet.GetRecordValues().GetValue("index_size").AsString();
|
||||
if (!StringUtil.IsEmpty(index))
|
||||
responseData.Table.Properties.Add(new AjaxResponse_Data.ItemLabelValue() { Label = "Indices", Value = index });
|
||||
// Unused space.
|
||||
String unused = dbResultSet.GetRecordValues().GetValue("unused").AsString();
|
||||
if (!StringUtil.IsEmpty(unused))
|
||||
responseData.Table.Properties.Add(new AjaxResponse_Data.ItemLabelValue() { Label = "Unused", Value = unused });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Complete response.
|
||||
responseData.Success = true;
|
||||
return Json(responseData);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Saxonite.Net.Core.Web.Admin.Controllers
|
||||
//-------------------------------------------------------------------
|
||||
[HttpPost]
|
||||
[Route("System/Ajax/GetLogFileList")]
|
||||
public IActionResult Ajax_GetLogFileList(Model_Sport model)
|
||||
public IActionResult Ajax_GetLogFileList(Model_System model)
|
||||
{
|
||||
String fn = GetType().Name + ".Ajax_GetLogFileList";
|
||||
String messageTitle = Localiser["system.caption.logs"];
|
||||
|
||||
Reference in New Issue
Block a user