예제 #1
0
        //methods
        private IConsumerBinding AddBinding <type>(string variableName, UATypeInfo typeInfo)
        {
            ConsumerBindingMonitoredValue <type> _return = new ConsumerBindingMonitoredValue <type>(typeInfo);

            _return.PropertyChanged += (x, y) => Trace($"{DateTime.Now.ToLongTimeString()}:{DateTime.Now.Millisecond} {variableName} = {((ConsumerBindingMonitoredValue<type>)x).ToString()}");
            return(_return);
        }
        public void GetConsumerBindingForMultidimensionalTypeTest()
        {
            ConsumerBindingFactory factory  = new ConsumerBindingFactory(null, _configuration);
            UATypeInfo             typeInfo = new UATypeInfo(BuiltInType.Byte, 2, new int[] { 21, 37 });

            Assert.Throws <ValueRankOutOfRangeException>(() => factory.GetConsumerBinding(_typeMetadata.RepositoryGroupName, _typeMetadata.TypeName, typeInfo));
        }
예제 #3
0
        public void ArrayMultiDimensionTest()
        {
            byte[] _EncodedValue = null;
            using (MemoryStream _stream = new MemoryStream())
                using (TestBinaryWriter _buffer = new TestBinaryWriter(_stream))
                {
                    Assert.IsNotNull(_buffer);
                    Int32[] _dimensions = new Int32[] { 2, 2 };
                    Int32[,] _array = new Int32[, ] {
                        { 0, 1 }, { 2, 3 }
                    };
                    Assert.AreEqual <int>(2, _array.Rank);
                    Assert.AreEqual <int>(4, _array.Length);
                    Assert.AreEqual <int>(_dimensions.Length, _array.Rank);
                    UATypeInfo _uaTypeInfo = new UATypeInfo(BuiltInType.Int32, _dimensions.Length, _dimensions);
                    Variant    _variant    = new Variant {
                        UATypeInfo = _uaTypeInfo, Value = _array
                    };
                    _buffer.Write(_buffer, _variant);
                    _buffer.Close();
                    _EncodedValue = _stream.ToArray();
                }
            Assert.IsNotNull(_EncodedValue);
            Assert.AreEqual <int>(33, _EncodedValue.Length);
            string _content = String.Join(", ", _EncodedValue);

            Assert.AreEqual <string>("198, 4, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0", _content);
        }
예제 #4
0
 /// <inheritdoc />
 IProducerBinding IBindingFactory.GetProducerBinding(
     string repository,
     string processValueName,
     UATypeInfo fieldTypeInfo)
 {
     throw new NotImplementedException();
 }
        public void GetConsumerBindingForNotSupportedTypeTest()
        {
            ConsumerBindingFactory factory  = new ConsumerBindingFactory(null, _configuration);
            UATypeInfo             typeInfo = new UATypeInfo(BuiltInType.NodeId, -2, new int[] { });

            Assert.Throws <UnsupportedTypeException>(() => factory.GetConsumerBinding(_typeMetadata.RepositoryGroupName, _typeMetadata.TypeName, typeInfo));
        }
예제 #6
0
            public Variant(UATypeInfo typeInfo, object value)
            {
                switch (typeInfo.BuiltInType)
                {
                case BuiltInType.Null:
                    throw new ArgumentOutOfRangeException(nameof(typeInfo), "Null is not permitted in the Variant");

                case BuiltInType.Boolean:
                case BuiltInType.SByte:
                case BuiltInType.Byte:
                case BuiltInType.Int16:
                case BuiltInType.UInt16:
                case BuiltInType.Int32:
                case BuiltInType.UInt32:
                case BuiltInType.Int64:
                case BuiltInType.UInt64:
                case BuiltInType.Float:
                case BuiltInType.Double:
                case BuiltInType.String:
                case BuiltInType.DateTime:
                    if (value == null)
                    {
                        throw new NullReferenceException("Value type cannot be null.");
                    }
                    break;

                default:
                    break;
                }
                UATypeInfo = typeInfo;
                Value      = value;
            }
예제 #7
0
        private IConsumerBinding AddBinding <type>(string variableName, UATypeInfo typeInfo)
        {
            _logger.EnteringMethodBinding();
            ConsumerBindingMonitoredValue <type> returnValue = new ConsumerBindingMonitoredValue <type>(typeInfo);

            returnValue.PropertyChanged += (x, y) => _ViewModel.Trace($"{DateTime.Now.ToLongTimeString()}:{DateTime.Now.Millisecond} {variableName} = {((ConsumerBindingMonitoredValue<type>)x).ToString()}");
            return(returnValue);
        }
