private async void addToCourse_Click(object sender, EventArgs e) { try { //get course name from list string courseName = (courseDataGridView.Rows[courseDataGridView.CurrentCell.RowIndex].Cells["courseName"].Value.ToString()); string studentName = allStudentsGrid.Rows[allStudentsGrid.CurrentCell.RowIndex].Cells["studentName"].Value.ToString(); //verify that selected student is to be added DialogResult addStudent = MessageBox.Show("Are you sure you want to invite " + studentName + " to " + courseName + "?", "Add Student", MessageBoxButtons.YesNo); if (addStudent == DialogResult.Yes) { string restResult = "No Call Made"; //this will be over written by results from web call var tokenParameter = coursesAccessToken; //Create //get student ID from list Int64 studentID = Int64.Parse(allStudentsGrid.Rows[allStudentsGrid.CurrentCell.RowIndex].Cells["studentID"].Value.ToString()); string endPoint = Properties.Settings.Default.InstructureSite + "/api/v1/courses/" + CanvasAPIMainForm.GlobalCourseID + "/enrollments?";//Get base endpoint from setting var enrollmentUserId = new Dictionary <string, string> { { "enrollment[user_id]", allStudentsGrid.Rows[allStudentsGrid.CurrentCell.RowIndex].Cells["user_ID"].Value.ToString() }, }; //Make api call try { //add student and repopulate list restResult = await requester.MakePOSTRequestAsync(endPoint, Properties.Settings.Default.CurrentAccessToken, enrollmentUserId); MessageBox.Show(studentName + " has been invited to " + courseName); populateCourseStudents(); } catch (Exception apiException) { MessageBox.Show("Error during API call.\n" + apiException.Message); } } } //end try catch (Exception apiException) { MessageBox.Show("Error adding student to course.\n" + apiException.Message, "Authentication error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
}//End Load Course Click private async void buttonSubmitAssign_Click(object sender, EventArgs e) { //create variables string restResult = "No Call Made"; //this will be over written by results from web call string endPoint = Properties.Settings.Default.InstructureSite + "/api/v1/courses/" + Convert.ToString(nudCourseID.Value) + "/assignments?"; //Get base endpoint from setting int assignToMake = Convert.ToInt32(nudNumberOfAssign.Value); int assignNumber = 0; //Getting assignment group key back currentAssignment.assignment_group_id = (from kvp in assignmentGroupvaluesAssign where kvp.Value == Convert.ToString(cbxAssignmentGroup.SelectedItem) select kvp.Key).FirstOrDefault(); //Obtain student group assignment key back currentAssignment.group_category_id = (from kvp in assignmentStudentGroupvalues where kvp.Value == Convert.ToString(cbxStudentAssignmentGroup.SelectedItem) select kvp.Key).FirstOrDefault(); //Setting parameters currentAssignment.grading_type = currentAssignment.GradingType(Convert.ToString(comboBoxGradeType.SelectedItem)); currentAssignment.points_possible = textBoxPoints.Text; currentAssignment.omit_from_final_grade = checkBoxOmit.Checked; currentAssignment.due_at = currentAssignment.DueDate(checkBoxDueDate.Checked, dtpDueDate.Value, dtpDueTime.Value); var fileTypes = currentAssignment.FileTypes(checkBoxFileTypes.Checked, textBoxFileTypes.Text); var unlock = currentAssignment.UnlockAt(checkBoxUnlock.Checked, dtpUnlockDate.Value, dtpUnlockTime.Value); var lockDate = currentAssignment.LockAt(checkBoxLock.Checked, dtpLockDate.Value, dtpLockTime.Value); var peerReview = currentAssignment.PeerReview(checkBoxPeer.Checked); var peerReviewAuto = currentAssignment.PeerReviewAuto(checkBoxPeer.Checked, radioButtonPeerManual.Checked); var assignPublish = currentAssignment.AssignPublish(checkBoxPublish.Checked); //Set submission type variable string assignSubmType = ""; if (comboBoxSubTypes.SelectedItem != null) { if (comboBoxSubTypes.SelectedItem.ToString() == "Online") { assignSubmType = currentAssignment.AssignOnlineSubmissionTypes(checkBoxFileUpload.Checked, checkBoxTextEntry.Checked, checkBoxWebsite.Checked, checkBoxMedia.Checked); } else { assignSubmType = currentAssignment.AssignSubmissionTypesNotOnline(comboBoxSubTypes.SelectedItem.ToString()); } } //Make API Call try { //Validate fields //Write out submit header rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", "Assign Name", "Status")); //Write Repeating submit if (xbxUseBase.Checked == true) { try { //Validate Number in text var pattern = @"\[([^\]]*)\]"; var inputNumber = Regex.Match(txbBaseName.Text, pattern).Value.Replace("[", "").Replace("]", ""); assignNumber = Convert.ToInt32(inputNumber); //While loop to run until Quizes to make is zero try { for (int i = 1; i <= assignToMake; i++) { //Incrementing assignment number currentAssignment.name = Regex.Replace(txbBaseName.Text, @"\[([^\]]*)\]", Convert.ToString(assignNumber)); //Formating Quiz Description for HTML currentAssignment.description = Regex.Replace(rtbAssignInstructions.Text, @"\[([^\]]*)\]", currentAssignment.name); //REST Call var jsonString = $"{{\"wiki_page\":{JsonConvert.SerializeObject(currentAssignment)}}}"; restResult = await requester.MakePOSTRequestAsync(endPoint, jsonString); //Write Results to Text box rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", currentAssignment.name, "Created")); assignNumber++; }//End Repeating submit while statement //Clear Assign Names txbBaseName.Text = ""; txbAssignName.Text = ""; }//End try catch (Exception apiException) { MessageBox.Show(apiException.Message); } }//End try On validating text in bracket catch (FormatException bracketNumberException) { MessageBox.Show("Please enter a number in brackets or uncheck \"Use base Name and Increment\"\n\n" + bracketNumberException.Message); }//End Catch on validating text in bracket } //Write single submit else { //Creating Assign Title and making it HTML safe currentAssignment.name = txbAssignName.Text; //Formating Assignment Description for HTML currentAssignment.description = Regex.Replace(rtbAssignInstructions.Text, @"\[([^\]]*)\]", txbAssignName.Text); //REST Call var jsonString = $"{{\"assignment\":{JsonConvert.SerializeObject(currentAssignment)}}}"; restResult = await requester.MakePOSTRequestAsync(endPoint, jsonString); //Reset form for next submit nudCourseID.TabStop = false; txbBaseName.TabStop = false; //Write Results to Text box rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", txbAssignName.Text, "Created")); } // end else } //End Single Submit catch (Exception apiException) { rtbResults.AppendText("Submit Failed: " + apiException.Message + "\n"); } }//End Submit
}//End Load Course Click private async void buttonSubmitAssign_Click(object sender, EventArgs e) { //create variables string restResult = "No Call Made"; //this will be over written by results from web call var tokenParameter = parameters.AccessToken(); //Create string endPoint = Properties.Settings.Default.InstructureSite + "/api/v1/courses/" + Convert.ToString(nudCourseID.Value) + "/assignments?"; //Get base endpoint from setting int assignToMake = Convert.ToInt32(nudNumberOfAssign.Value); int assignNumber = 0; //Getting assignment group key back var assignmentGroupKey = (from kvp in assignmentGroupvaluesAssign where kvp.Value == Convert.ToString(cbxAssignmentGroup.SelectedItem) select kvp.Key).FirstOrDefault(); //Obtain student group assignment key back var studentGroupAssignKey = (from kvp in assignmentStudentGroupvalues where kvp.Value == Convert.ToString(cbxStudentAssignmentGroup.SelectedItem) select kvp.Key).FirstOrDefault(); //Setting parameters var assignmentTypeParameter = parameters.AssignmentGroup(assignmentGroupKey); var groupAssignParameter = parameters.GroupAssignment(checkBoxGroupAssign.Checked, studentGroupAssignKey); var assignGradingType = parameters.GradingType(Convert.ToString(comboBoxGradeType.SelectedItem)); var assignPointsPossible = parameters.PointsPossible(Convert.ToInt32(textBoxPoints.Text)); var omitGrade = parameters.OmitGrade(checkBoxOmit.Checked); var dueDate = parameters.DueDate(checkBoxDueDate.Checked, dtpDueDate.Value, dtpDueTime.Value); var fileTypes = parameters.FileTypes(checkBoxFileTypes.Checked, textBoxFileTypes.Text); var unlock = parameters.UnlockAt(checkBoxUnlock.Checked, dtpUnlockDate.Value, dtpUnlockTime.Value); var lockDate = parameters.LockAt(checkBoxLock.Checked, dtpLockDate.Value, dtpLockTime.Value); var peerReview = parameters.PeerReview(checkBoxPeer.Checked); var peerReviewAuto = parameters.PeerReviewAuto(checkBoxPeer.Checked, radioButtonPeerManual.Checked); var assignPublish = parameters.AssignPublish(checkBoxPublish.Checked); //Set submission type variable string assignSubmType = ""; if (comboBoxSubTypes.SelectedItem != null) { if (comboBoxSubTypes.SelectedItem.ToString() == "Online") { assignSubmType = parameters.AssignOnlineSubmissionTypes(checkBoxFileUpload.Checked, checkBoxTextEntry.Checked, checkBoxWebsite.Checked, checkBoxMedia.Checked); } else { assignSubmType = parameters.AssignSubmissionTypesNotOnline(comboBoxSubTypes.SelectedItem.ToString()); } } //combining all parameters var allParameters = assignGradingType + assignSubmType + assignPointsPossible + omitGrade + dueDate + fileTypes + unlock + lockDate + peerReview + peerReviewAuto + groupAssignParameter + assignPublish + assignmentTypeParameter; //Make API Call try { //Validate fields //Write out submit header rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", "Assign Name", "Status")); //Write Repeating submit if (xbxUseBase.Checked == true) { try { //Validate Number in text var pattern = @"\[([^\]]*)\]"; var inputNumber = Regex.Match(txbBaseName.Text, pattern).Value.Replace("[", "").Replace("]", ""); assignNumber = Convert.ToInt32(inputNumber); //While loop to run until Quizes to make is zero try { while (assignToMake > 0) { //Incrementing assignment number var incrementedAssignName = Regex.Replace(txbBaseName.Text, @"\[([^\]]*)\]", Convert.ToString(assignNumber)); var htmlSafeIncrementedAssignName = Uri.EscapeDataString(incrementedAssignName); var assignTitleParameter = "&assignment[name]=" + htmlSafeIncrementedAssignName; //Formating Quiz Description for HTML var incrementedAssignInstruction = Regex.Replace(rtbAssignInstructions.Text, @"\[([^\]]*)\]", incrementedAssignName); var htmlSafeIncrementedAssignInstruction = Uri.EscapeDataString(incrementedAssignInstruction); var assignDescriptionParameter = parameters.AssignDescription(htmlSafeIncrementedAssignInstruction); //REST Call restResult = await requester.MakePOSTRequestAsync(endPoint, Properties.Settings.Default.CurrentAccessToken, assignTitleParameter + allParameters + assignDescriptionParameter); //Write Results to Text box rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", incrementedAssignName, "Created")); assignNumber++; assignToMake--; }//End Repeating submit while statement //Clear Assign Names txbBaseName.Text = ""; txbAssignName.Text = ""; }//End try catch (Exception apiException) { MessageBox.Show(apiException.Message); } }//End try On validating text in bracket catch (FormatException bracketNumberException) { MessageBox.Show("Please enter a number in brackets or uncheck \"Use base Name and Increment\"\n\n" + bracketNumberException.Message); }//End Catch on validating text in bracket } //Write single submit else { //Creating Assign Title and making it HTML safe var assignTitleParameter = "&assignment[name]=" + Uri.EscapeDataString(txbAssignName.Text); //Formating Assignment Description for HTML var incrementedAssignInstruction = Regex.Replace(rtbAssignInstructions.Text, @"\[([^\]]*)\]", txbAssignName.Text); //Makeing Assignment instruction HTML Safe var htmlSafeIncrementedAssignInstruction = Uri.EscapeDataString(incrementedAssignInstruction); //Setting Assignment description parameter var assignDescriptionParameter = parameters.AssignDescription(htmlSafeIncrementedAssignInstruction); restResult = await requester.MakePOSTRequestAsync(endPoint, Properties.Settings.Default.CurrentAccessToken, assignTitleParameter + allParameters + assignDescriptionParameter); //Reset form for next submit nudCourseID.TabStop = false; txbBaseName.TabStop = false; //Write Results to Text box rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", txbAssignName.Text, "Created")); } // end else } //End Single Submit catch (Exception apiException) { rtbResults.AppendText("Submit Failed: " + apiException.Message + "\n"); } }//End Submit
private async void buttonSubmitPage_Click(object sender, EventArgs e) { string restResult = "No Call Made"; //this will be over written by results from web call string endPoint = Properties.Settings.Default.InstructureSite + "/api/v1/courses/" + Convert.ToString(nudCourseID.Value) + "/pages?"; //Get base endpoint from setting Requester requester = new Requester(); int pageToMake = Convert.ToInt32(nudNumberOfAssign.Value); int pageNumber = 0; //Setting parameters currentPage.editing_roles = currentPage.EditRoles(radioButtonTeachers.Checked, radioButtonTeachandStu.Checked, radioButtonAnyone.Checked); currentPage.notify_of_update = checkBoxContentChange.Checked; currentPage.published = checkBoxPagePublish.Checked; //combining all parameters //Make API Call try { //Validate fields //Write out submit header rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", "Page Name", "Status")); //Write Repeating submit if (xbxUseBase.Checked == true) { try { //Validate Number in text var pattern = @"\[([^\]]*)\]"; var inputNumber = Regex.Match(txbBaseName.Text, pattern).Value.Replace("[", "").Replace("]", ""); pageNumber = Convert.ToInt32(inputNumber); //While loop to run until Quizes to make is zero try { for (int i = 1; i <= pageToMake; i++) { //Incrementing page number currentPage.title = Regex.Replace(txbBaseName.Text, @"\[([^\]]*)\]", Convert.ToString(pageNumber)); currentPage.body = Regex.Replace(rtbPageBody.Text, @"\[([^\]]*)\]", currentPage.title); //REST Call var jsonString = $"{{\"wiki_page\":{JsonConvert.SerializeObject(currentPage)}}}"; restResult = await requester.MakePOSTRequestAsync(endPoint, jsonString); //Write Results to Text box rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", currentPage.title, "Created")); pageNumber++; }//End Repeating submit while statement //Clear Page names txbBaseName.Text = ""; txbPageName.Text = ""; }//End try catch (Exception apiException) { MessageBox.Show(apiException.Message); } }//End try On validating text in bracket catch (FormatException bracketNumberException) { MessageBox.Show("Please enter a number in brackets or uncheck \"Use base Name and Increment\"\n\n" + bracketNumberException.Message); }//End Catch on validating text in bracket } //Write single submit else { currentPage.title = txbPageName.Text; currentPage.body = Regex.Replace(rtbPageBody.Text, @"\[([^\]]*)\]", txbPageName.Text); var jsonString = $"{{\"wiki_page\":{JsonConvert.SerializeObject(currentPage)}}}"; restResult = await requester.MakePOSTRequestAsync(endPoint, jsonString); //Reset form for next submit nudCourseID.TabStop = false; txbBaseName.TabStop = false; //Write Results to Text box rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", txbPageName.Text, "Created")); } // end else } //End Single Submit catch (Exception apiException) { rtbResults.AppendText("Submit Failed: " + apiException.Message + "\n"); } }//End Submit
}//End Control items in response combo box //submit Button private async void btnSubmitQuiz_Click(object sender, EventArgs e) { //create variables string restResult = "No Call Made"; //this will be over written by results from web call string endPoint = Properties.Settings.Default.InstructureSite + "/api/v1/courses/" + Convert.ToString(nudCourseID.Value) + "/quizzes?"; //Get base endpoint from setting Requester requester = new Requester(); int quizesToMake = Convert.ToInt32(nudNumberOfQuiz.Value); int quizNumber = 0; currentQuiz.quiz_type = currentQuiz.QuizType(Convert.ToString(cbxQuizType.SelectedItem)); //Getting key back currentQuiz.assignment_group_id = (from kvp in assignmentGroupvalues where kvp.Value == Convert.ToString(cbxAssignmentGroup.SelectedItem) select kvp.Key).FirstOrDefault(); currentQuiz.time_limit = currentQuiz.QuizTimeLimit(xbxTimeLimit.Checked, Convert.ToInt32(nudMinutes.Value)); currentQuiz.shuffle_answers = xbxShuffle.Checked; currentQuiz.hide_results = currentQuiz.HideResults(xbxQuizResponses.Checked, xbxOnlyAfterLastAttempt.Checked); currentQuiz.show_correct_answers = xbxSeeCorrectAnswers.Checked; currentQuiz.show_correct_answers_last_attempt = xbxCorrectAnswersAfterLastAttempt.Checked; currentQuiz.show_correct_aswers_at = currentQuiz.ShowCorrectAnswerAt(xbxSeeCorrectAnswers.Checked, dtpShow.Checked, dtpShow.Value, dtpShowTime.Value); currentQuiz.hide_correct_answers_at = currentQuiz.HideCorrectAnswerAt(xbxSeeCorrectAnswers.Checked, dtpHide.Checked, dtpHide.Value, dtpHideTime.Value); currentQuiz.allowed_attempts = currentQuiz.AllowedAttempts(xbxAttempts.Checked, xbxLimitAttempts.Checked, Convert.ToInt32(nudAttempts.Value)); currentQuiz.scoring_policy = currentQuiz.ScoringPolicy(Convert.ToString(cbxScoreToKeep.SelectedItem)); currentQuiz.one_question_at_a_time = xbxOneQuestionTime.Checked; currentQuiz.cant_go_back = currentQuiz.CantGoBack(xbxOneQuestionTime.Checked, xbxLockQuestion.Checked); currentQuiz.access_code = currentQuiz.AccessCode(xbxAccessCode.Checked, txbAccessCode.Text); currentQuiz.ip_filter = currentQuiz.IpAddressFiltering(xbxIPAddresses.Checked, txbIPAddresses.Text); currentQuiz.one_time_results = currentQuiz.OneTimeResults(xbxQuizResponses.Checked, xbxOnlyOnce.Checked); currentQuiz.require_lockdown_browser = xbxRequireLockDownBowser.Checked; currentQuiz.require_lockdown_browser_for_results = currentQuiz.RequireLockdownBrowsertoVeiwResults(xbxRequireLockDownBowser.Checked, xbxRequireLockDownBrowsertoViewResuts.Checked); currentQuiz.due_at = currentQuiz.DueDate(dtpDueDate.Checked, dtpDueDate.Value, dtpDueDateTime.Value); currentQuiz.unlock_at = currentQuiz.UnlockDate(dtpUnlockDate.Checked, dtpUnlockDate.Value, dtpUnlockDateTime.Value); currentQuiz.lock_at = currentQuiz.LockDate(dtpLockDate.Checked, dtpLockDate.Value, dtpLockDateTime.Value); currentQuiz.published = xbxPublish.Checked; //Make API Call try { //Write out submit header rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", "Quiz Name", "Status")); //Write Repeating submit if (xbxUseBase.Checked == true) { try { //Validate Number in text var pattern = @"\[([^\]]*)\]"; var inputNumber = Regex.Match(txbBaseName.Text, pattern).Value.Replace("[", "").Replace("]", ""); quizNumber = Convert.ToInt32(inputNumber); //While loop to run until Quizzes to make is zero try { for (int loopIndex = 1; loopIndex <= quizesToMake; loopIndex++) { //Incrementing quiz number currentQuiz.title = Regex.Replace(txbBaseName.Text, @"\[([^\]]*)\]", Convert.ToString(quizNumber)); //Formating Quiz Description for HTML currentQuiz.description = Regex.Replace(rtbQuizInstructions.Text, @"\[([^\]]*)\]", currentQuiz.title); //REST Call var jsonString = $"{{\"quiz\":{JsonConvert.SerializeObject(currentQuiz)}}}"; //restResult = await requester.MakeRequestAsync(endPoint, Properties.Settings.Default.CurrentAccessToken, quizTitleParameter + allParameters + quizDescriptionParameter); restResult = await requester.MakePOSTRequestAsync(endPoint, jsonString); //Write Results to Text box rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", currentQuiz.title, "Created")); quizNumber++; }//End Repeating submit while statement //Clear QuizNames txbBaseName.Text = ""; txbQuizName.Text = ""; }//End try catch (Exception apiException) { MessageBox.Show(apiException.Message); } }//End try On validating text in bracket catch (FormatException bracketNumberException) { MessageBox.Show("Please enter a number in brackets or uncheck \"Use base Name and Increment\"\n\n" + bracketNumberException.Message); }//End Catch on validating text in bracket } //Write single submit else { //Creating Quiz Title and making it HTML safe currentQuiz.title = txbQuizName.Text; //Formating Quiz Description for HTML currentQuiz.description = Regex.Replace(rtbQuizInstructions.Text, @"\[([^\]]*)\]", txbQuizName.Text); //restResult = await requester.MakeRequestAsync(endPoint, Properties.Settings.Default.CurrentAccessToken, quizTitleParameter + allParameters + quizDescriptionParameter); var jsonString = $"{{\"quiz\":{JsonConvert.SerializeObject(currentQuiz)}}}"; restResult = await requester.MakePOSTRequestAsync(endPoint, jsonString); //Reset form for next submit nudCourseID.TabStop = false; txbBaseName.TabStop = false; //Write Results to Text box rtbResults.AppendText(String.Format("{0,-50} {1,-10}\n", txbQuizName.Text, "Created")); }//End Single Submit } catch (Exception apiException) { rtbResults.AppendText("Submit Failed: " + apiException.Message + "\n"); } }//End Submit