mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 优化 Console.Write 平台兼容问题;#643
This commit is contained in:
parent
7379050bfd
commit
fd770e06b1
@ -49,7 +49,7 @@ namespace FreeSql.Extensions.LazyLoading
|
||||
if (!dll.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) &&
|
||||
!dll.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) continue;
|
||||
|
||||
Console.WriteLine(dll);
|
||||
//Console.WriteLine(dll);
|
||||
var dllName = string.Empty;
|
||||
var idx = dll.LastIndexOf('/');
|
||||
if (idx != -1) dllName = dll.Substring(idx + 1);
|
||||
|
@ -4316,7 +4316,7 @@
|
||||
</summary>
|
||||
<param name="policy">策略</param>
|
||||
</member>
|
||||
<member name="M:FreeSql.Internal.ObjectPool.ObjectPool`1.getFree(System.Boolean)">
|
||||
<member name="M:FreeSql.Internal.ObjectPool.ObjectPool`1.GetFree(System.Boolean)">
|
||||
<summary>
|
||||
获取可用资源,或创建资源
|
||||
</summary>
|
||||
|
@ -33,7 +33,6 @@ namespace FreeSql.Internal.ObjectPool
|
||||
|
||||
public void OnGet(Object<T> obj)
|
||||
{
|
||||
//Console.WriteLine("Get: " + obj);
|
||||
OnGetObject?.Invoke(obj);
|
||||
}
|
||||
|
||||
@ -41,7 +40,6 @@ namespace FreeSql.Internal.ObjectPool
|
||||
#else
|
||||
public Task OnGetAsync(Object<T> obj)
|
||||
{
|
||||
//Console.WriteLine("GetAsync: " + obj);
|
||||
OnGetObject?.Invoke(obj);
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
@ -54,7 +52,6 @@ namespace FreeSql.Internal.ObjectPool
|
||||
|
||||
public void OnReturn(Object<T> obj)
|
||||
{
|
||||
//Console.WriteLine("Return: " + obj);
|
||||
}
|
||||
|
||||
public bool OnCheckAvailable(Object<T> obj)
|
||||
|
@ -9,6 +9,40 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql.Internal.ObjectPool
|
||||
{
|
||||
internal class TestTrace
|
||||
{
|
||||
internal static void WriteLine(string text, ConsoleColor backgroundColor)
|
||||
{
|
||||
try //#643
|
||||
{
|
||||
var bgcolor = Console.BackgroundColor;
|
||||
var forecolor = Console.ForegroundColor;
|
||||
Console.BackgroundColor = backgroundColor;
|
||||
|
||||
switch (backgroundColor)
|
||||
{
|
||||
case ConsoleColor.Yellow:
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
break;
|
||||
case ConsoleColor.DarkGreen:
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
break;
|
||||
}
|
||||
Console.Write(text);
|
||||
Console.BackgroundColor = bgcolor;
|
||||
Console.ForegroundColor = forecolor;
|
||||
Console.WriteLine();
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(text);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象池管理类
|
||||
@ -74,16 +108,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
{
|
||||
|
||||
if (UnavailableException != null)
|
||||
{
|
||||
var bgcolor = Console.BackgroundColor;
|
||||
var forecolor = Console.ForegroundColor;
|
||||
Console.BackgroundColor = ConsoleColor.DarkYellow;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write($"【{Policy.Name}】恢复检查时间:{DateTime.Now.AddSeconds(interval)}");
|
||||
Console.BackgroundColor = bgcolor;
|
||||
Console.ForegroundColor = forecolor;
|
||||
Console.WriteLine();
|
||||
}
|
||||
TestTrace.WriteLine($"【{Policy.Name}】恢复检查时间:{DateTime.Now.AddSeconds(interval)}", ConsoleColor.DarkYellow);
|
||||
|
||||
while (UnavailableException != null)
|
||||
{
|
||||
@ -97,7 +122,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
try
|
||||
{
|
||||
|
||||
var conn = getFree(false);
|
||||
var conn = GetFree(false);
|
||||
if (conn == null) throw new Exception($"CheckAvailable 无法获得资源,{this.Statistics}");
|
||||
|
||||
try
|
||||
@ -116,14 +141,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var bgcolor = Console.BackgroundColor;
|
||||
var forecolor = Console.ForegroundColor;
|
||||
Console.BackgroundColor = ConsoleColor.DarkYellow;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write($"【{Policy.Name}】仍然不可用,下一次恢复检查时间:{DateTime.Now.AddSeconds(interval)},错误:({ex.Message})");
|
||||
Console.BackgroundColor = bgcolor;
|
||||
Console.ForegroundColor = forecolor;
|
||||
Console.WriteLine();
|
||||
TestTrace.WriteLine($"【{Policy.Name}】仍然不可用,下一次恢复检查时间:{DateTime.Now.AddSeconds(interval)},错误:({ex.Message})", ConsoleColor.DarkYellow);
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,14 +178,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
|
||||
Policy.OnAvailable();
|
||||
|
||||
var bgcolor = Console.BackgroundColor;
|
||||
var forecolor = Console.ForegroundColor;
|
||||
Console.BackgroundColor = ConsoleColor.DarkGreen;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write($"【{Policy.Name}】已恢复工作");
|
||||
Console.BackgroundColor = bgcolor;
|
||||
Console.ForegroundColor = forecolor;
|
||||
Console.WriteLine();
|
||||
TestTrace.WriteLine($"【{Policy.Name}】已恢复工作", ConsoleColor.DarkGreen);
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +188,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
try
|
||||
{
|
||||
|
||||
var conn = getFree(false);
|
||||
var conn = GetFree(false);
|
||||
if (conn == null) throw new Exception($"LiveCheckAvailable 无法获得资源,{this.Statistics}");
|
||||
|
||||
try
|
||||
@ -260,7 +271,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
/// 获取可用资源,或创建资源
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private Object<T> getFree(bool checkAvailable)
|
||||
private Object<T> GetFree(bool checkAvailable)
|
||||
{
|
||||
|
||||
if (running == false)
|
||||
@ -300,7 +311,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
public Object<T> Get(TimeSpan? timeout = null)
|
||||
{
|
||||
|
||||
var obj = getFree(true);
|
||||
var obj = GetFree(true);
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
@ -357,7 +368,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
async public Task<Object<T>> GetAsync()
|
||||
{
|
||||
|
||||
var obj = getFree(true);
|
||||
var obj = GetFree(true);
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
|
@ -1,21 +0,0 @@
|
||||
case DataType.Firebird:
|
||||
type = Type.GetType("FreeSql.Firebird.FirebirdProvider`1,FreeSql.Provider.Firebird")?.MakeGenericType(typeof(TMark));
|
||||
if (type == null) throwNotFind("FreeSql.Provider.Firebird.dll", "FreeSql.Firebird.FirebirdProvider<>");
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
static Lazy<IFreeSql> firebirdLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5")
|
||||
//.UseConnectionFactory(FreeSql.DataType.Firebird, () => new FirebirdSql.Data.FirebirdClient.FbConnection(@"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5"))
|
||||
.UseAutoSyncStructure(true)
|
||||
.UseLazyLoading(true)
|
||||
.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
|
||||
//.UseNoneCommandParameter(true)
|
||||
|
||||
.UseMonitorCommand(
|
||||
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象,在执行前
|
||||
(cmd, traceLog) => Console.WriteLine(traceLog))
|
||||
.Build());
|
||||
public static IFreeSql firebird => firebirdLazy.Value;
|
Loading…
x
Reference in New Issue
Block a user