예제 #8
0
 private static void Compare(UATypeInfo source, UATypeInfo mirror)
 {
     Assert.IsNotNull(source);
     Assert.IsNotNull(mirror);
     CollectionAssert.AreEqual(source.ArrayDimensions, mirror.ArrayDimensions);
     Assert.AreEqual <BuiltInType>(source.BuiltInType, mirror.BuiltInType);
     Compare(source.TypeName, mirror.TypeName);
     Assert.AreEqual <int>(source.ValueRank, mirror.ValueRank);
 }
        public void GetConsumerBindingTest()
        {
            ConsumerBindingFactory factory = new ConsumerBindingFactory(null, _configuration);

            factory.Initialise(_consumerViewModel);
            UATypeInfo       typeInfo = new UATypeInfo(BuiltInType.Byte, -1, new int[] { });
            IConsumerBinding binding  = factory.GetConsumerBinding(_typeMetadata.RepositoryGroupName, _typeMetadata.TypeName, typeInfo);

            Assert.NotNull(binding);
        }
예제 #10
0
 /// <inheritdoc />
 IConsumerBinding IBindingFactory.GetConsumerBinding(
     string repositoryGroup,
     string processValueName,
     UATypeInfo fieldTypeInfo)
 {
     NewRepositoryReceived?.Invoke(this, repositoryGroup);
     var(binding, type) = GetConsumerBinding(repositoryGroup, processValueName, fieldTypeInfo);
     NewBindingCreated?.Invoke(this, new CreateBindingEventArgs(repositoryGroup, processValueName, type));
     return(binding);
 }
예제 #11
0
 public static bool ContainsMultidimensionalArray(this UATypeInfo typeInfo)
 {
     if (typeInfo is null)
     {
         return(false);
     }
     else
     {
         return(typeInfo.ValueRank == 0 || typeInfo.ValueRank > 1);
     }
 }
예제 #12
0
 /// <summary>
 /// Updates the value converter.
 /// </summary>
 /// <param name="converter">The converter.</param>
 /// <param name="repositoryGroup">The repository group.</param>
 /// <param name="sourceEncoding">The source encoding.</param>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// repositoryGroup
 /// or
 /// sourceEncoding
 /// </exception>
 public void UpdateValueConverter(IBinding binding, string repositoryGroup, UATypeInfo sourceEncoding)
 {
     if (repositoryGroup != m_RepositoryGroup)
     {
         throw new ArgumentOutOfRangeException("repositoryGroup");
     }
     if (sourceEncoding.BuiltInType != binding.Encoding.BuiltInType)
     {
         throw new ArgumentOutOfRangeException("sourceEncoding");
     }
 }
예제 #13
0
 public static bool ContainsArray(this UATypeInfo typeInfo)
 {
     if (typeInfo is null)
     {
         return(false);
     }
     else
     {
         return(typeInfo.ValueRank >= 0);
     }
 }
예제 #14
0
        public void ConstructorTest()
        {
            UATypeInfo   typeInfo     = new UATypeInfo(BuiltInType.DateTime);
            Subscription subscription = new Subscription(typeInfo, _typMetadata, "alias", DateTime.MinValue);

            Assert.NotNull(subscription.TypeInfo);
            Assert.NotNull(subscription.Value);
            Assert.NotNull(subscription.UaTypeMetadata);
            Assert.Equal(_typMetadata, subscription.UaTypeMetadata);
            Assert.Equal(DateTime.MinValue, subscription.Value);
            Assert.Equal(typeInfo, subscription.TypeInfo);
        }
