Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace MeSS
- {
- // This is a helper class for Web Service requests
- //----------------------------------------------------------------------------------------------------
- // Example of Use
- //
- // TempleLDAPEntry result = WebService.getLDAPEntryByAccessnet("tue71468");
- // or
- // TempleLDAPEntry result = WebService.getLDAPEntryByTUID("915006167");
- //
- // The 'result' variable will contain all info listed in the Web Services document on BB
- //----------------------------------------------------------------------------------------------------
- // Get the user's listed email address:
- //
- // string emailAddress = result.mail;
- //----------------------------------------------------------------------------------------------------
- public static class WebService
- {
- private static string webServiceUsername = "yourusername";
- private static string webServicePassword = "yourpassword";
- // Takes a 9-digit TUID (like '915006167')
- // Returns a TempleLDAPEntry object
- public static TempleLDAPEntry getLDAPEntryByTUID(string tuID)
- {
- // Create the WebService proxy, send the search request and receive the TempleLDAPEntry object
- WS_LDAPSearch.LDAP_Search ldapProxy = new WS_LDAPSearch.LDAP_Search();
- WS_LDAPSearch.TempleLDAPEntry[] results = new WS_LDAPSearch.TempleLDAPEntry[1];
- results = ldapProxy.Search(webServiceUsername, webServicePassword, "templeEduTUID", tuID);
- WS_LDAPSearch.TempleLDAPEntry resultEntry = results[0];
- // Check if request was successful
- if (resultEntry.result == null) // Success
- {
- // Create our TempleLDAPEntry object to be returned
- TempleLDAPEntry personLDAPEntry = new TempleLDAPEntry();
- personLDAPEntry.templeEduID = resultEntry.templeEduTUID;
- personLDAPEntry.uID = resultEntry.uid;
- personLDAPEntry.cn = resultEntry.cn;
- personLDAPEntry.givenName = resultEntry.givenName;
- personLDAPEntry.sn = resultEntry.sn;
- personLDAPEntry.eduPersonAffiliation = resultEntry.eduPersonAffiliation;
- personLDAPEntry.eduPersonPrimaryAffiliation = resultEntry.eduPersonPrimaryAffiliation;
- personLDAPEntry.mail = resultEntry.mail;
- return personLDAPEntry;
- }
- else // Something went wrong..
- {
- return null;
- }
- }
- // Takes an AccessNet ID (like 'tue71468')
- // Returns a TempleLDAPEntry object
- public static TempleLDAPEntry getLDAPEntryByAccessnet(string accessnetID)
- {
- // Create the WebService proxy, send the search request and receive the TempleLDAPEntry object
- WS_LDAPSearch.LDAP_Search ldapProxy = new WS_LDAPSearch.LDAP_Search();
- WS_LDAPSearch.TempleLDAPEntry[] results = new WS_LDAPSearch.TempleLDAPEntry[1];
- results = ldapProxy.Search(webServiceUsername, webServicePassword, "uid", accessnetID);
- WS_LDAPSearch.TempleLDAPEntry resultEntry = results[0];
- // Check if request was successful
- if (resultEntry.result == null) // Success
- {
- // Create our TempleLDAPEntry object to be returned
- TempleLDAPEntry personLDAPEntry = new TempleLDAPEntry();
- personLDAPEntry.templeEduID = resultEntry.templeEduTUID;
- personLDAPEntry.uID = resultEntry.uid;
- personLDAPEntry.cn = resultEntry.cn;
- personLDAPEntry.givenName = resultEntry.givenName;
- personLDAPEntry.sn = resultEntry.sn;
- personLDAPEntry.eduPersonAffiliation = resultEntry.eduPersonAffiliation;
- personLDAPEntry.eduPersonPrimaryAffiliation = resultEntry.eduPersonPrimaryAffiliation;
- personLDAPEntry.mail = resultEntry.mail;
- return personLDAPEntry;
- }
- else // Something went wrong..
- {
- return null;
- }
- }
- // Takes nothing
- // Returns a term object that contains all term data
- // Returns null if an error occurred
- public static Term getCurrentTerm()
- {
- WS_StudentSearch.WS_Student studentProxy = new WS_StudentSearch.WS_Student();
- WS_StudentSearch.Result results = new WS_StudentSearch.Result();
- results = studentProxy.GetCurrentTerm(webServiceUsername, webServicePassword);
- // Check if request was successful
- if (results.Status == "OK") // Success
- {
- Term returnTerm = new Term();
- WS_StudentSearch.Term[] t = results.Terms;
- returnTerm.termCode = t[0].code;
- returnTerm.termName = t[0].name;
- returnTerm.startDate = t[0].startDate;
- returnTerm.endDate = t[0].endDate;
- return returnTerm;
- }
- else // Something went wrong...
- {
- return null;
- }
- }
- // Takes a term code (4 digit year followed by 2 digit week)
- // Returns a term object that contains all term data
- public static Term getTermByTermCode(string termCode)
- {
- WS_StudentSearch.WS_Student studentProxy = new WS_StudentSearch.WS_Student();
- WS_StudentSearch.Result results = new WS_StudentSearch.Result();
- results = studentProxy.GetTermByTermCode(webServiceUsername, webServicePassword, termCode);
- // Check if request was successful
- if (results.Status == "OK") // Success
- {
- Term returnTerm = new Term();
- WS_StudentSearch.Term[] t = results.Terms;
- returnTerm.termCode = t[0].code;
- returnTerm.termName = t[0].name;
- returnTerm.startDate = t[0].startDate;
- returnTerm.endDate = t[0].endDate;
- return returnTerm;
- }
- else // Something went wrong...
- {
- return null;
- }
- }
- // Takes a date (can be MM/DD/YYYY, YYYY/MM/DD, MM/DD/YY)
- // Returns a term object that contains all term data
- public static Term GetTermByDate(string date)
- {
- WS_StudentSearch.WS_Student studentProxy = new WS_StudentSearch.WS_Student();
- WS_StudentSearch.Result results = new WS_StudentSearch.Result();
- results = studentProxy.GetTermByDate(webServiceUsername, webServicePassword, date);
- // Check if request was successful
- if (results.Status == "OK") // Success
- {
- Term returnTerm = new Term();
- WS_StudentSearch.Term[] t = results.Terms;
- returnTerm.termCode = t[0].code;
- returnTerm.termName = t[0].name;
- returnTerm.startDate = t[0].startDate;
- returnTerm.endDate = t[0].endDate;
- return returnTerm;
- }
- else // Something went wrong...
- {
- return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement