コード例 #1
0
        /// <summary>
        ///     Производит загрузку из проекта B#
        /// </summary>
        protected virtual void LoadFromBSharp()
        {
            var config = new ConfigurationLoader(ConfigurationOptions).Load();

            BSharpContext = config.GetContext();
            var xml = config.GetConfig();

            xml.Apply(this);
            Definition = xml;
            foreach (var x in xml.Attributes())
            {
                var name = x.Name.LocalName;
                if (!ContainsKey(name))
                {
                    Set(name, x.Value);
                }
            }
            foreach (var x in xml.Elements())
            {
                var name = x.Name.LocalName;
                if (!ContainsKey(name))
                {
                    var val = x.Attr("code");
                    if (string.IsNullOrWhiteSpace(val))
                    {
                        val = x.Value;
                    }
                    Set(name, val);
                }
            }
        }
コード例 #2
0
        private int GetNextValue(string componentCode, string sensorCode)
        {
            var    sensorConfig = _configLoader.GetConfig(componentCode, sensorCode);
            var    lastValue    = _lastSensorValues[sensorCode];
            double modifier     = (_random.NextDouble() / 100.0); // up to 1%

            if (_random.Next(10) % 2 == 1)
            {
                modifier = 1.0 + modifier;
            }
            else
            {
                modifier = 1.0 - modifier;
            }

            double newValue = lastValue * modifier;

            var maxVal = _maxValues[sensorCode];

            if (sensorConfig.Signed)
            {
                if (newValue >= maxVal)
                {
                    newValue -= maxVal * 0.1;
                }
                else if (newValue <= -_maxValues[sensorCode])
                {
                    newValue += maxVal * 0.1;
                }
            }
            else
            {
                if (newValue >= _maxValues[sensorCode])
                {
                    newValue = maxVal * 0.9;
                }
            }

            _lastSensorValues[sensorCode] = newValue;

            return((int)newValue);
        }