public AttachmentRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy, flags) {
     SetContentType(propertyContext);
     SetContentDisposition(propertyContext);
     SetStream(propertyContext);
     SetHeader(propertyContext.Target);
 }
 public static InlinePropertyRepresentation 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<InlinePropertyRepresentation>(new object[] {oidStrategy, new PropertyRepresentationStrategy(oidStrategy ,req, propertyContext, flags)}, optionals);
 }
        public static InlineCollectionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList<OptionalProperty> optionals, RestControlFlags flags, bool asTableColumn) {
            var collectionRepresentationStrategy = AbstractCollectionRepresentationStrategy.GetStrategy(asTableColumn, true, oidStrategy, req, propertyContext, flags);

            int? 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.Length > 0) {
                var members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m));
                optionals.Add(new OptionalProperty(JsonPropertyNames.Members, members));
            }


            if (optionals.Count == 0) {
                return new InlineCollectionRepresentation(oidStrategy, collectionRepresentationStrategy);
            }
            return CreateWithOptionals<InlineCollectionRepresentation>(new object[] {oidStrategy, collectionRepresentationStrategy}, optionals);
        }
 public static InlineCollectionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList<OptionalProperty> optionals, RestControlFlags flags) {
     var collectionRepresentationStrategy = new CollectionRepresentationStrategy(oidStrategy, req, propertyContext, flags);
     if (optionals.Count == 0) {
         return new InlineCollectionRepresentation(oidStrategy, collectionRepresentationStrategy);
     }
     return CreateWithOptionals<InlineCollectionRepresentation>(new object[] {oidStrategy, collectionRepresentationStrategy}, optionals);
 }
 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));
 }
        public PropertyContextFacade ToPropertyContextFacade(IFrameworkFacade facade, INakedObjectsFramework framework) {
            var pc = new PropertyContextFacade {
                Property = new AssociationFacade(Property, facade, framework),
                Mutated = Mutated
            };

            return ToContextFacade(pc, facade, framework);
        }
        public PropertyContextFacade ToPropertyContextFacade(IFrameworkFacade facade) {
            var pc = new PropertyContextFacade {
                Property = new AssociationFacade(Property, Target, facade),
                Mutated = Mutated
            };

            return ToContextFacade(pc, facade);
        }
        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();
        }
 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();
     };
 }
 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);
 }
 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;
 }
 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);
 }
        public static PropertyRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList<OptionalProperty> optionals, RestControlFlags flags) {
            var strategy = AbstractPropertyRepresentationStrategy.GetStrategy(false, oidStrategy, req, propertyContext, flags);

            if (!RestUtils.IsBlobOrClob(propertyContext.Specification) && !RestUtils.IsAttachment(propertyContext.Specification)) {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, strategy.GetPropertyValue(oidStrategy, req, propertyContext.Property, propertyContext.Target, flags, false, strategy.UseDateOverDateTime())));
            }

            RestUtils.AddChoices(oidStrategy, req, propertyContext, optionals, flags);
            
            return CreateWithOptionals<PropertyRepresentation>(new object[] {oidStrategy, strategy}, optionals);
        }
 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;
 }
        public static InlineCollectionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList<OptionalProperty> optionals, RestControlFlags flags) {
            if (propertyContext.Property.IsEager(propertyContext.Target) && !propertyContext.Target.IsTransient) {
                IEnumerable<IObjectFacade> collectionItems = propertyContext.Property.GetValue(propertyContext.Target).ToEnumerable();
                IEnumerable<LinkRepresentation> items = collectionItems.Select(i => LinkRepresentation.Create(oidStrategy ,new ValueRelType(propertyContext.Property, new UriMtHelper(oidStrategy ,req, i)), flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(i))));
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, items.ToArray()));
            }

            var collectionRepresentationStrategy = new CollectionRepresentationStrategy(oidStrategy ,req, propertyContext, flags);
            if (optionals.Count == 0) {
                return new InlineCollectionRepresentation(oidStrategy, collectionRepresentationStrategy);
            }
            return CreateWithOptionals<InlineCollectionRepresentation>(new object[] {oidStrategy, collectionRepresentationStrategy}, optionals);
        }
        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 RestSnapshot(IOidStrategy oidStrategy, PropertyContextFacade propertyContext, HttpRequestMessage req, RestControlFlags flags)
     : this(oidStrategy, req, true) {
     populator = () => {
         Representation = PromptRepresentation.Create(oidStrategy, propertyContext, req, flags);
         SetHeaders();
     };
 }
 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);
         }
     }
 }
 public RestSnapshot(IOidStrategy oidStrategy, PropertyContextFacade propertyContext, HttpRequestMessage req, RestControlFlags flags, bool value)
     : 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 CollectionWithDetailsRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy, req, propertyContext, flags) {}
 public PropertyTableRowRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags) :
     base(oidStrategy, req, propertyContext, flags) {}
        public static AbstractCollectionRepresentationStrategy GetStrategy(bool asTableColumn,  bool inline, IOidStrategy oidStrategy, HttpRequestMessage 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 && DoNotCount(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 DoNotCount(PropertyContextFacade propertyContext) {
     return propertyContext.Property.DoNotCount && !propertyContext.Property.RenderEagerly;
 }
 private static bool InlineDetails(PropertyContextFacade propertyContext, RestControlFlags flags) {
     return flags.InlineDetailsInCollectionMemberRepresentations || propertyContext.Property.RenderEagerly;
 }
 protected AbstractCollectionRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy, req, propertyContext, flags) {           
 }
 protected string GetAttachmentFileName(PropertyContextFacade context) {
     IObjectFacade no = context.Property.GetValue(context.Target);
     return no != null ? no.GetAttachment().FileName : "UnknownFile";
 }
 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);
 }
 public static void AddChoices(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList<OptionalProperty> optionals, RestControlFlags flags) {
     if (propertyContext.Property.IsChoicesEnabled != Choices.NotEnabled && !propertyContext.Property.GetChoicesParameters().Any()) {
         IObjectFacade[] choices = propertyContext.Property.GetChoices(propertyContext.Target, null);
         object[] choicesArray = choices.Select(c => GetChoiceValue(oidStrategy, req, c, propertyContext.Property, flags)).ToArray();
         optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
     }
 }
 public static Representation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags) {
     return new AttachmentRepresentation(oidStrategy, req, propertyContext, flags);
 }
 public CollectionRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy ,req, propertyContext, flags) {
     collection = propertyContext.Property.GetValue(propertyContext.Target);
 }