예제 #15
0
        /// <summary>
        /// Helper method that creates the consumer binding.
        /// </summary>
        /// <param name="variableName">Name of the variable.</param>
        /// <returns>IConsumerBinding.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">variableName</exception>
        public IConsumerBinding GetConsumerBinding(string variableName, BuiltInType encoding)
        {
            UATypeInfo _uaTypeInfo = new UATypeInfo(encoding);

            if (variableName == "Value1")
            {
                Value1 = new ConsumerBindingMonitoredValue <string>(_uaTypeInfo);
                return(Value1);
            }
            else if (variableName == "Value2")
            {
                Value2 = new ConsumerBindingMonitoredValue <double>(_uaTypeInfo);
                return(Value2);
            }
            throw new ArgumentOutOfRangeException("variableName");
        }
        private IConsumerBinding Bind <type>(UaTypeMetadata typeMetadata, UATypeInfo typeInfo)
        {
            ConsumerBindingMonitoredValue <type> binding = new ConsumerBindingMonitoredValue <type>(typeInfo);

            binding.PropertyChanged += (sender, args) =>
            {
                if (_subscriptions.TryGetValue(typeMetadata, out ISubscription subscription))
                {
                    _logger?.LogInfo($"Value updated to {sender.ToString()} for subscription {subscription.UaTypeMetadata.ToString()}");
                    subscription.InvokeValueUpdated();
                }
            };
            ISubscription subscription = new Subscription(
                typeInfo,
                typeMetadata,
                _configuration.GetAliasForRepositoryGroup(typeMetadata.RepositoryGroupName),
                binding
                );

            _subscriptions[typeMetadata] = subscription;
            _consumerViewModel.AddSubscription(subscription);
            return(binding);
        }
        //methods
        private IProducerBinding AddBinding <type>(string key, UATypeInfo typeInfo)
        {
            IVariable _variable     = m_NodesDictionary[key];
            Type      _expectedType = typeof(type);

            if (!_expectedType.GetUATypeInfo().IsEqual(_variable.ValueType))
            {
                throw new ArgumentOutOfRangeException($"Wrong argument type: {_expectedType.GetUATypeInfo()} but expected {_variable.ValueType}");
            }
            ProducerBindingMonitoredValue <type> _binding = new ProducerBindingMonitoredValue <type>(key, typeInfo)
            {
                MonitoredValue = default(type)
            };

            _variable.OnStateChanged += (context, node, changes) =>
            {
                if (changes == NodeStateChangeMasks.Value)
                {
                    _binding.MonitoredValue = (type)_variable.Value;
                }
            };
            return(_binding);
        }
 public void ContainsMultidimensionalArrayForNonMultidimensionalArrayTypesTest(UATypeInfo typeInfo)
 {
     Assert.False(typeInfo.ContainsMultidimensionalArray());
 }
 public void ContainsArrayForNonArrayTypesTest(UATypeInfo typeInfo)
 {
     Assert.False(typeInfo.ContainsArray());
 }
 public void ContainsArrayForArrayTypesTest(UATypeInfo typeInfo)
 {
     Assert.True(typeInfo.ContainsArray());
 }
예제 #21
0
 public void UpdateValueConverter(IBinding binding, string repositoryGroup, UATypeInfo sourceEncoding)
 {
     Assert.IsNotNull(binding);
     binding.Culture   = null;
     binding.Converter = null;
     binding.Parameter = null;
 }
예제 #22
0
 public IProducerBinding GetProducerBinding(string repositoryGroup, string variableName, UATypeInfo encoding)
 {
     throw new NotImplementedException();
 }
예제 #23
0
            public IConsumerBinding GetConsumerBinding(string repositoryGroup, string processValueName, UATypeInfo field)
            {
                IConsumerBinding _ncb = new ConsumerBindingMonitoredValue <object>(new UATypeInfo(field.BuiltInType));
                string           _key = String.Format("{0}.{1}", repositoryGroup, processValueName);

                m_Repository.Add(_key, _ncb);
                return(_ncb);
            }
예제 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProducerBinding{type}" /> class.
 /// </summary>
 /// <param name="valueName">Name of the variable in the repository that is placeholder of the value.</param>
 /// <param name="getValue">Captures a delegate used to assign new value to local resources.</param>
 /// <param name="targetType">Type of the target.</param>
 public ProducerBinding(string valueName, Func <type> getValue, UATypeInfo targetType) : base(targetType)
 {
     GetReadValueDelegate = getValue;
     m_VariableName       = valueName;
 }
예제 #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProducerBinding{type}" /> class.
 /// </summary>
 /// <param name="valueName">Name of the "repository group" and "variable" separated by "."</param>
 /// <param name="targetType">Type of the target.</param>
 /// <remarks>The <see cref="ProducerBinding{type}.GetReadValueDelegate" /> that captures a delegate used to assign new value to local variable in the data repository.</remarks>
 protected ProducerBinding(string valueName, UATypeInfo targetType) : this(valueName, () => default(type), targetType)
 {
 }
