Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. private async Task CreateTopicFromCsvAsync()
  2. {
  3. var topicGenerator = new TopicCsvGenerator();
  4.  
  5. using (var client = this.CreateMissionManagerClient())
  6. {
  7. var mission = (await client.GetMissionsAsync()).First();
  8.  
  9. string topicName;
  10. var topicCsvString = topicGenerator.GenerateTopic(out topicName);
  11.  
  12. var jobHandle =
  13. await
  14. client.CreateTopicFromCsv(mission.ID, new MemoryStream(Encoding.UTF8.GetBytes(topicCsvString)));
  15.  
  16. var jobStatus = await client.GetJobStatusAsync(jobHandle, waitAll: true);
  17.  
  18. while (!jobStatus.Completed.HasValue)
  19. {
  20. jobStatus = await client.GetJobStatusAsync(jobHandle, waitAll: true);
  21. }
  22.  
  23. var topic = (await client.GetTopicsAsync()).FirstOrDefault(x => x.Name == topicName);
  24.  
  25. await client.CreateIdenticonsForTopicAsync(topic.ID);
  26. }
  27. }
  28.  
  29.  
  30. private async Task QueryQuestionAsync()
  31. {
  32. using (var client = this.CreateMissionManagerClient())
  33. {
  34. var questions = await client.GetQuestionsAsync();
  35.  
  36. var questionsClone = await client.GetQuestionsAsync();
  37.  
  38. var question = questions.FirstOrDefault();
  39.  
  40. var questionClone = await client.GetQuestionByIDAsync(question.ID);
  41.  
  42. var createQuestion = new Question()
  43. {
  44. Text = "Who shot Mr. Burns?",
  45. QuestionType = QuestionType.MultipleChoice,
  46. OptionRender = OptionRenderTypes.PhotoAndDisplayName,
  47. Answers = new[]
  48. {
  49. new Answer()
  50. {
  51. Text = "Maggie Simpson",
  52. Grade = 1
  53. },
  54. new Answer()
  55. {
  56. Text = "Homer Simpson",
  57. Grade = 0
  58. },
  59. new Answer()
  60. {
  61. Text = "Lisa Simpson",
  62. Grade = 0
  63. },
  64. new Answer()
  65. {
  66. Text = "Bart Simpson",
  67. Grade = 0
  68. },
  69. new Answer()
  70. {
  71. Text = "Marge Simpson",
  72. Grade = 0
  73. },
  74. }
  75. };
  76.  
  77. var createdQuestion = await client.CreateQuestionAsync(createQuestion);
  78.  
  79. var createdQuestionClone = await client.GetQuestionByIDAsync(createdQuestion.ID);
  80.  
  81. createdQuestionClone.Text += "??";
  82. createdQuestionClone.Answers.First(x => x.Grade == 1).Text += 1;
  83.  
  84. var updatedQuestion1 = await client.UpdateQuestionAsync(createdQuestionClone);
  85.  
  86. var margeSimpsonAnswer = updatedQuestion1.Answers.First(x => x.Text == "Marge Simpson");
  87. updatedQuestion1.Answers.Remove(margeSimpsonAnswer);
  88.  
  89. var updatedQuestion2 = await client.UpdateQuestionAsync(updatedQuestion1);
  90.  
  91. updatedQuestion2.Answers.Add(new Answer()
  92. {
  93. Text = "Abe Simpson",
  94. Grade = 0
  95. });
  96.  
  97. var updatedQuestion3 = await client.UpdateQuestionAsync(updatedQuestion2);
  98.  
  99. var xxx = await client.GetQuestionByIDAsync(updatedQuestion3.ID);
  100.  
  101. await client.DeleteQuestionByIDAsync(xxx.ID);
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement