public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { base.CreateAddressSpace(externalReferences); // hard code a sample branch that has the method added. NodeId branchId = DaModelUtils.ConstructIdForDaElement("Static/Simple Types", -1, NamespaceIndex); // create the method. MethodState method = new MethodState(null); method.NodeId = GenerateNodeId(); method.BrowseName = new QualifiedName("GenerateRandomValues", NamespaceIndex); method.DisplayName = method.BrowseName.Name; method.Executable = true; method.UserExecutable = true; method.ReferenceTypeId = ReferenceTypeIds.HasComponent; method.Handle = "Static/Simple Types"; method.AddReference(ReferenceTypeIds.HasComponent, true, branchId); m_references[branchId] = new IReference[] { new NodeStateReference(ReferenceTypeIds.HasComponent, false, method) }; // save the node for later lookup (all tightly coupled children are added with this call). AddPredefinedNode(SystemContext, method); // register handler. method.OnCallMethod = new GenericMethodCalledEventHandler(DoGenerateRandomValues); }
public MethodState CreateAddMethodState( NodeState parent, AasUaBaseEntity.CreateMode mode, string browseDisplayName, Argument[] inputArgs = null, Argument[] outputArgs = null, NodeId referenceTypeFromParentId = null, NodeId methodDeclarationId = null, GenericMethodCalledEventHandler onCalled = null) { // method node var m = new MethodState(parent); m.BrowseName = "" + browseDisplayName; m.DisplayName = "" + browseDisplayName; m.Description = new LocalizedText("en", browseDisplayName); m.NodeId = nodeMgr.New(nodeMgr.SystemContext, mode, m); if (methodDeclarationId != null) { m.MethodDeclarationId = methodDeclarationId; } m.Executable = true; m.UserExecutable = true; nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, m); if (parent != null) { parent.AddChild(m); } if (referenceTypeFromParentId != null) { if (parent != null) { parent.AddReference(referenceTypeFromParentId, false, m.NodeId); if (referenceTypeFromParentId == ReferenceTypeIds.HasComponent) { m.AddReference(referenceTypeFromParentId, true, parent.NodeId); } if (referenceTypeFromParentId == ReferenceTypeIds.HasProperty) { m.AddReference(referenceTypeFromParentId, true, parent.NodeId); } } } // can have inputs, outputs for (int i = 0; i < 2; i++) { // pretty argument list var arguments = (i == 0) ? inputArgs : outputArgs; if (arguments == null || arguments.Length < 1) { continue; } // make a property for this var prop = CreateAddPropertyState <Argument[]>( m, mode, (i == 0) ? "InputArguments" : "OutputArguments", DataTypeIds.Argument, arguments, ReferenceTypeIds.HasProperty, typeDefinitionId: VariableTypeIds.PropertyType, valueRank: 1); // explicitely add arguments ass well? if (i == 0) { m.InputArguments = prop; } if (i == 1) { m.OutputArguments = prop; } } // event handler if (onCalled != null) { m.OnCallMethod = onCalled; } return(m); }
/// <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); }