Beispiel #1
0
        //refactor: This is also implemented in the full counter object so maybe we should rethink this functionality
        /// <summary>
        /// Sets the value as received from the Qbox for the given measurement time.
        /// It uses the Storage Provider to actually store the data
        /// Every time the data is presented the LastValue property will be updated with the value.
        /// </summary>
        public void SetValue(DateTime measurementTime, ulong value, QboxStatus ioQboxStatus)
        {
            Guard.IsNotNull(StorageProvider, "storage provider is missing");

            var formula     = FormulaForTime(measurementTime);
            var formulaEuro = RateForTime();
            var lastValue   = GetLastRecord(measurementTime);

            Record runningTotal = StorageProvider.SetValue(measurementTime, value, formula, formulaEuro, lastValue);

            if (runningTotal != null)
            {
                runningTotal.Id = LastValueKey;
                ClientRepositories.MetaData?.Save(runningTotal);
            }

            if (lastValue != null && runningTotal != null && runningTotal.Raw > lastValue.Raw)
            {
                var counterKey = String.IsNullOrEmpty(StorageId) ? CounterId.ToString(CultureInfo.InvariantCulture) : StorageId;
                ioQboxStatus.LastValidDataReceivedPerCounter[counterKey] = DateTime.Now.ToUniversalTime();

                if (IsElectricityConsumptionCounter)
                {
                    ioQboxStatus.LastElectricityConsumptionSeen = DateTime.Now.ToUniversalTime();
                }
                else if (IsElectricityGenerationCounter)
                {
                    ioQboxStatus.LastElectricityGenerationSeen = DateTime.Now.ToUniversalTime();
                }
                else if (IsGasCounter)
                {
                    ioQboxStatus.LastGasConsumptionSeen = DateTime.Now.ToUniversalTime();
                }
                else
                {
                    // We end up here for counters that can't be properly mapped to either LastElectricityConsumptionSeen, LastElectricityGenerationSeen or
                    // LastGasConsumptionSeen. This doesn't mean that we couldn't handle the data. So to update the status to reflect that we saw SOME
                    // valid data, we update LastElectricityConsumptionSeen.
                    ioQboxStatus.LastElectricityConsumptionSeen = DateTime.Now.ToUniversalTime();
                }
            }
        }
Beispiel #2
0
 public MiniPoco()
 {
     QboxStatus = new QboxStatus();
 }