public static SubscribeResponse BuildFrom(string responseText) { var parts = responseText.Split('\n'); var jsonResponse = JsonConvert.DeserializeObject <JsonRpcResponse>(parts[0]); var instance = new SubscribeResponse(jsonResponse.Id.Value); instance.Extranonce1 = jsonResponse.Result[1].ToString(); instance.Extranonce2Size = int.Parse(jsonResponse.Result[2].ToString()); var otherJsonResponse = parts.Skip(1).Where(x => !string.IsNullOrWhiteSpace(x)) .Select(x => JsonConvert.DeserializeObject <JsonRpcRequest>(x)) .ToArray(); //Notify Response if (otherJsonResponse.Any(x => x.Method == "mining.notify")) { var request = otherJsonResponse.First(x => x.Method == "mining.notify"); instance.Notify = NotifyRequest.BuildFrom(request); } if (otherJsonResponse.Any(x => x.Method == "mining.set_difficulty")) { var request = otherJsonResponse.First(x => x.Method == "mining.set_difficulty"); var setDifficultyRequest = new SetDifficultyRequest(); setDifficultyRequest.Difficulty = request.Params[0].ToObject <int>(); instance.SetDifficulty = setDifficultyRequest; } return(instance); }
private void SlushMiningPoolClient_OnEnqueMessage(object sender, string e) { Task.Factory.StartNew(() => { var str = ""; lock (this.synObject) { str = this._queue.Dequeue(); } var jObject = JObject.Parse(str); var id = jObject["id"]; if (id != null && this._requestTable.ContainsKey(id.ToString())) { var request = this._requestTable[id.ToString()]; var reponse = JsonConvert.DeserializeObject <JsonRpcResponse>(str); if (request is AuthorizeRequest) { var authResponse = AuthorizeResponse.BuildFrom(reponse); this.RaiseOnAuthorizeResponse(new ReceiveMessageEventArgs <AuthorizeResponse>(authResponse)); } if (request is SubscribeRequest) { var subScribeResponse = SubscribeResponse.BuildFrom(reponse); this.RaiseOnSubscribeResponse(new ReceiveMessageEventArgs <SubscribeResponse>(subScribeResponse)); } if (request is ShareRequest) { var shareResponse = ShareResponse.BuildFrom(reponse); this.RaiseOnShareResponse(new ReceiveMessageEventArgs <ShareResponse>(shareResponse)); } } else { var method = jObject["method"].ToString(); if (!string.IsNullOrWhiteSpace(method)) { if (method == "mining.notify") { var jsonRequest = JsonConvert.DeserializeObject <JsonRpcRequest>(str); var request = NotifyRequest.BuildFrom(jsonRequest); this.RaiseOnNotifyRequest(new ReceiveMessageEventArgs <NotifyRequest>(request)); } if (method == "mining.set_difficulty") { var jsonRequest = JsonConvert.DeserializeObject <JsonRpcRequest>(str); var request = SetDifficultyRequest.BuildFrom(jsonRequest); this.RaiseOnSetDifficultyRequest(new ReceiveMessageEventArgs <SetDifficultyRequest>(request)); } } } }); }