示例#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>
        /// Imports a DataTypeDefinition
        /// </summary>
        private Opc.Ua.DataTypeDefinition Import(UADataType dataType, Opc.Ua.Export.DataTypeDefinition source, NamespaceTable namespaceUris)
        {
            if (source == null)
            {
                return(null);
            }

            Opc.Ua.DataTypeDefinition definition = null;

            if (source.Field != null)
            {
                // check if definition is for enumeration or structure.
                bool isStructure = Array.Exists <DataTypeField>(source.Field, delegate(DataTypeField fieldLookup)
                {
                    return(fieldLookup.Value == -1);
                });

                if (isStructure)
                {
                    StructureDefinition structureDefinition = new StructureDefinition();
                    structureDefinition.BaseDataType = ImportNodeId(source.BaseType, namespaceUris, true);

                    if (source.IsUnion)
                    {
                        structureDefinition.StructureType = StructureType.Union;
                    }

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

                        foreach (DataTypeField field in source.Field)
                        {
                            if (field.IsOptional)
                            {
                                structureDefinition.StructureType = StructureType.StructureWithOptionalFields;
                            }

                            StructureField output = new StructureField();

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

                            fields.Add(output);
                        }

                        structureDefinition.Fields = fields.ToArray();
                    }
                    definition = structureDefinition;
                }
                else
                {
                    EnumDefinition enumDefinition = new EnumDefinition();
                    if (source.Field != null)
                    {
                        List <EnumField> fields = new List <EnumField>();

                        foreach (DataTypeField field in source.Field)
                        {
                            EnumField output = new EnumField();

                            output.Name        = field.Name;
                            output.DisplayName = Import(field.DisplayName);
                            output.Description = Import(field.Description);
                            output.Value       = field.Value;

                            fields.Add(output);
                        }

                        enumDefinition.Fields = fields.ToArray();
                    }
                    definition = enumDefinition;
                }
            }

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

            Opc.Ua.DataTypeDefinition definition = null;

            if (source.Field != null)
            {
                // check if definition is for enumeration or structure.
                bool isStructure = Array.Exists <DataTypeField>(source.Field, delegate(DataTypeField fieldLookup) {
                    return(fieldLookup.Value == -1);
                });

                if (isStructure)
                {
                    StructureDefinition sd = new StructureDefinition();
                    sd.BaseDataType = ImportNodeId(source.BaseType, namespaceUris, true);

                    if (source.IsUnion)
                    {
                        sd.StructureType = StructureType.Union;
                    }

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

                        foreach (DataTypeField field in source.Field)
                        {
                            if (sd.StructureType == StructureType.Structure ||
                                sd.StructureType == StructureType.Union)
                            {
                                if (field.IsOptional)
                                {
                                    sd.StructureType = StructureType.StructureWithOptionalFields;
                                }
                                else if (field.AllowSubTypes)
                                {
                                    if (source.IsUnion)
                                    {
                                        sd.StructureType = (StructureType)4; // StructureType.UnionWithSubtypedValues;
                                    }
                                    else
                                    {
                                        sd.StructureType = (StructureType)3; // StructureType.StructureWithSubtypedValues;
                                    }
                                }
                            }

                            StructureField output = new StructureField();

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

                            if (sd.StructureType == StructureType.Structure ||
                                sd.StructureType == StructureType.Union)
                            {
                                output.IsOptional = false;
                            }
                            else if (sd.StructureType == (StructureType)3 || //StructureType.StructureWithSubtypedValues ||
                                     sd.StructureType == (StructureType)4)   //StructureType.UnionWithSubtypedValues)
                            {
                                output.IsOptional = field.AllowSubTypes;
                            }
                            else
                            {
                                output.IsOptional = field.IsOptional;
                            }

                            fields.Add(output);
                        }

                        sd.Fields = fields.ToArray();
                    }

                    definition = sd;
                }
                else
                {
                    EnumDefinition ed = new EnumDefinition();
                    ed.IsOptionSet = source.IsOptionSet;

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

                        foreach (DataTypeField field in source.Field)
                        {
                            EnumField output = new EnumField();

                            output.Name        = field.Name;
                            output.DisplayName = Import(field.DisplayName);
                            output.Description = Import(field.Description);
                            output.Value       = field.Value;

                            fields.Add(output);
                        }

                        ed.Fields = fields.ToArray();
                    }

                    definition = ed;
                }
            }

            return(definition);
        }