/// <summary> /// Calculate the cost for a crowd-sensing task. /// </summary> /// <param name="response"></param> /// <returns></returns> public bool CalcCostCSTask(out APIResponseDTO response) { IncentiveAssigned incentiveValue = null; CalcTaskCostRequestDTO csTask; CalcTaskCostResponseDTO calcCostDTO = new CalcTaskCostResponseDTO(); response = new APIResponseDTO(); try { if (!GetCSTaskToPay(out csTask)) { response.SetErrorResponse("Invalid Request please try again!", APIResponseDTO.RESULT_TYPE.ERROR); return(false); } Global.Log.DebugFormat("Client ID: {0}", csTask.UserID); if (!serverMgr.RemoteIncentiveEngine.CalcTaskCost(csTask.Task, csTask.UserID, out incentiveValue) || incentiveValue == null) { response.SetErrorResponse("Cannot calculate the task cost. Please try again!", APIResponseDTO.RESULT_TYPE.ERROR); return(false); } calcCostDTO.IncentiveToPay = incentiveValue; response.SetResponse(calcCostDTO, APIResponseDTO.RESULT_TYPE.SUCCESS); Global.Log.DebugFormat("User ID: [{0}] has to Pay [{1}]", csTask.UserID, incentiveValue.ToString()); return(true); } catch (Exception ex) { Global.Log.Error(ex.Message); response.SetResponse(new Dictionary <string, string>() { { "errorMessage", "Cannot calculate the task cost. Please try again!" } } , APIResponseDTO.RESULT_TYPE.ERROR); return(false); } }