Advertisement
Guest User

Untitled

a guest
Feb 1st, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5.  
  6. namespace MeSS
  7. {
  8.     // This is a helper class for Web Service requests
  9.     //----------------------------------------------------------------------------------------------------
  10.     // Example of Use
  11.     //
  12.     //      TempleLDAPEntry result = WebService.getLDAPEntryByAccessnet("tue71468");
  13.     //     or
  14.     //      TempleLDAPEntry result = WebService.getLDAPEntryByTUID("915006167");
  15.     //
  16.     // The 'result' variable will contain all info listed in the Web Services document on BB
  17.     //----------------------------------------------------------------------------------------------------
  18.     // Get the user's listed email address:
  19.     //
  20.     //      string emailAddress = result.mail;
  21.     //----------------------------------------------------------------------------------------------------
  22.  
  23.     public static class WebService
  24.     {
  25.         private static string webServiceUsername = "yourusername";
  26.         private static string webServicePassword = "yourpassword";
  27.  
  28.  
  29.         // Takes a 9-digit TUID (like '915006167')
  30.         // Returns a TempleLDAPEntry object
  31.         public static TempleLDAPEntry getLDAPEntryByTUID(string tuID)
  32.         {
  33.             // Create the WebService proxy, send the search request and receive the TempleLDAPEntry object
  34.             WS_LDAPSearch.LDAP_Search ldapProxy = new WS_LDAPSearch.LDAP_Search();
  35.             WS_LDAPSearch.TempleLDAPEntry[] results = new WS_LDAPSearch.TempleLDAPEntry[1];
  36.             results = ldapProxy.Search(webServiceUsername, webServicePassword, "templeEduTUID", tuID);
  37.             WS_LDAPSearch.TempleLDAPEntry resultEntry = results[0];
  38.  
  39.             // Check if request was successful
  40.             if (resultEntry.result == null) // Success
  41.             {
  42.                 // Create our TempleLDAPEntry object to be returned
  43.                 TempleLDAPEntry personLDAPEntry = new TempleLDAPEntry();
  44.                 personLDAPEntry.templeEduID = resultEntry.templeEduTUID;
  45.                 personLDAPEntry.uID = resultEntry.uid;
  46.                 personLDAPEntry.cn = resultEntry.cn;
  47.                 personLDAPEntry.givenName = resultEntry.givenName;
  48.                 personLDAPEntry.sn = resultEntry.sn;
  49.                 personLDAPEntry.eduPersonAffiliation = resultEntry.eduPersonAffiliation;
  50.                 personLDAPEntry.eduPersonPrimaryAffiliation = resultEntry.eduPersonPrimaryAffiliation;
  51.                 personLDAPEntry.mail = resultEntry.mail;
  52.                 return personLDAPEntry;
  53.             }
  54.             else // Something went wrong..
  55.             {
  56.                 return null;
  57.             }
  58.         }
  59.  
  60.         // Takes an AccessNet ID (like 'tue71468')
  61.         // Returns a TempleLDAPEntry object
  62.         public static TempleLDAPEntry getLDAPEntryByAccessnet(string accessnetID)
  63.         {
  64.             // Create the WebService proxy, send the search request and receive the TempleLDAPEntry object
  65.             WS_LDAPSearch.LDAP_Search ldapProxy = new WS_LDAPSearch.LDAP_Search();
  66.             WS_LDAPSearch.TempleLDAPEntry[] results = new WS_LDAPSearch.TempleLDAPEntry[1];
  67.             results = ldapProxy.Search(webServiceUsername, webServicePassword, "uid", accessnetID);
  68.             WS_LDAPSearch.TempleLDAPEntry resultEntry = results[0];
  69.  
  70.             // Check if request was successful
  71.             if (resultEntry.result == null) // Success
  72.             {
  73.                 // Create our TempleLDAPEntry object to be returned
  74.                 TempleLDAPEntry personLDAPEntry = new TempleLDAPEntry();
  75.                 personLDAPEntry.templeEduID = resultEntry.templeEduTUID;
  76.                 personLDAPEntry.uID = resultEntry.uid;
  77.                 personLDAPEntry.cn = resultEntry.cn;
  78.                 personLDAPEntry.givenName = resultEntry.givenName;
  79.                 personLDAPEntry.sn = resultEntry.sn;
  80.                 personLDAPEntry.eduPersonAffiliation = resultEntry.eduPersonAffiliation;
  81.                 personLDAPEntry.eduPersonPrimaryAffiliation = resultEntry.eduPersonPrimaryAffiliation;
  82.                 personLDAPEntry.mail = resultEntry.mail;
  83.                 return personLDAPEntry;
  84.             }
  85.             else // Something went wrong..
  86.             {
  87.                 return null;
  88.             }
  89.         }
  90.  
  91.         // Takes nothing
  92.         // Returns a term object that contains all term data
  93.         // Returns null if an error occurred
  94.         public static Term getCurrentTerm()
  95.         {
  96.             WS_StudentSearch.WS_Student studentProxy = new WS_StudentSearch.WS_Student();
  97.             WS_StudentSearch.Result results = new WS_StudentSearch.Result();
  98.             results = studentProxy.GetCurrentTerm(webServiceUsername, webServicePassword);
  99.  
  100.             // Check if request was successful
  101.             if (results.Status == "OK") // Success
  102.             {
  103.                 Term returnTerm = new Term();
  104.                 WS_StudentSearch.Term[] t = results.Terms;
  105.                 returnTerm.termCode = t[0].code;
  106.                 returnTerm.termName = t[0].name;
  107.                 returnTerm.startDate = t[0].startDate;
  108.                 returnTerm.endDate = t[0].endDate;
  109.  
  110.                 return returnTerm;
  111.             }
  112.             else // Something went wrong...
  113.             {
  114.                 return null;
  115.  
  116.             }
  117.         }
  118.  
  119.         // Takes a term code (4 digit year followed by 2 digit week)
  120.         // Returns a term object that contains all term data
  121.         public static Term getTermByTermCode(string termCode)
  122.         {
  123.             WS_StudentSearch.WS_Student studentProxy = new WS_StudentSearch.WS_Student();
  124.             WS_StudentSearch.Result results = new WS_StudentSearch.Result();
  125.             results = studentProxy.GetTermByTermCode(webServiceUsername, webServicePassword, termCode);
  126.  
  127.             // Check if request was successful
  128.             if (results.Status == "OK") // Success
  129.             {
  130.                 Term returnTerm = new Term();
  131.                 WS_StudentSearch.Term[] t = results.Terms;
  132.                 returnTerm.termCode = t[0].code;
  133.                 returnTerm.termName = t[0].name;
  134.                 returnTerm.startDate = t[0].startDate;
  135.                 returnTerm.endDate = t[0].endDate;
  136.  
  137.                 return returnTerm;
  138.             }
  139.             else // Something went wrong...
  140.             {
  141.                 return null;
  142.  
  143.             }
  144.         }
  145.  
  146.         // Takes a date (can be MM/DD/YYYY, YYYY/MM/DD, MM/DD/YY)
  147.         // Returns a term object that contains all term data
  148.         public static Term GetTermByDate(string date)
  149.         {
  150.             WS_StudentSearch.WS_Student studentProxy = new WS_StudentSearch.WS_Student();
  151.             WS_StudentSearch.Result results = new WS_StudentSearch.Result();
  152.             results = studentProxy.GetTermByDate(webServiceUsername, webServicePassword, date);
  153.  
  154.             // Check if request was successful
  155.             if (results.Status == "OK") // Success
  156.             {
  157.                 Term returnTerm = new Term();
  158.                 WS_StudentSearch.Term[] t = results.Terms;
  159.                 returnTerm.termCode = t[0].code;
  160.                 returnTerm.termName = t[0].name;
  161.                 returnTerm.startDate = t[0].startDate;
  162.                 returnTerm.endDate = t[0].endDate;
  163.  
  164.                 return returnTerm;
  165.             }
  166.             else // Something went wrong...
  167.             {
  168.                 return null;
  169.  
  170.             }
  171.         }
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement