66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Net.Http;
|
||
using APT.Infrastructure.Api;
|
||
using APT.Infrastructure.EF;
|
||
using Microsoft.Extensions.Configuration;
|
||
|
||
namespace APT.API
|
||
{
|
||
public class CombindedConnectionGenerator : IConnectionGenerator
|
||
{
|
||
static Lazy<Random> random = new Lazy<Random>();
|
||
private readonly IConfiguration configuration;
|
||
public string TenantKey => "";
|
||
|
||
public CombindedConnectionGenerator(IConfiguration configuration)
|
||
{
|
||
this.configuration = configuration;
|
||
}
|
||
|
||
|
||
public string GetConnection(TenantOption option, TenantInfo tenantInfo)
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
} |