public void AddSensorValue(IntSensorValue 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(IntSensorValue data)
        {
            string            serializedValue = GetStringData(data);
            CommonSensorValue commonValue     = new CommonSensorValue();

            commonValue.TypedValue = serializedValue;
            commonValue.SensorType = SensorType.IntSensor;
            EnqueueData(commonValue);
        }
        public void AddValue(int value, string comment)
        {
            IntSensorValue data = new IntSensorValue()
            {
                IntValue = value, Path = Path, Time = DateTime.Now, Key = ProductKey, Comment = comment
            };

            SendValue(data);
        }
        public void AddValue(int value)
        {
            IntSensorValue data = new IntSensorValue()
            {
                IntValue = value, Path = Path, Time = DateTime.Now, Key = ProductKey
            };

            SendValue(data);
        }
        public void AddValue(int value, SensorStatus status, string comment = null)
        {
            IntSensorValue data = new IntSensorValue()
            {
                IntValue = value, Path = Path, Time = DateTime.Now, Key = ProductKey, Status = status
            };

            if (!string.IsNullOrEmpty(comment))
            {
                data.Comment = comment;
            }
            SendValue(data);
        }
Esempio n. 6
0
 public ActionResult <IntSensorValue> Post([FromBody] IntSensorValue sensorValue)
 {
     try
     {
         _monitoringCore.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
     {
         IntSensorValue typedData = (IntSensorValue)data;
         return(JsonConvert.SerializeObject(typedData));
         //return Serializer.Serialize(typedData);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(string.Empty);
     }
 }
 public ActionResult <IntSensorValue> Post([FromBody] IntSensorValue sensorValue)
 {
     try
     {
         _dataCollector.ReportSensorsCount(1);
         _dataReceiver.AddSensorValue(sensorValue);
         return(Ok(sensorValue));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "Failed to put data!");
         return(BadRequest(sensorValue));
     }
 }
Esempio n. 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);
        }
        private IntSensorValue GetValue()
        {
            int          val;
            string       comment;
            SensorStatus status;

            lock (_syncRoot)
            {
                val     = _currentValue;
                comment = _currentComment;
                status  = _currentStatus;
            }

            IntSensorValue result = new IntSensorValue()
            {
                IntValue = val, Path = Path, Key = ProductKey, Time = DateTime.Now, Comment = comment, Status = status
            };

            return(result);
        }
Esempio n. 11
0
 private static IntSensorData GetIntSensorTypedData(IntSensorValue sensorValue) =>
 GetSensorData(sensorValue.IntValue, sensorValue.Comment);