private void SetContentType(PropertyContextSurface context)
        {
            INakedObjectSurface no = context.Property.GetNakedObject(context.Target);
            string mtv             = no != null?no.GetAttachment().MimeType : AttachmentContext.DefaultMimeType;

            contentType = new MediaTypeHeaderValue(mtv);
        }
 protected MemberRepresentationStrategy(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags) : base(flags)
 {
     this.req             = req;
     this.propertyContext = propertyContext;
     objectUri            = new UriMtHelper(req, propertyContext);
     self = new MemberRelType(RelValues.Self, new UriMtHelper(req, propertyContext));
 }
 public UriMtHelper(HttpRequestMessage req, PropertyContextSurface propertyContext) : this(req) {
     assoc       = propertyContext.Property;
     nakedObject = propertyContext.Target;
     spec        = nakedObject.Specification;
     LinkObjectId oid = OidStrategyHolder.OidStrategy.GetOid(nakedObject);
     cachedId   = oid.InstanceId;
     cachedType = oid.DomainType;
 }
示例#4
0
        public PropertyContextSurface ToPropertyContextSurface(INakedObjectsSurface surface) {
            var pc = new PropertyContextSurface {
                Property = new NakedObjectAssociationWrapper(Property, surface),
                Mutated = Mutated,
            };

            return ToContextSurface(pc, surface);
        }
 public AttachmentRepresentation(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags)
     : base(flags)
 {
     SetContentType(propertyContext);
     SetContentDisposition(propertyContext);
     SetStream(propertyContext);
     SetHeader(propertyContext.Target);
 }
示例#6
0
        public PropertyContextSurface ToPropertyContextSurface(INakedObjectsSurface surface, INakedObjectsFramework framework)
        {
            var pc = new PropertyContextSurface {
                Property = new NakedObjectAssociationWrapper(Property, surface, framework),
                Mutated  = Mutated,
            };

            return(ToContextSurface(pc, surface, framework));
        }
示例#7
0
 public RestSnapshot(PropertyContextSurface propertyContext, ListContextSurface listContext, HttpRequestMessage req, RestControlFlags flags)
     : this(req, true)
 {
     logger.DebugFormat("RestSnapshot:propertyprompt");
     populator = () => {
         representation = PromptRepresentation.Create(propertyContext, listContext, req, flags);
         SetHeaders();
     };
 }
 public static InlinePropertyRepresentation Create(HttpRequestMessage req, PropertyContextSurface propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags)
 {
     if (!RestUtils.IsBlobOrClob(propertyContext.Specification) && !RestUtils.IsAttachment(propertyContext.Specification))
     {
         optionals.Add(new OptionalProperty(JsonPropertyNames.Value, GetPropertyValue(req, propertyContext.Property, propertyContext.Target, flags)));
     }
     RestUtils.AddChoices(req, propertyContext, optionals, flags);
     return(CreateWithOptionals <InlinePropertyRepresentation>(new object[] { new PropertyRepresentationStrategy(req, propertyContext, flags) }, optionals));
 }
示例#9
0
 public static void AddChoices(HttpRequestMessage req, PropertyContextSurface propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags)
 {
     if (propertyContext.Property.IsChoicesEnabled && !propertyContext.Property.GetChoicesParameters().Any())
     {
         INakedObjectSurface[] choices = propertyContext.Property.GetChoices(propertyContext.Target, null);
         object[] choicesArray         = choices.Select(c => GetChoiceValue(req, c, propertyContext.Property, flags)).ToArray();
         optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
     }
 }
 protected PromptRepresentation(PropertyContextSurface propertyContext, ListContextSurface listContext, HttpRequestMessage req, RestControlFlags flags)
     : base(flags)
 {
     SetScalars(propertyContext.Property.Id);
     SetChoices(listContext, propertyContext, req);
     SelfRelType = new PromptRelType(RelValues.Self, new UriMtHelper(req, propertyContext));
     SetLinks(req, listContext.ElementType, new ObjectRelType(RelValues.Up, new UriMtHelper(req, propertyContext.Target)));
     SetExtensions();
     SetHeader(listContext.IsListOfServices);
 }
 protected CollectionValueRepresentation(PropertyContextSurface propertyContext, HttpRequestMessage req, RestControlFlags flags)
     : base(flags)
 {
     SetScalars(propertyContext);
     SetValue(propertyContext, req, flags);
     SelfRelType = new CollectionValueRelType(RelValues.Self, new UriMtHelper(req, propertyContext));
     SetLinks(req, propertyContext, new ObjectRelType(RelValues.Up, new UriMtHelper(req, propertyContext.Target)));
     SetExtensions();
     SetHeader(propertyContext.Target);
 }
        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));
        }
