public StringContent GetBlockChain(string query) { String blockChain = string.Empty; WebClient web = new WebClient(); string blockChainPath = ConfigurationManager.AppSettings["BlockChainURL"].ToString(); System.IO.Stream stream = web.OpenRead(blockChainPath); List <MovieBlockChainResponse> items = new List <MovieBlockChainResponse>(); using (System.IO.StreamReader reader = new System.IO.StreamReader(stream)) { blockChain = reader.ReadToEnd(); IList <JToken> results = JObject.Parse(blockChain)["blockchain"].Values("data").ToList(); int index = 0; MovieReviewResponse movieReviewResponse = new MovieReviewResponse(); foreach (JToken result in results) { if (index == 0) { index++; continue; } dynamic userinfo = JsonConvert.DeserializeObject <object>(result.ToString()); if (userinfo.userName.Value.ToString() == query) { int currentmovieid = 0; int.TryParse(userinfo.movieId.Value.ToString(), out currentmovieid); MovieDBResponse moveinfo = GetMovieInfo(currentmovieid); if (moveinfo != null && movieReviewResponse.OverView == null) { GetMoveInfo(movieReviewResponse, moveinfo); } MovieBlockChainResponse movieBlockChainResponse = new MovieBlockChainResponse(); { GetUserInformation(blockChain, index, userinfo, movieBlockChainResponse); }; items.Add(movieBlockChainResponse); } index++; } movieReviewResponse.Votecount = items.Count; movieReviewResponse.VoteAverage = Math.Round((double)items.Count / 5); movieReviewResponse.Reviews = items; return(GetStaticcontent(JsonConvert.SerializeObject(movieReviewResponse).ToString())); } }
private static void GetUserInformation(string blockChain, int index, dynamic userinfo, MovieBlockChainResponse movieBlockChainResponse) { movieBlockChainResponse.userName = userinfo.userName.Value; movieBlockChainResponse.rating = userinfo.rating.Value; movieBlockChainResponse.textReview = userinfo.textReview.Value; JToken indexobject = JObject.Parse(blockChain)["blockchain"][index]; movieBlockChainResponse.Index = (long)Convert.ToDouble(indexobject["index"].ToString()); movieBlockChainResponse.PreviousHash = indexobject["previousHash"].ToString(); movieBlockChainResponse.TimeStamp = (long)Convert.ToDouble(indexobject["timestamp"].ToString()); movieBlockChainResponse.Hash = indexobject["hash"].ToString(); movieBlockChainResponse.nonce = (long)Convert.ToDouble(indexobject["nonce"].ToString()); }