示例#1
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);
 }
示例#2
0
 public AttachmentRepresentation(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags)
     : base(flags) {
     SetContentType(propertyContext);
     SetContentDisposition(propertyContext);
     SetStream(propertyContext);
     SetHeader(propertyContext.Target);
 }
示例#3
0
 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);
 }
示例#4
0
 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;
 }
示例#5
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();
     };
 }
示例#6
0
 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);
 }
示例#7
0
 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);
 }
示例#8
0
        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.Specification)), Flags));
            }

            Links = tempLinks.ToArray();
        }
示例#9
0
        public static InlineMemberAbstractRepresentation 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 InlineCollectionRepresentation.Create(req, propertyContext, optionals, flags);
            }

            return InlinePropertyRepresentation.Create(req, propertyContext, optionals, flags);
        }
示例#10
0
        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);
        }
示例#11
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();
     };
 }
示例#12
0
 public static PromptRepresentation Create(PropertyContextSurface propertyContext, ListContextSurface listContext, HttpRequestMessage req, RestControlFlags flags) {
     return new PromptRepresentation(propertyContext, listContext, req, flags);
 }
示例#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);
         }
     }
 }
示例#14
0
 public PropertyRepresentationStrategy(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags) :
     base(req, propertyContext, flags) {}
示例#15
0
 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);
 }
示例#16
0
 public CollectionRepresentationStrategy(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags) : base(req, propertyContext, flags) {
     collection = propertyContext.Property.GetNakedObject(propertyContext.Target);
 }
示例#17
0
 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));
 }
示例#18
0
 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};
 }
示例#19
0
 public static CollectionValueRepresentation Create(PropertyContextSurface propertyContext, HttpRequestMessage req, RestControlFlags flags) {
     return new CollectionValueRepresentation(propertyContext, req, flags);
 }
示例#20
0
 private void SetChoices(ListContextSurface listContext, PropertyContextSurface propertyContext, HttpRequestMessage req) {
     Choices = listContext.List.Select(c => RestUtils.GetChoiceValue(req, c, propertyContext.Property, Flags)).ToArray();
 }
示例#21
0
 private void SetScalars(PropertyContextSurface propertyContext) {
     Id = propertyContext.Property.Id;
 }
示例#22
0
 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();
 }
示例#23
0
 private void SetStream(PropertyContextSurface context) {
     INakedObjectSurface no = context.Property.GetNakedObject(context.Target);
     AsStream = no != null ? no.GetAttachment().Content : new MemoryStream();
 }
示例#24
0
 protected string GetAttachmentFileName(PropertyContextSurface context) {
     INakedObjectSurface no = context.Property.GetNakedObject(context.Target);
     return no != null ? no.GetAttachment().FileName : "UnknownFile";
 }
示例#25
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));
     }
 }
示例#26
0
 public static Representation Create(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags) {
     return new AttachmentRepresentation(req, propertyContext, flags);
 }