public Tuple <int, JObject> ReadMessage() { var message = MindRpcFormatter.ReadMessage(this.sslStream); var body = JObject.Parse(message.Item2); return(Tuple.Create(MindRpcFormatter.GetRpcIdFromHeader(message.Item1), body)); }
public async Task <JObject> SendRequest(IDictionary <string, object> body, int schemaVersion) { string requestType = null; object requestTypeObj; if (body.TryGetValue("type", out requestTypeObj)) { requestType = requestTypeObj as string; } if (string.IsNullOrEmpty(requestType)) { throw new ArgumentException("Body must contain 'type' tag", "body"); } string tsn = null; object tsnObj; if (body.TryGetValue("bodyId", out tsnObj)) { tsn = tsnObj as string; } var bodyText = JsonConvert.SerializeObject(body, this.jsonSettings); ////Debug.WriteLine("Sending Message:\n" + bodyText); var requestRpcId = Interlocked.Increment(ref this.lastRpcId); var reponseObservable = this.receiveSubject .Where(message => message.Item1 == requestRpcId) .Select(message => message.Item2) .Take(1); var messageBytes = MindRpcFormatter.EncodeRequest(this.connectionMode, this.sessionId, tsn, requestRpcId, schemaVersion, this.headerInfo, requestType, bodyText); this.sslStream.Write(messageBytes, 0, messageBytes.Length); this.sslStream.Flush(); return(await reponseObservable); }