Exemplo n.º 1
0
        public static bool GetDTOFromRequest(HttpRequest request, out APIRequestDTO requestDTO, string typeFullName, ref string errorMessage)
        {
            string postBody;

            requestDTO = null;

            try
            {
                //get the entire post body
                if (!GetPostBodyFromRequest(request, out postBody, ref errorMessage))
                {
                    return(false);
                }
                if (!GetDTOFromPostBody(postBody, out requestDTO, typeFullName, ref errorMessage))
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                errorMessage += ex.Message;
                return(false);
            }
        }
Exemplo n.º 2
0
        private bool GetUserFromRequest(HttpRequest request, out APIRequestDTO requestDTO)
        {
            string errorMessage = null;

            requestDTO = null;

            try
            {
                if (!Library.GetDTOFromRequest(request, out requestDTO, typeof(APIRequestDTO).FullName, ref errorMessage))
                {
                    Global.Log.Error(errorMessage);
                    return(false);
                }
                Global.Log.DebugFormat("User ID: [{0}] changed the scheme to [Descentralized]", requestDTO.UserID);
                return(true);
            }
            catch (Exception ex)
            {
                Global.Log.Error(ex.Message);
                return(false);
            }
        }
Exemplo n.º 3
0
        private static bool GetDTOFromPostBody(string postBody, out APIRequestDTO requestDTO, string typeFullName, ref string errorMessage)
        {
            requestDTO = null;

            try
            {
                //check the right type to deserialize
                if (String.IsNullOrEmpty(postBody))
                {
                    return(false);
                }

                if (typeof(APIRequestDTO).FullName.Equals(typeFullName))
                {
                    requestDTO = JsonConvert.DeserializeObject <APIRequestDTO>(postBody);
                    return(true);
                }
                if (typeof(CalcTaskCostRequestDTO).FullName.Equals(typeFullName))
                {
                    requestDTO = JsonConvert.DeserializeObject <CalcTaskCostRequestDTO>(postBody);
                    return(true);
                }
                if (typeof(TaskPayCreateRequestDTO).FullName.Equals(typeFullName))
                {
                    requestDTO = JsonConvert.DeserializeObject <TaskPayCreateRequestDTO>(postBody);
                    return(true);
                }
                if (typeof(GetTopicRequestDTO).FullName.Equals(typeFullName))
                {
                    requestDTO = JsonConvert.DeserializeObject <GetTopicRequestDTO>(postBody);
                    return(true);
                }
                //the typeFullName variable is used to check the sensingtasktype
                if (typeFullName.Equals(TaskTypeEnum.InteractiveTask.ToString()))
                {
                    requestDTO = JsonConvert.DeserializeObject <InteractiveTaskReportDTO>(postBody);
                    return(true);
                }
                if (typeFullName.Equals(TaskTypeEnum.SensingTask.ToString()))
                {
                    requestDTO = JsonConvert.DeserializeObject <SensingTaskReportDTO>(postBody);
                    return(true);
                }

                if (typeof(ExecuteTaskDTO).FullName.Equals(typeFullName))
                {
                    requestDTO = JsonConvert.DeserializeObject <ExecuteTaskDTO>(postBody);
                    return(true);
                }
                if (typeof(GetMultichainAddressDTO).FullName.Equals(typeFullName))
                {
                    requestDTO = JsonConvert.DeserializeObject <GetMultichainAddressDTO>(postBody);
                    return(true);
                }
                return(false);
            }
            catch (Exception)
            {
                errorMessage = Resources.InvalidJSONFormat;
                requestDTO   = null;
                return(false);
            }
        }