示例#1
0
        /// <summary>
        /// Imports a DataTypeDefinition
        /// </summary>
        private Opc.Ua.DataTypeDefinition2 Import(Opc.Ua.Export.DataTypeDefinition source, NamespaceTable namespaceUris)
        {
            if (source == null)
            {
                return(null);
            }

            Opc.Ua.DataTypeDefinition2 definition = new Opc.Ua.DataTypeDefinition2();

            definition.Name         = ImportQualifiedName(source.Name, namespaceUris);
            definition.SymbolicName = source.SymbolicName;

            if (source.Field != null)
            {
                List <Opc.Ua.DataTypeDefinitionField> fields = new List <Opc.Ua.DataTypeDefinitionField>();

                foreach (DataTypeField field in source.Field)
                {
                    Opc.Ua.DataTypeDefinitionField output = new Opc.Ua.DataTypeDefinitionField();

                    output.Name         = field.Name;
                    output.SymbolicName = field.SymbolicName;
                    output.Description  = Import(field.Description);
                    output.DataType     = ImportNodeId(field.DataType, namespaceUris, true);
                    output.ValueRank    = field.ValueRank;
                    output.Value        = field.Value;

                    fields.Add(output);
                }

                definition.Fields = fields;
            }

            return(definition);
        }
示例#2
0
        /// <summary>
        /// Imports a DataTypeDefinition
        /// </summary>
        private Opc.Ua.DataTypeDefinition2 Import(UADataType dataType, Opc.Ua.Export.DataTypeDefinition source, NamespaceTable namespaceUris)
        {
            if (source == null)
            {
                return(null);
            }

            Opc.Ua.DataTypeDefinition2 definition = new Opc.Ua.DataTypeDefinition2();

            var browseName = ImportQualifiedName(dataType.BrowseName, namespaceUris);

            definition.Name = browseName;

            if (!String.IsNullOrEmpty(source.Name))
            {
                definition.Name = ImportQualifiedName(source.Name, namespaceUris);

                // check for bad input.
                if (definition.Name.NamespaceIndex == 0 && browseName.NamespaceIndex != 0)
                {
                    definition.Name = new QualifiedName(definition.Name.Name, browseName.NamespaceIndex);
                }
            }

            definition.SymbolicName     = source.SymbolicName;
            definition.DataTypeModifier = DataTypeModifier.None;

            if (source.IsOptionSet)
            {
                definition.DataTypeModifier = DataTypeModifier.OptionSet;
            }
            else if (source.IsUnion)
            {
                definition.DataTypeModifier = DataTypeModifier.Union;
            }

            if (source.Field != null)
            {
                List <Opc.Ua.DataTypeDefinitionField> fields = new List <Opc.Ua.DataTypeDefinitionField>();

                foreach (DataTypeField field in source.Field)
                {
                    Opc.Ua.DataTypeDefinitionField output = new Opc.Ua.DataTypeDefinitionField();

                    output.Name         = field.Name;
                    output.SymbolicName = field.SymbolicName;
                    output.Description  = Import(field.Description);
                    output.DataType     = ImportNodeId(field.DataType, namespaceUris, true);
                    output.ValueRank    = field.ValueRank;
                    output.Value        = field.Value;

                    fields.Add(output);
                }

                definition.Fields = fields;
            }

            return(definition);
        }
        /// <summary>
        /// Exports a DataTypeDefinition
        /// </summary>
        private Opc.Ua.Export.DataTypeDefinition Export(Opc.Ua.DataTypeDefinition2 source, NamespaceTable namespaceUris)
        {
            if (source == null)
            {
                return(null);
            }

            DataTypeDefinition definition = new DataTypeDefinition();

            definition.Name         = Export(source.Name, namespaceUris);
            definition.SymbolicName = source.SymbolicName;

            switch (source.DataTypeModifier)
            {
            case DataTypeModifier.Union: { definition.IsUnion = true; break; }

            case DataTypeModifier.OptionSet: { definition.IsOptionSet = true; break; }
            }

            if (source.Fields != null)
            {
                List <Opc.Ua.Export.DataTypeField> fields = new List <DataTypeField>();

                foreach (DataTypeDefinitionField field in source.Fields)
                {
                    Opc.Ua.Export.DataTypeField output = new Opc.Ua.Export.DataTypeField();

                    output.Name         = field.Name;
                    output.SymbolicName = field.SymbolicName;
                    output.Description  = Export(new Opc.Ua.LocalizedText[] { field.Description });

                    if (NodeId.IsNull(field.DataType))
                    {
                        output.DataType = Export(DataTypeIds.BaseDataType, namespaceUris);
                    }
                    else
                    {
                        output.DataType = Export(field.DataType, namespaceUris);
                    }

                    output.ValueRank = field.ValueRank;
                    output.Value     = field.Value;

                    fields.Add(output);
                }

                definition.Field = fields.ToArray();
            }

            return(definition);
        }