コード例 #1
0
        private void SendValue(DoubleSensorValue data)
        {
            string            serializedValue = GetStringData(data);
            CommonSensorValue commonValue     = new CommonSensorValue();

            commonValue.TypedValue = serializedValue;
            commonValue.SensorType = SensorType.DoubleSensor;
            EnqueueData(commonValue);
        }
コード例 #2
0
        public void AddValue(double value, string comment)
        {
            DoubleSensorValue data = new DoubleSensorValue()
            {
                DoubleValue = value, Path = Path, Time = DateTime.Now, Key = ProductKey, Comment = comment
            };

            SendValue(data);
        }
コード例 #3
0
        public void AddValue(double value)
        {
            DoubleSensorValue data = new DoubleSensorValue()
            {
                DoubleValue = value, Path = Path, Time = DateTime.Now, Key = ProductKey
            };

            SendValue(data);
        }
コード例 #4
0
        public void AddValue(double value, SensorStatus status, string comment = null)
        {
            DoubleSensorValue data = new DoubleSensorValue()
            {
                DoubleValue = value, Path = Path, Time = DateTime.Now, Key = ProductKey, Status = status
            };

            if (!string.IsNullOrEmpty(comment))
            {
                data.Comment = comment;
            }
            SendValue(data);
        }
コード例 #5
0
 public ActionResult <DoubleSensorValue> Post([FromBody] DoubleSensorValue sensorValue)
 {
     try
     {
         _monitoringCore.AddSensorValue(sensorValue);
         return(Ok(sensorValue));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "Failed to put data!");
         return(BadRequest(sensorValue));
     }
 }
コード例 #6
0
 protected override string GetStringData(SensorValueBase data)
 {
     try
     {
         DoubleSensorValue typedData = (DoubleSensorValue)data;
         return(JsonConvert.SerializeObject(typedData));
         //return Serializer.Serialize(typedData);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(string.Empty);
     }
 }
コード例 #7
0
 public ActionResult <DoubleSensorValue> Post([FromBody] DoubleSensorValue sensorValue)
 {
     try
     {
         _dataCollector.ReportSensorsCount(1);
         _dataReceiver.AddSensorValue(sensorValue);
         return(Ok(sensorValue));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "Failed to put data!");
         return(BadRequest(sensorValue));
     }
 }
コード例 #8
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);
        }
コード例 #9
0
        private DoubleSensorValue GetValue()
        {
            double       val;
            string       comment;
            SensorStatus status;

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

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

            return(result);
        }
コード例 #10
0
        public void AddSensorValue(DoubleSensorValue 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}'");
            }
        }
コード例 #11
0
 private static DoubleSensorData GetDoubleSensorTypedData(DoubleSensorValue sensorValue) =>
 GetSensorData(sensorValue.DoubleValue, sensorValue.Comment);