diff --git a/IoTSharp.Data.TimeSeries/ShardingStorage.cs b/IoTSharp.Data.TimeSeries/ShardingStorage.cs
index 4d904938717e08881ca604812acd94ea871cf86e..3d55fc92d9b85c98288f2e22db46d24e3d8a9a3a 100644
--- a/IoTSharp.Data.TimeSeries/ShardingStorage.cs
+++ b/IoTSharp.Data.TimeSeries/ShardingStorage.cs
@@ -1,29 +1,18 @@
using IoTSharp.Contracts;
using IoTSharp.Data;
+using IoTSharp.Data.Shardings;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using IoTSharp.Data.Shardings;
namespace IoTSharp.Storage
{
- ///
- /// 由于此模式目前无法通过EFCore.Sharding 进行Group By 获取最新遥测数据, 和Select 新对象, 所以, 最新遥测依然从DataStorage表里获取,历史从分表里获取
- /// 更多内容可以参考
- ///
public class ShardingStorage : IStorage
{
private readonly AppSettings _appSettings;
private readonly ILogger _logger;
- //private readonly IServiceScope scope;
private readonly IServiceScopeFactory _scopeFactor;
-
public ShardingStorage(ILogger logger, IServiceScopeFactory scopeFactor
, IOptions options
@@ -31,7 +20,6 @@ namespace IoTSharp.Storage
{
_appSettings = options.Value;
_logger = logger;
- //scope = scopeFactor.CreateScope();
_scopeFactor = scopeFactor;
}
@@ -53,7 +41,7 @@ namespace IoTSharp.Storage
}
catch (Exception ex)
{
- _logger.LogError(ex, $"{ deviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
+ _logger.LogError(ex, $"{deviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
throw;
}
}
@@ -77,13 +65,11 @@ namespace IoTSharp.Storage
}
catch (Exception ex)
{
- _logger.LogError(ex, $"{ deviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
+ _logger.LogError(ex, $"{deviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
throw;
}
}
-
-
public Task> LoadTelemetryAsync(Guid deviceId, string keys, DateTime begin, DateTime end, TimeSpan every, Aggregate aggregate)
{
return Task.Run(() =>
@@ -112,13 +98,12 @@ namespace IoTSharp.Storage
}
catch (Exception ex)
{
- _logger.LogError(ex, $"{ deviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
+ _logger.LogError(ex, $"{deviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
throw;
}
});
}
-
-
+
public async Task<(bool result, List telemetries)> StoreTelemetryAsync(PlayloadData msg)
{
bool result = false;
@@ -135,7 +120,7 @@ namespace IoTSharp.Storage
{
if (kp.Value != null)
{
- var tdata = new TelemetryData() { DateTime = msg.ts, DeviceId = msg.DeviceId, KeyName = kp.Key};
+ var tdata = new TelemetryData() { DateTime = msg.ts, DeviceId = msg.DeviceId, KeyName = kp.Key };
tdata.FillKVToMe(kp);
lst.Add(tdata);
telemetries.Add(tdata);
@@ -150,7 +135,6 @@ namespace IoTSharp.Storage
_logger.LogError(ex, $"{msg.DeviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
}
-
try
{
using (var scope = _scopeFactor.CreateScope())
@@ -171,7 +155,7 @@ namespace IoTSharp.Storage
{
_logger.LogError(ex, $"{msg.DeviceId}数据处理失败{ex.Message} {ex.InnerException?.Message} ");
}
- return (result,telemetries);
+ return (result, telemetries);
}
}
}
\ No newline at end of file