public void ReadNodeAttributeSetArray()
        {
            var na1 = new NodeAttributeSet();

            na1.SetAttribute(Attributes.NodeClass, NodeClass.Variable);
            na1.SetAttribute(Attributes.BrowseName, new QualifiedName("Somename1"));
            na1.SetAttribute(Attributes.NodeId, new NodeId(Guid.NewGuid()));
            na1.SetAttribute(Attributes.DisplayName, new LocalizedText("hello world2"));
            na1.SetAttribute(Attributes.Value, 623465);
            na1.SetAttribute(Attributes.Description, new LocalizedText("test22"));
            na1.SetAttribute(Attributes.DataType, new NodeId(Guid.NewGuid()));
            var na2 = new NodeAttributeSet();

            na2.SetAttribute(Attributes.NodeClass, NodeClass.Variable);
            na2.SetAttribute(Attributes.BrowseName, new QualifiedName("Somename3"));
            na2.SetAttribute(Attributes.NodeId, new NodeId(Guid.NewGuid()));
            na2.SetAttribute(Attributes.DisplayName, new LocalizedText("hello world2"));
            na2.SetAttribute(Attributes.Value, 345);
            na2.SetAttribute(Attributes.Description, new LocalizedText("test33"));
            na2.SetAttribute(Attributes.DataType, new NodeId(Guid.NewGuid()));
            var na3 = new NodeAttributeSet();

            na3.SetAttribute(Attributes.NodeClass, NodeClass.Variable);
            na3.SetAttribute(Attributes.BrowseName, new QualifiedName("Somename6"));
            na3.SetAttribute(Attributes.NodeId, new NodeId(Guid.NewGuid()));
            na3.SetAttribute(Attributes.DisplayName, new LocalizedText("hello world3"));
            na3.SetAttribute(Attributes.Value, "nanananahhh");
            na3.SetAttribute(Attributes.Description, new LocalizedText("test44"));
            na3.SetAttribute(Attributes.DataType, new NodeId(Guid.NewGuid()));
            var expected = new[] { na1, na2, na3 };
            var json     = Serializer.SerializeObject(expected);
            var result   = Serializer.DeserializeObject <NodeAttributeSet[]>(json);

            Assert.True(expected.SetEqualsSafe(result, Utils.IsEqual));
        }
