Exemplo n.º 1
0
        public static IEnumerable <SensorMetadata> ReadDataFromCsvFile(string filePath)
        {
            var text = File.ReadAllText(filePath);

            using (var csvReader = new CsvReader(new StringReader(text)))
            {
                List <SensorMetadata> sensorMetadata = new List <SensorMetadata>();
                var sensorData = csvReader.GetRecords <SensorData>();
                foreach (var data in sensorData)
                {
                    SensorMetadata sensorMeta = new SensorMetadata
                    {
                        ExternalId = data.ExternalId
                    };
                    sensorMeta.SensorProperties.Add("TargetNodeDisplayName", new Property(data.TargetNodeDisplayName));
                    sensorMeta.SensorProperties.Add("PollFrequency", new Property(data.ExternalPollFrequency.ToString()));
                    sensorMeta.SensorProperties.Add("TargetPath", new Property(data.TargetPath.ToString()));
                    sensorMeta.SensorProperties.Add("SensorReadingType", new Property(data.ExternalReadingType.ToString()));
                    sensorMeta.SensorProperties.Add("ExternalIndexDelayTimeSec", new Property(data.ExternalIndexDelayTimeSec.ToString()));
                    sensorMeta.SensorProperties.Add("Description", new Property(data.ExternalSensorColumnDescription.ToString()));
                    sensorMeta.SensorProperties.Add("MeasureUnit", new Property(data.ExternalColumnMeasureunit.ToString()));
                    sensorMetadata.Add(sensorMeta);
                }
                return(sensorMetadata);
            }
        }
Exemplo n.º 2
0
        public ActionResult <SensorMetadata> GetSensorMetadata(string type)
        {
            if (type == null)
            {
                return(BadRequest("No sensor type specified"));
            }

            if (type.ToLower() == _serviceHandThree.SensorType.ToLower())
            {
                SensorMetadata metadata = new SensorMetadata(type, _serviceHandThree.Timeout.ToString(), _serviceHandThree.Threshold.ToString());
                return(metadata);
            }

            return(BadRequest("Sensor type doesn't exist"));
        }
Exemplo n.º 3
0
        public static MessageWrapper GetAvailableSensors(string sourceId, EventType eventType, string sensorListFilePath)
        {
            try
            {
                RemoteSourceAvailableSensors availableSensors = new RemoteSourceAvailableSensors();
                availableSensors.SourceId  = sourceId;
                availableSensors.EventType = eventType;
                string csvText = File.ReadAllText(sensorListFilePath);
                using (var reader = new TransmitListReader(csvText, eventType))
                {
                    var sensors = reader.ReadAll();
                    switch (eventType)
                    {
                    case EventType.AlarmEventType:
                    case EventType.StateChangeEventType:
                        /* EventID, DisplayName, PollFrequency, Path */
                        foreach (var sensor in sensors)
                        {
                            var sensorMetadata = new SensorMetadata()
                            {
                                SensorId = sensor.SensorId,
                            };
                            sensorMetadata.Properties.Add(Constants.KnownPropertyNames.SensorMetadata.DisplayName, new Property(sensor.TargetNodeDisplayName));
                            availableSensors.Sensors.Add(sensorMetadata);
                        }
                        break;

                    case EventType.SensorDataEventType:
                        foreach (var sensor in sensors)
                        {
                            var sensorMetadata = new SensorMetadata()
                            {
                                SensorId = sensor.SensorId,
                            };
                            VectorElementMetadata vector = new VectorElementMetadata()
                            {
                                Name       = string.IsNullOrEmpty(sensor.VectorElementsData.First().Name) ? sensor.VectorElementsData.First().Name : sensor.VectorElementsData.First().Description,
                                SourceUnit = sensor.VectorElementsData.First().MeasureUnit,
                            };
                            sensorMetadata.VectorElementsData.Add(vector);
                            sensorMetadata.Properties.Add(Constants.KnownPropertyNames.SensorMetadata.DisplayName, new Property(sensor.TargetNodeDisplayName));
                            availableSensors.Sensors.Add(sensorMetadata);
                        }
                        break;

                    case EventType.DataframeEventType:
                        foreach (var sensor in sensors)
                        {
                            var sensorMetadata = new SensorMetadata()
                            {
                                SensorId = sensor.SensorId,
                            };
                            sensorMetadata.Properties.Add(Constants.KnownPropertyNames.SensorMetadata.DisplayName, new Property(sensor.TargetNodeDisplayName));
                            availableSensors.Sensors.Add(sensorMetadata);
                        }
                        break;
                    }
                }
                var messageWrapper = availableSensors.ToMessageWrapper();
                return(messageWrapper);
            }
            catch (Exception)
            {
                return(null);
            }
        }