コード例 #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;
        }
コード例 #2
1
        public static MapRepresentation Create(HttpRequestMessage req, IList<ContextSurface> contexts, Format format, RestControlFlags flags, MediaTypeHeaderValue mt) {
            OptionalProperty[] memberValues = contexts.Select(c => new OptionalProperty(c.Id, GetMap(req, c, flags))).ToArray();
            INakedObjectSurface target = contexts.First().Target;
            MapRepresentation mapRepresentation;

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

                if (flags.SimpleDomainModel) {
                    var dt = new OptionalProperty(JsonPropertyNames.DomainType, target.Specification.DomainTypeName());
                    tempProperties.Add(dt);
                }

                if (flags.FormalDomainModel) {
                    var links = new OptionalProperty(JsonPropertyNames.Links, new[] {
                        Create(new OptionalProperty(JsonPropertyNames.Rel, RelValues.DescribedBy),
                               new OptionalProperty(JsonPropertyNames.Href, new UriMtHelper(req, target.Specification).GetDomainTypeUri()))
                    });
                    tempProperties.Add(links);
                }

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

            mapRepresentation.SetContentType(mt);

            return mapRepresentation;
        }
コード例 #3
0
 protected ParameterTypeRepresentation(HttpRequestMessage req, ParameterTypeContextSurface parameterTypeContext, RestControlFlags flags) : base(flags) {
     SetScalars(parameterTypeContext);
     SelfRelType = new ParamTypeRelType(RelValues.Self, new UriMtHelper(req, parameterTypeContext));
     SetLinks(req, parameterTypeContext);
     SetExtensions();
     SetHeader();
 }
コード例 #4
0
 private UserRepresentation(HttpRequestMessage req, IPrincipal user, RestControlFlags flags) : base(flags) {
     SelfRelType = new UserRelType(RelValues.Self, new UriMtHelper(req));
     SetLinks(new HomePageRelType(RelValues.Up, new UriMtHelper(req)));
     SetScalars(user);
     SetExtensions();
     SetHeader();
 }
コード例 #5
0
 protected MemberTypeRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyTypeContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy, flags) {
     SetScalars(propertyContext);
     SelfRelType = new TypeMemberRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, propertyContext));
     SetExtensions();
     SetHeader();
 }
コード例 #6
0
 public ActionRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext, RestControlFlags flags)
     : base(oidStrategy, flags) {
     this.req = req;
     this.actionContext = actionContext;
     self = new MemberRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, actionContext));
     parameterList = GetParameterList();
 }
コード例 #7
0
 public RestSnapshot(IOidStrategy oidStrategy, ActionResultContextFacade actionResultContext, HttpRequestMessage req, RestControlFlags flags)
     : this(oidStrategy,actionResultContext, req, true) {
     populator = () => {
         representation = ActionResultRepresentation.Create(oidStrategy ,req, actionResultContext, flags);
         SetHeaders();
     };
 }
コード例 #8
0
 public AttachmentRepresentation(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags)
     : base(flags) {
     SetContentType(propertyContext);
     SetContentDisposition(propertyContext);
     SetStream(propertyContext);
     SetHeader(propertyContext.Target);
 }
コード例 #9
0
 protected ActionResultRepresentation(HttpRequestMessage req, ActionResultContextSurface actionResult, RestControlFlags flags) : base(flags) {
     SelfRelType = new ActionResultRelType(RelValues.Self, new UriMtHelper(req, actionResult.ActionContext));
     SetResultType(actionResult);
     SetLinks(req, actionResult);
     SetExtensions();
     SetHeader();
 }
コード例 #10
0
 public static InlinePropertyRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList<OptionalProperty> optionals, RestControlFlags flags) {
     if (!RestUtils.IsBlobOrClob(propertyContext.Specification) && !RestUtils.IsAttachment(propertyContext.Specification)) {
         optionals.Add(new OptionalProperty(JsonPropertyNames.Value, GetPropertyValue(oidStrategy ,req, propertyContext.Property, propertyContext.Target, flags)));
     }
     RestUtils.AddChoices(oidStrategy , req, propertyContext, optionals, flags);
     return CreateWithOptionals<InlinePropertyRepresentation>(new object[] {oidStrategy, new PropertyRepresentationStrategy(oidStrategy ,req, propertyContext, flags)}, optionals);
 }
