/// <summary> /// Processes a request into a response. /// </summary> public ApiResponse ProcessRequest(ApiRequest request) { Initialize(request); ApiResponse response = null; try { response = new ApiResponse(AuthUser, request); bool success = ProcessCoreFunctions(request, response); if (!success) success = ProcessApplicationFunctions(request, response); if (!success) { response.Status = MethodStatus.Fail; response.ErrorMessages.Add("Method not found."); } } catch { response = new ApiResponse(null, request); response.Status = MethodStatus.Fail; response.ErrorMessages.Add("An exception has occurred."); } return response; }
/// <summary> /// Constructor /// </summary> public ApiResponse(SessionAuthUser authUser, ApiRequest request) : base(authUser) { if (request == null) throw new ArgumentNullException("request"); TrackingID = request.TrackingID; Function = request.Function; ErrorMessages = new StringList(); }
/// <summary> /// Calls the listed endpoint on this controller. /// </summary> public static ApiResponse CallApi(SessionAuthUser authUser, string function, object dataObject = null) { CommonApiController controller = BaseCallApiController.GetController<CommonApiController>(); ApiRequest request = new ApiRequest(authUser, function); request.DataObject = dataObject; IHttpActionResult actionResult = controller.ProcessRequest(request); ApiResponse response = AssertAsValid<ApiResponse>(actionResult); Assert.IsNotNull(response.DataObject); return response; }
public IHttpActionResult ProcessRequest(ApiRequest request) { if (PublicConfigurationSettings.GetApiProcessor == null) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, PublicConfigurationSettings.CONFIG_ERROR)); } ApiProcessor processor = PublicConfigurationSettings.GetApiProcessor.Invoke(); ApiResponse response = processor.ProcessRequest(request); if (response == null) { return NotFound(); } return Ok(response); }
/// <summary> /// Processes any core functions. /// </summary> private bool ProcessCoreFunctions(ApiRequest request, ApiResponse response) { if (request.Function.Equals(CoreFunctions.AddressGetClientAddresses)) { response.DataObject = PublicLogicManager.Address.GetClientAddresses(); return true; } return false; }
private void Initialize(ApiRequest request) { AuthManager authManager = PublicConfigurationSettings.GetAuthManager(); AuthUser = authManager.GetAuthUser(request.UserIdentifier); InitializeSpecificItems(); }
/// <summary> /// Processes application specific functions. /// </summary> protected abstract bool ProcessApplicationFunctions(ApiRequest request, ApiResponse response);