Esempio n. 1
0
        internal static TResponse PostHandle <TResponse>(this TResponse response, IOperation operation) where TResponse : ICamundaResponse
        {
            if (!response.IsWithoutErrors())
            {
                throw CommonExceptions.CamundaRequestCanNotBeSent(operation, response.Status, response.Reason, response.Output);
            }

            var settings = new JsonSerializerSettings
            {
                ContractResolver  = new CamundaResponseJsonResolver(),
                NullValueHandling = NullValueHandling.Ignore
            };

            var intermediateResponse = JsonConvert.DeserializeObject <IntermediateCamundaResponse <object> >(response.Output, settings);

            if (intermediateResponse.IsWithoutErrors())
            {
                var property = response.GetType().GetProperty(nameof(IntermediateCamundaResponse <object> .Response));
                var value    = JsonConvert.DeserializeObject(intermediateResponse.Output, property.PropertyType, settings);
                property.SetPropertyValue(response, value);
            }
            else
            {
                response.Errors = JsonConvert.DeserializeObject(intermediateResponse.Output, settings);
            }

            response.Status = intermediateResponse.Status;
            response.Output = intermediateResponse.Output;
            response.Reason = intermediateResponse.Reason;

            return(response);
        }