示例#13
0
 private static void FilterBlobsAndClobs(PropertyContextSurface propertyContext, RestControlFlags flags)
 {
     if (!flags.BlobsClobs)
     {
         if (RestUtils.IsBlobOrClob(propertyContext.Specification) && !RestUtils.IsAttachment(propertyContext.Specification))
         {
             throw new PropertyResourceNotFoundNOSException(propertyContext.Id);
         }
     }
 }
        private void SetContentDisposition(PropertyContextSurface context)
        {
            INakedObjectSurface no = context.Property.GetNakedObject(context.Target);
            string cd = no != null?no.GetAttachment().ContentDisposition : AttachmentContext.DefaultContentDisposition;

            string fn = no != null?no.GetAttachment().FileName : AttachmentContext.DefaultFileName;

            ContentDisposition = new ContentDispositionHeaderValue(cd)
            {
                FileName = fn
            };
        }
        private void SetLinks(HttpRequestMessage req, PropertyContextSurface propertyContext, RelType parentRelType)
        {
            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(parentRelType, Flags),
                LinkRepresentation.Create(SelfRelType, Flags)
            };

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

            Links = tempLinks.ToArray();
        }
示例#16
0
 public RestSnapshot(PropertyContextSurface propertyContext, HttpRequestMessage req, RestControlFlags flags, bool value = false)
     : this(propertyContext, req, false)
 {
     FilterBlobsAndClobs(propertyContext, flags);
     populator = () => {
         if (value)
         {
             representation = CollectionValueRepresentation.Create(propertyContext, req, flags);
         }
         else
         {
             representation = RequestingAttachment() ? AttachmentRepresentation.Create(req, propertyContext, flags) :
                              MemberAbstractRepresentation.Create(req, propertyContext, flags);
         }
         SetHeaders();
     };
 }
        public static InlineCollectionRepresentation Create(HttpRequestMessage req, PropertyContextSurface propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags)
        {
            if (propertyContext.Property.IsEager(propertyContext.Target) && !propertyContext.Target.IsTransient())
            {
                IEnumerable <INakedObjectSurface> collectionItems = propertyContext.Property.GetNakedObject(propertyContext.Target).ToEnumerable();
                IEnumerable <LinkRepresentation>  items           = collectionItems.Select(i => LinkRepresentation.Create(new ValueRelType(propertyContext.Property, new UriMtHelper(req, i)), flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(i))));
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, items.ToArray()));
            }

            var collectionRepresentationStrategy = new CollectionRepresentationStrategy(req, propertyContext, flags);

            if (optionals.Count == 0)
            {
                return(new InlineCollectionRepresentation(collectionRepresentationStrategy));
            }
            return(CreateWithOptionals <InlineCollectionRepresentation>(new object[] { collectionRepresentationStrategy }, optionals));
        }
示例#18
0
        public static MemberAbstractRepresentation Create(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags)
        {
            IConsentSurface 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(CollectionRepresentation.Create(req, propertyContext, optionals, flags));
            }

            return(PropertyRepresentation.Create(req, propertyContext, optionals, flags));
        }
 public static Representation Create(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags)
 {
     return(new AttachmentRepresentation(req, propertyContext, flags));
 }
        private void SetStream(PropertyContextSurface context)
        {
            INakedObjectSurface no = context.Property.GetNakedObject(context.Target);

            AsStream = no != null?no.GetAttachment().Content : new MemoryStream();
        }
 public CollectionRepresentationStrategy(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags) : base(req, propertyContext, flags)
 {
     collection = propertyContext.Property.GetNakedObject(propertyContext.Target);
 }
 public PropertyRepresentationStrategy(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags) :
     base(req, propertyContext, flags)
 {
 }
 public static CollectionValueRepresentation Create(PropertyContextSurface propertyContext, HttpRequestMessage req, RestControlFlags flags)
 {
     return(new CollectionValueRepresentation(propertyContext, req, flags));
 }
        private void SetValue(PropertyContextSurface propertyContext, HttpRequestMessage req, RestControlFlags flags)
        {
            IEnumerable <INakedObjectSurface> collectionItems = propertyContext.Property.GetNakedObject(propertyContext.Target).ToEnumerable();

            Value = collectionItems.Select(i => LinkRepresentation.Create(new ValueRelType(propertyContext.Property, new UriMtHelper(req, i)), flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(i)))).ToArray();
        }
        protected string GetAttachmentFileName(PropertyContextSurface context)
        {
            INakedObjectSurface no = context.Property.GetNakedObject(context.Target);

            return(no != null?no.GetAttachment().FileName : "UnknownFile");
        }
 private void SetScalars(PropertyContextSurface propertyContext)
 {
     Id = propertyContext.Property.Id;
 }
 private void SetChoices(ListContextSurface listContext, PropertyContextSurface propertyContext, HttpRequestMessage req)
 {
     Choices = listContext.List.Select(c => RestUtils.GetChoiceValue(req, c, propertyContext.Property, Flags)).ToArray();
 }
 public static PromptRepresentation Create(PropertyContextSurface propertyContext, ListContextSurface listContext, HttpRequestMessage req, RestControlFlags flags)
 {
     return(new PromptRepresentation(propertyContext, listContext, req, flags));
 }