/// <summary> /// Returns the string representation of the object. /// </summary> public string ToString(string format, IFormatProvider provider) { if (format == null) { return(String.Format(provider, "{0}", StatusCodes.GetBrowseName((0xFFFF0000 & ToCode(this))))); } throw new FormatException(String.Format("Invalid format string: '{0}'.", format)); }
/// <summary> /// Returns the string representation of the object. /// </summary> /// <remarks> /// Returns the string representation of the object. /// </remarks> /// <param name="format">(Unused) The format of the string. Always specify null for this parameter</param> /// <param name="formatProvider">The provider to use for the formatting</param> /// <exception cref="FormatException">Thrown if you specify a value for the Format parameter</exception> public string ToString(string format, IFormatProvider formatProvider) { if (format == null) { string text = StatusCodes.GetBrowseName(m_code & 0xFFFF0000); if (!String.IsNullOrEmpty(text)) { return String.Format(formatProvider, "{0}", text); } return String.Format(formatProvider, "0x{0:X8}", m_code); } throw new FormatException(Utils.Format("Invalid format string: '{0}'.", format)); }
/// <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 Exception CreateSoapFault(IServiceRequest request, Exception exception) { ServiceFault fault = CreateFault(request, exception); // get the error from the header. ServiceResult error = fault.ResponseHeader.ServiceResult; if (error == null) { error = ServiceResult.Create(StatusCodes.BadUnexpectedError, "An unknown error occurred."); } // construct the fault code and fault reason. string codeName = StatusCodes.GetBrowseName(error.Code); return(new ServiceResultException((uint)error.StatusCode, codeName, exception)); }
/// <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 Exception CreateSoapFault(IServiceRequest request, Exception exception) { ServiceFault fault = CreateFault(request, exception); // get the error from the header. ServiceResult error = fault.ResponseHeader.ServiceResult; if (error == null) { error = ServiceResult.Create(StatusCodes.BadUnexpectedError, "An unknown error occurred."); } // construct the fault code and fault reason. string codeName = StatusCodes.GetBrowseName(error.Code); FaultCode code = null; FaultReason reason = null; if (!LocalizedText.IsNullOrEmpty(error.LocalizedText)) { reason = new FaultReason(new FaultReasonText(Utils.Format("{0}", error.LocalizedText), CultureInfo.InvariantCulture)); } else { reason = new FaultReason(new FaultReasonText(codeName, CultureInfo.InvariantCulture)); } if (!String.IsNullOrEmpty(error.SymbolicId)) { FaultCode subcode = new FaultCode(error.SymbolicId, error.NamespaceUri); code = new FaultCode(codeName, Namespaces.OpcUa, subcode); } else { code = new FaultCode(codeName, Namespaces.OpcUa); } // throw the fault. return(new FaultException <ServiceFault>(fault, reason, code)); }
/// <summary> /// Returns a formatted string with the contents of exception. /// </summary> public string ToLongString() { StringBuilder buffer = new StringBuilder(); buffer.Append("Id: "); buffer.Append(StatusCodes.GetBrowseName(m_code)); if (!String.IsNullOrEmpty(m_symbolicId)) { buffer.AppendLine(); buffer.Append("SymbolicId: "); buffer.Append(m_symbolicId); } if (!LocalizedText.IsNullOrEmpty(m_localizedText)) { buffer.AppendLine(); buffer.Append("Description: "); buffer.Append(m_localizedText); } if (AdditionalInfo != null && AdditionalInfo.Length > 0) { buffer.AppendLine(); buffer.Append(AdditionalInfo); } ServiceResult innerResult = m_innerResult; if (innerResult != null) { buffer.AppendLine(); buffer.Append("==="); buffer.AppendLine(); buffer.Append(innerResult.ToLongString()); } return(buffer.ToString()); }
/// <summary> /// Looks up the symbolic name for a status code. /// </summary> /// <remarks> /// Looks up the symbolic name for a status code. /// </remarks> /// <param name="code">The numeric error-code to convert to a textual description</param> public static string LookupSymbolicId(uint code) { return(StatusCodes.GetBrowseName(code & 0xFFFF0000)); }