public void AddMessage(IActorMessage msg) { if (msg is ControlMessages.HangUp) { if (!recieveMessagesOnly) { if (null != msg.Status && !msg.Status.Task.IsCompleted) { msg.Status.SetResult(msg); } return; } hangUp = (msg as ControlMessages.HangUp); Kill(); return; } if (recieveMessagesOnly) { throw new Telegraphy.Net.OperatorCannotSendMessagesException(); } // Serialize the message first try { if (msg is MsgType) { SerializeAndSend(msg, Queue, (MsgType)msg); } else if ((msg as IActorMessage).Message is MsgType) { SerializeAndSend(msg, Queue, (MsgType)(msg as IActorMessage).Message); } else { throw new DontKnowHowToSerializeTypeException(msg.GetType().ToString()); } if (null != msg.Status && !msg.Status.Task.IsCanceled) { msg.Status.TrySetResult(msg); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.GetType() + ":" + ex.Message + ex.StackTrace); Exception foundEx = null; var handler = this.FindExceptionHandler(_exceptionTypeToHandler, ex, out foundEx); if (null != handler) { handler.Invoke(foundEx); } } }
public void AddMessage(IActorMessage msg) { if (msg is ControlMessages.HangUp) { if (!recieveMessagesOnly) { if (null != msg.Status && !msg.Status.Task.IsCompleted) { msg.Status.SetResult(msg); } return; } hangUp = (msg as ControlMessages.HangUp); Kill(); return; } if (recieveMessagesOnly) { throw new Telegraphy.Net.OperatorCannotSendMessagesException(); } if (!(msg is EmailMsg)) { throw new UnsupportedMessageException("Outlook Email Operators only support the EmailMsg type. They do not support " + msg.GetType()); } try { SendEmail((EmailMsg)msg, this.emailAddress, this.password, this.fromFriendlyName); if (null != msg.Status && !msg.Status.Task.IsCanceled) { msg.Status.TrySetResult(msg); } } catch (Exception ex) { Exception foundEx = null; var handler = this.FindExceptionHandler(_exceptionTypeToHandler, ex, out foundEx); if (null != handler) { handler.Invoke(foundEx); } if (null != msg.Status && !msg.Status.Task.IsCanceled) { msg.Status.TrySetException(ex); } } }
public void AddMessage(IActorMessage msg) { if (msg is ControlMessages.HangUp) { if (!recieveMessagesOnly) { if (null != msg.Status && !msg.Status.Task.IsCompleted) { msg.Status.SetResult(msg); } return; } hangUp = (msg as ControlMessages.HangUp); Kill(); return; } if (recieveMessagesOnly) { throw new Telegraphy.Net.OperatorCannotSendMessagesException(); } // TODO allow the serializers to be passed in as IActors // Serialize the message first try { SerializeAndSend(msg, queue); if (null != msg.Status && !msg.Status.Task.IsCanceled) { msg.Status.TrySetResult(msg); } } catch (Exception ex) { Exception foundEx = null; var handler = this.FindExceptionHandler(_exceptionTypeToHandler, ex, out foundEx); if (null != handler) { handler.Invoke(foundEx); } } }
public void AddMessage(IActorMessage msg) { try { if (msg is ControlMessages.HangUp) { if (null != hangUp) { return; } if (null != queue) { this.reciever?.CloseAsync().Wait(); this.sender?.CloseAsync().Wait(); if (null != msg.Status && !msg.Status.Task.IsCompleted) { msg.Status.SetResult(msg); } return; } this.reciever?.CloseAsync().Wait(); this.sender?.CloseAsync().Wait(); hangUp = (msg as ControlMessages.HangUp); foreach (var switchboard in this.Switchboards) { switchboard.Disable(); } return; } if (this.recievingOnly) { throw new OperatorCannotSendMessagesException(); } System.Diagnostics.Debug.Assert(null != sender); var message = SerializeAndSend(msg, this.sender); if (null != msg.Status) { msg.Status?.SetResult(new ServiceBusMessage(message)); } } catch (Exception ex) { Exception foundEx = null; var handler = this.FindExceptionHandler(_exceptionTypeToHandler, ex, out foundEx); if (null != handler) { handler.Invoke(foundEx); } if (null != msg.Status && !msg.Status.Task.IsCanceled) { msg.Status.TrySetException(ex); } } }