public override Task <InvertorProducingStatistic> GetInvertorStatisticsAsync(InvertorProducingStatisticRequest request, ServerCallContext context) { try { InvertorProducingStatistic statisticsNow = db.InvertorProducingStatistics.Where(x => x.InvertorId == request.InvertorId && x.Date >= request.FromDate).First(); if (powerInMW) { statisticsNow.PredictedProducing /= 1000; statisticsNow.ActivePower /= 1000; statisticsNow.ProducedEnergy /= 1000; } return(Task.FromResult(statisticsNow)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(Task.FromResult(new InvertorProducingStatistic())); } }
public override async Task GetInvertorStatisticForChartAsync(InvertorProducingStatisticRequest request, IServerStreamWriter <InvertorProducingStatistic> responseStream, ServerCallContext context) { try { List <InvertorProducingStatistic> statistics = db.InvertorProducingStatistics.Where(x => x.InvertorId == request.InvertorId && x.Date >= request.FromDate).ToList(); foreach (InvertorProducingStatistic item in statistics) { if (powerInMW) { item.ProducedEnergy /= 1000; item.PredictedProducing /= 1000; } await responseStream.WriteAsync(item); } } catch (Exception ex) { Console.WriteLine(ex.Message); await responseStream.WriteAsync(new InvertorProducingStatistic()); } }