- Timestamp:
- Aug 12, 2015, 6:10:28 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/Handlers/ApiHandler.cs
r247 r250 4 4 using System.IO; 5 5 using System.Net; 6 using System.Reflection; 6 7 using System.Threading; 7 8 … … 14 15 public ApiHandler (string staticPart, string moduleName = null) : base(moduleName) { 15 16 this.staticPart = staticPart; 16 addApi ("getlandclaims", new GetLandClaims ()); 17 addApi ("getplayersonline", new GetPlayersOnline ()); 18 addApi ("getplayerslocation", new GetPlayersLocation ()); 19 addApi ("getplayerinventory", new GetPlayerInventory ()); 20 addApi ("getstats", new GetStats ()); 17 18 foreach (Type t in Assembly.GetExecutingAssembly ().GetTypes ()) { 19 if (!t.IsAbstract && t.IsSubclassOf (typeof(WebAPI))) { 20 ConstructorInfo ctor = t.GetConstructor (new Type[0]); 21 if (ctor != null) { 22 WebAPI apiInstance = (WebAPI)ctor.Invoke (new object[0]); 23 addApi (t.Name.ToLower (), apiInstance); 24 } 25 } 26 } 21 27 } 22 28 … … 38 44 } else { 39 45 foreach (KeyValuePair<string, WebAPI> kvp in apis) { 40 try{41 if (apiName.StartsWith (kvp.Key)){46 if (apiName.StartsWith (kvp.Key)) { 47 try { 42 48 kvp.Value.HandleRequest (req, resp, user, permissionLevel); 43 49 return; 50 } catch (Exception e) { 51 Log.Error ("Error in ApiHandler.HandleRequest(): Handler {0} threw an exception:", kvp.Key); 52 Log.Exception (e); 53 resp.StatusCode = (int)HttpStatusCode.InternalServerError; 54 return; 44 55 } 45 } catch (Exception e) {46 Log.Out ("Error in ApiHandler.HandleRequest(): Handler threw an exception: " + e);47 resp.StatusCode = (int)HttpStatusCode.InternalServerError;48 return;49 56 } 50 57 }
Note:
See TracChangeset
for help on using the changeset viewer.