private void SetLinks(HttpRequestMessage req, ObjectContextFacade objectContext) {
            var tempLinks = new List<LinkRepresentation>();

            if (Flags.FormalDomainModel) {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy ,new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(OidStrategy ,req, objectContext.Specification)), Flags));
            }
            Links = tempLinks.ToArray();
        }
 public RestSnapshot(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags, HttpStatusCode httpStatusCode = HttpStatusCode.OK)
     : this(oidStrategy, objectContext, req, true) {
     populator = () => {
         HttpStatusCode = httpStatusCode;
         Representation = ObjectRepresentation.Create(oidStrategy, objectContext, req, flags);
         SetHeaders();
     };
 }
 public ObjectContextFacade ToObjectContextFacade(IFrameworkFacade facade) {
     var oc = new ObjectContextFacade {
         VisibleProperties = VisibleProperties == null ? null : VisibleProperties.Select(p => p.ToPropertyContextFacade(facade)).ToArray(),
         VisibleActions = VisibleActions == null ? null : VisibleActions.Select(p => p.ToActionContextFacade(facade)).ToArray(),
         Mutated = Mutated
     };
     return ToContextFacade(oc, facade);
 }
 public ObjectContextFacade ToObjectContextFacade(IFrameworkFacade facade, INakedObjectsFramework framework) {
     var oc = new ObjectContextFacade {
         VisibleProperties = VisibleProperties == null ? null : VisibleProperties.Select(p => p.ToPropertyContextFacade(facade, framework)).ToArray(),
         VisibleActions = VisibleActions == null ? null : VisibleActions.Select(p => p.ToActionContextFacade(facade, framework)).ToArray(),
         Mutated = Mutated,
         RedirectedUrl = RedirectedUrl
     };
     return ToContextFacade(oc, facade, framework);
 }
 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);
 }
        private LinkRepresentation[] CreateIsOfTypeLinks(HttpRequestMessage req, ObjectContextFacade objectContext) {
            var spec = objectContext.Target.Specification;

            return new[] {
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSubtypeOf), Flags,
                    new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSubtypeOf),
                    new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof (object))))))),
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSupertypeOf), Flags,
                    new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSupertypeOf),
                    new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof (object)))))))
            };
        }
        private void SetLinksAndMembers(HttpRequestMessage req, ObjectContextFacade objectContext) {
            var tempLinks = new List<LinkRepresentation>();
            if (!objectContext.Mutated && !IsProtoPersistent(objectContext.Target)) {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy, SelfRelType, Flags));
            }

            // custom isSub/SupertypeOf links 

            tempLinks.AddRange(CreateIsOfTypeLinks(req, objectContext));

            SetMembers(objectContext, req, tempLinks);
            Links = tempLinks.ToArray();
        }
        private void SetLinksAndMembers(HttpRequestMessage req, ObjectContextFacade objectContext) {
            var tempLinks = new List<LinkRepresentation>();
            if (!objectContext.Mutated && !objectContext.Target.IsTransient) {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy, SelfRelType, Flags));
            }

            if (Flags.FormalDomainModel) {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy ,new DomainTypeRelType(RelValues.DescribedBy, new UriMtHelper(OidStrategy, req, objectContext.Specification)), Flags));
            }

            // temp disable icons 
            //tempLinks.Add(LinkRepresentation.Create(new IconRelType(objectUri), Flags));
            SetMembers(objectContext, req, tempLinks);
            Links = tempLinks.ToArray();
        }
        protected ListRepresentation(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags, ActionContextFacade actionContext)
            : base(oidStrategy, flags) {
            IObjectFacade 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(oidStrategy, req, no)).ToArray();

            SetLinks(req, actionContext);
            SetExtensions();
            SetHeader(false);
        }
        private void SetMembers(ObjectContextFacade objectContext, HttpRequestMessage req, List<LinkRepresentation> tempLinks) {
            PropertyContextFacade[] visiblePropertiesAndCollections = objectContext.VisibleProperties;

            if (!Flags.BlobsClobs) {
                // filter any blobs and clobs 
                visiblePropertiesAndCollections = visiblePropertiesAndCollections.Where(vp => !RestUtils.IsBlobOrClob(vp.Specification)).ToArray();
            }

            PropertyContextFacade[] 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(OidStrategy, new ObjectRelType(RelValues.Update, new UriMtHelper(OidStrategy ,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(OidStrategy ,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(OidStrategy, new ObjectsRelType(RelValues.Persist, new UriMtHelper(OidStrategy, 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(OidStrategy ,req, p, Flags)).ToArray();

            InlineActionRepresentation[] actions = objectContext.Target.IsTransient ? new InlineActionRepresentation[] {}
                : objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(OidStrategy ,req, a, Flags)).ToArray();


            IEnumerable<InlineMemberAbstractRepresentation> allMembers = properties.Union(actions);

            Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object) m));
        }
 private void SetScalars(ObjectContextFacade objectContext) {
     Value = RestUtils.ObjectToPredefinedType(objectContext.Target.Object);
 }
 protected ScalarRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, ObjectContextFacade objectContext, RestControlFlags flags)
     : base(oidStrategy, flags) {
     SetScalars(objectContext);
     SetLinks(req, objectContext);
     SetExtensions();
 }
 public BadPersistArgumentsException(string message, ObjectContextFacade context, IList<ContextFacade> contexts, RestControlFlags flags) : base(message, context, contexts) {
     Flags = flags;
 }
 private static IObjectFacade Page(ObjectContextFacade objectContext, RestControlFlags flags, ActionContextFacade actionContext) {
     return objectContext.Target.Page(flags.Page, PageSize(flags, actionContext), true);
 }
 private void SetScalars(ObjectContextFacade objectContext) {
     Title = objectContext.Target.TitleString;
 }
 private void SetHeader(ObjectContextFacade objectContext) {
     caching = objectContext.Specification.IsService ? CacheType.NonExpiring : CacheType.Transactional;
     SetEtag(objectContext.Target);
 }
 private void SetActions(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags) {
     InlineActionRepresentation[] actions = objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(oidStrategy, req, a, flags)).ToArray();
     Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object) m));
 }
 protected bool HasError(ObjectContextFacade ar) {
     return !string.IsNullOrEmpty(ar.Reason) || ar.VisibleProperties.Any(p => !string.IsNullOrEmpty(p.Reason));
 }
 private static IObjectFacade Page(ObjectContextFacade objectContext, RestControlFlags flags) {
  
     return objectContext.Target.Page(flags.Page, flags.PageSize);
 }
 private void SetLinks(HttpRequestMessage req, ObjectContextFacade objectContext) {
     Links = new LinkRepresentation[] {};
 }
 protected PagedListRepresentation(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags, ActionContextFacade actionContext)
     : base(oidStrategy, Page(objectContext, flags), req, flags, actionContext) {
   
     SetPagination(objectContext.Target, flags);
 }
 public static ScalarRepresentation Create(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags) {
     return new ScalarRepresentation(oidStrategy, req, objectContext, flags);
 }
        public static ObjectRepresentation Create(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags) {
            if (objectContext.Target != null && (objectContext.Specification.IsService || !objectContext.Target.IsTransient)) {
                return CreateObjectWithOptionals(oidStrategy ,objectContext, req, flags);
            }

            return new ObjectRepresentation(oidStrategy ,req, objectContext, flags);
        }
        private static ObjectRepresentation CreateObjectWithOptionals(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags) {
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(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[] {oidStrategy ,req, objectContext, flags}, props);
        }
 private UriMtHelper GetHelper(IOidStrategy oidStrategy, HttpRequestMessage req, ObjectContextFacade objectContext) {
     return new UriMtHelper(oidStrategy, req, objectContext.Target);
 }