コード例 #11
0
 protected MemberRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy ,flags) {
     this.req = req;
     this.propertyContext = propertyContext;
     objectUri = new UriMtHelper(oidStrategy ,req, propertyContext);
     self = new MemberRelType(RelValues.Self, new UriMtHelper(oidStrategy , req, propertyContext));
 }
コード例 #12
0
 protected TypeActionInvokeRepresentation(HttpRequestMessage req, TypeActionInvokeContext context, RestControlFlags flags) : base(flags) {
     SelfRelType = new TypeActionInvokeRelType(RelValues.Self, new UriMtHelper(req, context));
     SetScalars(context);
     SetLinks(req, context);
     SetExtensions();
     SetHeader();
 }
コード例 #13
0
 protected ParameterRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, IActionParameterFacade parameter, RestControlFlags flags)
     : base(oidStrategy, flags) {
     SetName(parameter);
     SetExtensions(req, objectFacade, parameter, flags);
     SetLinks(req, objectFacade, parameter);
     SetHeader(objectFacade);
 }
コード例 #14
0
 protected HomePageRepresentation(HttpRequestMessage req, RestControlFlags flags) : base(flags) {
     Log.DebugFormat("HomePageRepresentation");
     SelfRelType = new HomePageRelType(RelValues.Self, new UriMtHelper(req));
     SetLinks(req);
     SetExtensions();
     SetHeader();
 }
コード例 #15
0
 public static InlineCollectionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList<OptionalProperty> optionals, RestControlFlags flags) {
     var collectionRepresentationStrategy = new CollectionRepresentationStrategy(oidStrategy, req, propertyContext, flags);
     if (optionals.Count == 0) {
         return new InlineCollectionRepresentation(oidStrategy, collectionRepresentationStrategy);
     }
     return CreateWithOptionals<InlineCollectionRepresentation>(new object[] {oidStrategy, collectionRepresentationStrategy}, optionals);
 }
コード例 #16
0
 public RestSnapshot(ActionResultContextSurface actionResultContext, HttpRequestMessage req, RestControlFlags flags)
     : this(actionResultContext, req, true) {
     populator = () => {
         representation = ActionResultRepresentation.Create(req, actionResultContext, flags);
         SetHeaders();
     };
 }
コード例 #17
0
 public static CollectionRepresentation Create(HttpRequestMessage req, PropertyContextSurface propertyContext, IList<OptionalProperty> optionals, RestControlFlags flags) {
     var collectionRepresentationStrategy = new CollectionRepresentationStrategy(req, propertyContext, flags);
     if (optionals.Count == 0) {
         return new CollectionRepresentation(collectionRepresentationStrategy);
     }
     return CreateWithOptionals<CollectionRepresentation>(new object[] {collectionRepresentationStrategy}, optionals);
 }
コード例 #18
0
 public RestSnapshot(ParameterContextSurface parmContext, ListContextSurface listContext, HttpRequestMessage req, RestControlFlags flags)
     : this(req, true) {
     logger.DebugFormat("RestSnapshot:parameterprompt");
     populator = () => {
         representation = PromptRepresentation.Create(parmContext, listContext, req, flags);
         SetHeaders();
     };
 }
コード例 #19
0
 private ListRepresentation(IOidStrategy oidStrategy, ITypeFacade[] specs, HttpRequestMessage req, RestControlFlags flags)
     : base(oidStrategy, flags) {
     Value = specs.Select(s => CreateDomainLink(oidStrategy, req, s)).ToArray();
     SelfRelType = new TypesRelType(RelValues.Self, new UriMtHelper(oidStrategy, req));
     SetLinks(req);
     SetExtensions();
     SetHeader(true);
 }
コード例 #20
0
 private VersionRepresentation(HttpRequestMessage req, IDictionary<string, string> capabilitiesMap, RestControlFlags flags) : base(flags) {
     SelfRelType = new VersionRelType(RelValues.Self, new UriMtHelper(req));
     SetScalars();
     SetLinks(new HomePageRelType(RelValues.Up, new UriMtHelper(req)));
     SetOptionalCapabilities(capabilitiesMap);
     SetExtensions();
     SetHeader();
 }
