Esempio n. 1
0
        void ILineParser.Parse(string text, ILineParserVisitor visitor, string objectAddress)
        {
            var match = _regEx.Match(text);

            if (!match.Success)
            {
                return;
            }

            string classifierText = null;

            if (_classifierGroup != null)
            {
                classifierText = match.Groups[_classifierGroup].Value;
            }
            else if (_classifierFromObjectAddress)
            {
                classifierText = objectAddress;
            }

            var e = (EventBase)Activator.CreateInstance(_eventDataType);

            e.ObjectId = classifierText;
            _eventDescriptor.FillEvent(e);

            foreach (var fd in _eventDescriptor.Fields)
            {
                string val;
                if (fd.FromObjectAddress)
                {
                    val = objectAddress;
                }
                else
                {
                    val = match.Groups[fd.Group].Value;
                    if (string.IsNullOrEmpty(val))
                    {
                        // TODO: Check whether field is optional.
                        continue;
                    }
                }
                // TODO: decide whether conversion is necessary...
                fd.Field.SetValue(e, fd.Converter.ConvertFromInvariantString(val));
            }
            visitor.VisitEvent(e);
        }
Esempio n. 2
0
        void ILineParser.Parse(string text, ILineParserVisitor visitor, string objectAddress)
        {
            var match = _regEx.Match(text);

            if (!match.Success)
            {
                return;
            }

            string objectId = null;

            if (_classifierGroup != null)
            {
                objectId = match.Groups[_classifierGroup].Value;
            }
            else if (_classifierFromObjectAddress)
            {
                objectId = objectAddress;
            }

            foreach (var ts in _timeSeries)
            {
                var val = match.Groups[ts.From].Value;
                if (string.IsNullOrEmpty(val))
                {
                    // TODO: Check whether field is optional.
                    continue;
                }
                var numVal = double.Parse(val, CultureInfo.InvariantCulture);
                if (ts.Scale != 0)
                {
                    numVal *= ts.Scale;
                }
                string dynamicName = null;
                if (ts.NameFromGroup != null)
                {
                    dynamicName = match.Groups[ts.NameFromGroup].Value;
                }
                string dynamicUnit = null;
                if (ts.UnitFromGroup != null)
                {
                    dynamicUnit = match.Groups[ts.UnitFromGroup].Value;
                }
                visitor.VisitTimeSeries(ts, objectId, dynamicName, dynamicUnit, numVal);
            }
        }