public void AddSensorValue(BoolSensorValue value)
        {
            try
            {
                string productName = _productManager.GetProductNameByKey(value.Key);

                bool isNew = false;
                if (!_productManager.IsSensorRegistered(productName, value.Path))
                {
                    isNew = true;
                    _productManager.AddSensor(productName, value);
                }
                DateTime   timeCollected = DateTime.Now;
                SensorData updateMessage = _converter.Convert(value, productName, timeCollected, isNew ? TransactionType.Add : TransactionType.Update);
                _queueManager.AddSensorData(updateMessage);
                _valuesCache.AddValue(productName, updateMessage);

                SensorDataEntity dataObject = _converter.ConvertToDatabase(value, timeCollected);
                Task.Run(() => SaveSensorValue(dataObject, productName));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Failed to add value for sensor '{value?.Path}'");
            }
        }
        private void SendValue(BoolSensorValue data)
        {
            string            serializedValue = GetStringData(data);
            CommonSensorValue commonValue     = new CommonSensorValue();

            commonValue.TypedValue = serializedValue;
            commonValue.SensorType = SensorType.BooleanSensor;
            EnqueueData(commonValue);
        }
        public void AddValue(bool value, string comment)
        {
            BoolSensorValue data = new BoolSensorValue()
            {
                BoolValue = value, Comment = comment, Path = Path, Time = DateTime.Now, Key = ProductKey
            };

            SendValue(data);
        }
        public void AddValue(bool value)
        {
            BoolSensorValue data = new BoolSensorValue()
            {
                BoolValue = value, Path = Path, Time = DateTime.Now, Key = ProductKey
            };

            SendValue(data);
        }
Beispiel #5
0
 public ActionResult <BoolSensorValue> Post([FromBody] BoolSensorValue sensorValue)
 {
     try
     {
         _monitoringCore.AddSensorValue(sensorValue);
         return(Ok(sensorValue));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "Failed to put data!");
         return(BadRequest(sensorValue));
     }
 }
        public void AddValue(bool value, SensorStatus status, string comment = null)
        {
            BoolSensorValue data = new BoolSensorValue()
            {
                BoolValue = value, Path = Path, Status = status, Key = ProductKey, Time = DateTime.Now
            };

            if (!string.IsNullOrEmpty(comment))
            {
                data.Comment = comment;
            }
            SendValue(data);
        }
 public ActionResult <BoolSensorValue> Post([FromBody] BoolSensorValue sensorValue)
 {
     try
     {
         _dataCollector.ReportSensorsCount(1);
         _dataReceiver.AddSensorValue(sensorValue);
         return(Ok(sensorValue));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "Failed to put data!");
         return(BadRequest(sensorValue));
     }
 }
 protected override string GetStringData(SensorValueBase data)
 {
     try
     {
         BoolSensorValue typedData = (BoolSensorValue)data;
         return(JsonConvert.SerializeObject(typedData));
         //return Serializer.Serialize(typedData);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(string.Empty);
     }
 }
Beispiel #9
0
        internal static string GetTypedData(SensorValueBase sensorValue)
        {
            object sensorData = sensorValue switch
            {
                BoolSensorValue boolSensorValue => GetBoolSensorTypedData(boolSensorValue),
                IntSensorValue intSensorValue => GetIntSensorTypedData(intSensorValue),
                DoubleSensorValue doubleSensorValue => GetDoubleSensorTypedData(doubleSensorValue),
                StringSensorValue stringSensorValue => GetStringSensorTypedData(stringSensorValue),
                IntBarSensorValue intBarSensorValue => GetIntBarSensorTypedData(intBarSensorValue),
                DoubleBarSensorValue doubleBarSensorValue => GetDoubleBarSensorTypedData(doubleBarSensorValue),
                FileSensorBytesValue fileSensorBytesValue => GetFileSensorBytesTypedData(fileSensorBytesValue),
                UnitedSensorValue unitedSensorValue => GetUnitedSensorTypedData(unitedSensorValue),
                _ => null,
            };

            return(sensorData != null?JsonSerializer.Serialize(sensorData) : string.Empty);
        }
Beispiel #10
0
 private static BoolSensorData GetBoolSensorTypedData(BoolSensorValue sensorValue) =>
 GetSensorData(sensorValue.BoolValue, sensorValue.Comment);