Ejemplo n.º 1
0
 /// <summary>
 /// Initializes the instance with its defalt attribute values.
 /// </summary>
 protected InstanceNodeModel(NodeClass nodeClass, BaseNodeModel parent) :
     base(nodeClass)
 {
     Parent = parent;
     if (Parent != null)
     {
         ReferenceTypeId = ReferenceTypeIds.HasComponent;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert to stack object
        /// </summary>
        /// <param name="nodeModel"></param>
        /// <param name="context"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static NodeState ToNodeState(this BaseNodeModel nodeModel, ISystemContext context,
                                            NodeState parent = null)
        {
            NodeState state;

            switch (nodeModel)
            {
            case ViewNodeModel viewState:
                state = new ViewState {
                    ContainsNoLoops = viewState.ContainsNoLoops ?? false,
                    EventNotifier   = viewState.EventNotifier ?? EventNotifiers.None,
                };
                break;

            case TypeNodeModel typeState:
                switch (typeState)
                {
                case VariableTypeNodeModel variableType:
                    switch (variableType)
                    {
                    case DataVariableTypeNodeModel data:
                        state = new BaseDataVariableTypeState();
                        break;

                    case PropertyTypeNodeModel property:
                        state = new PropertyTypeState();
                        break;

                    default:
                        return(null);
                    }
                    var baseVariableTypeState = state as BaseVariableTypeState;
                    baseVariableTypeState.ArrayDimensions =
                        variableType.ArrayDimensions;
                    baseVariableTypeState.DataType =
                        variableType.DataType;
                    baseVariableTypeState.ValueRank =
                        variableType.ValueRank ?? ValueRanks.Scalar;
                    baseVariableTypeState.WrappedValue =
                        variableType.Value ?? Variant.Null;
                    break;

                case ObjectTypeNodeModel objectType:
                    state = new BaseObjectTypeState();
                    break;

                case ReferenceTypeNodeModel referenceType:
                    state = new ReferenceTypeState {
                        Symmetric   = referenceType.Symmetric ?? false,
                        InverseName = referenceType.InverseName
                    };
                    break;

                case DataTypeNodeModel dataType:
                    state = new DataTypeState {
                        //  Definition = dataType.Definition.ToDataTypeDefinition()
                    };
                    break;

                default:
                    return(null);
                }
                var baseTypeState = state as BaseTypeState;
                baseTypeState.IsAbstract = typeState.IsAbstract ?? false;
                break;

            case InstanceNodeModel instanceState:
                switch (instanceState)
                {
                case VariableNodeModel variable:
                    switch (variable)
                    {
                    case DataVariableNodeModel data:
                        state = new BaseDataVariableState(parent);
                        break;

                    case PropertyNodeModel property:
                        state = new PropertyState(parent);
                        break;

                    default:
                        return(null);
                    }
                    var baseVariableState = state as BaseVariableState;
                    baseVariableState.ArrayDimensions =
                        variable.ArrayDimensions;
                    baseVariableState.DataType =
                        variable.DataType;
                    baseVariableState.ValueRank =
                        variable.ValueRank ?? ValueRanks.Scalar;
                    baseVariableState.Value =
                        variable.Value?.Value;
                    baseVariableState.AccessLevel =
                        variable.AccessLevel ?? AccessLevels.CurrentRead;
                    baseVariableState.UserAccessLevel =
                        variable.UserAccessLevel ?? AccessLevels.CurrentRead;
                    baseVariableState.IsValueType =
                        variable.IsValueType;
                    baseVariableState.Historizing =
                        variable.Historizing ?? false;
                    baseVariableState.MinimumSamplingInterval =
                        variable.MinimumSamplingInterval ?? 0.0;
                    baseVariableState.ModellingRuleId =
                        variable.ModellingRuleId;
                    baseVariableState.NumericId =
                        variable.NumericId;
                    baseVariableState.ReferenceTypeId =
                        variable.ReferenceTypeId;
                    baseVariableState.StatusCode =
                        variable.StatusCode ?? StatusCodes.Good;
                    baseVariableState.Timestamp =
                        variable.Timestamp ?? DateTime.MinValue;
                    baseVariableState.TypeDefinitionId =
                        variable.TypeDefinitionId;
                    break;

                case ObjectNodeModel obj:
                    state = new BaseObjectState(parent)
                    {
                        EventNotifier = obj.EventNotifier ?? EventNotifiers.None
                    };
                    break;

                case MethodNodeModel method:
                    state = new MethodState(parent)
                    {
                        UserExecutable      = method.UserExecutable,
                        Executable          = method.Executable,
                        MethodDeclarationId = method.MethodDeclarationId
                    };
                    break;

                default:
                    return(null);
                }
                break;

            default:
                return(null);
            }
            state.BrowseName    = nodeModel.BrowseName;
            state.Description   = nodeModel.Description;
            state.DisplayName   = nodeModel.DisplayName;
            state.Handle        = nodeModel.Handle;
            state.NodeId        = nodeModel.NodeId;
            state.SymbolicName  = nodeModel.SymbolicName;
            state.WriteMask     = nodeModel.WriteMask ?? AttributeWriteMask.None;
            state.UserWriteMask = nodeModel.UserWriteMask ?? AttributeWriteMask.None;
            state.Initialized   = true;
            foreach (var child in nodeModel.GetChildren(context))
            {
                state.AddChild(child.ToNodeState(context, state) as BaseInstanceState);
            }
            foreach (var reference in nodeModel.References)
            {
                state.AddReference(reference.ReferenceTypeId, reference.IsInverse,
                                   reference.TargetId);
            }
            return(state);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Convert to service object
        /// </summary>
        /// <param name="state"></param>
        /// <param name="context"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static BaseNodeModel ToNodeModel(this NodeState state, ISystemContext context,
                                                BaseNodeModel parent = null)
        {
            BaseNodeModel nodeModel;

            switch (state)
            {
            case ViewState viewState:
                nodeModel = new ViewNodeModel {
                    ContainsNoLoops = viewState.ContainsNoLoops.ToNullable(false),
                    EventNotifier   = viewState.EventNotifier.ToNullable(EventNotifiers.None),
                };
                break;

            case BaseTypeState typeState:
                switch (typeState)
                {
                case BaseVariableTypeState variableType:
                    switch (variableType)
                    {
                    case BaseDataVariableTypeState data:
                        nodeModel = new DataVariableTypeNodeModel();
                        break;

                    case PropertyTypeState property:
                        nodeModel = new PropertyTypeNodeModel();
                        break;

                    default:
                        return(null);
                    }
                    var baseVariableTypeState = nodeModel as VariableTypeNodeModel;
                    baseVariableTypeState.ArrayDimensions =
                        variableType.ArrayDimensions?.ToArray();
                    baseVariableTypeState.DataType =
                        variableType.DataType;
                    baseVariableTypeState.ValueRank =
                        variableType.ValueRank.ToNullable(ValueRanks.Scalar);
                    baseVariableTypeState.Value =
                        variableType.WrappedValue;
                    break;

                case BaseObjectTypeState objectType:
                    nodeModel = new ObjectTypeNodeModel();
                    break;

                case ReferenceTypeState referenceType:
                    nodeModel = new ReferenceTypeNodeModel {
                        Symmetric   = referenceType.Symmetric.ToNullable(false),
                        InverseName = referenceType.InverseName
                    };
                    break;

                case DataTypeState dataType:
                    nodeModel = new DataTypeNodeModel {
                        //  Definition = dataType.Definition.ToDataTypeDefinition(),
                        Purpose = Schema.DataTypePurpose.Normal
                    };
                    break;

                default:
                    return(null);
                }
                var baseTypeState = nodeModel as TypeNodeModel;
                baseTypeState.IsAbstract = typeState.IsAbstract.ToNullable(false);
                break;

            case BaseInstanceState instanceState:
                switch (instanceState)
                {
                case BaseVariableState variable:
                    switch (variable)
                    {
                    case BaseDataVariableState data:
                        nodeModel = new DataVariableNodeModel(parent);
                        break;

                    case PropertyState property:
                        nodeModel = new PropertyNodeModel(parent);
                        break;

                    default:
                        return(null);
                    }
                    var baseVariableState = nodeModel as VariableNodeModel;
                    baseVariableState.ArrayDimensions =
                        variable.ArrayDimensions.ToArray();
                    baseVariableState.DataType =
                        variable.DataType;
                    baseVariableState.ValueRank =
                        variable.ValueRank.ToNullable(ValueRanks.Scalar);
                    baseVariableState.Value =
                        variable.WrappedValue;
                    baseVariableState.AccessLevel =
                        variable.AccessLevel.ToNullable(AccessLevels.CurrentRead);
                    baseVariableState.UserAccessLevel =
                        variable.UserAccessLevel.ToNullable(AccessLevels.CurrentRead);
                    baseVariableState.IsValueType =
                        variable.IsValueType;
                    baseVariableState.Historizing =
                        variable.Historizing.ToNullable(false);
                    baseVariableState.MinimumSamplingInterval =
                        variable.MinimumSamplingInterval.ToNullable(0.0);
                    baseVariableState.ModellingRuleId =
                        variable.ModellingRuleId;
                    baseVariableState.NumericId =
                        variable.NumericId;
                    baseVariableState.ReferenceTypeId =
                        variable.ReferenceTypeId;
                    baseVariableState.StatusCode =
                        variable.StatusCode.ToNullable(StatusCodes.Good);
                    baseVariableState.Timestamp =
                        variable.Timestamp.ToNullable(DateTime.MinValue);
                    baseVariableState.TypeDefinitionId =
                        variable.TypeDefinitionId;
                    break;

                case BaseObjectState obj:
                    nodeModel = new ObjectNodeModel(parent)
                    {
                        EventNotifier = obj.EventNotifier.ToNullable(EventNotifiers.None)
                    };
                    break;

                case MethodState method:
                    nodeModel = new MethodNodeModel(parent)
                    {
                        UserExecutable      = method.UserExecutable,
                        Executable          = method.Executable,
                        MethodDeclarationId = method.MethodDeclarationId,
                    };
                    break;

                default:
                    return(null);
                }
                break;

            default:
                return(null);
            }
            nodeModel.BrowseName    = state.BrowseName;
            nodeModel.Description   = state.Description;
            nodeModel.DisplayName   = state.DisplayName;
            nodeModel.Handle        = state.Handle;
            nodeModel.NodeId        = state.NodeId;
            nodeModel.SymbolicName  = state.SymbolicName;
            nodeModel.WriteMask     = state.WriteMask.ToNullable(AttributeWriteMask.None);
            nodeModel.UserWriteMask = state.UserWriteMask.ToNullable(AttributeWriteMask.None);
            var children = new List <BaseInstanceState>();

            state.GetChildren(context, children);
            foreach (var child in children)
            {
                nodeModel.AddChild(child.ToNodeModel(context, nodeModel) as InstanceNodeModel);
            }
            var references = new List <IReference>();

            state.GetReferences(context, references);
            foreach (var reference in references)
            {
                nodeModel.AddReference(reference.ReferenceTypeId, reference.IsInverse,
                                       reference.TargetId);
            }
            return(nodeModel);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Create object node
 /// </summary>
 public ObjectNodeModel(BaseNodeModel parent = null) :
     base(NodeClass.Object, parent)
 {
 }
 /// <summary>
 /// Create method node
 /// </summary>
 public MethodNodeModel(BaseNodeModel parent = null) :
     base(NodeClass.Method, parent)
 {
     Executable     = true;
     UserExecutable = true;
 }
        /// <inheritdoc/>
        public virtual void Decode(IDecoder decoder)
        {
            decoder.PushNamespace(Namespaces.OpcUa);
            decoder.PushNamespace(Namespaces.OpcUaXsd);
            Node               = CreateModel(decoder.ReadString(kTypeFieldName));
            Node.NodeId        = decoder.ReadNodeId(nameof(Node.NodeId));
            Node.SymbolicName  = decoder.ReadString(nameof(Node.SymbolicName));
            Node.BrowseName    = decoder.ReadQualifiedName(nameof(Node.BrowseName));
            Node.DisplayName   = decoder.ReadLocalizedText(nameof(Node.DisplayName));
            Node.Description   = decoder.ReadLocalizedText(nameof(Node.Description));
            Node.WriteMask     = decoder.ReadEnumerated <AttributeWriteMask>(nameof(Node.WriteMask));
            Node.UserWriteMask = decoder.ReadEnumerated <AttributeWriteMask>(nameof(Node.UserWriteMask));
            switch (Node)
            {
            case InstanceNodeModel instanceState:
                instanceState.ReferenceTypeId =
                    decoder.ReadNodeId(nameof(instanceState.ReferenceTypeId));
                instanceState.TypeDefinitionId =
                    decoder.ReadNodeId(nameof(instanceState.TypeDefinitionId));
                instanceState.ModellingRuleId =
                    decoder.ReadNodeId(nameof(instanceState.ModellingRuleId));
                instanceState.NumericId =
                    decoder.ReadUInt32(nameof(instanceState.NumericId));
                switch (instanceState)
                {
                case ObjectNodeModel objectState:
                    objectState.EventNotifier =
                        decoder.ReadByte(nameof(objectState.EventNotifier));
                    break;

                case VariableNodeModel variableState:
                    variableState.Value =
                        decoder.ReadVariant(nameof(variableState.Value));
                    variableState.StatusCode =
                        decoder.ReadStatusCode(nameof(variableState.StatusCode));
                    variableState.DataType =
                        decoder.ReadNodeId(nameof(variableState.DataType));
                    variableState.ValueRank =
                        decoder.ReadInt32(nameof(variableState.ValueRank));
                    variableState.ArrayDimensions =
                        decoder.ReadUInt32Array(nameof(variableState.ArrayDimensions))?.ToArray();
                    variableState.AccessLevel =
                        decoder.ReadByte(nameof(variableState.AccessLevel));
                    variableState.AccessLevelEx =
                        decoder.ReadUInt32(nameof(variableState.AccessLevelEx));
                    variableState.UserAccessLevel =
                        decoder.ReadByte(nameof(variableState.UserAccessLevel));
                    variableState.MinimumSamplingInterval =
                        decoder.ReadDouble(nameof(variableState.MinimumSamplingInterval));
                    variableState.Historizing =
                        decoder.ReadBoolean(nameof(variableState.Historizing));
                    break;

                case MethodNodeModel methodState:
                    methodState.Executable =
                        decoder.ReadBoolean(nameof(methodState.Executable));
                    methodState.UserExecutable =
                        decoder.ReadBoolean(nameof(methodState.UserExecutable));
                    break;
                }
                break;

            case TypeNodeModel typeState:
                typeState.IsAbstract  = decoder.ReadBoolean(nameof(typeState.IsAbstract));
                typeState.SuperTypeId = decoder.ReadNodeId(nameof(typeState.SuperTypeId));
                switch (Node)
                {
                case VariableTypeNodeModel variableTypeState:
                    variableTypeState.Value =
                        decoder.ReadVariant(nameof(variableTypeState.Value));
                    variableTypeState.DataType =
                        decoder.ReadNodeId(nameof(variableTypeState.DataType));
                    variableTypeState.ValueRank =
                        decoder.ReadInt32(nameof(variableTypeState.ValueRank));
                    variableTypeState.ArrayDimensions =
                        decoder.ReadUInt32Array(nameof(variableTypeState.ArrayDimensions))?.ToArray();
                    break;

                case ReferenceTypeNodeModel refTypeState:
                    refTypeState.Symmetric =
                        decoder.ReadBoolean(nameof(refTypeState.Symmetric));
                    refTypeState.InverseName =
                        decoder.ReadLocalizedText(nameof(refTypeState.InverseName));
                    break;

                case DataTypeNodeModel dataTypeState:
                    var definitionType = GetDefinitionType(
                        decoder.ReadString(kDefinitionTypeFieldName));
                    dataTypeState.Definition = (DataTypeDefinition)decoder.ReadEncodeable(
                        nameof(dataTypeState.Definition), definitionType);
                    dataTypeState.Purpose = decoder.ReadEnumerated <Schema.DataTypePurpose>(
                        nameof(dataTypeState.Purpose));
                    break;

                case ObjectTypeNodeModel objectTypeState:
                    break;
                }
                break;

            case ViewNodeModel viewState:
                viewState.EventNotifier   = decoder.ReadByte(nameof(viewState.EventNotifier));
                viewState.ContainsNoLoops = decoder.ReadBoolean(nameof(viewState.ContainsNoLoops));
                break;
            }

            var ctx      = decoder.Context.ToSystemContext();
            var children = decoder.ReadEncodeableArray <EncodeableNodeModel>(kChildrenFieldName);

            foreach (var child in children.Select(n => n.Node).OfType <InstanceNodeModel>())
            {
                Node.AddChild(child);
            }
            var references = decoder.ReadEncodeableArray <EncodeableReferenceModel>(kReferencesFieldName);

            Node.AddReferences(references.Select(r => r.Reference).ToList());
            decoder.PopNamespace();
            decoder.PopNamespace();
        }
 /// <summary>
 /// Create encodeable node state
 /// </summary>
 /// <param name="state"></param>
 public EncodeableNodeModel(BaseNodeModel state)
 {
     Node = state;
 }
 /// <summary>
 /// Create variable node
 /// </summary>
 /// <param name="parent"></param>
 protected VariableNodeModel(BaseNodeModel parent = null) :
     base(NodeClass.Variable, parent)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Create property state.
 /// </summary>
 public PropertyNodeModel(BaseNodeModel parent = null) :
     base(parent)
 {
 }
 /// <summary>
 /// Create data variable node
 /// </summary>
 public DataVariableNodeModel(BaseNodeModel parent = null) :
     base(parent)
 {
 }