提交 6fa70f3d 编写于 作者: 麦壳饼's avatar 麦壳饼

镜像内加入工具

上级 58bf9aa3
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free" > /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
apt-get -y -q update && apt-get install -y -q apt-utils libgdiplus libc6-dev lsof net-tools wget sqlite3 python3 bashtop && \
apt-get autoremove -y && apt-get clean && apt-get autoclean && rm /var/cache/apt/* -rf && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN curl -o TDengine-client.tar.gz https://www.taosdata.com/download/download-gettingStarted.php?pkg=tdengine_linux && \ RUN curl -o TDengine-client.tar.gz https://www.taosdata.com/download/download-gettingStarted.php?pkg=tdengine_linux && \
tar -xzvf TDengine-client.tar.gz && rm TDengine-client.tar.gz -f && cd $(ls TDengine-client* -d) && ./install_client.sh && \ tar -xzvf TDengine-client.tar.gz && rm TDengine-client.tar.gz -f && cd $(ls TDengine-client* -d) && ./install_client.sh && \
rm $(pwd) -rf rm $(pwd) -rf
......
...@@ -253,9 +253,9 @@ namespace IoTSharp.Handlers ...@@ -253,9 +253,9 @@ namespace IoTSharp.Handlers
{ {
try try
{ {
var _xdev = _device.Get<Device>(args.ClientId); if (_device.Exists(args.ClientId))
if (_xdev.HasValue)
{ {
var _xdev = _device.Get<Device>(args.ClientId);
var dev = _xdev.Value; var dev = _xdev.Value;
using (var scope = _scopeFactor.CreateScope()) using (var scope = _scopeFactor.CreateScope())
using (var _dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>()) using (var _dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>())
...@@ -269,7 +269,7 @@ namespace IoTSharp.Handlers ...@@ -269,7 +269,7 @@ namespace IoTSharp.Handlers
} }
else else
{ {
_logger.LogError($"Server_ClientDisconnected ClientId:{args.ClientId} DisconnectType:{args.DisconnectType}, 未能在缓存中找到"); _logger.LogWarning($"Server_ClientDisconnected ClientId:{args.ClientId} DisconnectType:{args.DisconnectType}, 未能在缓存中找到");
} }
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -60,7 +60,12 @@ namespace IoTSharp ...@@ -60,7 +60,12 @@ namespace IoTSharp
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
var settings = Configuration.Get<AppSettings>();
var settings= Configuration.Get<AppSettings>();
services.Configure((Action<AppSettings>)(setting =>
{
Configuration.Bind(setting);
}));
services.AddDbContextPool<ApplicationDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("IoTSharp")), poolSize: settings.DbContextPoolSize); services.AddDbContextPool<ApplicationDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("IoTSharp")), poolSize: settings.DbContextPoolSize);
services.AddIdentity<IdentityUser, IdentityRole>() services.AddIdentity<IdentityUser, IdentityRole>()
.AddRoles<IdentityRole>() .AddRoles<IdentityRole>()
......
...@@ -62,8 +62,10 @@ namespace IoTSharp.Storage ...@@ -62,8 +62,10 @@ namespace IoTSharp.Storage
{ {
using (TaosConnection db = new TaosConnection(_taosBuilder.ConnectionString)) using (TaosConnection db = new TaosConnection(_taosBuilder.ConnectionString))
{ {
db.Open();
string sql = $"select last_row(*) from telemetrydata where deviceid='{deviceId:N}' group by deviceid,keyname"; string sql = $"select last_row(*) from telemetrydata where deviceid='{deviceId:N}' group by deviceid,keyname";
List<TelemetryDataDto> dt = SqlToTDD(db, sql, "last_row(", ")", string.Empty); List<TelemetryDataDto> dt = SqlToTDD(db, sql, "last_row(", ")", string.Empty);
db.Close();
return Task.FromResult(dt); return Task.FromResult(dt);
} }
} }
...@@ -119,10 +121,12 @@ namespace IoTSharp.Storage ...@@ -119,10 +121,12 @@ namespace IoTSharp.Storage
{ {
using (TaosConnection db = new TaosConnection(_taosBuilder.ConnectionString)) using (TaosConnection db = new TaosConnection(_taosBuilder.ConnectionString))
{ {
db.Open();
IEnumerable<string> kvs = from k in keys IEnumerable<string> kvs = from k in keys
select $" keyname = '{k}' "; select $" keyname = '{k}' ";
string sql = $"select last_row(*) from telemetrydata where deviceid='{deviceId:N}' and ({string.Join("or", kvs) }) group by deviceid,keyname"; string sql = $"select last_row(*) from telemetrydata where deviceid='{deviceId:N}' and ({string.Join("or", kvs) }) group by deviceid,keyname";
List<TelemetryDataDto> dt = SqlToTDD(db, sql, "last_row(", ")", string.Empty); List<TelemetryDataDto> dt = SqlToTDD(db, sql, "last_row(", ")", string.Empty);
db.Close();
return Task.FromResult(dt); return Task.FromResult(dt);
} }
} }
...@@ -148,10 +152,12 @@ namespace IoTSharp.Storage ...@@ -148,10 +152,12 @@ namespace IoTSharp.Storage
{ {
using (TaosConnection db = new TaosConnection(_taosBuilder.ConnectionString)) using (TaosConnection db = new TaosConnection(_taosBuilder.ConnectionString))
{ {
db.Open();
IEnumerable<string> kvs = from k in keys IEnumerable<string> kvs = from k in keys
select $" keyname = '{k}' "; select $" keyname = '{k}' ";
string sql = $"select tbname,keyname from telemetrydata where deviceid='{deviceId:N}' and ({string.Join("or", kvs) }) "; string sql = $"select tbname,keyname from telemetrydata where deviceid='{deviceId:N}' and ({string.Join("or", kvs) }) ";
List<TelemetryDataDto> dt = SQLToDTByDate(begin, end, db, sql); List<TelemetryDataDto> dt = SQLToDTByDate(begin, end, db, sql);
db.Close();
return Task.FromResult(dt); return Task.FromResult(dt);
} }
} }
...@@ -165,8 +171,10 @@ namespace IoTSharp.Storage ...@@ -165,8 +171,10 @@ namespace IoTSharp.Storage
{ {
using (TaosConnection db = new TaosConnection(_taosBuilder.ConnectionString)) using (TaosConnection db = new TaosConnection(_taosBuilder.ConnectionString))
{ {
db.Open();
string sql = $"select tbname,keyname from telemetrydata where deviceid='{deviceId:N}'"; string sql = $"select tbname,keyname from telemetrydata where deviceid='{deviceId:N}'";
List<TelemetryDataDto> dt = SQLToDTByDate(begin, end, db, sql); List<TelemetryDataDto> dt = SQLToDTByDate(begin, end, db, sql);
db.Close();
return Task.FromResult(dt); return Task.FromResult(dt);
} }
} }
...@@ -230,18 +238,27 @@ namespace IoTSharp.Storage ...@@ -230,18 +238,27 @@ namespace IoTSharp.Storage
lst.Add(vals); lst.Add(vals);
} }
}); });
await Retry.RetryOnAny(10, async f =>
try
{ {
db.Open(); db.Open();
var cmd = db.CreateCommand($"INSERT INTO {string.Join("\r\n", lst)}"); var cmd = db.CreateCommand($"INSERT INTO {string.Join("\r\n", lst)}");
_logger.LogInformation(cmd.CommandText); _logger.LogInformation(cmd.CommandText);
int dt = await cmd.ExecuteNonQueryAsync(); int dt = await cmd.ExecuteNonQueryAsync();
db.Close(); db.Close();
_logger.LogInformation($"数据入库完成,共数据{lst.Count}条,写入{dt}条"); _logger.LogInformation($"数据入库完成,共数据{lst.Count}条,写入{dt}条");
}, ef => }
{ catch (Exception ex)
_logger.LogError(ef.ex, $"{msg.DeviceId}数据处理第{ef.current}次失败{ef.ex.Message} {ef.ex.InnerException?.Message} "); {
}); _logger.LogError(ex, $"{msg.DeviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
}
finally
{
db.Dispose();
}
} }
} }
catch (TaosException ex) catch (TaosException ex)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册