The cloud manager acts as an intermediary for syncing between the local biskilog server manager and the biskilog accounting web application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.0 KiB

1 year ago
using Cloud_Manager;
using Cloud_Manager.Models.ClientContractModels;
using Cloud_Manager.Models.Enums;
using Cloud_Manager.Models.Interfaces;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace Cloud_Manager.Services
{
public class ConnectionService : IConnectionService
{
private readonly BiskilogContext m_context;
private readonly IConfiguration m_configuration;
public ConnectionService(BiskilogContext a_context, IConfiguration configuration)
{
m_context = a_context;
m_configuration = configuration;
}
/// <summary>
/// Prepares and returns the connection string for a client using the specified database id
/// </summary>
/// <param name="a_databaseId">Specified database id to use</param>
/// <returns></returns>
public string GetClientConnectionString(int a_databaseId)
{
Databasemap? dbMap = m_context.Databasemaps.Find(a_databaseId);
if (dbMap != null)
{
string rawConString = m_configuration.GetConnectionString("PrivateConnection")!.ToString();
return string.Format(rawConString, dbMap.Domain, dbMap.DbName);
}
return ConnectionEnums.ConnectionNotEstablished.ToString();
}
/// <summary>
/// Prepare the DB context from the specified connection string
/// </summary>
/// <param name="a_context"></param>
/// <param name="a_connectionString"></param>
/// <returns>A configured BiskAcdbContext</returns>
public object PrepareDBContext(string a_connectionString)
{
throw new NotImplementedException();
//DbContextOptionsBuilder<BiskAcdbContext> acdbContext = new DbContextOptionsBuilder<BiskAcdbContext>();
//acdbContext.UseMySql(a_connectionString, new MariaDbServerVersion(new Version()));
//return new BiskAcdbContext(acdbContext.Options);
}
}
}