Esempio n. 1
0
 //loop solution of reading the sensor identifier with data
 protected internal void IterateThroughLogs()
 {
     foreach (var line in _logFile.Split("\r\n").Skip(1)) // can be parallelized  //skip reference initial line
     {
         if (Regex.IsMatch(line, SensorsLogPattern))
         {
             //split identifier
             //inititalize sensor using the identifier
             var sensor = sensorFactory.Create(line.SensorInfoExtract());
             if (sensor != null)
             {
                 InitliazedSensors.Add(sensor);
             }
         }
         else
         {
             //always add to the last added sensor in our collection
             InitliazedSensors.LastOrDefault().Add(line.SplitLine()[1]);
         }
     }
 }
Esempio n. 2
0
        public IEnumerable <Sensor> Parse(string content)
        {
            if (String.IsNullOrWhiteSpace(content))
            {
                return(new Sensor[0]);
            }

            var    result          = new List <Sensor>();
            var    referenceValues = new Dictionary <string, double>();
            Sensor currentSensor   = null;

            foreach (var line in content.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries))
            {
                var lineParts = line.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                if (line.StartsWith("reference"))
                {
                    referenceValues.Clear();
                    referenceValues.Add("temperature", Convert.ToDouble(lineParts[1]));
                    referenceValues.Add("humidity", Convert.ToDouble(lineParts[2]));
                    referenceValues.Add("ppm", Convert.ToDouble(lineParts[3]));
                    continue;
                }

                if (_sensorFactory.SensorNames.Contains(lineParts[0]))
                {
                    currentSensor = _sensorFactory.Create(referenceValues, lineParts[0], lineParts[1]);
                    result.Add(currentSensor);
                    continue;
                }

                currentSensor?.AddReading(lineParts[1]);
            }

            return(result);
        }