예제 #26
0
        private (IConsumerBinding Binding, Type BindingType) GetConsumerBinding(string repositoryGroup, string variableName, UATypeInfo typeInfo)
        {
            if (typeInfo.ValueRank == 0 || typeInfo.ValueRank > 1)
            {
                throw new ArgumentOutOfRangeException(nameof(typeInfo.ValueRank));
            }
            switch (typeInfo.BuiltInType)
            {
            case BuiltInType.Boolean:
                return(typeInfo.ValueRank < 0 ? AddBinding <bool>() : AddBinding <bool[]>());

            case BuiltInType.SByte:
                return(typeInfo.ValueRank < 0 ? AddBinding <sbyte>() : AddBinding <sbyte[]>());

            case BuiltInType.Byte:
                return(typeInfo.ValueRank < 0 ? AddBinding <byte>() : AddBinding <byte[]>());

            case BuiltInType.Int16:
                return(typeInfo.ValueRank < 0 ? AddBinding <short>() : AddBinding <short[]>());

            case BuiltInType.UInt16:
                return(typeInfo.ValueRank < 0 ? AddBinding <ushort>() : AddBinding <ushort[]>());

            case BuiltInType.Int32:
                return(typeInfo.ValueRank < 0 ? AddBinding <int>() : AddBinding <int[]>());

            case BuiltInType.UInt32:
                return(typeInfo.ValueRank < 0 ? AddBinding <uint>() : AddBinding <uint[]>());

            case BuiltInType.Int64:
                return(typeInfo.ValueRank < 0 ? AddBinding <long>() : AddBinding <long[]>());

            case BuiltInType.UInt64:
                return(typeInfo.ValueRank < 0 ? AddBinding <ulong>() : AddBinding <ulong[]>());

            case BuiltInType.Float:
                return(typeInfo.ValueRank < 0 ? AddBinding <float>() : AddBinding <float[]>());

            case BuiltInType.Double:
                return(typeInfo.ValueRank < 0 ? AddBinding <double>() : AddBinding <double[]>());

            case BuiltInType.String:
                return(typeInfo.ValueRank < 0 ? AddBinding <string>() : AddBinding <string[]>());

            case BuiltInType.DateTime:
                return(typeInfo.ValueRank < 0 ? AddBinding <DateTime>() : AddBinding <DateTime[]>());

            case BuiltInType.Guid:
                return(typeInfo.ValueRank < 0 ? AddBinding <Guid>() : AddBinding <Guid[]>());

            case BuiltInType.ByteString:
                return(typeInfo.ValueRank < 0 ? AddBinding <byte[]>() : AddBinding <byte[][]>());

            default:
                throw new ArgumentOutOfRangeException(nameof(typeInfo.BuiltInType));
            }

            (IConsumerBinding Binding, Type BindingType) AddBinding <T>()
            {
                return(this.AddBinding <T>(repositoryGroup, variableName, typeInfo), typeof(T));
            }
        }
예제 #27
0
        private IConsumerBinding AddBinding <T>(string repositoryGroup, string variableName, UATypeInfo typeInfo)
        {
            var monitoredValue = new ConsumerBindingMonitoredValue <T>(typeInfo);

            if (!_consumerBindings.ContainsKey(repositoryGroup))
            {
                _consumerBindings[repositoryGroup] = new Dictionary <string, IConsumerBinding>();
            }
            _consumerBindings[repositoryGroup][variableName] = monitoredValue;
            return(monitoredValue);
        }
예제 #28
0
 private Variant(object value, UATypeInfo type)
 {
     Value      = value;
     UATypeInfo = type;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProducerBinding{type}" /> class.
 /// </summary>
 /// <param name="valueName">Name of the "repository group" and "variable" separated by "."</param>
 /// <param name="targetType">Type of the target.</param>
 /// <remarks>The <see cref="ProducerBinding{type}.GetReadValueDelegate" /> that captures a delegate used to assign new value to local variable in the data repository.</remarks>
 public ProducerBindingMonitoredValue(string valueName, UATypeInfo targetType)
     : base(valueName, targetType)
 {
 }
예제 #30
0
 public IConsumerBinding GetConsumerBinding(string repositoryGroup, string processValueName, UATypeInfo field)
 {
     return(new ConsumerBinding <int>(x => { }, new UATypeInfo(field.BuiltInType)));
 }