示例#1
0
        public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
        {
            MediaTypeHeaderValue mediaType = UriMtHelper.GetJsonMediaType(RepresentationTypes.List);

            Helper.AddListRepresentationParameter(mediaType, flags);
            return(mediaType);
        }
        public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
        {
            var mediaType = UriMtHelper.GetJsonMediaType(UriMtHelper.GetObjectMediaType());

            Helper.AddObjectRepresentationParameter(mediaType, flags);
            return(mediaType);
        }
        private void ValidateOutgoingJsonMediaType()
        {
            var contentType        = Representation.GetContentType();
            var headers            = requestMessage.GetTypedHeaders();
            var incomingParameters = headers.Accept.SelectMany(a => a.Parameters).ToList();

            var incomingProfiles = incomingParameters.Where(nv => nv.Name.ToString() == "profile").Select(nv => nv.Value).Distinct().ToArray();
            var outgoingProfiles = contentType != null?contentType.Parameters.Where(nv => nv.Name == "profile").Select(nv => nv.Value).Distinct().ToArray() : new StringSegment[]
            {
            };

            if (incomingProfiles.Any() && outgoingProfiles.Any() && !outgoingProfiles.Intersect(incomingProfiles).Any())
            {
                if (outgoingProfiles.Contains(UriMtHelper.GetJsonMediaType(RepresentationTypes.Error).Parameters.First().Value))
                {
                    // outgoing error so even though incoming profiles does not include error representation return error anyway but with 406 code
                    HttpStatusCode = HttpStatusCode.NotAcceptable;
                }
                else
                {
                    var msg = DebugFilter(() => $"Failed outgoing json MT validation ic: {string.Join(',', incomingProfiles.ToArray())} og: {string.Join(',', outgoingProfiles.ToArray())}");

                    // outgoing profile not included in incoming profiles and not already an error so throw a 406
                    throw new ValidationException((int)HttpStatusCode.NotAcceptable, msg);
                }
            }
        }
        private void ValidateOutgoingJsonMediaType()
        {
            var contentType = Representation.GetContentType();
            List <NameValueHeaderValue> incomingParameters = requestMessage.Headers.Accept.SelectMany(a => a.Parameters).ToList();

            string[] incomingProfiles = incomingParameters.Where(nv => nv.Name == "profile").Select(nv => nv.Value).Distinct().ToArray();
            string[] outgoingProfiles = contentType != null?contentType.Parameters.Where(nv => nv.Name == "profile").Select(nv => nv.Value).Distinct().ToArray() : new string[]
            {
            };

            if (incomingProfiles.Any() && outgoingProfiles.Any() && !outgoingProfiles.Intersect(incomingProfiles).Any())
            {
                if (outgoingProfiles.Contains(UriMtHelper.GetJsonMediaType(RepresentationTypes.Error).Parameters.First().Value))
                {
                    // outgoing error so even though incoming profiles does not include error representation return error anyway but with 406 code
                    HttpStatusCode = HttpStatusCode.NotAcceptable;
                }
                else
                {
                    // outgoing profile not included in incoming profiles and not already an error so throw a 406
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable));
                }
            }
        }
 public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
 {
     return(UriMtHelper.GetJsonMediaType(Helper.GetInvokeMediaType()));
 }
 public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
 {
     return(UriMtHelper.GetJsonMediaType(RepresentationTypes.User));
 }
 public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) => UriMtHelper.GetJsonMediaType(RepresentationTypes.CollectionValue);
示例#8
0
        public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
        {
            MediaTypeHeaderValue mediaType = UriMtHelper.GetJsonMediaType(RepresentationTypes.Prompt);

            return(mediaType);
        }
        private void MapToRepresentation(Exception e, HttpRequestMessage req)
        {
            if (e is WithContextNOSException)
            {
                ArgumentsRepresentation.Format format = e is BadPersistArgumentsException ? ArgumentsRepresentation.Format.Full : ArgumentsRepresentation.Format.MembersOnly;
                RestControlFlags flags = e is BadPersistArgumentsException ? ((BadPersistArgumentsException)e).Flags : RestControlFlags.DefaultFlags();

                var contextNosException = e as WithContextNOSException;

                if (contextNosException.Contexts.Any(c => c.ErrorCause == Cause.Disabled || c.ErrorCause == Cause.Immutable))
                {
                    Representation = NullRepresentation.Create();
                }
                else if (e is BadPersistArgumentsException && contextNosException.ContextFacade != null && contextNosException.Contexts.Any())
                {
                    Representation = ArgumentsRepresentation.Create(oidStrategy, req, contextNosException.ContextFacade, contextNosException.Contexts, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else if (contextNosException.ContextFacade != null)
                {
                    Representation = ArgumentsRepresentation.Create(oidStrategy, req, contextNosException.ContextFacade, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else if (contextNosException.Contexts.Any())
                {
                    Representation = ArgumentsRepresentation.Create(oidStrategy, req, contextNosException.Contexts, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else
                {
                    Representation = NullRepresentation.Create();
                }
            }
            else if (e is ResourceNotFoundNOSException ||
                     e is NotAllowedNOSException ||
                     e is PreconditionFailedNOSException ||
                     e is PreconditionMissingNOSException ||
                     e is NoContentNOSException)
            {
                Representation = NullRepresentation.Create();
            }
            else
            {
                Representation = ErrorRepresentation.Create(oidStrategy, e);
            }
        }
 WithContextNOSException wce when wce.Contexts.Any() => ArgumentsRepresentation.Create(oidStrategy, frameworkFacade, req, wce.Contexts, ArgumentsRepresentation.Format.MembersOnly, RestControlFlags.DefaultFlags(), UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments)),
示例#11
0
 public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) => UriMtHelper.GetJsonMediaType(UriMtHelper.GetMenuMediaType());