/// <summary> /// Initializes the node id with an identifier. /// </summary> public ExpandedNodeId(NodeId nodeId) { if (nodeId != null) { Identifier = nodeId.Identifier; } }
/// <summary> /// Creates a new browser object with a set of filters. /// </summary> public NodeBrowser( ISystemContext context, ViewDescription view, NodeId referenceType, bool includeSubtypes, BrowseDirection browseDirection, QualifiedName browseName, IEnumerable<IReference> additionalReferences, bool internalOnly) { m_context = context; m_view = view; m_referenceType = referenceType; m_includeSubtypes = includeSubtypes; m_browseDirection = browseDirection; m_browseName = browseName; m_internalOnly = internalOnly; m_references = new List<IReference>(); m_index = 0; // add any additional references if they meet the criteria. if (additionalReferences != null) { foreach (IReference reference in additionalReferences) { if (IsRequired(reference.ReferenceTypeId, reference.IsInverse)) { m_references.Add(reference); } } } }
/// <summary> /// Initializes an instance of the argument. /// </summary> public Argument(string name, NodeId dataType, int valueRank, string description) { this.m_name = name; this.m_dataType = dataType; this.m_valueRank = valueRank; this.m_description = description; }
/// <summary> /// Creates the monitored item based on the current definition. /// </summary> /// <param name="session">The session.</param> /// <returns>The monitored item.</returns> public MonitoredItem CreateMonitoredItem(Session session) { // choose the server object by default. if (AreaId == null) { AreaId = ObjectIds.Server; } // create the item with the filter. MonitoredItem monitoredItem = new MonitoredItem(); monitoredItem.DisplayName = null; monitoredItem.StartNodeId = AreaId; monitoredItem.RelativePath = null; monitoredItem.NodeClass = NodeClass.Object; monitoredItem.AttributeId = Attributes.EventNotifier; monitoredItem.IndexRange = null; monitoredItem.Encoding = null; monitoredItem.MonitoringMode = MonitoringMode.Reporting; monitoredItem.SamplingInterval = 0; monitoredItem.QueueSize = UInt32.MaxValue; monitoredItem.DiscardOldest = true; monitoredItem.Filter = ConstructFilter(session); // save the definition as the handle. monitoredItem.Handle = this; return monitoredItem; }
/// <summary> /// Initializes the control with a root and a set of hierarchial reference types to follow. /// </summary> /// <param name="session">The session.</param> /// <param name="rootId">The root of the hierarchy to browse.</param> /// <param name="referenceTypeIds">The reference types to follow.</param> public void Initialize( Session session, NodeId rootId, params NodeId[] referenceTypeIds) { BrowseCTRL.Initialize(session, rootId, referenceTypeIds); }
/// <summary> /// Handles the generate values method. /// </summary> protected override ServiceResult OnGenerateValues( ISystemContext context, MethodState method, NodeId objectId, uint count) { TestDataSystem system = context.SystemHandle as TestDataSystem; if (system == null) { return StatusCodes.BadOutOfService; } GenerateValue(system, SByteValue); GenerateValue(system, ByteValue); GenerateValue(system, Int16Value); GenerateValue(system, UInt16Value); GenerateValue(system, Int32Value); GenerateValue(system, UInt32Value); GenerateValue(system, UInt32Value); GenerateValue(system, Int64Value); GenerateValue(system, UInt64Value); GenerateValue(system, FloatValue); GenerateValue(system, DoubleValue); GenerateValue(system, NumberValue); GenerateValue(system, IntegerValue); GenerateValue(system, UIntegerValue); return base.OnGenerateValues(context, method, objectId, count); }
/// <summary> /// Prompts the user to edit a value. /// </summary> public Variant ShowDialog(Session session, NodeId nodeId) { m_session = session; m_nodeId = nodeId; #region Task #B2 - Write Value // generate a default value based on the data type. m_value = Variant.Null; m_sourceType = GetExpectedType(session, nodeId); if (m_sourceType != null) { m_value = new Variant(TypeInfo.GetDefaultValue(m_sourceType.BuiltInType), m_sourceType); } // cast the value to a string. ValueTB.Text = (string)TypeInfo.Cast(m_value.Value, m_value.TypeInfo, BuiltInType.String); #endregion if (ShowDialog() != DialogResult.OK) { return Variant.Null; } return m_value; }
/// <summary> /// Creates a new browser object with a set of filters. /// </summary> public AreaBrowser( ISystemContext context, ViewDescription view, NodeId referenceType, bool includeSubtypes, BrowseDirection browseDirection, QualifiedName browseName, IEnumerable<IReference> additionalReferences, bool internalOnly, AreaState area) : base( context, view, referenceType, includeSubtypes, browseDirection, browseName, additionalReferences, internalOnly) { m_stage = Stage.Begin; if (area != null) { m_area = AreaState.GetDirectory(context, area.NodeId); m_isRoot = area.IsRoot; } }
/// <summary> /// Initializes a new instance of the <see cref="BlockState"/> class. /// </summary> /// <param name="nodeManager">The context.</param> /// <param name="nodeId">The node id.</param> /// <param name="block">The block.</param> public BlockState( HistoricalAccessServerNodeManager nodeManager, NodeId nodeId, UnderlyingSystemBlock block) : base(null) { m_blockId = block.Id; m_nodeManager = nodeManager; this.SymbolicName = block.Name; this.NodeId = nodeId; this.BrowseName = new QualifiedName(block.Name, nodeId.NamespaceIndex); this.DisplayName = new LocalizedText(block.Name); this.Description = null; this.WriteMask = 0; this.UserWriteMask = 0; this.EventNotifier = EventNotifiers.None; UnderlyingSystem system = nodeManager.SystemContext.SystemHandle as UnderlyingSystem; if (system != null) { IList<UnderlyingSystemTag> tags = block.GetTags(); for (int ii = 0; ii < tags.Count; ii++) { BaseVariableState variable = CreateVariable(nodeManager.SystemContext, tags[ii]); AddChild(variable); variable.OnSimpleWriteValue = OnWriteTagValue; } } }
/// <summary> /// Creates a new browser object with a set of filters. /// </summary> /// <param name="context">The system context to use.</param> /// <param name="view">The view which may restrict the set of references/nodes found.</param> /// <param name="referenceType">The type of references being followed.</param> /// <param name="includeSubtypes">Whether subtypes of the reference type are followed.</param> /// <param name="browseDirection">Which way the references are being followed.</param> /// <param name="browseName">The browse name of a specific target (used when translating browse paths).</param> /// <param name="additionalReferences">Any additional references that should be included.</param> /// <param name="internalOnly">If true the browser should not making blocking calls to external systems.</param> /// <param name="itemId">The item id.</param> /// <param name="namespaceIndex">Index of the namespace.</param> public DaElementBrowser( ISystemContext context, ViewDescription view, NodeId referenceType, bool includeSubtypes, BrowseDirection browseDirection, QualifiedName browseName, IEnumerable<IReference> additionalReferences, bool internalOnly, string itemId, ushort namespaceIndex) : base( context, view, referenceType, includeSubtypes, browseDirection, browseName, additionalReferences, internalOnly) { m_itemId = itemId; m_namespaceIndex = namespaceIndex; m_stage = Stage.Begin; }
public void Show(Session session, NodeId nodeId) { m_session = session; m_nodeId = nodeId; Show(); }
/// <summary> /// Initializes a memory tag for a buffer. /// </summary> /// <param name="parent">The buffer that owns the tag.</param> /// <param name="offet">The offset of the tag address in the memory buffer.</param> public MemoryTagState(MemoryBufferState parent, uint offet) : base(parent) { // these objects are created an discarded during each operation. // the metadata is derived from the parameters passed to constructors. NodeId = new NodeId(Utils.Format("{0}[{1}]", parent.SymbolicName, offet), parent.NodeId.NamespaceIndex); BrowseName = new QualifiedName(Utils.Format("{1:X8}", parent.SymbolicName, offet), parent.TypeDefinitionId.NamespaceIndex); DisplayName = BrowseName.Name; Description = null; WriteMask = AttributeWriteMask.None; UserWriteMask = AttributeWriteMask.None; ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HasComponent; TypeDefinitionId = new NodeId(VariableTypes.MemoryTagType, parent.TypeDefinitionId.NamespaceIndex); ModellingRuleId = null; NumericId = offet; DataType = new NodeId((uint)parent.ElementType); ValueRank = ValueRanks.Scalar; ArrayDimensions = null; AccessLevel = AccessLevels.CurrentReadOrWrite; UserAccessLevel = AccessLevels.CurrentReadOrWrite; MinimumSamplingInterval = parent.MaximumScanRate; Historizing = false; // re-direct read and write operations to the parent. OnReadValue = parent.ReadTagValue; OnWriteValue = parent.WriteTagValue; m_offset = offet; }
/// <summary> /// Updates the list of references. /// </summary> private void UpdateList(Session session, NodeId nodeId) { m_nodeId = nodeId; ReferencesLV.Items.Clear(); List<ReferenceDescription> references = Browse(session, nodeId); DisplayReferences(session, references); }
/// <summary> /// Prompts the user to view or edit the value. /// </summary> public object ShowDialog( Session session, NodeId nodeId, uint attributeId, string name, object value, bool readOnly, string caption) { if (!String.IsNullOrEmpty(caption)) { this.Text = caption; } OkBTN.Visible = !readOnly; ValueCTRL.ChangeSession(session); ValueCTRL.ShowValue(nodeId, attributeId, name, value, readOnly); if (base.ShowDialog() != DialogResult.OK) { return null; } return ValueCTRL.GetValue(); }
/// <summary> /// Creates a new browser object with a set of filters. /// </summary> public Browser( ISystemContext context, ViewDescription view, NodeId referenceType, bool includeSubtypes, BrowseDirection browseDirection, QualifiedName browseName, IEnumerable<IReference> additionalReferences, bool internalOnly, Opc.Ua.Client.Session client, NamespaceMapper mapper, NodeState source, NodeId rootId) : base( context, view, referenceType, includeSubtypes, browseDirection, browseName, additionalReferences, internalOnly) { m_client = client; m_mapper = mapper; m_source = source; m_rootId = rootId; m_stage = Stage.Begin; }
public void Show(Session session, NodeId objectId, NodeId methodId) { m_session = session; m_objectId = objectId; m_methodId = methodId; Show(); }
/// <summary> /// Sets the lock for the phase. /// </summary> public void SetPhaseLock(NodeId phaseId, NodeId lockId) { if (m_mapping == null) { m_mapping = new NodeIdDictionary<NodeId>(); } m_mapping[phaseId] = lockId; }
/// <summary> /// Sets the phase for the rig. /// </summary> public void SetPhase(NodeId phaseId) { if (m_knownPhases == null) { m_knownPhases = new List<NodeId>(); } m_knownPhases.Add(phaseId); }
/// <summary> /// Returns true if the phase is valid. /// </summary> public bool IsValidPhase(NodeId phaseId) { if (m_knownPhases != null) { return m_knownPhases.Contains(phaseId); } return false; }
public static string GetNodeIdAsJson(Opc.Ua.NodeId nodeId, NamespaceTable namespaceTable) { var nsUrl = namespaceTable.GetString(nodeId.NamespaceIndex); var nsNodeId = new NSNodeId() { id = nodeId.ToString(), namespaceUrl = nsUrl }; var nid = System.Text.Json.JsonSerializer.Serialize(nsNodeId); return(nid); }
/// <summary> /// Sets the method called by the control. /// </summary> public void SetMethod(NodeId objectId, NodeId methodId) { StringBuilder buffer = new StringBuilder(); buffer.Append("Calling Method "); buffer.Append(m_session.NodeCache.GetDisplayText(methodId)); buffer.Append(" on Object "); buffer.Append(m_session.NodeCache.GetDisplayText(objectId)); this.Text = buffer.ToString(); CallRequestCTRL.SetMethod(objectId, methodId); }
/// <summary> /// Displays the dialog. /// </summary> public void Show(Session session, NodeId nodeId) { m_session = session; m_nodeId = nodeId; #region Task #B3 - Subscribe Data CreateSubscription(); #endregion Show(); }
/// <summary> /// Returns true if the snapshort is an instance of the specified type. /// </summary> /// <param name="context">The context to use when checking the type definition.</param> /// <param name="typeDefinitionId">The type of the instance.</param> /// <returns> /// True if the object is an instance of the specified type. /// </returns> public bool IsTypeOf(FilterContext context, NodeId typeDefinitionId) { if (!NodeId.IsNull(typeDefinitionId)) { if (!context.TypeTree.IsTypeOf(m_typeDefinitionId, typeDefinitionId)) { return false; } } return true; }
public static ReferenceDescriptionCollection Browse(Session session, NodeId nodeId) { var desc = new BrowseDescription { NodeId = nodeId, BrowseDirection = BrowseDirection.Forward, IncludeSubtypes = true, NodeClassMask = 0U, ResultMask = 63U, }; return Browse(session, desc, true); }
public void Show(Session session, NodeId objectId, NodeId methodId) { m_session = session; m_objectId = objectId; m_methodId = methodId; #region Task #B4 - Call a Method UpdateArguments(session, methodId); #endregion Show(); }
/// <summary> /// Prompts the user to edit a value. /// </summary> public Variant ShowDialog(Session session, NodeId nodeId) { m_session = session; m_nodeId = nodeId; if (ShowDialog() != DialogResult.OK) { return Variant.Null; } return m_value; }
/// <summary cref="ITypeTable.IsKnown(NodeId)" /> public bool IsKnown(NodeId typeId) { if (NodeId.IsNull(typeId)) { return false; } lock (m_lock) { return m_nodes.ContainsKey(typeId); } }
/// <summary> /// Creates a relative path to follow the forward reference type to find the specified browse name. /// </summary> public RelativePath(NodeId referenceTypeId, bool isInverse, bool includeSubtypes, QualifiedName browseName) { Initialize(); RelativePathElement element = new RelativePathElement(); element.ReferenceTypeId = referenceTypeId; element.IsInverse = isInverse; element.IncludeSubtypes = includeSubtypes; element.TargetName = browseName; m_elements.Add(element); }
public NodeId ShowDialog(Session session, NodeId value) { if (session == null) throw new ArgumentNullException("session"); m_browser = new Browser(session); m_rootId = Objects.RootFolder; this.Identifier = value; Popup myPopup = new Popup(); myPopup.Child = this; myPopup.IsOpen = true; return this.Identifier; }
/// <summary> /// Gets the lock for the phase. /// </summary> public NodeId GetLockForPhase(NodeId phaseId) { if (m_mapping != null) { NodeId lockId = null; if (m_mapping.TryGetValue(phaseId, out lockId)) { return lockId; } } return null; }
/// <summary> /// Initializes a new instance of the <see cref="SegmentState"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="nodeId">The node id.</param> /// <param name="segment">The segment.</param> public SegmentState(ISystemContext context, NodeId nodeId, UnderlyingSystemSegment segment) : base(null) { m_segmentPath = segment.Id; this.TypeDefinitionId = ObjectTypeIds.FolderType; this.SymbolicName = segment.Name; this.NodeId = nodeId; this.BrowseName = new QualifiedName(segment.Name, nodeId.NamespaceIndex); this.DisplayName = new LocalizedText(segment.Name); this.Description = null; this.WriteMask = 0; this.UserWriteMask = 0; this.EventNotifier = EventNotifiers.None; }
/// <summary> /// Imports a NodeId /// </summary> private Opc.Ua.NodeId ImportNodeId(string source, NamespaceTable namespaceUris, bool lookupAlias) { if (String.IsNullOrEmpty(source)) { return(Opc.Ua.NodeId.Null); } // parse the string. Opc.Ua.NodeId nodeId = Opc.Ua.NodeId.Parse(source); if (nodeId.NamespaceIndex > 0) { ushort namespaceIndex = ImportNamespaceIndex(nodeId.NamespaceIndex, namespaceUris); nodeId = new Opc.Ua.NodeId(nodeId.Identifier, namespaceIndex); } return(nodeId); }
/// <summary> /// Adds type to the table. A browse name is only required if it is a ReferenceType. /// </summary> /// <param name="subTypeId">The sub type identifier.</param> /// <param name="superTypeId">The super type identifier.</param> /// <remarks> /// Updates the any existing entry. /// </remarks> public void AddSubtype(NodeId subTypeId, NodeId superTypeId) { AddSubtype(subTypeId, superTypeId, null); }
/// <summary> /// Adds type to the table. A browse name is only required if it is a ReferenceType. /// </summary> /// <param name="subTypeId">The sub type identifier.</param> /// <param name="superTypeId">The super type identifier.</param> /// <param name="browseName">Name of the browse.</param> /// <remarks> /// Updates the any existing entry. /// </remarks> public void AddReferenceSubtype(NodeId subTypeId, NodeId superTypeId, QualifiedName browseName) { AddSubtype(subTypeId, superTypeId, browseName); }
/// <summary> /// Initializes a guid node identifier. /// </summary> /// <remarks> /// Creates a new instance of the class while specifying the <see cref="Guid"/> value /// of the node we are wrapping. /// </remarks> /// <param name="value">The Guid value of the node we are wrapping</param> public ExpandedNodeId(Guid value) { Initialize(); m_nodeId = new NodeId(value); }
/// <summary> /// Returns the BuiltInType type for the DataTypeId. /// </summary> public static BuiltInType GetBuiltInType(NodeId datatypeId) { return(TypeInfo.GetBuiltInType(datatypeId)); }
/// <summary> /// Initializes an opaque node identifier with a namespace index. /// </summary> /// <remarks> /// Creates a new instance of the class while allowing you to specify the node /// and namespace index. /// </remarks> /// <param name="namespaceIndex">The index of the namespace that this node should belong to</param> /// <param name="value">The id of the node we are wrapping</param> public ExpandedNodeId(byte[] value, ushort namespaceIndex) { Initialize(); m_nodeId = new NodeId(value, namespaceIndex); }
/// <summary> /// Write the value for any non-value attribute. /// </summary> protected override ServiceResult WriteNonValueAttribute( ISystemContext context, uint attributeId, object value) { ServiceResult result = null; switch (attributeId) { case Attributes.DataType: { NodeId dataType = value as NodeId; if (dataType == null) { return(StatusCodes.BadTypeMismatch); } if ((WriteMask & AttributeWriteMask.DataType) == 0) { return(StatusCodes.BadNotWritable); } if (OnWriteDataType != null) { result = OnWriteDataType(context, this, ref dataType); } if (ServiceResult.IsGood(result)) { DataType = dataType; } return(result); } case Attributes.ValueRank: { int?valueRankRef = value as int?; if (valueRankRef == null) { return(StatusCodes.BadTypeMismatch); } if ((WriteMask & AttributeWriteMask.ValueRank) == 0) { return(StatusCodes.BadNotWritable); } int valueRank = valueRankRef.Value; if (OnWriteValueRank != null) { result = OnWriteValueRank(context, this, ref valueRank); } if (ServiceResult.IsGood(result)) { ValueRank = valueRank; } return(result); } case Attributes.ArrayDimensions: { IList <uint> arrayDimensions = value as IList <uint>; if ((WriteMask & AttributeWriteMask.ArrayDimensions) == 0) { return(StatusCodes.BadNotWritable); } if (OnWriteArrayDimensions != null) { result = OnWriteArrayDimensions(context, this, ref arrayDimensions); } if (ServiceResult.IsGood(result)) { if (arrayDimensions != null) { m_arrayDimensions = new ReadOnlyList <uint>(arrayDimensions); } else { ArrayDimensions = null; } } return(result); } } return(base.WriteNonValueAttribute(context, attributeId, value)); }
/// <summary> /// Returns the system type for the datatype. /// </summary> public static Type GetSystemType(NodeId datatypeId, EncodeableFactory factory) { return(TypeInfo.GetSystemType(datatypeId, factory)); }
/// <summary> /// Adds or replaces a reference. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="replace">if set to <c>true</c> reference is replaced.</param> private void Add(IReference key, T value, bool replace) { // validate key. ValidateReference(key, true); m_version++; // look up the reference type. ReferenceTypeEntry entry = null; if (!m_references.TryGetValue(key.ReferenceTypeId, out entry)) { entry = new ReferenceTypeEntry(); m_references.Add(key.ReferenceTypeId, entry); } // handle reference to external targets. if (key.TargetId.IsAbsolute) { Dictionary <ExpandedNodeId, LinkedListNode <KeyValuePair <IReference, T> > > targets = null; if (key.IsInverse) { if (entry.InverseExternalTargets == null) { entry.InverseExternalTargets = new Dictionary <ExpandedNodeId, LinkedListNode <KeyValuePair <IReference, T> > >(); } targets = entry.InverseExternalTargets; } else { if (entry.ForwardExternalTargets == null) { entry.ForwardExternalTargets = new Dictionary <ExpandedNodeId, LinkedListNode <KeyValuePair <IReference, T> > >(); } targets = entry.ForwardExternalTargets; } // create a new target. LinkedListNode <KeyValuePair <IReference, T> > node = new LinkedListNode <KeyValuePair <IReference, T> >(new KeyValuePair <IReference, T>(key, value)); // check if target already exists. LinkedListNode <KeyValuePair <IReference, T> > existingNode = null; if (!targets.TryGetValue(key.TargetId, out existingNode)) { existingNode = node; m_list.AddLast(node); } // need to replace reference in linked linked as well as the target list. else { if (!replace) { throw new ArgumentException("Key already exists in dictionary.", "key"); } m_list.AddAfter(existingNode, node); m_list.Remove(existingNode); } targets[key.TargetId] = node; } // handle reference to internal target. else { NodeIdDictionary <LinkedListNode <KeyValuePair <IReference, T> > > targets = null; if (key.IsInverse) { if (entry.InverseTargets == null) { entry.InverseTargets = new NodeIdDictionary <LinkedListNode <KeyValuePair <IReference, T> > >(); } targets = entry.InverseTargets; } else { if (entry.ForwardTargets == null) { entry.ForwardTargets = new NodeIdDictionary <LinkedListNode <KeyValuePair <IReference, T> > >(); } targets = entry.ForwardTargets; } NodeId targetId = (NodeId)key.TargetId; // create a new target. LinkedListNode <KeyValuePair <IReference, T> > node = new LinkedListNode <KeyValuePair <IReference, T> >(new KeyValuePair <IReference, T>(key, value)); // check if target already exists. LinkedListNode <KeyValuePair <IReference, T> > existingNode = null; if (!targets.TryGetValue(targetId, out existingNode)) { existingNode = node; m_list.AddLast(node); } // need to replace reference in linked linked as well as the target list. else { if (!replace) { throw new ArgumentException("Key already exists in dictionary.", "key"); } m_list.AddAfter(existingNode, node); m_list.Remove(existingNode); } targets[targetId] = node; } }
/// <summary> /// Removes a node from the set. /// </summary> /// <param name="nodeId">The node identifier.</param> /// <returns>The result of the removal.</returns> /// <remarks> /// The NodeId must reference the strings for the node set. /// </remarks> public bool Remove(NodeId nodeId) { return(m_nodes.Remove(nodeId)); }
/// <summary> /// Removes the reference from the node. /// </summary> /// <param name="referenceTypeId">The reference type identifier.</param> /// <param name="isInverse">if set to <c>true</c> this is inverse reference.</param> /// <param name="targetId">The target identifier.</param> /// <returns>The result of removal.</returns> public bool Remove(NodeId referenceTypeId, bool isInverse, ExpandedNodeId targetId) { return(m_references.Remove(new ReferenceNode(referenceTypeId, isInverse, targetId))); }
/// <summary> /// Adds the reference to the node. /// </summary> /// <param name="referenceTypeId">The reference type identifier.</param> /// <param name="isInverse">if set to <c>true</c> this is inverse reference.</param> /// <param name="targetId">The target identifier.</param> public void Add(NodeId referenceTypeId, bool isInverse, ExpandedNodeId targetId) { m_references[new ReferenceNode(referenceTypeId, isInverse, targetId)] = null; }
/// <summary> /// Initializes a new instance of the <see cref="ExpandedNodeId"/> class. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="namespaceIndex">The namespace index.</param> /// <param name="namespaceUri">The namespace URI.</param> /// <param name="serverIndex">The server index.</param> public ExpandedNodeId(object identifier, ushort namespaceIndex, string namespaceUri, uint serverIndex) { m_nodeId = new NodeId(identifier, namespaceIndex); m_namespaceUri = namespaceUri; m_serverIndex = serverIndex; }
/// <summary> /// Initializes a node id by parsing a node id string. /// </summary> /// <remarks> /// Creates a new instance of the class while allowing you to specify the id of the node. /// </remarks> /// <param name="text">The textual id of the node being wrapped</param> public ExpandedNodeId(string text) { Initialize(); m_nodeId = new NodeId(text); }
/// <summary> /// Initializes an opaque node identifier with a namespace index. /// </summary> /// <remarks> /// Creates a new instance of the class while allowing you to specify the node and namespace. /// </remarks> /// <param name="namespaceUri">The namespace that this node belongs to</param> /// <param name="value">The node we are wrapping</param> public ExpandedNodeId(byte[] value, string namespaceUri) { Initialize(); m_nodeId = new NodeId(value); SetNamespaceUri(namespaceUri); }
/// <summary> /// Adds a node to the type table if it is a type and does not already exist. If it exists references are updated. /// </summary> /// <param name="node">The node.</param> public void Add(ILocalNode node) { // ignore null. if (node == null || NodeId.IsNull(node.NodeId)) { return; } // ignore non-types. if ((node.NodeClass & (NodeClass.ObjectType | NodeClass.VariableType | NodeClass.ReferenceType | NodeClass.DataType)) == 0) { return; } NodeId localsuperTypeId = null; // find the supertype. ExpandedNodeId superTypeId = node.References.FindTarget(ReferenceTypeIds.HasSubtype, true, false, null, 0); if (superTypeId != null) { localsuperTypeId = ExpandedNodeId.ToNodeId(superTypeId, m_namespaceUris); if (localsuperTypeId == null) { throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "A valid supertype identifier is required."); } } lock (m_lock) { // lookup the supertype. TypeInfo superTypeInfo = null; if (localsuperTypeId != null) { if (!m_nodes.TryGetValue(localsuperTypeId, out superTypeInfo)) { throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "A valid supertype identifier is required."); } } // create the type info. TypeInfo typeInfo = null; if (!m_nodes.TryGetValue(node.NodeId, out typeInfo)) { typeInfo = new TypeInfo(); m_nodes.Add(node.NodeId, typeInfo); } // update the info. typeInfo.NodeId = node.NodeId; typeInfo.SuperType = superTypeInfo; typeInfo.Deleted = false; // add to supertype. if (superTypeInfo != null) { superTypeInfo.AddSubType(typeInfo); } // remove the encodings. if (typeInfo.Encodings != null) { foreach (NodeId encoding in typeInfo.Encodings) { m_encodings.Remove(encoding); } } // any new encodings. IList <IReference> encodings = node.References.Find(ReferenceTypeIds.HasEncoding, false, false, null); if (encodings.Count > 0) { typeInfo.Encodings = new NodeId[encodings.Count]; for (int ii = 0; ii < encodings.Count; ii++) { typeInfo.Encodings[ii] = ExpandedNodeId.ToNodeId(encodings[ii].TargetId, m_namespaceUris); m_encodings[typeInfo.Encodings[ii]] = typeInfo; } } // add reference type. if ((node.NodeClass & NodeClass.ReferenceType) != 0) { if (!QualifiedName.IsNull(typeInfo.BrowseName)) { m_referenceTypes.Remove(typeInfo.BrowseName); } typeInfo.BrowseName = node.BrowseName; m_referenceTypes[node.BrowseName] = typeInfo; } } }
/// <summary> /// Returns true if the node exists in the nodeset. /// </summary> /// <param name="nodeId">The node identifier.</param> /// <returns> /// <c>true</c> if the node exists in the nodeset; otherwise, <c>false</c>. /// </returns> /// <remarks> /// The NodeId must reference the strings for the node set. /// </remarks> public bool Contains(NodeId nodeId) { return(m_nodes.ContainsKey(nodeId)); }
/// <summary> /// Returns the string representation of the embededobject. /// </summary> /// <param name="format">(Unused). Leave this as null</param> /// <param name="formatProvider">The provider of a mechanism for retrieving an object to control formatting.</param> /// <returns> /// A <see cref="T:System.String"/> containing the value of the current embeded instance in the specified format. /// </returns> /// <exception cref="FormatException">Thrown if the <i>format</i> parameter is not null</exception> public string ToString(string format, IFormatProvider formatProvider) { if (format == null) { if (m_body is byte[]) { return(String.Format(formatProvider, "Byte[{0}]", ((byte[])m_body).Length)); } if (m_body is XmlElement) { return(String.Format(formatProvider, "<{0}>", ((XmlElement)m_body).Name)); } if (m_body is IFormattable) { return(String.Format(formatProvider, "{0}", ((IFormattable)m_body).ToString(null, formatProvider))); } if (m_body is IEncodeable) { StringBuilder body = new StringBuilder(); PropertyInfo[] properties = m_body.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance); foreach (PropertyInfo property in properties) { object[] attributes = property.GetCustomAttributes(typeof(DataMemberAttribute), true).ToArray(); for (int ii = 0; ii < attributes.Length; ii++) { DataMemberAttribute contract = attributes[ii] as DataMemberAttribute; if (contract != null) { if (body.Length == 0) { body.Append('{'); } else { body.Append(" | "); } body.AppendFormat("{0}", property.GetGetMethod().Invoke(m_body, null)); } } } if (body.Length > 0) { body.Append('}'); } return(String.Format(formatProvider, "{0}", body)); } if (!NodeId.IsNull(this.m_typeId)) { return(String.Format(formatProvider, "{{{0}}}", this.m_typeId)); } return("(null)"); } throw new FormatException(Utils.Format("Invalid format string: '{0}'.", format)); }
public AliasToUse(string alias, NodeId nodeId) { Alias = alias; NodeId = nodeId; }
/// <summary> /// Reads the value for any non-value attribute. /// </summary> protected override ServiceResult ReadNonValueAttribute( ISystemContext context, uint attributeId, ref object value) { ServiceResult result = null; switch (attributeId) { case Attributes.DataType: { NodeId dataType = m_dataType; if (OnReadDataType != null) { result = OnReadDataType(context, this, ref dataType); } if (ServiceResult.IsGood(result)) { value = dataType; } return(result); } case Attributes.ValueRank: { int valueRank = m_valueRank; if (OnReadValueRank != null) { result = OnReadValueRank(context, this, ref valueRank); } if (ServiceResult.IsGood(result)) { value = valueRank; } return(result); } case Attributes.ArrayDimensions: { IList <uint> arrayDimensions = m_arrayDimensions; if (OnReadArrayDimensions != null) { result = OnReadArrayDimensions(context, this, ref arrayDimensions); } if (ServiceResult.IsGood(result)) { value = arrayDimensions; } return(result); } } return(base.ReadNonValueAttribute(context, attributeId, ref value)); }
/// <summary> /// Called when the Respond method is called. /// </summary> /// <param name="context">The system context.</param> /// <param name="method">The method being called.</param> /// <param name="objectId">The id of the object.</param> /// <param name="selectedResponse">The selected response.</param> /// <returns>Any error.</returns> protected virtual ServiceResult OnRespondCalled( ISystemContext context, MethodState method, NodeId objectId, int selectedResponse) { ServiceResult error = null; try { if (!this.EnabledState.Id.Value) { return(error = StatusCodes.BadConditionDisabled); } if (!this.DialogState.Id.Value) { return(error = StatusCodes.BadDialogNotActive); } if (selectedResponse < 0 || selectedResponse >= this.ResponseOptionSet.Value.Length) { return(error = StatusCodes.BadDialogResponseInvalid); } if (OnRespond == null) { return(error = StatusCodes.BadNotSupported); } error = OnRespond(context, this, selectedResponse); // report a state change event. if (ServiceResult.IsGood(error)) { ReportStateChange(context, false); } } finally { if (this.AreEventsMonitored) { AuditConditionRespondEventState e = new AuditConditionRespondEventState(null); TranslationInfo info = new TranslationInfo( "AuditConditionDialogResponse", "en-US", "The Respond method was called."); e.Initialize( context, this, EventSeverity.Low, new LocalizedText(info), ServiceResult.IsGood(error), DateTime.UtcNow); e.SetChildValue(context, BrowseNames.SourceNode, NodeId, false); e.SetChildValue(context, BrowseNames.SourceName, "Method/Respond", false); e.SetChildValue(context, BrowseNames.MethodId, method.NodeId, false); e.SetChildValue(context, BrowseNames.InputArguments, new object[] { selectedResponse }, false); e.SetChildValue(context, BrowseNames.SelectedResponse, selectedResponse.ToString(), false); ReportEvent(context, e); } } return(error); }
/// <summary> /// Returns the BuiltInType type for the DataTypeId. /// </summary> public static BuiltInType GetBuiltInType(NodeId datatypeId, ITypeTable typeTree) { return(TypeInfo.GetBuiltInType(datatypeId, typeTree)); }
/// <summary> /// Removes all of the specified references. /// </summary> /// <param name="referenceTypeId">The reference type identifier.</param> /// <param name="isInverse">if set to <c>true</c> this is inverse reference.</param> /// <returns>The result of removal.</returns> public bool RemoveAll(NodeId referenceTypeId, bool isInverse) { return(m_references.RemoveAll(referenceTypeId, isInverse)); }
/// <summary> /// Updates the specified namespace tables and returns a NodeId that references those tables. /// </summary> /// <param name="nodeId">The node identifier.</param> /// <param name="namespaceUris">The namespace URIs.</param> /// <returns>A NodeId that references those tables.</returns> public NodeId Import(NodeId nodeId, NamespaceTable namespaceUris) { return(Translate(nodeId, namespaceUris, m_namespaceUris)); }
/// <summary> /// Initializes a guid node identifier. /// </summary> /// <remarks> /// Creates a new instance of the class while allowing you to specify the byte[] id /// of the node. /// </remarks> /// <param name="value">The id of the node we are wrapping</param> public ExpandedNodeId(byte[] value) { Initialize(); m_nodeId = new NodeId(value); }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="context">The current context.</param> /// <param name="parent">The parent.</param> /// <param name="nodeClass">The node class.</param> /// <param name="browseName">The browse name.</param> /// <param name="referenceTypeId">The reference type between the parent and the node.</param> /// <param name="typeDefinitionId">The type definition.</param> /// <returns>Returns null if the type is not known.</returns> public virtual NodeState CreateInstance( ISystemContext context, NodeState parent, NodeClass nodeClass, QualifiedName browseName, NodeId referenceTypeId, NodeId typeDefinitionId) { NodeState child = null; if (m_types != null && !NodeId.IsNull(typeDefinitionId)) { Type type = null; if (m_types.TryGetValue(typeDefinitionId, out type)) { return(Activator.CreateInstance(type, parent) as NodeState); } } switch (nodeClass) { case NodeClass.Variable: { if (context.TypeTable != null && context.TypeTable.IsTypeOf(referenceTypeId, ReferenceTypeIds.HasProperty)) { child = new PropertyState(parent); break; } child = new BaseDataVariableState(parent); break; } case NodeClass.Object: { child = new BaseObjectState(parent); break; } case NodeClass.Method: { child = new MethodState(parent); break; } case NodeClass.ReferenceType: { child = new ReferenceTypeState(); break; } case NodeClass.ObjectType: { child = new BaseObjectTypeState(); break; } case NodeClass.VariableType: { child = new BaseDataVariableTypeState(); break; } case NodeClass.DataType: { child = new DataTypeState(); break; } case NodeClass.View: { child = new ViewState(); break; } default: { child = null; break; } } return(child); }
/// <summary> /// Updates the nodeset string tables and returns a NodeId that references those tables. /// </summary> /// <param name="nodeId">The node identifier.</param> /// <param name="targetNamespaceUris">The target namespace URIs.</param> /// <param name="targetServerUris">The target server URIs.</param> /// <param name="sourceNamespaceUris">The source namespace URIs.</param> /// <param name="sourceServerUris">The source server URIs.</param> /// <returns>A NodeId that references those tables.</returns> private static ExpandedNodeId Translate( ExpandedNodeId nodeId, NamespaceTable targetNamespaceUris, StringTable targetServerUris, NamespaceTable sourceNamespaceUris, StringTable sourceServerUris) { if (targetNamespaceUris == null) { throw new ArgumentNullException("targetNamespaceUris"); } if (sourceNamespaceUris == null) { throw new ArgumentNullException("sourceNamespaceUris"); } if (nodeId.ServerIndex > 0) { if (targetServerUris == null) { throw new ArgumentNullException("targetServerUris"); } if (sourceServerUris == null) { throw new ArgumentNullException("sourceServerUris"); } } if (NodeId.IsNull(nodeId)) { return(nodeId); } if (!nodeId.IsAbsolute) { return(Translate((NodeId)nodeId, targetNamespaceUris, sourceNamespaceUris)); } string namespaceUri = nodeId.NamespaceUri; if (nodeId.ServerIndex > 0) { if (String.IsNullOrEmpty(namespaceUri)) { namespaceUri = sourceNamespaceUris.GetString(nodeId.NamespaceIndex); } string serverUri = sourceServerUris.GetString(nodeId.ServerIndex); int index = targetServerUris.GetIndex(serverUri); if (index == -1) { index = targetServerUris.Append(serverUri); } return(new ExpandedNodeId(new NodeId(nodeId.Identifier, 0), namespaceUri, (uint)index)); } ushort namespaceIndex = 0; if (!String.IsNullOrEmpty(namespaceUri)) { int index = targetNamespaceUris.GetIndex(namespaceUri); if (index == -1) { index = targetNamespaceUris.Append(namespaceUri); } namespaceIndex = (ushort)index; } return(new NodeId(nodeId.Identifier, namespaceIndex)); }
/// <summary> /// Handles the TimedShelve method. /// </summary> protected virtual ServiceResult OnTimedShelve( ISystemContext context, MethodState method, NodeId objectId, double shelvingTime) { ServiceResult error = null; try { if (!this.EnabledState.Id.Value) { return(error = StatusCodes.BadConditionDisabled); } if (shelvingTime <= 0 || (this.MaxTimeShelved != null && shelvingTime > this.MaxTimeShelved.Value)) { return(error = StatusCodes.BadShelvingTimeOutOfRange); } if (!this.ShelvingState.IsCausePermitted(context, Methods.ShelvedStateMachineType_TimedShelve, false)) { return(error = StatusCodes.BadConditionAlreadyShelved); } if (OnShelve == null) { return(error = StatusCodes.BadNotSupported); } error = OnShelve(context, this, true, false, shelvingTime); // report a state change event. if (ServiceResult.IsGood(error)) { ReportStateChange(context, false); } } finally { if (this.AreEventsMonitored) { AuditConditionShelvingEventState e = new AuditConditionShelvingEventState(null); TranslationInfo info = new TranslationInfo( "AuditConditionTimedShelve", "en-US", "The TimedShelve method was called."); e.Initialize( context, this, EventSeverity.Low, new LocalizedText(info), ServiceResult.IsGood(error), DateTime.UtcNow); e.SourceName.Value = "Attribute/Call"; e.MethodId = new PropertyState <NodeId>(e); e.MethodId.Value = method.NodeId; e.InputArguments = new PropertyState <object[]>(e); e.InputArguments.Value = new object[] { shelvingTime }; ReportEvent(context, e); } } return(error); }
/// <summary> /// Removes all of the references of the specified type and direction. /// </summary> /// <param name="referenceTypeId">The reference type identifier.</param> /// <param name="isInverse">if set to <c>true</c> this is inverse reference.</param> /// <returns>The result of removal.</returns> public bool RemoveAll(NodeId referenceTypeId, bool isInverse) { // check for null. if (NodeId.IsNull(referenceTypeId)) { return(false); } // look up the reference type. ReferenceTypeEntry entry = null; if (!m_references.TryGetValue(referenceTypeId, out entry)) { return(false); } if (isInverse) { if (entry.InverseTargets != null) { foreach (LinkedListNode <KeyValuePair <IReference, T> > node in entry.InverseTargets.Values) { if (Object.ReferenceEquals(m_list, node.List)) { m_list.Remove(node); } entry.InverseTargets = null; } } if (entry.InverseExternalTargets != null) { foreach (LinkedListNode <KeyValuePair <IReference, T> > node in entry.InverseExternalTargets.Values) { if (Object.ReferenceEquals(m_list, node.List)) { m_list.Remove(node); } } entry.InverseExternalTargets = null; } } else { if (entry.ForwardTargets != null) { foreach (LinkedListNode <KeyValuePair <IReference, T> > node in entry.ForwardTargets.Values) { if (Object.ReferenceEquals(m_list, node.List)) { m_list.Remove(node); } } entry.ForwardTargets = null; } if (entry.ForwardExternalTargets != null) { foreach (LinkedListNode <KeyValuePair <IReference, T> > node in entry.ForwardExternalTargets.Values) { if (Object.ReferenceEquals(m_list, node.List)) { m_list.Remove(node); } } entry.ForwardExternalTargets = null; } } // check for empty set. if (entry.IsEmpty) { m_references.Remove(referenceTypeId); } return(true); }