83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using DigitalData.Modules.Database;
|
|
using DigitalData.Modules.Interfaces;
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZUGFeRDRESTService
|
|
{
|
|
public class Database: IDatabase
|
|
{
|
|
private DigitalData.Modules.Logging.Logger _Logger = null;
|
|
private string _gdPictureKey = null;
|
|
private Dictionary<string, XmlItemProperty> _propertyMap = null;
|
|
|
|
private const string QUERY_GET_GDPICTURE_KEY = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'";
|
|
private const string QUERY_GET_PROPERTY_MAP = "SELECT * FROM TBDD_ZUGFERD_XML_ITEMS WHERE ACTIVE = 1 ORDER BY XML_PATH";
|
|
|
|
public MSSQLServer MSSQL { get; set; }
|
|
|
|
public Database(ILogging Logging, IConfiguration Config)
|
|
{
|
|
var oLogConfig = Logging.LogConfig;
|
|
var oLogger = Logging.LogConfig.GetLogger();
|
|
var oAppConfig = Config.GetSection("Config");
|
|
|
|
oLogger.Debug("Establishing MSSQL Database connection..");
|
|
MSSQL = new MSSQLServer(oLogConfig, oAppConfig["MSSQLConnectionString"]);
|
|
|
|
oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
|
|
|
_Logger = oLogger;
|
|
}
|
|
|
|
public string GetGDPictureKey()
|
|
{
|
|
if (_gdPictureKey == null)
|
|
_gdPictureKey = MSSQL.GetScalarValue(QUERY_GET_GDPICTURE_KEY).ToString();
|
|
|
|
return _gdPictureKey;
|
|
}
|
|
|
|
public Dictionary<string, XmlItemProperty> GetPropertyMap()
|
|
{
|
|
if (_propertyMap == null)
|
|
{
|
|
_Logger.Debug("Property map does not exist, creating.");
|
|
|
|
_propertyMap = new Dictionary<string, XmlItemProperty>();
|
|
var oDatatable = MSSQL.GetDatatable(QUERY_GET_PROPERTY_MAP);
|
|
|
|
_Logger.Debug("Datatable Rows: [{0}]", oDatatable.Rows);
|
|
|
|
foreach (DataRow oRow in oDatatable.Rows)
|
|
{
|
|
_propertyMap.Add(oRow["XML_PATH"].ToString(), new XmlItemProperty()
|
|
{
|
|
Description = oRow["DESCRIPTION"].ToString(),
|
|
TableName = oRow["TABLE_NAME"].ToString(),
|
|
TableColumn = oRow["TABLE_COLUMN"].ToString(),
|
|
GroupScope = oRow["GROUP_SCOPE"].ToString(),
|
|
IsRequired = (bool)oRow["IS_REQUIRED"],
|
|
IsGrouped = (bool)oRow["IS_GROUPED"],
|
|
Specification = oRow["SPECIFICATION"].ToString()
|
|
});
|
|
}
|
|
} else
|
|
{
|
|
_Logger.Debug("Property map already exists, returning.");
|
|
}
|
|
|
|
_Logger.Debug("Returning Property Map with [{0}] entries.", _propertyMap.Count);
|
|
|
|
return _propertyMap;
|
|
}
|
|
}
|
|
}
|