/// <inheritdoc cref="IEncodeable.Decode(IDecoder)" /> public void Decode(IDecoder decoder) { UriVersion = decoder.ReadUInt32("UriVersion"); NamespaceUris = new NamespaceTable(); var uris = decoder.ReadStringArray("NamespaceUris"); if (uris != null && uris.Count > 0) { foreach (var uri in uris) { NamespaceUris.Append(uri); } } ServerUris = new StringTable(); uris = decoder.ReadStringArray("ServerUris"); if (uris != null && uris.Count > 0) { foreach (var uri in uris) { ServerUris.Append(uri); } } LocaleIds = new StringTable(); uris = decoder.ReadStringArray("LocaleIds"); if (uris != null && uris.Count > 0) { foreach (var uri in uris) { LocaleIds.Append(uri); } } decoder.SetMappingTables(NamespaceUris, ServerUris); uint typeId = decoder.ReadUInt32("ServiceId"); if (typeId > 0) { var systemType = decoder.Context.Factory.GetSystemType(new ExpandedNodeId(typeId, 0)); if (systemType == null) { throw ServiceResultException.Create(StatusCodes.BadDecodingError, "SessionLessServiceMessage message body has an unknown TypeId. {0}", typeId); } Message = decoder.ReadEncodeable("Body", systemType); } }
/// <summary> /// Initializes the object with a service result. /// </summary> /// <remarks> /// Initializes the object with a service result. /// </remarks> /// <param name="diagnosticsMask">The bitmask describing the type of diagnostic data</param> /// <param name="result">The transaction result</param> /// <param name="stringTable">An array of strings that may be used to provide additional diagnostic details</param> private void Initialize( ServiceResult result, DiagnosticsMasks diagnosticsMask, StringTable stringTable) { if (stringTable == null) { throw new ArgumentNullException(nameof(stringTable)); } m_symbolicId = -1; m_namespaceUri = -1; m_locale = -1; m_localizedText = -1; m_additionalInfo = null; m_innerStatusCode = StatusCodes.Good; m_innerDiagnosticInfo = null; if ((DiagnosticsMasks.ServiceSymbolicId & diagnosticsMask) != 0) { string symbolicId = result.SymbolicId; string namespaceUri = result.NamespaceUri; if (!String.IsNullOrEmpty(symbolicId)) { m_symbolicId = stringTable.GetIndex(result.SymbolicId); if (m_symbolicId == -1) { m_symbolicId = stringTable.Count; stringTable.Append(symbolicId); } if (!String.IsNullOrEmpty(namespaceUri)) { m_namespaceUri = stringTable.GetIndex(namespaceUri); if (m_namespaceUri == -1) { m_namespaceUri = stringTable.Count; stringTable.Append(namespaceUri); } } } } if ((DiagnosticsMasks.ServiceLocalizedText & diagnosticsMask) != 0) { if (!Opc.Ua.LocalizedText.IsNullOrEmpty(result.LocalizedText)) { if (!String.IsNullOrEmpty(result.LocalizedText.Locale)) { m_locale = stringTable.GetIndex(result.LocalizedText.Locale); if (m_locale == -1) { m_locale = stringTable.Count; stringTable.Append(result.LocalizedText.Locale); } } m_localizedText = stringTable.GetIndex(result.LocalizedText.Text); if (m_localizedText == -1) { m_localizedText = stringTable.Count; stringTable.Append(result.LocalizedText.Text); } } } if ((DiagnosticsMasks.ServiceAdditionalInfo & diagnosticsMask) != 0) { m_additionalInfo = result.AdditionalInfo; } if (result.InnerResult != null) { if ((DiagnosticsMasks.ServiceInnerStatusCode & diagnosticsMask) != 0) { m_innerStatusCode = result.InnerResult.StatusCode; } // recursively append the inner diagnostics. if ((DiagnosticsMasks.ServiceInnerDiagnostics & diagnosticsMask) != 0) { m_innerDiagnosticInfo = new DiagnosticInfo( result.InnerResult, diagnosticsMask, true, stringTable); } } }
/// <summary> /// Reads the schema information from a XML document. /// </summary> public void LoadFromBinary(ISystemContext context, Stream istrm, bool updateTables) { ServiceMessageContext messageContext = new ServiceMessageContext(); messageContext.NamespaceUris = context.NamespaceUris; messageContext.ServerUris = context.ServerUris; messageContext.Factory = context.EncodeableFactory; using (BinaryDecoder decoder = new BinaryDecoder(istrm, messageContext)) { // check if a namespace table was provided. NamespaceTable namespaceUris = new NamespaceTable(); if (!decoder.LoadStringTable(namespaceUris)) { namespaceUris = null; } // update namespace table. if (updateTables) { if (namespaceUris != null && context.NamespaceUris != null) { for (int ii = 0; ii < namespaceUris.Count; ii++) { context.NamespaceUris.GetIndexOrAppend(namespaceUris.GetString((uint)ii)); } } } // check if a server uri table was provided. StringTable serverUris = new StringTable(); if (namespaceUris != null && namespaceUris.Count > 1) { serverUris.Append(namespaceUris.GetString(1)); } if (!decoder.LoadStringTable(serverUris)) { serverUris = null; } // update server table. if (updateTables) { if (serverUris != null && context.ServerUris != null) { for (int ii = 0; ii < serverUris.Count; ii++) { context.ServerUris.GetIndexOrAppend(serverUris.GetString((uint)ii)); } } } // setup the mappings to use during decoding. decoder.SetMappingTables(namespaceUris, serverUris); int count = decoder.ReadInt32(null); for (int ii = 0; ii < count; ii++) { NodeState state = NodeState.LoadNode(context, decoder); this.Add(state); } } }
/// <summary> /// Initializes a string table from an XML stream. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="elementName">Name of the element.</param> /// <param name="stringTable">The string table.</param> /// <returns>True if the table was found. False otherwise.</returns> public bool LoadStringTable(string tableName, string elementName, StringTable stringTable) { PushNamespace(Namespaces.OpcUaXsd); try { if (!Peek(tableName)) { return false; } ReadStartElement(); while (Peek(elementName)) { string namespaceUri = ReadString(elementName); stringTable.Append(namespaceUri); } Skip(new XmlQualifiedName(tableName, Namespaces.OpcUaXsd)); return true; } finally { PopNamespace(); } }
/// <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> /// Creates an decoder to restore Variant values. /// </summary> private XmlDecoder CreateDecoder(ISystemContext context, XmlElement source) { ServiceMessageContext messageContext = new ServiceMessageContext(); messageContext.NamespaceUris = context.NamespaceUris; messageContext.ServerUris = context.ServerUris; messageContext.Factory = context.EncodeableFactory; XmlDecoder decoder = new XmlDecoder(source, messageContext); NamespaceTable namespaceUris = new NamespaceTable(); if (NamespaceUris != null) { for (int ii = 0; ii < NamespaceUris.Length; ii++) { namespaceUris.Append(NamespaceUris[ii]); } } StringTable serverUris = new StringTable(); if (ServerUris != null) { serverUris.Append(context.ServerUris.GetString(0)); for (int ii = 0; ii < ServerUris.Length; ii++) { serverUris.Append(ServerUris[ii]); } } decoder.SetMappingTables(namespaceUris, serverUris); return decoder; }
/// <summary> /// Loads a string table from a binary stream. /// </summary> public bool LoadStringTable(StringTable stringTable) { int count = ReadInt32(null); if (count < -0) { return false; } for (uint ii = 0; ii < count; ii++) { stringTable.Append(ReadString(null)); } return true; }