Очистка кода

This commit is contained in:
KharchenkoVV 2021-05-19 15:21:19 +05:00
parent b39be3547c
commit e3c916bc42
10 changed files with 26 additions and 32 deletions

View File

@ -154,7 +154,7 @@ namespace AsbCloudDb.Model
FillData(modelBuilder); FillData(modelBuilder);
} }
private void FillData(ModelBuilder modelBuilder) private static void FillData(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<Deposit>(entity => modelBuilder.Entity<Deposit>(entity =>
{ {
@ -210,9 +210,9 @@ namespace AsbCloudDb.Model
}).FirstOrDefault(); }).FirstOrDefault();
if (datesRange is null) if (datesRange is null)
return (From: DateTime.MinValue, To: DateTime.MaxValue); return (DateTime.MinValue, DateTime.MaxValue);
return (From: datesRange.From, To: datesRange.To); return (datesRange.From, datesRange.To);
} }
public async Task<int> CreatePartitionAsync<TEntity>(string propertyName, int id, CancellationToken token = default) public async Task<int> CreatePartitionAsync<TEntity>(string propertyName, int id, CancellationToken token = default)

View File

@ -4,6 +4,10 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;IDE0090;IDE0063</NoWarn>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" /> <PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="itext7" Version="7.1.15" /> <PackageReference Include="itext7" Version="7.1.15" />

View File

@ -128,7 +128,7 @@ namespace AsbCloudInfrastructure.Services
return 0; return 0;
} }
private string MakeToken(IEnumerable<Claim> claims) private static string MakeToken(IEnumerable<Claim> claims)
{ {
var now = DateTime.Now; var now = DateTime.Now;

View File

@ -6,7 +6,7 @@ namespace AsbCloudInfrastructure.Services
{ {
class BackgroundQueue : IBackgroundQueue class BackgroundQueue : IBackgroundQueue
{ {
private ConcurrentQueue<(Action action, int id)> tasks = private readonly ConcurrentQueue<(Action action, int id)> tasks =
new ConcurrentQueue<(Action action, int id)>(); new ConcurrentQueue<(Action action, int id)>();
private int id = 0; private int id = 0;

View File

@ -21,7 +21,7 @@ namespace AsbCloudInfrastructure.Services
while (!token.IsCancellationRequested) while (!token.IsCancellationRequested)
{ {
if (tasksQueue.TryDequeue(out var item)) if (tasksQueue.TryDequeue(out var item))
await Task.Run(item.action); await Task.Run(item.action, token);
else else
await Task.Delay(100, token); await Task.Delay(100, token);
} }

View File

@ -68,7 +68,7 @@ namespace AsbCloudInfrastructure.Services
public void UpdateData(string uid, IEnumerable<DataSaubBaseDto> dtos) public void UpdateData(string uid, IEnumerable<DataSaubBaseDto> dtos)
{ {
if (dtos == default || dtos.Count() <= 0) if (dtos == default || dtos.Any())
return; return;
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid); var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
@ -102,9 +102,9 @@ namespace AsbCloudInfrastructure.Services
if (telemetry is null) if (telemetry is null)
return null; return null;
var result = db.GetDatesRange<DataSaubBase>(telemetry.Id); var (From, To) = db.GetDatesRange<DataSaubBase>(telemetry.Id);
return new DatesRangeDto { From = result.From, To = result.To}; return new DatesRangeDto { From = From, To = To};
} }
} }
} }

View File

@ -17,8 +17,6 @@ namespace AsbCloudInfrastructure.Services
private readonly IMapper mapper; private readonly IMapper mapper;
private readonly ICacheTable<Event> cacheEvents; private readonly ICacheTable<Event> cacheEvents;
private readonly ICacheTable<TelemetryUser> cacheTUsers; private readonly ICacheTable<TelemetryUser> cacheTUsers;
private readonly ICacheTable<Telemetry> cacheTelemetry;
private readonly ICacheTable<Well> cacheWells;
public MessageService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService, MapperConfiguration mapperConfiguration) public MessageService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService, MapperConfiguration mapperConfiguration)
{ {
@ -27,8 +25,6 @@ namespace AsbCloudInfrastructure.Services
mapper = mapperConfiguration.CreateMapper(); mapper = mapperConfiguration.CreateMapper();
cacheEvents = cacheDb.GetCachedTable<Event>((AsbCloudDbContext)db); cacheEvents = cacheDb.GetCachedTable<Event>((AsbCloudDbContext)db);
cacheTUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db); cacheTUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db);
cacheTelemetry = cacheDb.GetCachedTable<Telemetry>((AsbCloudDbContext)db);
cacheWells = cacheDb.GetCachedTable<Well>((AsbCloudDbContext)db);
} }
public PaginationContainer<MessageDto> GetMessages(int wellId, IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32) public PaginationContainer<MessageDto> GetMessages(int wellId, IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32)
@ -39,20 +35,20 @@ namespace AsbCloudInfrastructure.Services
var events = cacheEvents.Select(e => e.IdTelemetry == telemetry.Id); var events = cacheEvents.Select(e => e.IdTelemetry == telemetry.Id);
if (events.Count() == 0) if (events.Any())
return null; return null;
var messages = from m in db.Messages var messages = from m in db.Messages
where m.IdTelemetry == telemetry.Id where m.IdTelemetry == telemetry.Id
select m; select m;
if ((categoryids != default) && (categoryids.Count() > 0)) if ((categoryids != default) && (categoryids.Any()))
{ {
var eventIds = from e in events var eventIds = from e in events
where categoryids.ToList().Contains(e.IdCategory) where categoryids.ToList().Contains(e.IdCategory)
select e.IdEvent; select e.IdEvent;
if (eventIds.Count() == 0) if (!eventIds.Any())
return null; return null;
messages = messages.Where(m => eventIds.Contains(m.IdEvent)); messages = messages.Where(m => eventIds.Contains(m.IdEvent));
@ -108,14 +104,14 @@ namespace AsbCloudInfrastructure.Services
if (telemetry is null) if (telemetry is null)
return null; return null;
var result = db.GetDatesRange<Message>(telemetry.Id); var (From, To) = db.GetDatesRange<Message>(telemetry.Id);
return new DatesRangeDto { From = result.From, To = result.To }; return new DatesRangeDto { From = From, To = To };
} }
public void Insert(string uid, IEnumerable<TelemetryMessageDto> dtos) public void Insert(string uid, IEnumerable<TelemetryMessageDto> dtos)
{ {
if (dtos.Count() == 0) if (dtos.Any())
return; return;
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid); var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);

