Exemplo n.º 1
0
    public void AddSensor(E_SensorType sensorType, bool activate)
    {
        SensorBase s = SensorFactory.Create(sensorType, Owner);

        s.Active = activate;
        Sensors[(int)sensorType] = s;
    }
Exemplo n.º 2
0
        public void TestSensorFactory_CreateOk(string type, string name)
        {
            var sensorInfo = new KeyValuePair <string, string>(name, type);

            Factory.Setup(envVariables);
            Factory.Create(sensorInfo);
            Assert.NotNull(Factory.Create(sensorInfo));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Parsed log and returns information about sensors defined inside log.
        /// </summary>
        /// <param name="readNextLine">Generic function for parsing any stream.</param>
        /// <returns>Parsed log</returns>
        /// <exception cref="InvalidReferenceFormatException"></exception>
        /// <exception cref="InvalidSensorTypeException"></exception>
        /// <exception cref="InvalidSensorValueException"></exception>
        /// <exception cref="MissingReferenceValueException"></exception>
        /// <exception cref="MissingSensorDefinitionException"></exception>
        /// <exception cref="NoReadingValuesException"></exception>
        private static string Parse(Func <string> readNextLine)
        {
            var     referenceMap = ReferenceValueParser.GetReferenceValues(readNextLine());
            var     result       = new Dictionary <string, string>();
            ISensor activeSensor = null;

            string line;

            while ((line = readNextLine()) != null)
            {
                if (line.Trim() == "")
                {
                    continue;
                }

                var(state, part1, part2) = TryNextState(line);

                switch (state)
                {
                case ParseStateEnum.Sensor:
                    AddToResult(activeSensor, result);
                    activeSensor = SensorFactory.Create(referenceMap, part1, part2);
                    break;

                case ParseStateEnum.Value:
                    if (activeSensor == null)
                    {
                        throw new MissingSensorDefinitionException();
                    }

                    activeSensor.HandleValue(part2);
                    break;

                default:
                    throw new InvalidSensorValueException(line);
                }
            }

            AddToResult(activeSensor, result);

            return(JsonConvert.SerializeObject(result));
        }