private static BlockScoreResponse GetBlockScoreResponse(string verb, string response) { BlockScoreResponse blockScoreResponse = null; if (!string.IsNullOrEmpty(response)) { try { blockScoreResponse = GetDesirializedResponse(verb, response); } catch (Exception e) { throw new Exception("blockscore: Unable to retrieve " + verb + " : " + e.Message); } } return(blockScoreResponse); }
/* * Get the questions set from Blockscore */ private void HandleQuestionSet(BlockScoreResponse verifyUsResult, BlockscoreAPI blockscore) { if (!string.IsNullOrEmpty(verifyUsResult.id)) { lblquestionrequest.Text = "verification_id = " + verifyUsResult.id.ToString(); BlockScoreQuestionsResponse questionSet = GetQuestionSet(blockscore); lblquestionresponse.Text = GetblockscoreQuestionsResponseoutput(questionSet); CheckAnswers(blockscore, questionSet); } }
/* * Ouput Blockscore Response object to a string */ private string GetblockscoreResponseoutput(BlockScoreResponse blockscoreresponse) { string strreturn = ""; strreturn += "<br/>id = " + blockscoreresponse.id; strreturn += "<br/>verification_id = " + blockscoreresponse.verification_id; strreturn += "<br/>question_set_id = " + blockscoreresponse.question_set_id; if (blockscoreresponse.error != null) { strreturn += "<br/>error_code = " + blockscoreresponse.error.code; strreturn += "<br/>error_message = " + blockscoreresponse.error.message; strreturn += "<br/>error_type = " + blockscoreresponse.error.type; } return strreturn; }
/* * Ouput Blockscore Questions Request object to a string */ private string GetblockscoreQuestionsRequestoutput(BlockScoreResponse questionset, List<BlockScoreAnswer> answerlist) { string strreturn = ""; strreturn += "verification_id = " + questionset.verification_id; strreturn += "<br/>question_set_id = " + questionset.question_set_id; strreturn += "<br/>answers : "; foreach (BlockScoreAnswer tempanswer in answerlist) { strreturn += "<div class='Tab1'>"; strreturn += "<br/> answer_id = " + tempanswer.answer_id; strreturn += "<br/> question_id = " + tempanswer.question_id; strreturn += "</div>"; } return strreturn; }
/* * Verify the Answers with Blockscore */ private void CheckAnswers(BlockscoreAPI blockscore, BlockScoreResponse questionSet) { if (!string.IsNullOrEmpty(questionSet.question_set_id)) { try { var random = new Random(); List<BlockScoreAnswer> answerlist = new List<BlockScoreAnswer> { new BlockScoreAnswer{question_id = "1", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)}, new BlockScoreAnswer{ question_id= "2", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)}, new BlockScoreAnswer{ question_id= "3", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)}, new BlockScoreAnswer{ question_id= "4", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)}, new BlockScoreAnswer{question_id = "5", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)}, }; lblquestionscorerequest.Text = GetblockscoreQuestionsRequestoutput(questionSet, answerlist); BlockScoreQuestionsScoreResponse blockscorequestionscoreresponse = blockscore.CheckQuestionAnswers(answerlist); lblquestionscoreresponse.Text = GetblockscoreQuestionsScoreResponseoutput(blockscorequestionscoreresponse); } catch (Exception e) { throw new Exception("Caught exception: " + e.Message + "\n"); } } }