public static MapRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ContextFacade contextFacade, IList<ContextFacade> contexts, Format format, RestControlFlags flags, MediaTypeHeaderValue mt) {
            var memberValues = contexts.Select(c => new OptionalProperty(c.Id, GetMap(oidStrategy, req, c, flags))).ToList();
            IObjectFacade target = contexts.First().Target;
            MapRepresentation mapRepresentation;

            if (format == Format.Full) {
                var tempProperties = new List<OptionalProperty>();

                if (!string.IsNullOrEmpty(contextFacade?.Reason)) {
                    tempProperties.Add(new OptionalProperty(JsonPropertyNames.XRoInvalidReason, contextFacade.Reason));
                }

                var dt = new OptionalProperty(JsonPropertyNames.DomainType, target.Specification.DomainTypeName(oidStrategy));
                tempProperties.Add(dt);

                var members = new OptionalProperty(JsonPropertyNames.Members, Create(memberValues.ToArray()));
                tempProperties.Add(members);
                mapRepresentation = Create(tempProperties.ToArray());
            }
            else {
                mapRepresentation = Create(memberValues.ToArray());
            }

            mapRepresentation.SetContentType(mt);

            return mapRepresentation;
        }
コード例 #2
0
        public static MapRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ContextFacade context, Format format, RestControlFlags flags, MediaTypeHeaderValue mt) {
            var objectContext = context as ObjectContextFacade;
            var actionResultContext = context as ActionResultContextFacade;
            MapRepresentation mapRepresentation;


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

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


            mapRepresentation.SetContentType(mt);


            return mapRepresentation;
        }
コード例 #3
0
 private static MapRepresentation CreateMap(ContextFacade 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());
 }
コード例 #4
0
        private static MapRepresentation GetMap(IOidStrategy oidStrategy, HttpRequestMessage req, ContextFacade context, RestControlFlags flags) {
            MapRepresentation value;

            // All reasons why we cannot create a linkrep
            if (context.Specification.IsParseable ||
                context.Specification.IsCollection ||
                context.ProposedValue == null ||
                context.ProposedObjectFacade == null ||
                context.ProposedObjectFacade.Specification.IsParseable) {
                value = CreateMap(context, context.ProposedValue);
            }
            else {
                value = CreateMap(context, RefValueRepresentation.Create(oidStrategy ,new ObjectRelType(RelValues.Self, new UriMtHelper(oidStrategy ,req, context.ProposedObjectFacade)), flags));
            }
            return value;
        }
        private static MapRepresentation GetMap(IOidStrategy oidStrategy, HttpRequestMessage req, ContextFacade context, RestControlFlags flags) {
            MapRepresentation value;

            // All reasons why we cannot create a linkrep
            if (context.Specification.IsCollection && context.ElementSpecification != null && !context.ElementSpecification.IsParseable) {
                var proposedObjectFacade = oidStrategy.FrameworkFacade.GetObject(context.ProposedValue);
                var coll = proposedObjectFacade.ToEnumerable().Select(no => CreateObjectRef(oidStrategy, req, no, flags)).ToArray();
                value = CreateMap(context, coll);
            }
            else if (context.Specification.IsParseable ||
                     context.ProposedValue == null ||
                     context.ProposedObjectFacade == null ||
                     context.ProposedObjectFacade.Specification.IsParseable) {
                value = CreateMap(context, context.ProposedValue);
            }
            else {
                value = CreateMap(context, RefValueRepresentation.Create(oidStrategy, new ObjectRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, context.ProposedObjectFacade)), flags));
            }
            return value;
        }
コード例 #6
0
 protected WithContextNOSException(string message, ContextFacade context)
     : base(message) {
     ContextFacade = context;
 }
コード例 #7
0
 private RestSnapshot(IOidStrategy oidStrategy, ContextFacade context, HttpRequestMessage req, bool validateAsJson)
     : this(oidStrategy, req, validateAsJson) {
     CheckForRedirection(oidStrategy, context, req);
 }
コード例 #8
0
        private static void CheckForRedirection(IOidStrategy oidStrategy, ContextFacade context, HttpRequestMessage req) {
            var ocs = context as ObjectContextFacade;
            var arcs = context as ActionResultContextFacade;
            Tuple<string, string> redirected = (ocs != null ? ocs.Redirected : null) ?? (arcs?.Result != null ? arcs.Result.Redirected : null);

            if (redirected != null) {
                Uri redirectAddress = new UriMtHelper(oidStrategy, req).GetRedirectUri(req, redirected.Item1, redirected.Item2);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MovedPermanently) {Headers = {Location = redirectAddress}});
            }
        }
コード例 #9
0
 private RestSnapshot(IOidStrategy oidStrategy, ContextFacade context, HttpRequestMessage req, bool validateAsJson)
     : this(oidStrategy, req, validateAsJson) {
     logger.DebugFormat("RestSnapshot:{0}", context.GetType().FullName);
     CheckForRedirection(oidStrategy, context, req);
 }
コード例 #10
0
 public BadArgumentsNOSException(string message, ContextFacade context)
     : base(message, context) {}
 protected WithContextNOSException(string message, ContextFacade context, IList<ContextFacade> contexts) : this(message) {
     Contexts = contexts;
     ContextFacade = context;
 }
 protected WithContextNOSException(string message, ContextFacade context) : this(message, context, null) {}
コード例 #13
0
 public BadRequestNOSException(string message, ContextFacade context) : base(message, context) {}
コード例 #14
0
 public BadArgumentsNOSException(string message, ContextFacade context, IList<ContextFacade> contexts)
    : base(message, context, contexts) { }