public void Populate() { rest = new RESTapi("http://ist.rit.edu/api"); // Get About information string jsonAbout = rest.getRESTData("/about/"); Console.WriteLine(jsonAbout); // Convert the JSON to an About C# object // use http://json2csharp.com // enter http://ist.rit.edu/api/about About about = JToken.Parse(jsonAbout).ToObject <About>(); lbl_aboutTitle.Text = about.title; richTextBox1.Text = about.description; lbl_about_quoteAuthor.Text = about.quoteAuthor; textBox1.Text = about.quote; // Get /resources/ string jsonRes = rest.getRESTData("/resources/"); // Create Resources object to load the parsed JSON Resources resources = JToken.Parse(jsonRes).ToObject <Resources>(); // Add the link text to the display lnkLbl_http.Text = resources.tutorsAndLabInformation.tutoringLabHoursLink; } // Populate()
private void Research() { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonResearch = baseRestURL.getRESTData("/research/"); research = JToken.Parse(jsonResearch).ToObject <Research>(); // Console.WriteLine(jsonResearch); try { for (int i = 0; i < research.byInterestArea.Count(); i++) { listboxResearchByInterestArea.Items.Add(research.byInterestArea[i].areaName); } } catch (Exception) { } try { for (int i = 0; i < research.byFaculty.Count(); i++) { listboxResearchByFaculty.Items.Add(research.byFaculty[i].facultyName + " (" + research.byFaculty[i].username + ")"); } } catch (Exception) { } }
private void Minors() { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonMinors = baseRestURL.getRESTData("/minors/"); minors = JToken.Parse(jsonMinors).ToObject <Minors>(); // Console.WriteLine(jsonMinors); listBoxUgMinorsName.Items.Clear(); try { for (int i = 0; i < minors.UgMinors.Count(); i++) { listBoxUgMinorsName.Items.Add(minors.UgMinors[i].name); } } catch (Exception) { } lblUgMinorsTitle.Text = ""; txtboxUgMinorsTitle.Text = ""; txtBoxUgNote.Text = ""; }
private void Degrees() { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonDegrees = baseRestURL.getRESTData("/degrees/"); degrees = JToken.Parse(jsonDegrees).ToObject <Degrees>(); // Console.WriteLine(jsonDegrees); lblDegreesTitle.Text = ""; txtboxDegreesDesc.Text = ""; }
// AboutUs Section #region AboutUs // About Us Tab private void AboutUs() { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonAbout = baseRestURL.getRESTData("/about/"); // Console.WriteLine(jsonAbout); AboutUs about = JToken.Parse(jsonAbout).ToObject <AboutUs>(); lblAboutUsTitle.Text = about.title; txtboxAboutUs.Text = '"' + about.quote + '"'; txtboxAboutUs.Text += " - " + about.quoteAuthor; txtboxAboutUsDesc.Text = about.description; }
public void Populate() { rest = new RESTapi("http://ist.rit.edu/api"); // Get About information string jsonAbout = rest.getRESTData("/about/"); // Convert the JSON to an About C# object // use http://json2csharp.com // enter http://ist.rit.edu/api/about About about = JToken.Parse(jsonAbout).ToObject <About>(); lbl_aboutTitle.Text = about.title; richTextBox1.Text = about.description; richTextBox1.SelectionAlignment = HorizontalAlignment.Center; lbl_about_quoteAuthor.Text = about.quoteAuthor; lbl_about_quoteAuthor.TextAlign = ContentAlignment.MiddleCenter; textBox1.Text = about.quote; textBox1.TextAlign = HorizontalAlignment.Center; } // Populate()
private void comboBoxCoursesDegree_SelectedIndexChanged(object sender, EventArgs e) { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonCourses = baseRestURL.getRESTData("/courses/"); courseses = JToken.Parse(jsonCourses).ToObject <Courses[]>(); int index = comboBoxCoursesDegree.SelectedIndex; dataGridViewDegreeCourses.Rows.Clear(); try { for (int i = 0; i < courseses.Count(); i++) { dataGridViewDegreeCourses.Rows.Add(courseses[index].courses[i]); } } catch (Exception) { } }
public void News() { Random ran = new Random(); RESTapi baseRestUrls = new RESTapi("http://ist.rit.edu/api"); string jsonNews = baseRestUrls.getRESTData("/news/"); Console.WriteLine(jsonNews); news = JToken.Parse(jsonNews).ToObject <News>(); int minBreakingNews = ran.Next(news.older.Count()); String desc = news.older[minBreakingNews].description; String title = news.older[minBreakingNews].title; dlgBreakingNews dlg = new dlgBreakingNews(title, desc); dlg.Show(); }
private void People() { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonPeople = baseRestURL.getRESTData("/people/"); people = JToken.Parse(jsonPeople).ToObject <People>(); lblPeopleFacultyMainTitle.Text = people.title; lblPeopleStaffMainTitle.Text = people.title; lblPeopleFacultySubtitle.Text = people.subTitle; lblPeopleStaffSubtitle.Text = people.subTitle; try { for (int i = 0; i < people.faculty.Count(); i++) { cbPeopleFacultyNames.Items.Add(people.faculty[i].name); } } catch (Exception) { } try { for (int i = 0; i < people.staff.Count(); i++) { cbPeopleStaff.Items.Add(people.staff[i].name); } } catch (Exception) { } // sets first choice to 0 so it is not automatically empty at first cbPeopleFacultyNames.SelectedIndex = 0; cbPeopleStaff.SelectedIndex = 0; }
private void Course() { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonCourses = baseRestURL.getRESTData("/courses/"); courseses = JToken.Parse(jsonCourses).ToObject <Courses[]>(); // Console.WriteLine(jsonCourses); try { for (int i = 0; i < courseses.Length; i++) { comboBoxCoursesDegree.Items.Add(courseses[i].degreeName); comboBoxCoursesDegree.SelectedIndex = 0; // Console.WriteLine(courseses[i].degreeName); } } catch (Exception) { } }
private void PutEvent(RESTapi.event_type type) { RESTapi.web_service ws = new RESTapi.web_service() { Item = new RESTapi.@event() { type = type, resource_type = ResourceType, resource_id = ResourceID, } }; /// IMPORTANT: Call the dispatcher IN A NEW THREAD or stuff will just /// randomly lock up / fail for no apparent reason! /// ThreadPool.QueueUserWorkItem(x => { this.Dispatcher.ProcessRequest(ws); }); }
/// <summary> /// This is an example of how to populate and call a more complicated /// RESTapi structure. We play an audio/video file from here... /// </summary> /// <param name="audioUri"></param> /// <param name="videoUri"></param> /// protected virtual void PlayFile(String audioUri, RESTapi.audio_type_option audioType = RESTapi.audio_type_option.audioxwav, String videoUri = "", RESTapi.video_type_option videoType = RESTapi.video_type_option.videoxvid) { bool hasAudio = !String.IsNullOrWhiteSpace(audioUri); bool hasVideo = !String.IsNullOrWhiteSpace(videoUri); RESTapi.web_service ws = new RESTapi.web_service() { Item = new RESTapi.call() { call_action = new RESTapi.call_action() { Item = new RESTapi.play() { offset = "0s", repeat = "0", delay = "0s", play_source = new RESTapi.play_source() { audio_uri = hasAudio ? audioUri : String.Empty, audio_type = audioType, audio_typeSpecified = hasAudio, video_uri = hasVideo ? videoUri : String.Empty, video_type = videoType, video_typeSpecified = hasVideo, } } } } }; if (hasAudio) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::PlayFile : Playing audio \"{0}\"...", audioUri); } if (hasVideo) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::PlayFile : Playing video \"{0}\"...", videoUri); } String responseString = String.Empty; if (RestHelpers.SendHttpRequest(out responseString, CallURI, "PUT", ws)) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::PlayFile : Play file OK"); LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, responseString); } else { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Error, "Call::PlayFile : Play file failed!"); PutEvent(RESTapi.event_type.end_play); } }
/// <summary> /// Ok - if we get here (!) then we have a valid event associated with a /// specific call. We should handle the event (obviously!) appropriately. /// </summary> /// <param name="ws">The web_service request to process</param> /// protected virtual void HandleEvent(RESTapi.web_service ws) { RESTapi.@event @event = ws.Item as RESTapi.@event; LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Event, "Call::HandleEvent : Processing event \"{0}\"", @event.type.ToString()); this._LastEvent = ws.Item as RESTapi.@event; this._LastEventData = null; if (this._LastEvent.event_data != null) { this._LastEventData = this._LastEvent.event_data.ToDictionary(x => x.name, x => x.value); /*string _Buf = ""; foreach (KeyValuePair<string, string> kv in this._LastEventData) { _Buf += string.Format(" => {0}->{1}\n", kv.Key, kv.Value); } Logger.LogMessage("Call::HandleEvent : Event has associated event data:\n{0}", _Buf);*/ } switch (@event.type) { case RESTapi.event_type.incoming: this.CallState = CallStateType.Ringing; OnIncoming(); break; case RESTapi.event_type.ringing: this.CallState = CallStateType.Ringing; OnRinging(); break; case RESTapi.event_type.accepted: this.CallState = CallStateType.Ringing; OnAccepted(); break; case RESTapi.event_type.answered: case RESTapi.event_type.connected: this.CallState = CallStateType.Connected; OnConnected(); break; case RESTapi.event_type.alarm: OnAlarm(); break; case RESTapi.event_type.dtmf: OnDtmf(); break; case RESTapi.event_type.end_play: OnEndPlay(); break; case RESTapi.event_type.hangup: this.CallState = CallStateType.Hangup; OnHangup(); break; default: LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Error, "Call::HandleEvent : Unhandled event \"{0}\"", @event.type.ToString()); break; } }
protected virtual void AnswerCall(RESTapi.media_type MediaType = RESTapi.media_type.audiovideo, bool AsyncCompletion = true) { /// <call answer="yes" media="audiovideo" signaling="yes" dtmf_mode="rfc2833" async_completion="yes" /// async_dtmf="yes" async_tone="yes" rx_delta="+0dB" tx_delta="+0dB" cpa="no" info_ack_mode="automatic"/> /// RESTapi.web_service ws = new RESTapi.web_service() { Item = new RESTapi.call() { answer = RESTapi.boolean_type.yes, answerSpecified = true, async_completion = AsyncCompletion ? RESTapi.boolean_type.yes : RESTapi.boolean_type.no, async_completionSpecified = true, media = MediaType, mediaSpecified = true, dtmf_mode = RESTapi.dtmf_mode_option.rfc2833, async_dtmf = RESTapi.boolean_type.yes, async_dtmfSpecified = true, async_tone = RESTapi.boolean_type.yes, async_toneSpecified = true, info_ack_mode = RESTapi.ack_mode_option.automatic, info_ack_modeSpecified = true, } }; String responseString = String.Empty; if (RestHelpers.SendHttpRequest(out responseString, CallURI, "PUT", ws)) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::AnswerCall : AnswerCall OK"); LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, responseString); // Note: If we use async_completion, we DON'T have to put the event // manually as it will (or rather... should) appear as a separate // event from the XMS server... // if (!AsyncCompletion) { PutEvent(RESTapi.event_type.answered); } } else { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Error, "Call::AnswerCall : AnswerCall failed!"); Hangup(); } }
protected virtual void AcceptCall(bool EarlyMedia = true, RESTapi.media_type MediaType = RESTapi.media_type.audiovideo) { /// <call accept="yes" early_media="yes" media="audiovideo" signaling="yes" dtmf_mode="rfc2833" /// async_dtmf="yes" async_tone="yes" rx_delta="+0dB" tx_delta="+0dB" cpa="no" info_ack_mode="automatic"/> /// RESTapi.web_service ws = new RESTapi.web_service() { Item = new RESTapi.call() { accept = RESTapi.boolean_type.yes, acceptSpecified = true, early_media = EarlyMedia ? RESTapi.boolean_type.yes : RESTapi.boolean_type.no, early_mediaSpecified = true, media = MediaType, mediaSpecified = true, dtmf_mode = RESTapi.dtmf_mode_option.rfc2833, async_dtmf = RESTapi.boolean_type.yes, async_dtmfSpecified = true, async_tone = RESTapi.boolean_type.yes, async_toneSpecified = true, info_ack_mode = RESTapi.ack_mode_option.automatic, info_ack_modeSpecified = true, } }; String responseString = String.Empty; if (RestHelpers.SendHttpRequest(out responseString, CallURI, "PUT", ws)) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::AcceptCall : Accept call OK"); LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, responseString); PutEvent(RESTapi.event_type.ringing); } else { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Error, "Call::AcceptCall : Accept call failed!"); Hangup(); } }
private void Employment() { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonEmployment = baseRestURL.getRESTData("/employment/"); employment = JToken.Parse(jsonEmployment).ToObject <Employment>(); lblEmpIntroTitle.Text = employment.introduction.title; txtBoxContentTitleAndDesc.Text = ""; lblEmploymentTitleDesc.Text = employment.employers.title + ": "; // Console.WriteLine(employment.employers.employerNames.Count()); try { for (int i = 0; i < employment.employers.employerNames.Count(); i++) { // Console.WriteLine(i+1); if (employment.employers.employerNames.Count() == (i + 1)) { // Console.WriteLine("Stopping at: " + i + " " + employment.employers.employerNames[i] + " "); lblEmploymentTitleDesc.Text += employment.employers.employerNames[i]; } else { lblEmploymentTitleDesc.Text += employment.employers.employerNames[i] + ", "; } } } catch (Exception) { } // Introduction Title and Desc try { for (int i = 0; i < employment.introduction.content.Count(); i++) { txtBoxContentTitleAndDesc.Text += employment.introduction.content[i].title + "\n"; txtBoxContentTitleAndDesc.Text += employment.introduction.content[i].description + "\n\n"; } } catch (Exception) { } // CoopTable try { for (int i = 0; i < employment.coopTable.coopInformation.Count(); i++) { dataGridViewCoopTable.Rows.Add( employment.coopTable.coopInformation[i].employer, // employer employment.coopTable.coopInformation[i].degree, // degree employment.coopTable.coopInformation[i].city, // city employment.coopTable.coopInformation[i].term // term ); } } catch (Exception) { } // sorting CoopTable A-Z dataGridViewCoopTable.Sort(dataGridViewCoopTable.Columns["Employer"], ListSortDirection.Ascending); }
private void Resources() { baseRestURL = new RESTapi("http://ist.rit.edu/api"); string jsonResources = baseRestURL.getRESTData("/resources/"); resources = JToken.Parse(jsonResources).ToObject <Resources>(); // Console.WriteLine(jsonResources); lblStudentResourcesTitle.Text = resources.title; lblStudentResourcesSubtitle.Text = resources.subTitle; lblResourcesStudyAbroad.Text = resources.studyAbroad.title; richTextBoxResourcesStudyAbroadDesc.Text = resources.studyAbroad.description; try { for (int i = 0; i < resources.studyAbroad.places.Count(); i++) { richTextBoxResourcesStudyAbroadDesc.Text += "\n\n- " + resources.studyAbroad.places[i].nameOfPlace + "\n\t" + resources.studyAbroad.places[i].description; } } catch (Exception) { } lblResourcesTutorTitle.Text = resources.tutorsAndLabInformation.title; richTextBoxResourcesTutorDesc.Text = resources.tutorsAndLabInformation.description; lblResourcesAdvisingAcademicTitle.Text = resources.studentServices.academicAdvisors.title; richtextboxAcademicAdvisorDesc.Text = resources.studentServices.academicAdvisors.description; linkLblAcademicAdvisor.Text = resources.studentServices.academicAdvisors.faq.title; lblResourcesAdvisingFacultyTitle.Text = resources.studentServices.facultyAdvisors.title; richtextboxFacultyAdvisorDesc.Text = resources.studentServices.facultyAdvisors.description; // Academic Advisors try { for (int i = 0; i < resources.studentServices.professonalAdvisors.advisorInformation.Count(); i++) { datagridviewResourcesAcademicAdvisor.Rows.Add( resources.studentServices.professonalAdvisors.advisorInformation[i].name, // name resources.studentServices.professonalAdvisors.advisorInformation[i].department, // department resources.studentServices.professonalAdvisors.advisorInformation[i].email // email ); } } catch (Exception) { } try { for (int i = 0; i < resources.studentServices.istMinorAdvising.minorAdvisorInformation.Count(); i++) { datagridviewResourcesISTAdvisor.Rows.Add( resources.studentServices.istMinorAdvising.minorAdvisorInformation[i].advisor, // name of advisor resources.studentServices.istMinorAdvising.minorAdvisorInformation[i].title, // title (department) resources.studentServices.istMinorAdvising.minorAdvisorInformation[i].email // email ); } } catch (Exception) { } lblResourcesAmbassadorsTitle.Text = resources.studentAmbassadors.title; pictureBoxResourcesAmbassadorsPic.ImageLocation = resources.studentAmbassadors.ambassadorsImageSource; try { for (int i = 0; i < (resources.studentAmbassadors.subSectionContent.Count() - 1); i++) { richTextBoxAmbassadorsContent.Text += resources.studentAmbassadors.subSectionContent[i].title + "\n"; richTextBoxAmbassadorsContent.Text += "- " + resources.studentAmbassadors.subSectionContent[i].description + "\n\n"; } } catch (Exception) { } lblResourcesAmbassadorsApplyDesc.Text = resources.studentAmbassadors.subSectionContent[6].description; linkLabelAmbassadorsUrl.Text = resources.studentAmbassadors.subSectionContent[6].title.ToUpper(); lblResourcesAmbassadorNote.Text = resources.studentAmbassadors.note; lblResourcesAcademicCoopInfoTitle.Text = resources.coopEnrollment.title; try { for (int i = 0; i < resources.coopEnrollment.enrollmentInformationContent.Count(); i++) { richTextBoxResourcesAcademicCoopInfoDesc.Text += resources.coopEnrollment.enrollmentInformationContent[i].title + "\n"; richTextBoxResourcesAcademicCoopInfoDesc.Text += resources.coopEnrollment.enrollmentInformationContent[i].description + "\n\n"; } } catch (Exception) { } linkLblResourcesGradOne.Text = resources.forms.graduateForms[0].formName; linkLblResourcesGradTwo.Text = resources.forms.graduateForms[1].formName; linkLblResourcesGradThree.Text = resources.forms.graduateForms[2].formName; linkLblResourcesGradFour.Text = resources.forms.graduateForms[3].formName; linkLblResourcesGradFive.Text = resources.forms.graduateForms[4].formName; linkLblResourcesGradSix.Text = resources.forms.graduateForms[5].formName; linkLblResourcesGradSeven.Text = resources.forms.graduateForms[6].formName; linkLblResourcesUnderOne.Text = resources.forms.undergraduateForms[0].formName; }