@@ -43,12 +43,10 @@ namespace HealthMonitor.Service.Biz.db | |||
if (conn == IntPtr.Zero) | |||
{ | |||
_logger.LogError($"连接 TDengine 失败...."); | |||
// Console.WriteLine("Connect to TDengine failed"); | |||
} | |||
else | |||
{ | |||
_logger.LogInformation($"连接 TDengine 成功...."); | |||
// Console.WriteLine("Connect to TDengine success"); | |||
} | |||
return conn; | |||
} | |||
@@ -94,20 +92,19 @@ namespace HealthMonitor.Service.Biz.db | |||
//... do something with res ... | |||
List<TDengineDriver.TDengineMeta> resMeta = LibTaos.GetMeta(res); | |||
List<Object> resData = LibTaos.GetData(res); | |||
List<object> resData = LibTaos.GetData(res); | |||
foreach (var meta in resMeta) | |||
{ | |||
Console.Write($"\t|{meta.name} {meta.TypeName()} ({meta.size})\t|"); | |||
_logger.LogInformation("\t|{meta.name} {meta.TypeName()} ({meta.size})\t|", meta.name, meta.TypeName(), meta.size); | |||
} | |||
for (int i = 0; i < resData.Count; i++) | |||
{ | |||
Console.Write($"|{resData[i].ToString()} \t"); | |||
//Console.WriteLine("{0},{1},{2}", i, resMeta.Count, (i) % resMeta.Count); | |||
_logger.LogInformation($"|{resData[i].ToString()} \t"); | |||
if (((i + 1) % resMeta.Count == 0)) | |||
{ | |||
Console.WriteLine(""); | |||
_logger.LogInformation(""); | |||
} | |||
} | |||
@@ -124,26 +121,6 @@ namespace HealthMonitor.Service.Biz.db | |||
} | |||
} | |||
//public void ExecuteInsertSQL(IntPtr conn, string sql) | |||
//{ | |||
// try | |||
// { | |||
// //sql = "INSERT INTO d1001 USING meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000) " + | |||
// // "d1002 USING power.meters TAGS('California.SanFrancisco', 3) VALUES('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000) " + | |||
// // "d1003 USING power.meters TAGS('California.LosAngeles', 2) VALUES('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000) " + | |||
// // "d1004 USING power.meters TAGS('California.LosAngeles', 3) VALUES('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000)('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)"; | |||
// IntPtr res = TDengine.Query(conn, sql); | |||
// CheckRes(conn, res, "failed to insert data"); | |||
// int affectedRows = TDengine.AffectRows(res); | |||
// Console.WriteLine("affectedRows " + affectedRows); | |||
// TDengine.FreeResult(res); | |||
// } | |||
// finally | |||
// { | |||
// TDengine.Close(conn); | |||
// } | |||
//} | |||
public void ExecuteInsertSQL(string sql) | |||
{ | |||
var conn = Connection(); | |||
@@ -156,7 +133,7 @@ namespace HealthMonitor.Service.Biz.db | |||
IntPtr res = TDengine.Query(conn, sql); | |||
CheckRes(conn, res, "failed to insert data"); | |||
int affectedRows = TDengine.AffectRows(res); | |||
Console.WriteLine("affectedRows " + affectedRows); | |||
_logger.LogInformation("affectedRows {affectedRows}" , affectedRows); | |||
TDengine.FreeResult(res); | |||
} | |||
finally | |||
@@ -175,7 +152,7 @@ namespace HealthMonitor.Service.Biz.db | |||
} | |||
else | |||
{ | |||
Console.WriteLine($"async query data failed, failed code {code}"); | |||
_logger.LogInformation("async query data failed, failed code {code}",code); | |||
} | |||
} | |||
// Iteratively call this interface until "numOfRows" is no greater than 0. | |||
@@ -183,23 +160,23 @@ namespace HealthMonitor.Service.Biz.db | |||
{ | |||
if (numOfRows > 0) | |||
{ | |||
Console.WriteLine($"{numOfRows} rows async retrieved"); | |||
_logger.LogInformation("{numOfRows} rows async retrieved", numOfRows); | |||
IntPtr pdata = TDengine.GetRawBlock(taosRes); | |||
List<TDengineMeta> metaList = TDengine.FetchFields(taosRes); | |||
List<object> dataList = LibTaos.ReadRawBlock(pdata, metaList, numOfRows); | |||
for (int i = 0; i < metaList.Count; i++) | |||
{ | |||
Console.Write("{0} {1}({2}) \t|", metaList[i].name, metaList[i].type, metaList[i].size); | |||
_logger.LogInformation("{0} {1}({2}) \t|", metaList[i].name, metaList[i].type, metaList[i].size); | |||
} | |||
Console.WriteLine(); | |||
_logger.LogInformation(""); | |||
for (int i = 0; i < dataList.Count; i++) | |||
{ | |||
if (i != 0 && i % metaList.Count == 0) | |||
{ | |||
Console.WriteLine("{0}\t|", dataList[i]); | |||
_logger.LogInformation("{dataList[i]}\t|", dataList[i]); | |||
} | |||
Console.Write("{0}\t|", dataList[i]); | |||
_logger.LogInformation("{dataList[i]}\t|", dataList[i]); | |||
} | |||
TDengine.FetchRawBlockAsync(taosRes, FetchRawBlockCallback, param); | |||
} | |||
@@ -207,11 +184,11 @@ namespace HealthMonitor.Service.Biz.db | |||
{ | |||
if (numOfRows == 0) | |||
{ | |||
Console.WriteLine("async retrieve complete."); | |||
_logger.LogInformation("async retrieve complete."); | |||
} | |||
else | |||
{ | |||
Console.WriteLine($"FetchRawBlockCallback callback error, error code {numOfRows}"); | |||
_logger.LogInformation("FetchRawBlockCallback callback error, error code {numOfRows}", numOfRows); | |||
} | |||
TDengine.FreeResult(taosRes); | |||
} | |||
@@ -63,10 +63,6 @@ namespace HealthMonitor.Service.Cache | |||
} | |||
catch (Exception ex) | |||
{ | |||
Console.WriteLine(ex.ToString() ); | |||
// _logger.LogError($"连接 TDengine 成功...."); | |||
_logger.LogError($"{nameof(GetBloodPressReferenceValueAsync)}发生异常:{ex.Message}, {ex.StackTrace}"); | |||
return new HmBloodPressReferenceValue | |||
{ | |||
@@ -1,7 +0,0 @@ | |||
namespace HealthMonitor.Service | |||
{ | |||
public class Class1 | |||
{ | |||
} | |||
} |
@@ -58,7 +58,6 @@ namespace HealthMonitor.Service.Resolver | |||
Method= topicHmBloodPress!.Method, | |||
IsDisplay=topicHmBloodPress!.IsDisplay ? 1 : 0 | |||
}; | |||
// Console.WriteLine($"SetResolveInfo" + _messageId.Value); | |||
} | |||
public override string ToString() | |||
@@ -74,21 +73,20 @@ namespace HealthMonitor.Service.Resolver | |||
#region 获取个人信息 | |||
var person = await _personCacheMgr.GetDeviceGpsPersonCacheBySerialNoAsync(bp.MessageId, bp.Serialno).ConfigureAwait(false); | |||
Console.WriteLine(person?.Person.PersonName); | |||
//验证这个信息是否存在 | |||
if (person == null || person?.Person.BornDate == null) | |||
{ | |||
Console.WriteLine("验证这个信息是否存在"); | |||
_logger.LogWarning("验证这个信息是否存在"); | |||
return; | |||
} | |||
// 验证年龄是否在范围 (2 - 120) | |||
var age = SafeType.SafeInt(DateTime.Today.Year - person?.Person.BornDate!.Value.Year!); | |||
if (age < 1 || age > 120) | |||
{ | |||
Console.WriteLine("验证年龄是否在范围 (2 - 120)"); | |||
_logger.LogWarning("验证年龄是否在范围 (2 - 120)"); | |||
return; | |||
} | |||
#endregion | |||
#endregion | |||
var gender = person?.Person.Gender == true ? 1 : 2; | |||
var isHypertension = SafeType.SafeBool(person?.Person.Ishypertension!); | |||
@@ -88,13 +88,13 @@ namespace HealthMonitor.Service.Sub | |||
var conn = TDengine.Connect(host, username, password, dbname, port); | |||
if (conn == IntPtr.Zero) | |||
{ | |||
_logger.LogError("reason:" + TDengine.Error(conn)); | |||
//throw new Exception("Connect to TDengine failed"+DateTime.Now.ToString()); | |||
_logger.LogError("reason:{TDengine.Error(conn)}", TDengine.Error(conn)); | |||
} | |||
else | |||
{ | |||
_logger.LogInformation($"连接 TDengine 成功...."); | |||
//Console.WriteLine("Connect to TDengine success"); | |||
} | |||
DoReceive(conn); | |||
} | |||
@@ -173,16 +173,15 @@ namespace HealthMonitor.Service.Sub | |||
} | |||
catch (Exception ex) | |||
{ | |||
_logger.LogError($"解析包发生异常:{ex.Message}, {ex.StackTrace}"); | |||
// Console.WriteLine(ex.Message); | |||
_logger.LogError("解析包发生异常:{ex.Message}, {ex.StackTrace}", ex.Message, ex.StackTrace); | |||
} | |||
} | |||
} | |||
} | |||
consumer.Commit(consumeRes); | |||
// Console.WriteLine("监听中...."); | |||
_logger.LogInformation($"监听中...."); | |||
_logger.LogInformation("监听中...."); | |||
} | |||
// close consumer after use.Otherwise will lead memory leak. | |||
@@ -193,15 +192,8 @@ namespace HealthMonitor.Service.Sub | |||
public void ParsePackage(ReceiveMessageModel model) | |||
{ | |||
var msg = _resolverFactory.ParseAndWrap(model); | |||
//Console.WriteLine("msg"); | |||
//cnt++; | |||
//Console.WriteLine(cnt); | |||
//Console.WriteLine(msg!.MessageId); | |||
if (msg == null) return; | |||
// ConcurrentQueue<ReceiveMessageModel> messageQueue = new ConcurrentQueue<ReceiveMessageModel>(); | |||
//_msgManager.EnqueueMsg(msg!); | |||
_msgQueueManager.Enqueue(msg); | |||
} | |||
} | |||
@@ -1,7 +0,0 @@ | |||
namespace HealthMonitor.Util | |||
{ | |||
public class Class1 | |||
{ | |||
} | |||
} |
@@ -1,57 +0,0 @@ | |||
using HealthMonitor.Service.Biz.db; | |||
using Microsoft.AspNetCore.Mvc; | |||
namespace HealthMonitor.WebApi.Controllers | |||
{ | |||
[ApiController] | |||
[Route("[controller]")] | |||
public class WeatherForecastController : ControllerBase | |||
{ | |||
private static readonly string[] Summaries = new[] | |||
{ | |||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | |||
}; | |||
private readonly ILogger<WeatherForecastController> _logger; | |||
private readonly TDengineService _serviceTDengine; | |||
public WeatherForecastController(ILogger<WeatherForecastController> logger, TDengineService serviceDengine) | |||
{ | |||
_logger = logger; | |||
_serviceTDengine = serviceDengine; | |||
} | |||
//[HttpGet(Name = "GetWeatherForecast")] | |||
//public IEnumerable<WeatherForecast> Get() | |||
//{ | |||
// return Enumerable.Range(1, 5).Select(index => new WeatherForecast | |||
// { | |||
// Date = DateTime.Now.AddDays(index), | |||
// TemperatureC = Random.Shared.Next(-20, 55), | |||
// Summary = Summaries[Random.Shared.Next(Summaries.Length)] | |||
// }) | |||
// .ToArray(); | |||
//} | |||
//[HttpGet(Name = "GetWeatherForecast")] | |||
//public async Task<IActionResult> Get() | |||
//{ | |||
// IntPtr conn = _serviceTDengine.Connection(); | |||
// var sql = "select * from gps_bloodpress"; | |||
// //Task.Factory.StartNew(async () => | |||
// //{ | |||
// // await _serviceTDengine.ExecuteQuerySQL(conn, sql); | |||
// //}); | |||
// _serviceTDengine.ExecuteQuerySQL(conn, sql); | |||
// //var res= await _serviceAliIot.QueryDeviceStatisticseAsync(nameof(Get)); | |||
// //var online = res?.OnlineCount; | |||
// return Ok("aa"); | |||
//} | |||
} | |||
} |
@@ -34,8 +34,8 @@ namespace HealthMonitor.WebApi | |||
catch (Exception ex) | |||
{ | |||
//Console.WriteLine(ex.Message); | |||
_logger.LogError($"未处理异常 message: {ex.Message}\n {ex.StackTrace}"); | |||
_logger.LogError("未处理异常 message: {ex.Message}\n {ex.StackTrace}", ex.Message, ex.StackTrace); | |||
} | |||
return true; | |||
@@ -1,13 +0,0 @@ | |||
namespace HealthMonitor.WebApi | |||
{ | |||
public class WeatherForecast | |||
{ | |||
public DateTime Date { get; set; } | |||
public int TemperatureC { get; set; } | |||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | |||
public string? Summary { get; set; } | |||
} | |||
} |
@@ -1,10 +1,5 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Information", | |||
"Microsoft.AspNetCore": "Warning" | |||
} | |||
}, | |||
"AllowedHosts": "*", | |||
"TDengineServiceConfig": { | |||
"Host": "47.116.142.20", | |||
"UserName": "root", | |||
@@ -23,7 +18,7 @@ | |||
"DefaultDatabase": 2, | |||
"Prefix": "_HM_", | |||
//"DefaultDatabase": 7, | |||
// "Prefix": "TELPO", | |||
// "Prefix": "TELPO", | |||
"Poolsize": 50, | |||
"ConnectTimeout": 5000, | |||
@@ -8,23 +8,22 @@ | |||
} | |||
}, | |||
"Serilog": { | |||
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Console", "Serilog.Expressions" ], | |||
"Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Async", "Serilog.Sinks.Console", "Serilog.Expressions" ], | |||
"MinimumLevel": { | |||
"Default": "Information", | |||
"Default": "Verbose", | |||
"Override": { | |||
"Microsoft": "Warning", | |||
"System": "Warning" | |||
"Microsoft.Hosting.Lifetime": "Information", | |||
"HttpClient": "Information" | |||
} | |||
}, | |||
"Enrich": [ | |||
"FromLogContext", | |||
"WithThreadId" | |||
], | |||
"WriteTo": [ | |||
{ | |||
"Name": "Console", | |||
"Args": { | |||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}] [Thread-{ThreadId}] [{SourceContext:l}] [{RequestId}]{NewLine}{Message}{NewLine}" | |||
"restrictedToMinimumLevel": "Verbose", | |||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff }[{Level:u3}] [Thread-{ThreadId}] [{SourceContext:l}] [{RequestId}] {Message:lj}{NewLine}{Exception}", | |||
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console" | |||
} | |||
}, | |||
{ | |||
@@ -35,13 +34,14 @@ | |||
{ | |||
"Name": "File", | |||
"Args": { | |||
"restrictedToMinimumLevel": "Information", | |||
"path": "/var/health_monitor/logs/infos/info.log", | |||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}] [Thread-{ThreadId}] [{SourceContext:l}] [{RequestId}] {Message}{NewLine}{Exception}", | |||
//"fileSizeLimitBytes": 524288000, | |||
"rollingInterval": "Day", | |||
"rollOnFileSizeLimit": "true", | |||
"retainedFileCountLimit": 7 | |||
"RestrictedToMinimumLevel": "Information", | |||
"RollingInterval": "Day", | |||
"RollOnFileSizeLimit": "true", | |||
"OutputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff }[{Level:u3}] [Thread-{ThreadId}] [{SourceContext:l}] [{RequestId}] {Message:lj}{NewLine}{Exception}", | |||
"Path": "/var/health_monitor/logs/infos/info.log", | |||
"RetainedFileCountLimit": 10 // "--设置日志文件个数最大值,默认31,意思就是只保留最近的31个日志文件", "等于null时永远保留文件": null | |||
//"FileSizeLimitBytes": 20971520, //设置单个文件大小为3M 默认1G | |||
//"RollOnFileSizeLimit": true //超过文件大小后创建新的 | |||
} | |||
} | |||
], | |||
@@ -92,13 +92,15 @@ | |||
{ | |||
"Name": "File", | |||
"Args": { | |||
"restrictedToMinimumLevel": "Error", | |||
"path": "/var/health_monitor/logs/errors/error.log", | |||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}] [Thread-{ThreadId}] [{SourceContext:l}] [{RequestId}] {Message}{NewLine}{Exception}", | |||
//"fileSizeLimitBytes": 524288000, | |||
"rollingInterval": "Day", | |||
"rollOnFileSizeLimit": "true", | |||
"retainedFileCountLimit": 7 | |||
"RestrictedToMinimumLevel": "Error", | |||
"RollingInterval": "Day", | |||
"RollOnFileSizeLimit": "true", | |||
"OutputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff }[{Level:u3}] [Thread-{ThreadId}][{SourceContext:l}] [{RequestId}] {Message:lj}{NewLine}{Exception}", | |||
"Path": "/var/health_monitor/logs/errors/error.log", | |||
"RetainedFileCountLimit": 15 // "--设置日志文件个数最大值,默认31,意思就是只保留最近的31个日志文件", "等于null时永远保留文件": null | |||
//"FileSizeLimitBytes": 20971520, //设置单个文件大小为3M 默认1G | |||
//"RollOnFileSizeLimit": true //超过文件大小后创建新的 | |||
} | |||
} | |||
], | |||
@@ -114,12 +116,5 @@ | |||
} | |||
} | |||
] | |||
}, | |||
//"Logging": { | |||
// "LogLevel": { | |||
// "Default": "Information", | |||
// "Microsoft.AspNetCore": "Warning" | |||
// } | |||
//}, | |||
"AllowedHosts": "*" | |||
} | |||
} |