private static bool InlineDetails(PropertyContextFacade propertyContext, RestControlFlags flags)
 {
     return(flags.InlineDetailsInPropertyMemberRepresentations ||
            propertyContext.Property.RenderEagerly ||
            propertyContext.Target.IsViewModelEditView ||
            propertyContext.Target.IsTransient);
 }
 public AttachmentRepresentation(IOidStrategy oidStrategy, HttpRequest req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy, flags)
 {
     SetContentType(propertyContext);
     SetContentDisposition(propertyContext);
     SetStream(propertyContext);
     SetHeader(propertyContext.Target);
 }
 public RestSnapshot(IOidStrategy oidStrategy, PropertyContextFacade propertyContext, HttpRequestMessage req, RestControlFlags flags)
     : this(oidStrategy, req, true)
 {
     populator = () => {
         Representation = PromptRepresentation.Create(oidStrategy, propertyContext, req, flags);
         SetHeaders();
     };
 }
 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));
 }
        private void SetContentType(PropertyContextFacade context)
        {
            IObjectFacade no = context.Property.GetValue(context.Target);
            Func <string> defaultMimeType = () => no == null ? AttachmentContextFacade.DefaultMimeType : no.GetAttachment().DefaultMimeType();
            string        mtv             = no == null || string.IsNullOrWhiteSpace(no.GetAttachment().MimeType) ? defaultMimeType() : no.GetAttachment().MimeType;

            contentType = new MediaTypeHeaderValue(mtv);
        }
 public static void AddChoices(IOidStrategy oidStrategy, HttpRequest req, PropertyContextFacade propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags)
 {
     if (propertyContext.Property.IsChoicesEnabled != Choices.NotEnabled && !propertyContext.Property.GetChoicesParameters().Any())
     {
         var choices      = propertyContext.Property.GetChoices(propertyContext.Target, null);
         var choicesArray = choices.Select(c => GetChoiceValue(oidStrategy, req, c, propertyContext.Property, flags)).ToArray();
         optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
     }
 }
Esempio n. 7
0
        private void SetLinks(HttpRequestMessage req, PropertyContextFacade propertyContext, RelType parentRelType)
        {
            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, parentRelType, Flags),
                LinkRepresentation.Create(OidStrategy, SelfRelType, Flags)
            };

            Links = tempLinks.ToArray();
        }
Esempio n. 8
0
        public PropertyContextFacade ToPropertyContextFacade(IFrameworkFacade facade)
        {
            var pc = new PropertyContextFacade {
                Property = new AssociationFacade(Property, Target, facade),
                Mutated  = Mutated
            };

            return(ToContextFacade(pc, facade));
        }
        private static PropertyContextFacade ValidatePropertyContext(PropertyContextFacade propertyContext)
        {
            if (!string.IsNullOrEmpty(propertyContext.Reason))
            {
                throw new BadArgumentsNOSException("Arguments invalid", propertyContext);
            }

            return(propertyContext);
        }
Esempio n. 10
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();
     };
 }
Esempio n. 11
0
        public PropertyContextFacade ToPropertyContextFacade(IFrameworkFacade facade, INakedObjectsFramework framework)
        {
            var pc = new PropertyContextFacade {
                Property = new AssociationFacade(Property, facade, framework),
                Mutated  = Mutated
            };

            return(ToContextFacade(pc, facade, framework));
        }
Esempio n. 12
0
 protected CollectionValueRepresentation(IOidStrategy oidStrategy, PropertyContextFacade propertyContext, HttpRequestMessage req, RestControlFlags flags)
     : base(oidStrategy, flags)
 {
     SetScalars(propertyContext);
     SetValue(propertyContext, req, flags);
     SelfRelType = new CollectionValueRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, propertyContext));
     SetLinks(req, propertyContext, new ObjectRelType(RelValues.Up, new UriMtHelper(oidStrategy, req, propertyContext.Target)));
     SetExtensions();
     SetHeader(propertyContext.Target);
 }
        private void SetContentType(PropertyContextFacade context)
        {
            var no = context.Property.GetValue(context.Target);

            string DefaultMimeType() => no == null ? AttachmentContextFacade.DefaultMimeType : no.GetAttachment().DefaultMimeType();

            var mtv = string.IsNullOrWhiteSpace(no?.GetAttachment().MimeType) ? DefaultMimeType() : no.GetAttachment().MimeType;

            contentType = new MediaTypeHeaderValue(mtv);
        }
