mh_frame_sps/APT.Infrastructure.EF/Infrastructure/CombindedConnectionGenerator.cs

71 lines
2.6 KiB
C#
Raw Permalink Normal View History

2026-04-07 13:47:52 +08:00
using System;
using System.Collections.Generic;
using System.Net.Http;
using APT.Infrastructure.EF;
using Microsoft.Extensions.Configuration;
using APT.Infrastructure.Api;
using System.Configuration;
namespace APT.Infrastructure.EF
{
public class CombindedConnectionGenerator : IConnectionGenerator
{
static Lazy<Random> random = new Lazy<Random>();
private readonly IConfiguration configuration;
public string TenantKey => "";
public string defaultstr = "User ID=postgres;Password=123456;Host=192.168.2.98;Port=5432;Database=opt_energy;CommandTimeout=1024;";
public CombindedConnectionGenerator(IConfiguration configuration)
{
this.configuration = configuration;
}
public string GetConnection(TenantOption option, TenantInfo tenantInfo)
{
if (tenantInfo == null)
tenantInfo = new TenantInfo();
if (string.IsNullOrEmpty(tenantInfo?.Conn))
tenantInfo.Conn = defaultstr;
return tenantInfo.Conn;
//var webapiUrl = "http://localhost:5001/api/DbConfigs";
//var httpResponseMsg = new HttpResponseMessage();
//using (var httpClient = new HttpClient())
//{
// httpResponseMsg = httpClient.GetAsync(webapiUrl).Result;
// var retrnUrl = httpResponseMsg.Content.ReadAsStringAsync().Result;
// dynamic urls = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(retrnUrl);
// if (urls != null)
// {
// List<dynamic> connList = new List<dynamic>();
// foreach (dynamic url in urls)
// {
// if (url.name == span)
// {
// connList.Add(url.conn);
// }
// }
// if (connList.Count > 0)
// {
// var mod = (random.Value.Next(100) % connList.Count);
// return connList[mod];
// }
// }
//}
//if (span.Length > 4 && int.TryParse(span[5].ToString(), out var number))
//{
//var mod = (random.Value.Next(1000) % 3)+1;
// return configuration.GetConnectionString($"{option.ConnectionPrefix}{mod}");
//}
throw new NotSupportedException("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}//
public bool MatchTenantKey(string tenantKey)
{
return true;
}
}
}