コード例 #21
0
 protected ListRepresentation(IOidStrategy oidStrategy, IMenuFacade[] menus, HttpRequestMessage req, RestControlFlags flags)
     : base(oidStrategy, flags) {
     Value = menus.Select(c => CreateMenuLink(oidStrategy, req, c)).ToArray();
     SelfRelType = new ListRelType(RelValues.Self, SegmentValues.Services, new UriMtHelper(oidStrategy, req));
     SetLinks(req);
     SetExtensions();
     SetHeader(true);
 }
コード例 #22
0
 public RestSnapshot(ListContextSurface listContext, HttpRequestMessage req, RestControlFlags flags)
     : this(req, true) {
     logger.DebugFormat("RestSnapshot:ServicesList");
     populator = () => {
         representation = ListRepresentation.Create(listContext, req, flags);
         SetHeaders();
     };
 }
コード例 #23
0
 protected ActionTypeRepresentation(HttpRequestMessage req, ActionTypeContextSurface actionTypeContext, RestControlFlags flags) : base(flags) {
     SelfRelType = new TypeMemberRelType(RelValues.Self, new UriMtHelper(req, actionTypeContext));
     SetScalars(actionTypeContext);
     SetLinks(req, actionTypeContext);
     SetParameters(req, actionTypeContext);
     SetExtensions();
     SetHeader();
 }
コード例 #24
0
 private ListRepresentation(INakedObjectSpecificationSurface[] specs, HttpRequestMessage req, RestControlFlags flags)
     : base(flags) {
     Value = specs.Select(s => CreateDomainLink(req, s)).ToArray();
     SelfRelType = new TypesRelType(RelValues.Self, new UriMtHelper(req));
     SetLinks(req);
     SetExtensions();
     SetHeader(true);
 }
コード例 #25
0
 protected ActionResultRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, ActionResultContextFacade actionResult, RestControlFlags flags)
     : base(oidStrategy, flags) {
     SelfRelType = new ActionResultRelType(RelValues.Self, new UriMtHelper(OidStrategy, req, actionResult.ActionContext));
     SetResultType(actionResult);
     SetLinks(req, actionResult);
     SetExtensions();
     SetHeader();
 }
コード例 #26
0
 protected ListRepresentation(ListContextSurface listContext, HttpRequestMessage req, RestControlFlags flags)
     : base(flags) {
     Value = listContext.List.Select(c => CreateObjectLink(req, c)).ToArray();
     SelfRelType = new ListRelType(RelValues.Self, SegmentValues.Services, new UriMtHelper(req, listContext.ElementType));
     SetLinks(req);
     SetExtensions();
     SetHeader(listContext.IsListOfServices);
 }
コード例 #27
0
 public RestSnapshot(IOidStrategy oidStrategy, PropertyContextFacade propertyContext, ListContextFacade listContext, HttpRequestMessage req, RestControlFlags flags)
     : this(oidStrategy,req, true) {
     logger.DebugFormat("RestSnapshot:propertyprompt");
     populator = () => {
         representation = PromptRepresentation.Create(oidStrategy ,propertyContext, listContext, req, flags);
         SetHeaders();
     };
 }
コード例 #28
0
 public RestSnapshot(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags, HttpStatusCode httpStatusCode = HttpStatusCode.OK)
     : this(oidStrategy,objectContext, req, true) {
     populator = () => {
         this.httpStatusCode = httpStatusCode;
         representation = ObjectRepresentation.Create(oidStrategy, objectContext, req, flags);
         SetHeaders();
     };
 }
コード例 #29
0
 protected FilterFromInvokeRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, FilterFromInvokeContext context, RestControlFlags flags)
     : base(oidStrategy, flags) {
     SelfRelType = new TypeActionFilterInvokeRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, context));
     SetScalar(context);
     SetValue(req, context);
     SetLinks(req, context);
     SetExtensions();
     SetHeader();
 }