Esempio n. 14
0
 protected PromptRepresentation(IOidStrategy oidStrategy, PropertyContextFacade propertyContext, HttpRequestMessage req, RestControlFlags flags)
     : base(oidStrategy, flags)
 {
     SetScalars(propertyContext.Property.Id);
     SetChoices(propertyContext, req);
     SelfRelType = new PromptRelType(RelValues.Self, GetSelfHelper(oidStrategy, propertyContext, req));
     SetLinks(req, propertyContext.Completions.ElementType, new ObjectRelType(RelValues.Up, GetParentHelper(oidStrategy, propertyContext, req)));
     SetExtensions();
     SetHeader(propertyContext.Completions.IsListOfServices);
 }
Esempio n. 15
0
 private static void FilterBlobsAndClobs(PropertyContextFacade propertyContext, RestControlFlags flags)
 {
     if (!flags.BlobsClobs)
     {
         if (RestUtils.IsBlobOrClob(propertyContext.Specification) && !RestUtils.IsAttachment(propertyContext.Specification))
         {
             throw new PropertyResourceNotFoundNOSException(propertyContext.Id);
         }
     }
 }
        private void SetContentDisposition(PropertyContextFacade context)
        {
            IObjectFacade no = context.Property.GetValue(context.Target);
            string        cd = no == null || string.IsNullOrWhiteSpace(no.GetAttachment().ContentDisposition) ? AttachmentContextFacade.DefaultContentDisposition : no.GetAttachment().ContentDisposition;
            string        fn = no != null?no.GetAttachment().FileName : AttachmentContextFacade.DefaultFileName;

            ContentDisposition = new ContentDispositionHeaderValue(cd)
            {
                FileName = fn
            };
        }
        private void SetContentDisposition(PropertyContextFacade context)
        {
            var no = context.Property.GetValue(context.Target);
            var cd = string.IsNullOrWhiteSpace(no?.GetAttachment().ContentDisposition) ? AttachmentContextFacade.DefaultContentDisposition : no.GetAttachment().ContentDisposition;
            var fn = no?.GetAttachment().FileName ?? AttachmentContextFacade.DefaultFileName;

            ContentDisposition = new ContentDispositionHeaderValue(cd)
            {
                FileName = fn
            };
        }
        public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext)
            : this(oidStrategy, req)
        {
            assoc        = propertyContext.Property;
            objectFacade = propertyContext.Target;
            spec         = objectFacade.Specification;
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);

            cachedId   = oid.InstanceId;
            CachedType = oid.DomainType;
        }
Esempio n. 19
0
        public static LinkRepresentation CreateTableRowValueLink(IObjectFacade no,
                                                                 PropertyContextFacade propertyContext,
                                                                 IOidStrategy oidStrategy,
                                                                 HttpRequestMessage req,
                                                                 RestControlFlags flags)
        {
            var columns = propertyContext.Property.TableViewData?.Item2;
            var rt      = new ValueRelType(propertyContext.Property, new UriMtHelper(oidStrategy, req, no));

            return(CreateTableRowValueLink(no, columns, rt, oidStrategy, req, flags));
        }
Esempio n. 20
0
        public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext)
            : this(oidStrategy, req)
        {
            assoc        = propertyContext.Property;
            objectFacade = propertyContext.Target;
            spec         = objectFacade.Specification;
            if (objectFacade.Specification.IsParseable)
            {
                throw new ArgumentException($"Cannot build URI  for parseable specification : {objectFacade.Specification.FullName}");
            }
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);

            cachedId   = propertyContext.Target.IsTransient ? "" : oid.InstanceId;
            CachedType = oid.DomainType;
        }
        private void SetLinks(HttpRequestMessage req, PropertyContextFacade propertyContext, RelType parentRelType)
        {
            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, parentRelType, Flags),
                LinkRepresentation.Create(OidStrategy, SelfRelType, Flags)
            };

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(OidStrategy, req, propertyContext.Property)), Flags));
                tempLinks.Add(LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.ElementType, new UriMtHelper(OidStrategy, req, propertyContext.Property.ElementSpecification)), Flags));
            }

            Links = tempLinks.ToArray();
        }
