public override void Dispatch(Message payload) { if (Environment.UserInteractive) { Console.WriteLine(payload.Content); Debug.WriteLine(payload.Content); } try { beforeSend(payload); } catch (Exception e) { Core.Settings.Current.Log.Add(e); } _out.Send(payload); }
public static void Add(string message, Message.EContentType type = Message.EContentType.Info) { var dir = Configuration.DataDirectory + "\\log"; if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); var ctn = DateTime.Now + " " + ("[" + type + "]").PadRight(20) + " " + message; Console.WriteLine(ctn); Debug.Print(ctn); _out.WriteLine(ctn); _out.Flush(); // if (Current.Log != null) Current.Log.AfterDispatch(new Message() {Content = message, Type = type}); }
public override void Dispatch(Message payload) { try { if (Environment.UserInteractive) { Console.WriteLine(payload.Content); Debug.WriteLine(payload.Content); } var bytePayload = payload.ToJson().Encrypt().ToSerializedBytes(); //var bytePayload = payload.ToJson().ToSerializedBytes(); _sender.Send(bytePayload, bytePayload.Length); return; } catch (Exception e) { // Use the system log, since errors here mean that we won't be able to send it remotely. // Core.Modules.Log.System.Add(e); } }
private void ListeningWorker() { try { var errPayload = new Message(); errPayload.Type = Message.EContentType.Warning; errPayload.Content = "(Encrypted / non-desserializable content received)"; var a = new Uri(_targetAddress); var ep = new IPEndPoint(IPAddress.Any, a.Port); _receiver = new UdpClient(); _receiver.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); _receiver.Client.ReceiveBufferSize = 65535; _receiver.Client.SendBufferSize = 2048; _receiver.Client.Bind(ep); while (!_mustStop) { try { var data = _receiver.Receive(ref ep); var strData = data.FromSerializedBytes<string>(); var payload = strData.Decrypt().FromJson<Message>(); DoMessageArrived(payload); } catch { DoMessageArrived(errPayload); } } } catch (Exception e) { // Use the system log, since errors here mean that we won't be able to send it remotely. Core.Modules.Log.System.Add(e); } }
private void DoMessageArrived(Message message) { if (MessageArrived == null) return; MessageArrived(message); }
private void _gateway_MessageArrived(Message message) { if (MessageArrived == null) return; MessageArrived(message); }
public virtual void beforeSend(Message payload) { }
public new void Add(string content, Message.EContentType type = null) { Debug.Write("[{0}] {1}".format(type.Code, content)); Console.WriteLine("[{0}] {1}".format(type.Code, content)); }
public void Send(Message message) { if (!_canSend) throw new InvalidOperationException("Channel was told at construction time it's not allowed to Send."); var payload = message.ToSerializedBytes(); if (message.Topic != "") _publisherSocket.SendMoreFrame(_topic).SendFrame(payload); else _publisherSocket.SendFrame(payload); }
public virtual void Add(string content, Message.EContentType type = null) { Console.WriteLine(content); }