public ICommsMessage ProcessMessage(object target, ICommsMessage msg) { switch (msg.Type) { case CommsMessageType.MethodInvoke: return _handleMethodInvoke(target, (IMethodInvokeCommsMessage)msg); case CommsMessageType.PropertyGet: return _handlePropertyGet(target, (IGetPropertyCommsMessage)msg); case CommsMessageType.PropertySet: return _handlePropertySet(target, (ISetPropertyCommsMessage)msg); case CommsMessageType.MethodInvokeResult: case CommsMessageType.PropertyGetResult: case CommsMessageType.PropertySetResult: throw Ex.Arg(() => msg, "A result comms message isn't valid for incoming communication"); case CommsMessageType.Exception: throw Ex.Arg(() => msg, "An exception comms message isn't valid this far on the incoming stack"); case CommsMessageType.Unknown: default: throw Ex.Arg(() => msg, string.Format("A comms message of type '{0}' isn't supported for incoming", msg.Type.ToString())); } }
public ICommsMessage SendMessage(ICommsMessage msg) { if (this.MessageReceived != null) { return this.MessageReceived(msg); } else { throw new InvalidOperationException("No objects are subscribed to the event"); } }
public string Write(ICommsMessage message) { if (message == null) throw Ex.ArgNull(() => message); try { return new XDocument( new XElement(Element_Name, Convert.ToBase64String( _serDeser.Serialise( message)))).ToString(SaveOptions.DisableFormatting); } catch (Exception ex) { throw new ApplicationException("Failed to write comms message to XML", ex); } }
public byte[] Serialise(ICommsMessage message) { if (message == null) throw Ex.ArgNull(() => message); try { var bf = new BinaryFormatter(); var data = new byte[] { }; using (var ms = new MemoryStream()) { bf.Serialize(ms, message); ms.Flush(); ms.Position = 0; data = ms.ToArray(); } return data; } catch (Exception ex) { throw new ApplicationException("Failed to serialise comms message", ex); } }
public ExceptionCommsMessage(ICommsMessage causingMessage, Exception exception) : base(CommsMessageType.Exception) { _causingMessage = causingMessage; _exception = exception; }
ICommsMessage bridge_MessageReceived(ICommsMessage msg) { lock (_lock) { if (!IsListening) { throw new InvalidOperationException("Direct incoming link received a message but isn't listening"); } try { return _processor.ProcessMessage(_target, msg); } catch (Exception ex) { return new ExceptionCommsMessage(msg, ex); } } }