public MessageErrorException(MessageError error) { this.error = error; }
private static void WriteValue(object value, BinaryWriter writer) { Type valueType = value == null ? typeof(DBNull) : value.GetType(); byte valueTypeCode = GetCode(valueType); writer.Write(valueTypeCode); if (value == null) { } else if (valueType == typeof(byte)) { writer.Write((byte)value); } else if (valueType == typeof(short)) { writer.Write((short)value); } else if (valueType == typeof(int)) { writer.Write((int)value); } else if (valueType == typeof(long)) { writer.Write((long)value); } else if (valueType == typeof(float)) { writer.Write((float)value); } else if (valueType == typeof(double)) { writer.Write((double)value); } else if (valueType == typeof(bool)) { writer.Write((bool)value); } else if (valueType == typeof(DateTime)) { value = ((DateTime)value).ToBinary(); writer.Write((long)value); } else if (valueType == typeof(TimeSpan)) { value = ((TimeSpan)value).Ticks; writer.Write((long)value); } else if (valueType == typeof(string)) { string s = (string)value; int sz = s.Length; writer.Write(sz); for (int i = 0; i < sz; i++) { writer.Write(s[i]); } // Extensions ... } else if (typeof(IServiceAddress).IsAssignableFrom(valueType)) { IServiceAddress address = (IServiceAddress)value; IServiceAddressHandler handler = ServiceAddresses.GetHandler(address); byte[] buffer = handler.ToBytes(address); int code = handler.GetCode(address.GetType()); writer.Write(code); writer.Write(buffer.Length); writer.Write(buffer); } else if (valueType == typeof(DataAddress)) { DataAddress dataAddr = (DataAddress)value; writer.Write(dataAddr.DataId); writer.Write(dataAddr.BlockId.High); writer.Write(dataAddr.BlockId.Low); } else if (valueType == typeof(MessageError)) { MessageError e = (MessageError)value; writer.Write(e.Source); writer.Write(e.Message); writer.Write(e.StackTrace); } else if (typeof(NodeSet).IsAssignableFrom(valueType)) { if (value is SingleNodeSet) { writer.Write((byte)1); } else if (value is CompressedNodeSet) { writer.Write((byte)2); } else { throw new Exception("Unknown NodeSet type: " + value.GetType()); } NodeSet nset = (NodeSet)value; // Write the node set, NodeId[] nodeIds = nset.NodeIds; int nsz = nodeIds.Length; writer.Write(nsz); for (int i = 0; i < nsz; i++) { NodeId nodeId = nodeIds[i]; writer.Write(nodeId.High); writer.Write(nodeId.Low); } // Write the binary encoding, byte[] buffer = nset.Buffer; int bsz = buffer.Length; writer.Write(bsz); writer.Write(buffer, 0, bsz); } else if (value is Array) { Array array = (Array)value; Type arrayType = array.GetType().GetElementType(); byte arrayTypeCode = GetCode(arrayType); int sz = array.Length; writer.Write(arrayTypeCode); writer.Write(sz); for (int i = 0; i < sz; i++) { object item = array.GetValue(i); WriteValue(item, writer); } } }
private static string GetErrorMessage(Message message) { MessageError error = GetError(message); return(error == null ? null : error.Message); }
private static string GetErrorStackTrace(Message message) { MessageError error = GetError(message); return(error == null ? null : error.StackTrace); }