public RestSnapshot(ObjectContextSurface objectContext, HttpRequestMessage req, RestControlFlags flags, HttpStatusCode httpStatusCode = HttpStatusCode.OK) : this(objectContext, req, true) { populator = () => { this.httpStatusCode = httpStatusCode; representation = ObjectRepresentation.Create(objectContext, req, flags); SetHeaders(); }; }
public static ObjectRepresentation Create(ObjectContextSurface objectContext, HttpRequestMessage req, RestControlFlags flags) { if (objectContext.Target != null && (objectContext.Specification.IsService() || !objectContext.Target.IsTransient())) { return(CreateObjectWithOptionals(objectContext, req, flags)); } return(new ObjectRepresentation(req, objectContext, flags)); }
public ObjectContextSurface ToObjectContextSurface(INakedObjectsSurface surface) { var oc = new ObjectContextSurface { VisibleProperties = VisibleProperties == null ? null : VisibleProperties.Select(p => p.ToPropertyContextSurface(surface)).ToArray(), VisibleActions = VisibleActions == null ? null : VisibleActions.Select(p => p.ToActionContextSurface(surface)).ToArray(), Mutated = Mutated, Redirected = Redirected }; return ToContextSurface(oc, surface); }
protected ObjectRepresentation(HttpRequestMessage req, ObjectContextSurface objectContext, RestControlFlags flags) : base(flags) { var objectUri = new UriMtHelper(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); }
private void SetLinks(HttpRequestMessage req, ObjectContextSurface objectContext) { var tempLinks = new List <LinkRepresentation>(); if (Flags.FormalDomainModel) { tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(req, objectContext.Specification)), Flags)); } Links = tempLinks.ToArray(); }
private void SetMembers(ObjectContextSurface objectContext, HttpRequestMessage req, List <LinkRepresentation> tempLinks) { PropertyContextSurface[] visiblePropertiesAndCollections = objectContext.VisibleProperties; if (!Flags.BlobsClobs) { // filter any blobs and clobs visiblePropertiesAndCollections = visiblePropertiesAndCollections.Where(vp => !RestUtils.IsBlobOrClob(vp.Specification)).ToArray(); } PropertyContextSurface[] visibleProperties = visiblePropertiesAndCollections.Where(p => !p.Property.IsCollection()).ToArray(); if (!objectContext.Target.IsTransient() && visibleProperties.Any(p => p.Property.IsUsable(objectContext.Target).IsAllowed)) { string[] ids = visibleProperties.Where(p => p.Property.IsUsable(objectContext.Target).IsAllowed&& !p.Property.IsInline()).Select(p => p.Id).ToArray(); OptionalProperty[] props = ids.Select(s => new OptionalProperty(s, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))).ToArray(); LinkRepresentation modifyLink = LinkRepresentation.Create(new ObjectRelType(RelValues.Update, new UriMtHelper(req, objectContext.Target)) { Method = RelMethod.Put }, Flags, new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(props))); tempLinks.Add(modifyLink); } if (objectContext.Target.IsTransient()) { KeyValuePair <string, object>[] ids = objectContext.Target.Specification.Properties.Where(p => !p.IsCollection() && !p.IsInline()).ToDictionary(p => p.Id, p => GetPropertyValue(req, p, objectContext.Target, Flags, true)).ToArray(); OptionalProperty[] props = ids.Select(kvp => new OptionalProperty(kvp.Key, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, kvp.Value)))).ToArray(); var argMembers = new OptionalProperty(JsonPropertyNames.Members, MapRepresentation.Create(props)); var args = new List <OptionalProperty> { argMembers }; LinkRepresentation persistLink = LinkRepresentation.Create(new ObjectsRelType(RelValues.Persist, new UriMtHelper(req, objectContext.Target.Specification)) { Method = RelMethod.Post }, Flags, new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args.ToArray()))); tempLinks.Add(persistLink); } InlineMemberAbstractRepresentation[] properties = visiblePropertiesAndCollections.Select(p => InlineMemberAbstractRepresentation.Create(req, p, Flags)).ToArray(); InlineActionRepresentation[] actions = objectContext.Target.IsTransient() ? new InlineActionRepresentation[] {} : objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(req, a, Flags)).ToArray(); IEnumerable <InlineMemberAbstractRepresentation> allMembers = properties.Union(actions); Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object)m)); }
public ObjectContextSurface ToObjectContextSurface(INakedObjectsSurface surface, INakedObjectsFramework framework) { var oc = new ObjectContextSurface { VisibleProperties = VisibleProperties == null ? null : VisibleProperties.Select(p => p.ToPropertyContextSurface(surface, framework)).ToArray(), VisibleActions = VisibleActions == null ? null : VisibleActions.Select(p => p.ToActionContextSurface(surface, framework)).ToArray(), Mutated = Mutated, Redirected = Redirected }; return(ToContextSurface(oc, surface, framework)); }
private void SetLinksAndMembers(HttpRequestMessage req, ObjectContextSurface objectContext) { var tempLinks = new List <LinkRepresentation>(); if (!objectContext.Mutated && !objectContext.Target.IsTransient()) { tempLinks.Add(LinkRepresentation.Create(SelfRelType, Flags)); } if (Flags.FormalDomainModel) { tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.DescribedBy, new UriMtHelper(req, objectContext.Specification)), Flags)); } // temp disable icons //tempLinks.Add(LinkRepresentation.Create(new IconRelType(objectUri), Flags)); SetMembers(objectContext, req, tempLinks); Links = tempLinks.ToArray(); }
protected ListRepresentation(ObjectContextSurface objectContext, HttpRequestMessage req, RestControlFlags flags, ActionContextSurface actionContext) : base(flags) { INakedObjectSurface list; if (flags.PageSize > 0 && objectContext.Target.Count() > flags.PageSize) { warnings.Add(string.Format("Result contains more than {0} objects only returning the first {0}", flags.PageSize)); list = objectContext.Target.Page(1, flags.PageSize); } else { list = objectContext.Target; } Value = list.ToEnumerable().Select(no => CreateObjectLink(req, no)).ToArray(); SetLinks(req, actionContext); SetExtensions(); SetHeader(false); }
private static ObjectRepresentation CreateObjectWithOptionals(ObjectContextSurface objectContext, HttpRequestMessage req, RestControlFlags flags) { LinkObjectId oid = OidStrategyHolder.OidStrategy.GetOid(objectContext.Target); var props = new List <OptionalProperty>(); if (objectContext.Specification.IsService()) { props.Add(new OptionalProperty(JsonPropertyNames.ServiceId, oid.DomainType)); } else { props.Add(new OptionalProperty(JsonPropertyNames.InstanceId, oid.InstanceId)); if (flags.SimpleDomainModel) { props.Add(new OptionalProperty(JsonPropertyNames.DomainType, oid.DomainType)); } } return(CreateWithOptionals <ObjectRepresentation>(new object[] { req, objectContext, flags }, props)); }
private void SetHeader(ObjectContextSurface objectContext) { caching = objectContext.Specification.IsService() ? CacheType.NonExpiring : CacheType.Transactional; SetEtag(objectContext.Target); }
private void SetScalars(ObjectContextSurface objectContext) { Title = objectContext.Target.TitleString(); }
public static ObjectRepresentation Create(INakedObjectSurface target, HttpRequestMessage req, RestControlFlags flags) { ObjectContextSurface oc = target.Surface.GetObject(target); return(Create(oc, req, flags)); }
public static ScalarRepresentation Create(ObjectContextSurface objectContext, HttpRequestMessage req, RestControlFlags flags) { return(new ScalarRepresentation(req, objectContext, flags)); }
private void SetScalars(ObjectContextSurface objectContext) { Value = RestUtils.ObjectToPredefinedType(objectContext.Target.Object); }
protected ScalarRepresentation(HttpRequestMessage req, ObjectContextSurface objectContext, RestControlFlags flags) : base(flags) { SetScalars(objectContext); SetLinks(req, objectContext); SetExtensions(); }