Ejemplo n.º 1
0
        async Task <RequestReadResult> TryReadPayloadAsObject(IHttpEntity requestEntity, Func <IHttpEntity, IType, string, Task <object> > reader, IOperation operation)
        {
            Log.CodecSupportsFullObjectResolution();
            foreach (var member in operation.Inputs.Where(m => m.Binder.IsEmpty))
            {
                Log.ProcessingMember(member);
                try
                {
                    var entityInstance = await reader(requestEntity,
                                                      member.Member.Type,
                                                      member.Member.Name);

                    Log.Result(entityInstance);

                    if (entityInstance != Missing.Value)
                    {
                        if (!member.Binder.SetInstance(entityInstance))
                        {
                            Log.BinderInstanceAssignmentFailed();
                            return(RequestReadResult.BinderFailure);
                        }
                        Log.BinderInstanceAssignmentSucceeded();
                    }
                }
                catch (Exception e)
                {
                    ErrorCollector.AddServerError(CreateErrorForException(e));
                    return(RequestReadResult.CodecFailure);
                }
            }
            return(RequestReadResult.Success);
        }
        bool TryReadPayloadAsObject(IHttpEntity requestEntity, IMediaTypeReader reader, IOperation operation)
        {
            Log.CodecSupportsFullObjectResolution();
            foreach (var member in from m in operation.Inputs
                     where m.Binder.IsEmpty
                     select m)
            {
                Log.ProcessingMember(member);
                try
                {
                    var entityInstance = reader.ReadFrom(requestEntity,
                                                         member.Member.Type,
                                                         member.Member.Name);
                    Log.Result(entityInstance);

                    if (entityInstance != Missing.Value)
                    {
                        if (!member.Binder.SetInstance(entityInstance))
                        {
                            Log.BinderInstanceAssignmentFailed();
                            return(false);
                        }
                        Log.BinderInstanceAssignmentSucceeded();
                    }
                }
                catch (Exception e)
                {
                    ErrorCollector.AddServerError(CreateErrorForException(e));
                    return(false);
                }
            }
            return(true);
        }