Beispiel #1
1
        public static MapRepresentation Create(HttpRequestMessage req, ContextSurface context, Format format, RestControlFlags flags, MediaTypeHeaderValue mt) {
            var objectContextSurface = context as ObjectContextSurface;
            var actionResultContextSurface = context as ActionResultContextSurface;
            MapRepresentation mapRepresentation;


            if (objectContextSurface != null) {
                List<OptionalProperty> optionalProperties = objectContextSurface.VisibleProperties.Where(p => p.Reason != null || p.ProposedValue != null).Select(c => new OptionalProperty(c.Id, GetMap(req, c, flags))).ToList();
                if (!string.IsNullOrEmpty(objectContextSurface.Reason)) {
                    optionalProperties.Add(new OptionalProperty(JsonPropertyNames.XRoInvalidReason, objectContextSurface.Reason));
                }
                mapRepresentation = Create(optionalProperties.ToArray());
            }
            else if (actionResultContextSurface != null) {
                List<OptionalProperty> optionalProperties = actionResultContextSurface.ActionContext.VisibleParameters.Select(c => new OptionalProperty(c.Id, GetMap(req, c, flags))).ToList();

                if (!string.IsNullOrEmpty(actionResultContextSurface.Reason)) {
                    optionalProperties.Add(new OptionalProperty(JsonPropertyNames.XRoInvalidReason, actionResultContextSurface.Reason));
                }
                mapRepresentation = Create(optionalProperties.ToArray());
            }
            else {
                mapRepresentation = GetMap(req, context, flags);
            }


            mapRepresentation.SetContentType(mt);


            return mapRepresentation;
        }
Beispiel #2
0
 private static MapRepresentation CreateMap(ContextSurface context, object obj) {
     var opts = new List<OptionalProperty> {new OptionalProperty(JsonPropertyNames.Value, obj)};
     if (!string.IsNullOrEmpty(context.Reason)) {
         opts.Add(new OptionalProperty(JsonPropertyNames.InvalidReason, context.Reason));
     }
     return Create(opts.ToArray());
 }
Beispiel #3
0
        private static MapRepresentation GetMap(HttpRequestMessage req, ContextSurface context, RestControlFlags flags) {
            MapRepresentation value;

            // All reasons why we cannot create a linkrep
            if (context.Specification.IsParseable() ||
                context.Specification.IsCollection() ||
                context.ProposedValue == null ||
                context.ProposedNakedObject == null ||
                context.ProposedNakedObject.Specification.IsParseable()) {
                value = CreateMap(context, context.ProposedValue);
            }
            else {
                value = CreateMap(context, RefValueRepresentation.Create(new ObjectRelType(RelValues.Self, new UriMtHelper(req, context.ProposedNakedObject)), flags));
            }
            return value;
        }
Beispiel #4
0
 public BadArgumentsNOSException(string message, ContextSurface context)
     : base(message, context)
 {
 }
Beispiel #5
0
 protected WithContextNOSException(string message, ContextSurface context)
     : base(message) {
     ContextSurface = context;
 }
 public BadRequestNOSException(string message, ContextSurface context) : base(message, context)
 {
 }
Beispiel #7
0
 private RestSnapshot(ContextSurface context, HttpRequestMessage req, bool validateAsJson)
     : this(req, validateAsJson) {
     logger.DebugFormat("RestSnapshot:{0}", context.GetType().FullName);
     CheckForRedirection(context, req);
 }
Beispiel #8
0
        private static void CheckForRedirection(ContextSurface context, HttpRequestMessage req) {
            var ocs = context as ObjectContextSurface;
            var arcs = context as ActionResultContextSurface;
            Tuple<string, string> redirected = (ocs != null ? ocs.Redirected : null) ?? (arcs != null && arcs.Result != null ? arcs.Result.Redirected : null);

            if (redirected != null) {
                Uri redirectAddress = new UriMtHelper(req).GetRedirectUri(req, redirected.Item1, redirected.Item2);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MovedPermanently) {Headers = {Location = redirectAddress}});
            }
        }
Beispiel #9
0
 public BadRequestNOSException(string message, ContextSurface context) : base(message, context) {}
Beispiel #10
0
 public BadArgumentsNOSException(string message, ContextSurface context)
     : base(message, context) {}
Beispiel #11
0
 protected WithContextNOSException(string message, ContextSurface context)
     : base(message)
 {
     ContextSurface = context;
 }