コード例 #30
0
 protected ObjectRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, ObjectContextFacade objectContext, RestControlFlags flags)
     : base(oidStrategy, flags) {
     var objectUri = new UriMtHelper(oidStrategy ,req, objectContext.Target);
     SetScalars(objectContext);
     SelfRelType = objectContext.Specification.IsService ? new ServiceRelType(RelValues.Self, objectUri) : new ObjectRelType(RelValues.Self, objectUri);
     SetLinksAndMembers(req, objectContext);
     SetExtensions(objectContext.Target);
     SetHeader(objectContext);
 }
コード例 #31
0
 public abstract MediaTypeHeaderValue GetMediaType(RestControlFlags flags);
コード例 #32
0
 public static void AddChoices(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags)
 {
     if (propertyContext.Property.IsChoicesEnabled != Choices.NotEnabled && !propertyContext.Property.GetChoicesParameters().Any())
     {
         IObjectFacade[] choices      = propertyContext.Property.GetChoices(propertyContext.Target, null);
         object[]        choicesArray = choices.Select(c => GetChoiceValue(oidStrategy, req, c, propertyContext.Property, flags)).ToArray();
         optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
     }
 }
コード例 #33
0
        public static object GetChoiceValue(IOidStrategy oidStrategy, IObjectFacade item, ChoiceRelType relType, RestControlFlags flags)
        {
            string title = SafeGetTitle(item);
            object value = ObjectToPredefinedType(item.GetDomainObject());

            return(item.Specification.IsParseable ? value : LinkRepresentation.Create(oidStrategy, relType, flags, new OptionalProperty(JsonPropertyNames.Title, title)));
        }
コード例 #34
0
 public static object GetChoiceValue(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade item, IActionParameterFacade parameter, RestControlFlags flags)
 {
     return(GetChoiceValue(oidStrategy, item, new ChoiceRelType(parameter, new UriMtHelper(oidStrategy, req, item)), flags));
 }
コード例 #35
0
        public static OptionalProperty CreateArgumentProperty(IOidStrategy oidStrategy, HttpRequestMessage req, Tuple <string, ITypeFacade> pnt, RestControlFlags flags)
        {
            var tempLinks = new List <LinkRepresentation>();

            if (flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(oidStrategy, new DomainTypeRelType(RelValues.DescribedBy, new UriMtHelper(oidStrategy, req, pnt.Item2)), flags));
            }

            return(new OptionalProperty(pnt.Item1, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object)),
                                                                            new OptionalProperty(JsonPropertyNames.Links, tempLinks.ToArray()))));
        }
コード例 #36
0
 public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
 {
     return(helper.GetIconMediaType());
 }
コード例 #37
0
 public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
 {
     return(UriMtHelper.GetJsonMediaType(RepresentationTypes.Version));
 }
コード例 #38
0
 public void AddObjectCollectionRepresentationParameter(MediaTypeHeaderValue mediaType, RestControlFlags flags)
 {
     if (assoc != null && assoc.IsCollection())
     {
         string parameterValue = GetParameterValue(flags, assoc.ElementSpecification);
         if (parameterValue != null)
         {
             mediaType.Parameters.Add(new NameValueHeaderValue(RestControlFlags.ElementTypeReserved, string.Format("\"{0}\"", parameterValue)));
         }
     }
 }
コード例 #39
0
        public void AddActionResultRepresentationParameter(MediaTypeHeaderValue mediaType, RestControlFlags flags)
        {
            INakedObjectSpecificationSurface resultSpec = action.ReturnType;
            bool isCollection = resultSpec.IsCollection() && !resultSpec.IsParseable();
            INakedObjectSpecificationSurface parameterValueSpec = isCollection ? action.ElementType : resultSpec;
            string parameterValue = GetParameterValue(flags, parameterValueSpec);

            if (parameterValue != null)
            {
                string parameterType = isCollection ? RestControlFlags.ElementTypeReserved : RestControlFlags.DomainTypeReserved;
                mediaType.Parameters.Add(new NameValueHeaderValue(parameterType, string.Format("\"{0}\"", parameterValue)));
            }
        }