View File

@ -14,16 +14,14 @@ namespace AsbCloudInfrastructure.Services
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly IConfiguration configuration; private readonly IConfiguration configuration;
private readonly ITelemetryService telemetryService; private readonly ITelemetryService telemetryService;
private readonly IServiceProvider serviceProvider;
private readonly IBackgroundQueue queue; private readonly IBackgroundQueue queue;
public ReportService(IAsbCloudDbContext db, IConfiguration configuration, ITelemetryService telemetryService, IServiceProvider serviceProvider, IBackgroundQueue queue) public ReportService(IAsbCloudDbContext db, IConfiguration configuration, ITelemetryService telemetryService, IBackgroundQueue queue)
{ {
this.db = db; this.db = db;
this.configuration = configuration; this.configuration = configuration;
this.telemetryService = telemetryService; this.telemetryService = telemetryService;
this.queue = queue; this.queue = queue;
this.serviceProvider = serviceProvider;
RootPath = "reports"; RootPath = "reports";
} }
@ -59,9 +57,9 @@ namespace AsbCloudInfrastructure.Services
if (telemetry is null) if (telemetry is null)
return null; return null;
var result = db.GetDatesRange<Report>(telemetry.Id); var (From, To) = db.GetDatesRange<Report>(telemetry.Id);
return new DatesRangeDto { From = result.From, To = result.To }; return new DatesRangeDto { From = From, To = To };
} }
private IReportGenerator GetReportGenerator(int wellId, DateTime begin, DateTime end, int stepSeconds, int format, AsbCloudDbContext context) private IReportGenerator GetReportGenerator(int wellId, DateTime begin, DateTime end, int stepSeconds, int format, AsbCloudDbContext context)

View File

@ -15,17 +15,13 @@ namespace AsbCloudWebApi.Controllers
[ApiController] [ApiController]
public class ReportController : ControllerBase public class ReportController : ControllerBase
{ {
private readonly IAsbCloudDbContext db;
private readonly IReportService reportService; private readonly IReportService reportService;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IWebHostEnvironment appEnvironment;
public ReportController(IAsbCloudDbContext db, IReportService reportService, IWellService wellService, IWebHostEnvironment appEnvironment) public ReportController(IReportService reportService, IWellService wellService)
{ {
this.db = db;
this.reportService = reportService; this.reportService = reportService;
this.wellService = wellService; this.wellService = wellService;
this.appEnvironment = appEnvironment;
} }
/// <summary> /// <summary>

View File

@ -136,9 +136,9 @@ namespace AsbCloudWebApi.Controllers
/// cli.ApiTelemetryDbAsync("1", new List&lt;FileParameter&gt; { file }).Wait(); /// cli.ApiTelemetryDbAsync("1", new List&lt;FileParameter&gt; { file }).Wait();
/// </example> /// </example>
/// </summary> /// </summary>
/// <param name="uid"></param> // <param name="uid"></param>
/// <param name="files"></param> // <param name="files"></param>
/// <returns></returns> // <returns></returns>
//[HttpPost] //[HttpPost]
//[Route("{uid}/db")] //[Route("{uid}/db")]
//public IActionResult PostDb(string uid, IFormFileCollection files) //public IActionResult PostDb(string uid, IFormFileCollection files)