38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
|
|
namespace Net.Data
|
|
{
|
|
public class LocalData
|
|
{
|
|
public static string ConnectionString { get; private set; }
|
|
|
|
// Esquema HANA: por defecto la compañia del Service Layer (SapServiceLayer:company)
|
|
public static string Schema { get; private set; }
|
|
|
|
// Unico punto de lectura de las credenciales HANA (seccion "Hana" de appsettings.json)
|
|
public static void Configure(IConfiguration configuration)
|
|
{
|
|
var server = configuration["Hana:server"];
|
|
var user = configuration["Hana:user"];
|
|
var password = configuration["Hana:password"];
|
|
|
|
if (string.IsNullOrWhiteSpace(server) || string.IsNullOrWhiteSpace(user) || string.IsNullOrEmpty(password))
|
|
{
|
|
throw new InvalidOperationException("Falta la seccion \"Hana\" (server, user, password) en appsettings.json");
|
|
}
|
|
|
|
ConnectionString = $"Server={server};UserName={user};Password={password}";
|
|
|
|
var schema = configuration["Hana:schema"];
|
|
if (string.IsNullOrWhiteSpace(schema)) schema = configuration["SapServiceLayer:company"];
|
|
if (string.IsNullOrWhiteSpace(schema))
|
|
{
|
|
throw new InvalidOperationException("Falta el esquema HANA: configure Hana:schema o SapServiceLayer:company en appsettings.json");
|
|
}
|
|
|
|
Schema = schema;
|
|
}
|
|
}
|
|
}
|