Esempio n. 1
0
        /// <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);
                }
            }
        }
Esempio n. 2
0
        /// <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));
        }