80 lines
3.1 KiB
C#
80 lines
3.1 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 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 TBEDM_XML_ITEMS WHERE SPECIFICATION = '{0}' AND ACTIVE = True ORDER BY XML_PATH";
|
|
|
|
public MSSQLServer MSSQL { get; set; }
|
|
public Firebird Firebird { get; set; }
|
|
|
|
public Database(ILogging Logging, IConfiguration Config)
|
|
{
|
|
var oLogConfig = Logging.LogConfig;
|
|
var oLogger = Logging.LogConfig.GetLogger();
|
|
var oAppConfig = Config.GetSection("Config");
|
|
var oFirebirdConfig = oAppConfig.GetSection("Firebird");
|
|
|
|
oLogger.Debug("Establishing MSSQL Database connection..");
|
|
MSSQL = new MSSQLServer(oLogConfig, oAppConfig["MSSQLConnectionString"]);
|
|
|
|
oLogger.Debug("Establishing Firebird Database connection..");
|
|
Firebird = new Firebird(oLogConfig,
|
|
oFirebirdConfig["Datasource"],
|
|
oFirebirdConfig["Database"],
|
|
oFirebirdConfig["Username"],
|
|
oFirebirdConfig["Password"]);
|
|
|
|
oLogger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
|
oLogger.Debug("Firebird Connection: [{0}]", Firebird.ConnectionString);
|
|
}
|
|
|
|
public string GetGDPictureKey()
|
|
{
|
|
if (_gdPictureKey == null)
|
|
_gdPictureKey = MSSQL.GetScalarValue(QUERY_GET_GDPICTURE_KEY).ToString();
|
|
|
|
return _gdPictureKey;
|
|
}
|
|
|
|
public Dictionary<String, XmlItemProperty> GetPropertyMap()
|
|
{
|
|
if (_propertyMap == null)
|
|
{
|
|
_propertyMap = new Dictionary<string, XmlItemProperty>();
|
|
var oDatatable = Firebird.GetDatatable(string.Format(QUERY_GET_PROPERTY_MAP, "DEFAULT"));
|
|
|
|
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"]
|
|
});
|
|
}
|
|
}
|
|
|
|
return _propertyMap;
|
|
}
|
|
}
|
|
}
|