//Получить свежие данные с сервера
 private void RefreshForecasts(bool handleConnecError = true)
 {
     try
     {
         ForecastsBlock = _forecastConnection.GetDataFromServer();
         OnForecastUpdated?.Invoke(this, ForecastsBlock);
     }
     catch (ConnectionException e)
     {
         if (handleConnecError)
         {
             ExceptionLogger.Log(e);
             OnConnectionLost?.Invoke(this, e);
             _reconnectTimer.Start();
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 2
0
        private void OnForecastUpdated(object sender, ForecastBlock forecastsBlock)
        {
            IsDataSated = true;
            _dialogController.IsDialogShown = false;
            var forecasts = forecastsBlock.Forecasts;

            /*var selectedForecasts = GetForecastsForPeriod(forecasts);
             * var forecastsAmount = selectedForecasts.Count;
             *
             * var chartValues = new ChartValues<Forecast>();
             * var realValues = new ChartValues<DateTimePoint>();
             * var forecastValues = new ChartValues<DateTimePoint>();
             * for (var i = 0; i < forecastsAmount && i < 500; i++)
             * {
             *  chartValues.Add(selectedForecasts[i]);
             *  var forecast = selectedForecasts[i];
             *  chartValues.Add(new DateTimePoint(forecast.ForecastTime, forecast.ForecastPower));
             *
             *  if (forecast.IsForecast)
             *      forecastValues.Add(new DateTimePoint(forecast.ForecastTime, forecast.ForecastPower));
             *  else
             *      realValues.Add(new DateTimePoint(forecast.ForecastTime, forecast.ForecastPower));
             * }
             *
             * var firstForecastDate = forecastValues.Min(x => x.DateTime);
             * var firstForecast = realValues.Where(x => x.DateTime < firstForecastDate).OrderByDescending(x => x.DateTime).FirstOrDefault();
             * forecastValues.Insert(0, firstForecast);
             *
             * AllValues = chartValues;
             * RealValues = realValues;
             * ForecastValues = forecastValues;*/

            var allDataValue      = new List <Forecast>();
            var measurementsValue = new List <Forecast>();
            var forecastsValue    = new List <Forecast>();
            var prevForecast      = forecasts.First();
            var isPreWasForecast  = prevForecast.IsForecast;

            for (var i = 0; i < forecasts.Count; i++)
            {
                var currentForecastData = forecasts[i];
                var isForecastNow       = currentForecastData.IsForecast;

                allDataValue.Add(currentForecastData);
                if (isForecastNow)
                {
                    forecastsValue.Add(currentForecastData);
                }
                else
                {
                    measurementsValue.Add(currentForecastData);
                }

                if (isForecastNow != isPreWasForecast)
                {
                    if (isPreWasForecast)
                    {
                        measurementsValue.Add(prevForecast);
                    }
                    else
                    {
                        measurementsValue.Add(currentForecastData);
                    }
                }

                isPreWasForecast = isForecastNow;
                prevForecast     = currentForecastData;
            }
            Consumption         = forecastsBlock.Consumption;
            ConsumptionDate     = forecastsValue.Last().ForecastTime.ToString("dd.MMM.yy");
            ForecastValues      = new ChartValues <Forecast>(forecastsValue.Distinct());
            MeasurementsValues  = new ChartValues <Forecast>(measurementsValue.Distinct());
            ChartForecastValues = new ChartValues <Forecast>(allDataValue.Distinct());
        }