Exemple #2
0
        public void ReadNodeAttributeSet(string encoderType, string decoderType)
        {
            var expected = new NodeAttributeSet();
            var map      = new AttributeMap();

            expected.SetAttribute(Attributes.NodeClass, NodeClass.Variable);
            expected.SetAttribute(Attributes.BrowseName, new QualifiedName("Somename"));
            expected.SetAttribute(Attributes.NodeId, new NodeId(Guid.NewGuid()));
            expected.SetAttribute(Attributes.DisplayName, new LocalizedText("en-us", "hello world"));
            expected.SetAttribute(Attributes.Value, 1235);
            expected.SetAttribute(Attributes.Description, new LocalizedText("test"));
            expected.SetAttribute(Attributes.DataType, new NodeId(Guid.NewGuid()));
            CreateSerializers(out var encoder, out var decoder);

            var buffer = encoder.Encode(encoderType, e => e.WriteEncodeable("test", expected, expected.GetType()));

            OutputJsonBuffer(encoderType, buffer);
            var result = decoder.Decode(decoderType, buffer, d => d.ReadEncodeable("test", typeof(NodeAttributeSet)));

            // The NR encoding ignores the Locale, skip the validation
            if (!IsNonReversibleEncoding(encoderType))
            {
                Assert.True(expected.IsEqual(result));
            }
        }
        public void ReadWriteNodeAttributeSetNull()
        {
            NodeAttributeSet expected = null;
            var json   = Serializer.SerializeObject(expected);
            var result = Serializer.DeserializeObject <NodeAttributeSet>(json);

            Assert.Equal(expected, result);
        }
        public void ReadNodeAttributeSet()
        {
            var expected = new NodeAttributeSet();

            expected.SetAttribute(Attributes.NodeClass, NodeClass.Variable);
            expected.SetAttribute(Attributes.BrowseName, new QualifiedName("Somename"));
            expected.SetAttribute(Attributes.NodeId, new NodeId(Guid.NewGuid()));
            expected.SetAttribute(Attributes.DisplayName, new LocalizedText("hello world"));
            expected.SetAttribute(Attributes.Value, 1235);
            expected.SetAttribute(Attributes.Description, new LocalizedText("test"));
            expected.SetAttribute(Attributes.DataType, new NodeId(Guid.NewGuid()));
            var json   = Serializer.SerializeObject(expected);
            var result = Serializer.DeserializeObject <NodeAttributeSet>(json);

            Assert.True(expected.IsEqual(result));
        }
        /// <summary>
        /// Convert to node attributes
        /// be encoded.
        /// </summary>
        /// <param name="nodeModel"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static INodeAttributes ToNodeAttributes(this BaseNodeModel nodeModel,
                                                       ISystemContext context)
        {
            var raw = new NodeAttributeSet(nodeModel.NodeId, context.NamespaceUris)
            {
                BrowseName          = nodeModel.BrowseName,
                DisplayName         = nodeModel.DisplayName,
                Description         = nodeModel.Description,
                WriteMask           = (uint?)nodeModel.WriteMask,
                AccessRestrictions  = nodeModel.AccessRestrictions,
                RolePermissions     = nodeModel.RolePermissions,
                UserRolePermissions = nodeModel.UserRolePermissions,
                UserWriteMask       = (uint?)nodeModel.UserWriteMask
            };

            switch (nodeModel)
            {
            case ObjectNodeModel o:
                raw.NodeClass     = NodeClass.Object;
                raw.EventNotifier = o.EventNotifier;
                break;

            case VariableNodeModel o:
                raw.NodeClass               = NodeClass.Variable;
                raw.DataType                = o.DataType;
                raw.ValueRank               = o.ValueRank;
                raw.ArrayDimensions         = o.ArrayDimensions;
                raw.AccessLevel             = o.AccessLevel;
                raw.AccessLevelEx           = o.AccessLevel;
                raw.UserAccessLevel         = (byte)o.UserAccessLevel;
                raw.MinimumSamplingInterval = o.MinimumSamplingInterval;
                raw.Historizing             = o.Historizing;
                raw.Value = new Variant(o.Value);
                break;

            case VariableTypeNodeModel o:
                raw.NodeClass       = NodeClass.VariableType;
                raw.IsAbstract      = o.IsAbstract;
                raw.DataType        = o.DataType;
                raw.ValueRank       = o.ValueRank;
                raw.ArrayDimensions = o.ArrayDimensions;
                raw.Value           = new Variant(o.Value);
                break;

            case MethodNodeModel o:
                raw.NodeClass      = NodeClass.Method;
                raw.Executable     = o.Executable;
                raw.UserExecutable = o.UserExecutable;
                break;

            case ObjectTypeNodeModel o:
                raw.NodeClass  = NodeClass.ObjectType;
                raw.IsAbstract = o.IsAbstract;
                break;

            case DataTypeNodeModel o:
                raw.NodeClass          = NodeClass.DataType;
                raw.IsAbstract         = o.IsAbstract;
                raw.DataTypeDefinition = new ExtensionObject(o.Definition);
                break;

            case ReferenceTypeNodeModel o:
                raw.NodeClass   = NodeClass.ReferenceType;
                raw.InverseName = o.InverseName;
                raw.IsAbstract  = o.IsAbstract;
                raw.Symmetric   = o.Symmetric;
                break;

            case ViewNodeModel o:
                raw.NodeClass       = NodeClass.View;
                raw.ContainsNoLoops = o.ContainsNoLoops;
                break;
            }
            foreach (var reference in nodeModel.GetAllReferences(context))
            {
                raw.References.Add(reference);
            }
            return(raw);
        }