/// <summary> /// Applies the diagnostic mask if the object was initialize with a ServiceResult. /// </summary> public void ApplyDiagnosticMasks(DiagnosticsMasks diagnosticMasks, StringTable stringTable) { if (m_result != null) { m_statusCode = m_result.StatusCode; m_diagnosticInfo = new DiagnosticInfo(m_result, diagnosticMasks, false, stringTable); } }
public TestDataSystem(ITestDataSystemCallback callback, NamespaceTable namespaceUris, StringTable serverUris) { m_callback = callback; m_minimumSamplingInterval = Int32.MaxValue; m_monitoredNodes = new Dictionary<uint,BaseVariableState>(); m_generator = new Opc.Ua.Test.DataGenerator(null); m_generator.NamespaceUris = namespaceUris; m_generator.ServerUris = serverUris; m_historyArchive = new HistoryArchive(); }
private ServiceMessageContext(bool shared) : this() { m_maxStringLength = UInt16.MaxValue; m_maxByteStringLength = UInt16.MaxValue*16; m_maxArrayLength = UInt16.MaxValue; m_maxMessageSize = UInt16.MaxValue*32; m_namespaceUris = new NamespaceTable(shared); m_serverUris = new StringTable(shared); m_factory = EncodeableFactory.GlobalFactory; }
/// <summary> /// Initializes the mapper. /// </summary> /// <param name="localNamespaceUris"></param> /// <param name="remoteNamespaceUris"></param> public void Initialize(StringTable localNamespaceUris, StringTable remoteNamespaceUris, string applicationUri) { m_localNamespaceIndexes = new int[remoteNamespaceUris.Count]; for (int ii = 1; ii < remoteNamespaceUris.Count; ii++) { string namespaceUri = remoteNamespaceUris.GetString((uint)ii); bool isTypeSystemUri = false; if (TypeSystemNamespaceUris != null) { for (int jj = 0; jj < TypeSystemNamespaceUris.Length; jj++) { if (TypeSystemNamespaceUris[jj] == namespaceUri) { isTypeSystemUri = true; break; } } } if (!isTypeSystemUri) { namespaceUri = applicationUri + ":" + namespaceUri; } m_localNamespaceIndexes[ii] = localNamespaceUris.GetIndexOrAppend(namespaceUri); } m_remoteNamespaceIndexes = new int[localNamespaceUris.Count]; for (int ii = 0; ii < m_localNamespaceIndexes.Length; ii++) { if (m_remoteNamespaceIndexes.Length > m_localNamespaceIndexes[ii]) { m_remoteNamespaceIndexes[m_localNamespaceIndexes[ii]] = ii; } } }
/// <summary> /// Imports a ExpandedNodeId /// </summary> private Opc.Ua.ExpandedNodeId ImportExpandedNodeId(string source, NamespaceTable namespaceUris, StringTable serverUris) { if (String.IsNullOrEmpty(source)) { return Opc.Ua.ExpandedNodeId.Null; } // parse the node. Opc.Ua.ExpandedNodeId nodeId = Opc.Ua.ExpandedNodeId.Parse(source); if (nodeId.ServerIndex <= 0 && nodeId.NamespaceIndex <= 0 && String.IsNullOrEmpty(nodeId.NamespaceUri)) { return nodeId; } uint serverIndex = ImportServerIndex(nodeId.ServerIndex, serverUris); ushort namespaceIndex = ImportNamespaceIndex(nodeId.NamespaceIndex, namespaceUris); if (serverIndex > 0) { string namespaceUri = nodeId.NamespaceUri; if (String.IsNullOrEmpty(nodeId.NamespaceUri)) { namespaceUri = namespaceUris.GetString(namespaceIndex); } nodeId = new Opc.Ua.ExpandedNodeId(nodeId.Identifier, 0, namespaceUri, serverIndex); return nodeId; } nodeId = new Opc.Ua.ExpandedNodeId(nodeId.Identifier, namespaceIndex, null, 0); return nodeId; }
/// <summary> /// Creates the response header. /// </summary> /// <param name="requestHeader">The object that contains description for the RequestHeader DataType.</param> /// <param name="exception">The exception used to create DiagnosticInfo assigned to the ServiceDiagnostics.</param> /// <returns>Returns a description for the ResponseHeader DataType. </returns> protected virtual ResponseHeader CreateResponse(RequestHeader requestHeader, Exception exception) { ResponseHeader responseHeader = new ResponseHeader(); responseHeader.Timestamp = DateTime.UtcNow; responseHeader.RequestHandle = requestHeader.RequestHandle; StringTable stringTable = new StringTable(); responseHeader.ServiceDiagnostics = new DiagnosticInfo(exception, (DiagnosticsMasks)requestHeader.ReturnDiagnostics, true, stringTable); responseHeader.StringTable = stringTable.ToArray(); return responseHeader; }
/// <summary> /// Creates the response header. /// </summary> /// <param name="requestHeader">The object that contains description for the RequestHeader DataType.</param> /// <param name="stringTable">The thread safe table of string constants.</param> /// <returns>Returns a description for the ResponseHeader DataType. </returns> protected virtual ResponseHeader CreateResponse(RequestHeader requestHeader, StringTable stringTable) { ResponseHeader responseHeader = new ResponseHeader(); responseHeader.Timestamp = DateTime.UtcNow; responseHeader.RequestHandle = requestHeader.RequestHandle; responseHeader.StringTable.AddRange(stringTable.ToArray()); return responseHeader; }
/// <summary> /// Reads the schema information from a XML document. /// </summary> public void LoadFromXml(ISystemContext context, Stream istrm, bool updateTables) { ServiceMessageContext messageContext = new ServiceMessageContext(); messageContext.NamespaceUris = context.NamespaceUris; messageContext.ServerUris = context.ServerUris; messageContext.Factory = context.EncodeableFactory; using (XmlReader reader = XmlReader.Create(istrm, Utils.DefaultXmlReaderSettings())) { XmlQualifiedName root = new XmlQualifiedName("ListOfNodeState", Namespaces.OpcUaXsd); XmlDecoder decoder = new XmlDecoder(null, reader, messageContext); NamespaceTable namespaceUris = new NamespaceTable(); if (!decoder.LoadStringTable("NamespaceUris", "NamespaceUri", 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)); } } } StringTable serverUris = new StringTable(); if (!decoder.LoadStringTable("ServerUris", "ServerUri", context.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)); } } } // set mapping. decoder.SetMappingTables(namespaceUris, serverUris); decoder.PushNamespace(Namespaces.OpcUaXsd); NodeState state = NodeState.LoadNode(context, decoder); while (state != null) { this.Add(state); state = NodeState.LoadNode(context, decoder); } decoder.Close(); } }
/// <summary> /// Converts the object to an EventFilterResult. /// </summary> public EventFilterResult ToEventFilterResult(DiagnosticsMasks diagnosticsMasks, StringTable stringTable) { EventFilterResult result = new EventFilterResult(); if (m_selectClauseResults != null && m_selectClauseResults.Count > 0) { foreach (ServiceResult clauseResult in m_selectClauseResults) { if (ServiceResult.IsBad(clauseResult)) { result.SelectClauseResults.Add(clauseResult.StatusCode); result.SelectClauseDiagnosticInfos.Add(new DiagnosticInfo(clauseResult, diagnosticsMasks, false, stringTable)); } else { result.SelectClauseResults.Add(StatusCodes.Good); result.SelectClauseDiagnosticInfos.Add(null); } } } if (m_whereClauseResults != null) { result.WhereClauseResult = m_whereClauseResults.ToContextFilterResult(diagnosticsMasks, stringTable); } return result; }
/// <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> /// Converts the object to an ContentFilterElementResult. /// </summary> /// <param name="diagnosticsMasks">The diagnostics masks.</param> /// <param name="stringTable">The string table.</param> /// <returns></returns> public ContentFilterElementResult ToContentFilterElementResult(DiagnosticsMasks diagnosticsMasks, StringTable stringTable) { ContentFilterElementResult result = new ContentFilterElementResult(); if (ServiceResult.IsGood(m_status)) { result.StatusCode = StatusCodes.Good; return result; } result.StatusCode = m_status.StatusCode; if (m_operandResults.Count == 0) { return result; } foreach (ServiceResult operandResult in m_operandResults) { if (ServiceResult.IsGood(operandResult)) { result.OperandStatusCodes.Add(StatusCodes.Good); result.OperandDiagnosticInfos.Add(null); } else { result.OperandStatusCodes.Add(operandResult.StatusCode); result.OperandDiagnosticInfos.Add(new DiagnosticInfo(operandResult, diagnosticsMasks, false, stringTable)); } } return result; }
/// <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(nameof(targetNamespaceUris)); } if (sourceNamespaceUris == null) { throw new ArgumentNullException(nameof(sourceNamespaceUris)); } if (nodeId.ServerIndex > 0) { if (targetServerUris == null) { throw new ArgumentNullException(nameof(targetServerUris)); } if (sourceServerUris == null) { throw new ArgumentNullException(nameof(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> /// Converts the object to an ContentFilterElementResult. /// </summary> /// <param name="diagnosticsMasks">The diagnostics masks.</param> /// <param name="stringTable">The string table.</param> /// <returns></returns> public ContentFilterElementResult ToContentFilterElementResult(DiagnosticsMasks diagnosticsMasks, StringTable stringTable) { ContentFilterElementResult result = new ContentFilterElementResult(); if (ServiceResult.IsGood(m_status)) { result.StatusCode = StatusCodes.Good; return(result); } result.StatusCode = m_status.StatusCode; if (m_operandResults.Count == 0) { return(result); } foreach (ServiceResult operandResult in m_operandResults) { if (ServiceResult.IsGood(operandResult)) { result.OperandStatusCodes.Add(StatusCodes.Good); result.OperandDiagnosticInfos.Add(null); } else { result.OperandStatusCodes.Add(operandResult.StatusCode); result.OperandDiagnosticInfos.Add(new DiagnosticInfo(operandResult, diagnosticsMasks, false, stringTable)); } } return(result); }
/// <summary> /// Creates an empty nodeset. /// </summary> public NodeSet() { m_namespaceUris = new NamespaceTable(); m_serverUris = new StringTable(); m_nodes = new Dictionary <NodeId, Node>(); }
/// <summary> /// Updates the specified string tables and returns a NodeId that references those tables. /// </summary> /// <param name="nodeId">The node identifier.</param> /// <param name="namespaceUris">The namespace URIs.</param> /// <param name="serverUris">The server URIs.</param> /// <returns>A NodeId that references those tables.</returns> public ExpandedNodeId Import(ExpandedNodeId nodeId, NamespaceTable namespaceUris, StringTable serverUris) { return(Translate(nodeId, namespaceUris, serverUris, m_namespaceUris, m_serverUris)); }
/// <summary> /// Translates a reference and adds it to the specified node. /// </summary> /// <param name="node">The node.</param> /// <param name="referenceToExport">The reference to export.</param> /// <param name="namespaceUris">The namespace URIs.</param> /// <param name="serverUris">The server URIs.</param> public void AddReference(Node node, ReferenceNode referenceToExport, NamespaceTable namespaceUris, StringTable serverUris) { ReferenceNode reference = new ReferenceNode(); reference.ReferenceTypeId = Translate(referenceToExport.ReferenceTypeId, m_namespaceUris, namespaceUris); reference.IsInverse = referenceToExport.IsInverse; reference.TargetId = Translate(referenceToExport.TargetId, m_namespaceUris, m_serverUris, namespaceUris, serverUris); node.References.Add(reference); }
/// <summary> /// Translates all elements in an array value. /// </summary> /// <param name="array">The array.</param> /// <param name="elementType">Type of the element.</param> /// <param name="namespaceUris">The namespace URIs.</param> /// <param name="serverUris">The server URIs.</param> private void TranslateArrayValue(Array array, BuiltInType elementType, NamespaceTable namespaceUris, StringTable serverUris) { if (array == null) { return; } int[] dimensions = new int[array.Rank]; for (int ii = 0; ii < dimensions.Length; ii++) { dimensions[ii] = array.GetLength(ii); } int length = array.Length; int[] indexes = new int[dimensions.Length]; for (int ii = 0; ii < length; ii++) { int divisor = length; for (int jj = 0; jj < indexes.Length; jj++) { divisor /= dimensions[jj]; indexes[jj] = (ii / divisor) % dimensions[jj]; } object element = array.GetValue(indexes); if (element != null) { if (elementType == BuiltInType.Variant) { element = ((Variant)element).Value; } element = TranslateValue(element, namespaceUris, serverUris); if (elementType == BuiltInType.Variant) { element = new Variant(element); } array.SetValue(element, indexes); } } }
/// <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("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> /// Exports a server index. /// </summary> private uint ImportServerIndex(uint serverIndex, StringTable serverUris) { // nothing special required for indexes 0. if (serverIndex <= 0) { return serverIndex; } // return a bad value if parameters are bad. if (serverUris == null || this.ServerUris == null || this.ServerUris.Length <= serverIndex - 1) { return UInt16.MaxValue; } // find or append uri. return serverUris.GetIndexOrAppend(this.ServerUris[serverIndex - 1]); }
/// <summary> /// Saves 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> public void SaveStringTable(string tableName, string elementName, StringTable stringTable) { if (stringTable == null || stringTable.Count <= 1) { return; } PushNamespace(Namespaces.OpcUaXsd); try { Push(tableName, Namespaces.OpcUaXsd); for (ushort ii = 1; ii < stringTable.Count; ii++) { WriteString(elementName, stringTable.GetString(ii)); } Pop(); } finally { PopNamespace(); } }
/// <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> /// Converts the object to an EventFilterResult. /// </summary> public EventFilterResult ToEventFilterResult(DiagnosticsMasks diagnosticsMasks, StringTable stringTable) { EventFilterResult result = new EventFilterResult(); if (m_selectClauseResults != null && m_selectClauseResults.Count > 0) { foreach (ServiceResult clauseResult in m_selectClauseResults) { if (ServiceResult.IsBad(clauseResult)) { result.SelectClauseResults.Add(clauseResult.StatusCode); result.SelectClauseDiagnosticInfos.Add(new DiagnosticInfo(clauseResult, diagnosticsMasks, false, stringTable)); } else { result.SelectClauseResults.Add(StatusCodes.Good); result.SelectClauseDiagnosticInfos.Add(null); } } } if (m_whereClauseResults != null) { result.WhereClauseResult = m_whereClauseResults.ToContextFilterResult(diagnosticsMasks, stringTable); } return(result); }
/// <summary> /// Converts the object to an ContentFilterResult. /// </summary> /// <param name="diagnosticsMasks">The diagnostics masks.</param> /// <param name="stringTable">The string table.</param> /// <returns></returns> public ContentFilterResult ToContextFilterResult(DiagnosticsMasks diagnosticsMasks, StringTable stringTable) { ContentFilterResult result = new ContentFilterResult(); if (m_elementResults == null || m_elementResults.Count == 0) { return result; } bool error = false; foreach (ElementResult elementResult in m_elementResults) { ContentFilterElementResult elementResult2 = null; if (elementResult == null || ServiceResult.IsGood(elementResult.Status)) { elementResult2 = new ContentFilterElementResult(); elementResult2.StatusCode = StatusCodes.Good; result.ElementResults.Add(elementResult2); result.ElementDiagnosticInfos.Add(null); continue; } error = true; elementResult2 = elementResult.ToContentFilterElementResult(diagnosticsMasks, stringTable); result.ElementResults.Add(elementResult2); result.ElementDiagnosticInfos.Add(new DiagnosticInfo(elementResult.Status, diagnosticsMasks, false, stringTable)); } if (!error) { result.ElementResults.Clear(); result.ElementDiagnosticInfos.Clear(); } return result; }
/// <summary> /// Converts the object to an ContentFilterResult. /// </summary> /// <param name="diagnosticsMasks">The diagnostics masks.</param> /// <param name="stringTable">The string table.</param> /// <returns></returns> public ContentFilterResult ToContextFilterResult(DiagnosticsMasks diagnosticsMasks, StringTable stringTable) { ContentFilterResult result = new ContentFilterResult(); if (m_elementResults == null || m_elementResults.Count == 0) { return(result); } bool error = false; foreach (ElementResult elementResult in m_elementResults) { ContentFilterElementResult elementResult2 = null; if (elementResult == null || ServiceResult.IsGood(elementResult.Status)) { elementResult2 = new ContentFilterElementResult(); elementResult2.StatusCode = StatusCodes.Good; result.ElementResults.Add(elementResult2); result.ElementDiagnosticInfos.Add(null); continue; } error = true; elementResult2 = elementResult.ToContentFilterElementResult(diagnosticsMasks, stringTable); result.ElementResults.Add(elementResult2); result.ElementDiagnosticInfos.Add(new DiagnosticInfo(elementResult.Status, diagnosticsMasks, false, stringTable)); } if (!error) { result.ElementResults.Clear(); result.ElementDiagnosticInfos.Clear(); } return(result); }
/// <summary> /// Initializes the tables used to map namespace and server uris during encoding. /// </summary> /// <param name="namespaceUris">The namespaces URIs referenced by the data being encoded.</param> /// <param name="serverUris">The server URIs referenced by the data being encoded.</param> public void SetMappingTables(NamespaceTable namespaceUris, StringTable serverUris) { m_namespaceMappings = null; if (namespaceUris != null && m_context.NamespaceUris != null) { m_namespaceMappings = namespaceUris.CreateMapping(m_context.NamespaceUris, false); } m_serverMappings = null; if (serverUris != null && m_context.ServerUris != null) { m_serverMappings = serverUris.CreateMapping(m_context.ServerUris, false); } }
/// <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> /// Creates a fault message. /// </summary> /// <param name="request">The request.</param> /// <param name="exception">The exception.</param> /// <returns>A fault message.</returns> protected static ServiceFault CreateFault(IServiceRequest request, Exception exception) { DiagnosticsMasks diagnosticsMask = DiagnosticsMasks.ServiceNoInnerStatus; ServiceFault fault = new ServiceFault(); if (request != null) { fault.ResponseHeader.Timestamp = DateTime.UtcNow; fault.ResponseHeader.RequestHandle = request.RequestHeader.RequestHandle; if (request.RequestHeader != null) { diagnosticsMask = (DiagnosticsMasks)request.RequestHeader.ReturnDiagnostics; } } ServiceResult result = null; ServiceResultException sre = exception as ServiceResultException; if (sre != null) { result = new ServiceResult(sre); Utils.Trace( Utils.TraceMasks.Service, "Service Fault Occured. Reason={0}", result); } else { result = new ServiceResult(exception, StatusCodes.BadUnexpectedError); Utils.Trace(exception, "SERVER - Unexpected Service Fault: {0}", exception.Message); } fault.ResponseHeader.ServiceResult = result.Code; StringTable stringTable = new StringTable(); fault.ResponseHeader.ServiceDiagnostics = new DiagnosticInfo( result, diagnosticsMask, true, stringTable); fault.ResponseHeader.StringTable = stringTable.ToArray(); return fault; }
/// <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; }