Esempio n. 22
0
 public RestSnapshot(IOidStrategy oidStrategy, PropertyContextFacade propertyContext, HttpRequestMessage req, RestControlFlags flags, bool value = false)
     : this(oidStrategy, propertyContext, req, false)
 {
     FilterBlobsAndClobs(propertyContext, flags);
     populator = () => {
         if (value)
         {
             representation = CollectionValueRepresentation.Create(oidStrategy, propertyContext, req, flags);
         }
         else
         {
             representation = RequestingAttachment() ? AttachmentRepresentation.Create(oidStrategy, req, propertyContext, flags) :
                              MemberAbstractRepresentation.Create(oidStrategy, req, propertyContext, flags);
         }
         SetHeaders();
     };
 }
        public static PropertyRepresentation 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 <PropertyRepresentation>(new object[] { oidStrategy, new PropertyRepresentationStrategy(oidStrategy, req, propertyContext, flags) }, optionals));
        }
        public static AbstractCollectionRepresentationStrategy GetStrategy(bool asTableColumn, bool inline, IOidStrategy oidStrategy, HttpRequest req, PropertyContextFacade propertyContext, RestControlFlags flags)
        {
            if (asTableColumn)
            {
                if (propertyContext.Property.DoNotCount)
                {
                    return(new CollectionMemberNotCountedRepresentationStrategy(oidStrategy, req, propertyContext, flags));
                }

                return(new CollectionMemberRepresentationStrategy(oidStrategy, req, propertyContext, flags));
            }

            if (inline && DoNotCountAndNotEager(propertyContext))
            {
                return(new CollectionMemberNotCountedRepresentationStrategy(oidStrategy, req, propertyContext, flags));
            }

            if (inline && !InlineDetails(propertyContext, flags))
            {
                return(new CollectionMemberRepresentationStrategy(oidStrategy, req, propertyContext, flags));
            }

            return(new CollectionWithDetailsRepresentationStrategy(oidStrategy, req, propertyContext, flags));
        }
 private static bool DoNotCountAndNotEager(PropertyContextFacade propertyContext) => propertyContext.Property.DoNotCount && !propertyContext.Property.RenderEagerly;
 private static bool InlineDetails(PropertyContextFacade propertyContext, RestControlFlags flags) => flags.InlineDetailsInCollectionMemberRepresentations || propertyContext.Property.RenderEagerly;
 protected AbstractCollectionRepresentationStrategy(IOidStrategy oidStrategy, HttpRequest req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy, req, propertyContext, flags)
 {
 }
Esempio n. 28
0
        public static InlineMemberAbstractRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags, bool asTableColumn)
        {
            IConsentFacade consent   = propertyContext.Property.IsUsable(propertyContext.Target);
            var            optionals = new List <OptionalProperty>();

            if (consent.IsVetoed)
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.DisabledReason, consent.Reason));
            }

            if (propertyContext.Property.IsCollection)
            {
                return(InlineCollectionRepresentation.Create(oidStrategy, req, propertyContext, optionals, flags, asTableColumn));
            }

            return(InlinePropertyRepresentation.Create(oidStrategy, req, propertyContext, optionals, flags));
        }
        public static InlineCollectionRepresentation Create(IOidStrategy oidStrategy, HttpRequest req, PropertyContextFacade propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags, bool asTableColumn)
        {
            var collectionRepresentationStrategy = AbstractCollectionRepresentationStrategy.GetStrategy(asTableColumn, true, oidStrategy, req, propertyContext, flags);

            var size = collectionRepresentationStrategy.GetSize();

            if (size != null)
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Size, size));
            }

            var value = collectionRepresentationStrategy.GetValue();

            if (value != null)
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, value));
            }

            var actions = collectionRepresentationStrategy.GetActions();

            if (actions.Any())
            {
                var members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m));
                optionals.Add(new OptionalProperty(JsonPropertyNames.Members, members));
            }

            return(optionals.Any()
                ? CreateWithOptionals <InlineCollectionRepresentation>(new object[] { oidStrategy, collectionRepresentationStrategy }, optionals)
                : new InlineCollectionRepresentation(oidStrategy, collectionRepresentationStrategy));
        }
Esempio n. 30
0
 private void SetChoices(PropertyContextFacade propertyContext, HttpRequestMessage req)
 {
     Choices = propertyContext.Completions.List.Select(c => RestUtils.GetChoiceValue(OidStrategy, req, c, propertyContext.Property, Flags)).ToArray();
 }