Beispiel #1
0
        protected static object GetPropertyValue(HttpRequestMessage req, INakedObjectAssociationSurface property, INakedObjectSurface target, RestControlFlags flags, bool valueOnly = false)
        {
            INakedObjectSurface valueNakedObject = property.GetNakedObject(target);
            string title = RestUtils.SafeGetTitle(property, valueNakedObject);

            if (valueNakedObject == null)
            {
                return(null);
            }
            if (property.Specification.IsParseable() || property.Specification.IsCollection())
            {
                return(RestUtils.ObjectToPredefinedType(valueNakedObject.Object));
            }

            if (valueOnly)
            {
                return(RefValueRepresentation.Create(new ValueRelType(property, new UriMtHelper(req, valueNakedObject)), flags));
            }

            var helper    = new UriMtHelper(req, property.IsInline() ? target : valueNakedObject);
            var optionals = new List <OptionalProperty> {
                new OptionalProperty(JsonPropertyNames.Title, title)
            };

            if (property.IsEager(target))
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, ObjectRepresentation.Create(valueNakedObject, req, flags)));
            }

            return(LinkRepresentation.Create(new ValueRelType(property, helper), flags, optionals.ToArray()));
        }
Beispiel #2
0
 public UriMtHelper(HttpRequestMessage req, INakedObjectSurface nakedObject) : this(req) {
     this.nakedObject = nakedObject;
     spec = nakedObject.Specification;
     LinkObjectId oid = OidStrategyHolder.OidStrategy.GetOid(nakedObject);
     cachedId = oid.InstanceId;
     cachedType = oid.DomainType;
 }
Beispiel #3
0
        public static object GetChoiceValue(INakedObjectSurface item, ChoiceRelType relType, RestControlFlags flags)
        {
            string title = SafeGetTitle(item);
            object value = ObjectToPredefinedType(item.Object);

            return(item.Specification.IsParseable() ? value : LinkRepresentation.Create(relType, flags, new OptionalProperty(JsonPropertyNames.Title, title)));
        }
 protected ParameterRepresentation(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter, RestControlFlags flags) : base(flags)
 {
     SetName(parameter);
     SetExtensions(req, nakedObject, parameter, flags);
     SetLinks(req, nakedObject, parameter);
     SetHeader(nakedObject);
 }
        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);
        }
        private LinkRepresentation CreatePromptLink(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter)
        {
            var opts = new List <OptionalProperty>();

            var parameterContext = new ParameterContextSurface {
                Action    = parameter.Action,
                Target    = nakedObject,
                Parameter = parameter
            };

            if (parameter.IsAutoCompleteEnabled)
            {
                var arguments  = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.XRoSearchTerm, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))));
                var extensions = new OptionalProperty(JsonPropertyNames.Extensions, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.MinLength, parameter.AutoCompleteMinLength())));

                opts.Add(arguments);
                opts.Add(extensions);
            }
            else
            {
                Tuple <string, INakedObjectSpecificationSurface>[] parms = parameter.GetChoicesParameters();
                OptionalProperty[] args = parms.Select(tuple => RestUtils.CreateArgumentProperty(req, tuple, Flags)).ToArray();
                var arguments           = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args));
                opts.Add(arguments);
            }

            return(LinkRepresentation.Create(new PromptRelType(new UriMtHelper(req, parameterContext)), Flags, opts.ToArray()));
        }
        private LinkRepresentation CreateObjectLink(HttpRequestMessage req, INakedObjectSurface no)
        {
            var           helper = new UriMtHelper(req, no);
            ObjectRelType rt     = no.Specification.IsService() ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper);

            return(LinkRepresentation.Create(rt, Flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(no))));
        }
 public UriMtHelper(HttpRequestMessage req, INakedObjectSurface nakedObject) : this(req) {
     this.nakedObject = nakedObject;
     spec             = nakedObject.Specification;
     LinkObjectId oid = OidStrategyHolder.OidStrategy.GetOid(nakedObject);
     cachedId   = oid.InstanceId;
     cachedType = oid.DomainType;
 }
Beispiel #9
0
        private LinkRepresentation CreatePromptLink(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter) {
            var opts = new List<OptionalProperty>();

            var parameterContext = new ParameterContextSurface {
                Action = parameter.Action,
                Target = nakedObject,
                Parameter = parameter
            };

            if (parameter.IsAutoCompleteEnabled) {
                var arguments = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.XRoSearchTerm, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof (object))))));
                var extensions = new OptionalProperty(JsonPropertyNames.Extensions, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.MinLength, parameter.AutoCompleteMinLength())));

                opts.Add(arguments);
                opts.Add(extensions);
            }
            else {
                Tuple<string, INakedObjectSpecificationSurface>[] parms = parameter.GetChoicesParameters();
                OptionalProperty[] args = parms.Select(tuple => RestUtils.CreateArgumentProperty(req, tuple, Flags)).ToArray();
                var arguments = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args));
                opts.Add(arguments);
            }

            return LinkRepresentation.Create(new PromptRelType(new UriMtHelper(req, parameterContext)), Flags, opts.ToArray());
        }
        public MediaTypeHeaderValue GetAttachmentMediaType()
        {
            INakedObjectSurface no = assoc.GetNakedObject(nakedObject);
            string mtv             = no != null?no.GetAttachment().MimeType : "";

            return(new MediaTypeHeaderValue(string.IsNullOrWhiteSpace(mtv) ? "image/bmp" : mtv));
        }
        public static ParameterRepresentation Create(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter, RestControlFlags flags)
        {
            var optionals = new List <OptionalProperty>();

            if (parameter.IsChoicesEnabled && !parameter.GetChoicesParameters().Any())
            {
                INakedObjectSurface[] choices = parameter.GetChoices(nakedObject, null);
                object[] choicesArray         = choices.Select(c => RestUtils.GetChoiceValue(req, c, parameter, flags)).ToArray();
                optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
            }

            if (parameter.DefaultTypeIsExplicit(nakedObject))
            {
                INakedObjectSurface defaultNakedObject = parameter.GetDefault(nakedObject);
                if (defaultNakedObject != null)
                {
                    string title        = defaultNakedObject.TitleString();
                    object value        = RestUtils.ObjectToPredefinedType(defaultNakedObject.Object);
                    var    isValue      = defaultNakedObject.Specification.IsParseable() || (defaultNakedObject.Specification.IsCollection() && defaultNakedObject.ElementSpecification.IsParseable());
                    object defaultValue = isValue ? value : CreateDefaultLinks(req, parameter, defaultNakedObject, title, flags);

                    optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue));
                }
            }

            if (optionals.Count == 0)
            {
                return(new ParameterRepresentation(req, nakedObject, parameter, flags));
            }
            return(CreateWithOptionals <ParameterRepresentation>(new object[] { req, nakedObject, parameter, flags }, optionals));
        }
Beispiel #12
0
 public UriMtHelper(HttpRequestMessage req, ActionContextSurface actionContext) : this(req) {
     action = actionContext.Action;
     nakedObject = actionContext.Target;
     spec = nakedObject.Specification;
     LinkObjectId oid = OidStrategyHolder.OidStrategy.GetOid(nakedObject);
     cachedId = oid.InstanceId;
     cachedType = oid.DomainType;
 }
 public UriMtHelper(HttpRequestMessage req, ActionContextSurface actionContext) : this(req) {
     action      = actionContext.Action;
     nakedObject = actionContext.Target;
     spec        = nakedObject.Specification;
     LinkObjectId oid = OidStrategyHolder.OidStrategy.GetOid(nakedObject);
     cachedId   = oid.InstanceId;
     cachedType = oid.DomainType;
 }
 public int Count(INakedObjectSurface target)
 {
     if (IsCollection)
     {
         INakedObject result = assoc.GetNakedObject(((NakedObjectWrapper)target).WrappedNakedObject);
         return(result.GetCollectionFacetFromSpec().AsQueryable(result).Count());
     }
     return(0);
 }
Beispiel #15
0
 public INakedObjectSpecificationSurface GetElementType(INakedObjectSurface nakedObject)
 {
     if (IsCollection)
     {
         var introspectableSpecification = spec.GetFacet <ITypeOfFacet>().GetValueSpec(((NakedObjectWrapper)nakedObject).WrappedNakedObject, framework.MetamodelManager.Metamodel);
         var elementSpec = framework.MetamodelManager.GetSpecification(introspectableSpecification);
         return(new NakedObjectSpecificationWrapper(elementSpec, Surface, framework));
     }
     return(null);
 }
Beispiel #16
0
 protected void SetEtag(INakedObjectSurface target)
 {
     if (!target.Specification.IsService() && !target.Specification.IsImmutable(target))
     {
         string digest = target.Version.Digest;
         if (digest != null)
         {
             etag = digest;
         }
     }
 }
        public string GetTitle(INakedObjectSurface nakedObject)
        {
            var mask = assoc.GetFacet <IMaskFacet>();

            if (mask == null)
            {
                return(nakedObject.TitleString());
            }
            var titleFacet = ((NakedObjectSpecificationWrapper)nakedObject.Specification).WrappedValue.GetFacet <ITitleFacet>();

            return(titleFacet.GetTitleWithMask(mask.Value, ((NakedObjectWrapper)nakedObject).WrappedNakedObject, framework.NakedObjectManager));
        }
        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
            };
        }
        protected string GetKeyValues(INakedObjectSurface nakedObjectForKey)
        {
            string[]     keys;
            INakedObject wrappedNakedObject = ((NakedObjectWrapper)nakedObjectForKey).WrappedNakedObject;

            if (wrappedNakedObject.Spec.IsViewModel)
            {
                keys = wrappedNakedObject.Spec.GetFacet <IViewModelFacet>().Derive(wrappedNakedObject);
            }
            else
            {
                PropertyInfo[] keyPropertyInfo = nakedObjectForKey.GetKeys();
                keys = keyPropertyInfo.Select(pi => KeyRepresentation(pi.GetValue(nakedObjectForKey.Object, null))).ToArray();
            }

            return(GetKeyCodeMapper().CodeFromKey(keys, nakedObjectForKey.Object.GetType()));
        }
        private void SetExtensions(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter, RestControlFlags flags)
        {
            IDictionary <string, object> custom = parameter.ExtensionData();

            if (IsUnconditionalChoices(parameter))
            {
                Tuple <INakedObjectSurface, string>[] choices = parameter.GetChoicesAndTitles(nakedObject, null);
                Tuple <object, string>[] choicesArray         = choices.Select(tuple => new Tuple <object, string>(RestUtils.GetChoiceValue(req, tuple.Item1, parameter, flags), tuple.Item2)).ToArray();

                OptionalProperty[] op  = choicesArray.Select(tuple => new OptionalProperty(tuple.Item2, tuple.Item1)).ToArray();
                MapRepresentation  map = MapRepresentation.Create(op);
                custom = custom ?? new Dictionary <string, object>();
                custom[JsonPropertyNames.CustomChoices] = map;
            }

            string mask = parameter.Mask();

            if (!string.IsNullOrWhiteSpace(mask))
            {
                custom = custom ?? new Dictionary <string, object>();
                custom[JsonPropertyNames.CustomMask] = mask;
            }

            if (Flags.SimpleDomainModel)
            {
                Extensions = RestUtils.GetExtensions(friendlyname: parameter.Name(),
                                                     description: parameter.Description(),
                                                     pluralName: null,
                                                     domainType: null,
                                                     isService: null,
                                                     hasParams: null,
                                                     optional: !parameter.IsMandatory(),
                                                     maxLength: parameter.MaxLength(),
                                                     pattern: parameter.Pattern(),
                                                     memberOrder: null,
                                                     customExtensions: custom,
                                                     returnType: parameter.Specification,
                                                     elementType: parameter.ElementType);
            }
            else
            {
                Extensions = MapRepresentation.Create();
            }
        }
Beispiel #21
0
        private void SetLinks(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter) {
            var tempLinks = new List<LinkRepresentation>();


            if (Flags.FormalDomainModel) {
                var parameterTypeContextSurface = new ParameterTypeContextSurface {
                    Action = parameter.Action,
                    OwningSpecification = nakedObject.Specification,
                    Parameter = parameter
                };
                LinkRepresentation describedBy = LinkRepresentation.Create(new ParamTypeRelType(RelValues.DescribedBy, new UriMtHelper(req, parameterTypeContextSurface)), Flags);
                tempLinks.Add(describedBy);
            }

            if (parameter.IsAutoCompleteEnabled || parameter.GetChoicesParameters().Any()) {
                tempLinks.Add(CreatePromptLink(req, nakedObject, parameter));
            }

            Links = tempLinks.ToArray();
        }
        public static MapRepresentation Create(HttpRequestMessage req, IList <ContextSurface> contexts, Format format, RestControlFlags flags, MediaTypeHeaderValue mt)
        {
            OptionalProperty[]  memberValues = contexts.Select(c => new OptionalProperty(c.Id, GetMap(req, c, flags))).ToArray();
            INakedObjectSurface target       = contexts.First().Target;
            MapRepresentation   mapRepresentation;

            if (format == Format.Full)
            {
                var tempProperties = new List <OptionalProperty>();

                if (flags.SimpleDomainModel)
                {
                    var dt = new OptionalProperty(JsonPropertyNames.DomainType, target.Specification.DomainTypeName());
                    tempProperties.Add(dt);
                }

                if (flags.FormalDomainModel)
                {
                    var links = new OptionalProperty(JsonPropertyNames.Links, new[] {
                        Create(new OptionalProperty(JsonPropertyNames.Rel, RelValues.DescribedBy),
                               new OptionalProperty(JsonPropertyNames.Href, new UriMtHelper(req, target.Specification).GetDomainTypeUri()))
                    });
                    tempProperties.Add(links);
                }

                var members = new OptionalProperty(JsonPropertyNames.Members, Create(memberValues));
                tempProperties.Add(members);
                mapRepresentation = Create(tempProperties.ToArray());
            }
            else
            {
                mapRepresentation = Create(memberValues);
            }

            mapRepresentation.SetContentType(mt);

            return(mapRepresentation);
        }
        private void SetLinks(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter)
        {
            var tempLinks = new List <LinkRepresentation>();


            if (Flags.FormalDomainModel)
            {
                var parameterTypeContextSurface = new ParameterTypeContextSurface {
                    Action = parameter.Action,
                    OwningSpecification = nakedObject.Specification,
                    Parameter           = parameter
                };
                LinkRepresentation describedBy = LinkRepresentation.Create(new ParamTypeRelType(RelValues.DescribedBy, new UriMtHelper(req, parameterTypeContextSurface)), Flags);
                tempLinks.Add(describedBy);
            }

            if (parameter.IsAutoCompleteEnabled || parameter.GetChoicesParameters().Any())
            {
                tempLinks.Add(CreatePromptLink(req, nakedObject, parameter));
            }

            Links = tempLinks.ToArray();
        }
 private void SetExtensions(INakedObjectSurface nakedObject)
 {
     if (Flags.SimpleDomainModel)
     {
         Extensions = RestUtils.GetExtensions(friendlyname: nakedObject.Specification.SingularName(),
                                              description: nakedObject.Specification.Description(),
                                              pluralName: nakedObject.Specification.PluralName(),
                                              domainType: nakedObject.Specification.DomainTypeName(),
                                              isService: nakedObject.Specification.IsService(),
                                              hasParams: null,
                                              optional: null,
                                              maxLength: null,
                                              pattern: null,
                                              memberOrder: null,
                                              customExtensions: GetCustomExtensions(nakedObject),
                                              returnType: null,
                                              elementType: null);
     }
     else
     {
         Extensions = MapRepresentation.Create();
     }
 }
Beispiel #25
0
 private static object CreateDefaultLinks(HttpRequestMessage req, INakedObjectActionParameterSurface parameter, INakedObjectSurface defaultNakedObject, string title, RestControlFlags flags)  {
     if (defaultNakedObject.Specification.IsCollection()) {
         return  defaultNakedObject.ToEnumerable().Select(i => CreateDefaultLink(req, parameter, i, i.TitleString(), flags)).ToArray();
     }
     return CreateDefaultLink(req, parameter, defaultNakedObject, title, flags);
 }
Beispiel #26
0
 public string GetTitle(INakedObjectSurface nakedObject) {
     var mask = assoc.GetFacet<IMaskFacet>();
     if (mask == null) {
         return nakedObject.TitleString();
     }
     var titleFacet = ((NakedObjectSpecificationWrapper) nakedObject.Specification).WrappedValue.GetFacet<ITitleFacet>();
     return titleFacet.GetTitleWithMask(mask.Value, ((NakedObjectWrapper) nakedObject).WrappedNakedObject);
 }
Beispiel #27
0
 public INakedObjectSurface[] GetCompletions(INakedObjectSurface target, string autoCompleteParm) {
     var oneToOneFeature = assoc as IOneToOneFeature;
     return oneToOneFeature != null ? oneToOneFeature.GetCompletions(((NakedObjectWrapper)target).WrappedNakedObject, autoCompleteParm).Select(no => NakedObjectWrapper.Wrap(no, Surface)).Cast<INakedObjectSurface>().ToArray() : null;
 }
Beispiel #28
0
 public INakedObjectSurface[] GetChoices(INakedObjectSurface target, IDictionary<string, INakedObjectSurface> parameterNameValues) {
     var oneToOneFeature = assoc as IOneToOneFeature;
     return oneToOneFeature != null ? oneToOneFeature.GetChoices(((NakedObjectWrapper)target).WrappedNakedObject, null).Select(no => NakedObjectWrapper.Wrap(no, Surface)).Cast<INakedObjectSurface>().ToArray() : null;
 }
Beispiel #29
0
 public bool IsVisible(INakedObjectSurface nakedObject) {
     return assoc.IsVisible(NakedObjectsContext.Session, ((NakedObjectWrapper) nakedObject).WrappedNakedObject);
 }
Beispiel #30
0
 public IConsentSurface IsUsable(INakedObjectSurface target) {
     IConsent consent = assoc.IsUsable(NakedObjectsContext.Session, ((NakedObjectWrapper) target).WrappedNakedObject);
     return new ConsentWrapper(consent);
 }
Beispiel #31
0
 public bool DefaultTypeIsExplicit(INakedObjectSurface nakedObject) {
     return nakedObjectActionParameter.GetDefaultType(((NakedObjectWrapper) nakedObject).WrappedNakedObject) == TypeOfDefaultValue.Explicit;
 }
Beispiel #32
0
        private void SetExtensions(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter, RestControlFlags flags) {
            IDictionary<string, object> custom = parameter.ExtensionData();

            if (IsUnconditionalChoices(parameter)) {
                Tuple<INakedObjectSurface, string>[] choices = parameter.GetChoicesAndTitles(nakedObject, null);
                Tuple<object, string>[] choicesArray = choices.Select(tuple => new Tuple<object, string>(RestUtils.GetChoiceValue(req, tuple.Item1, parameter, flags), tuple.Item2)).ToArray();

                OptionalProperty[] op = choicesArray.Select(tuple => new OptionalProperty(tuple.Item2, tuple.Item1)).ToArray();
                MapRepresentation map = MapRepresentation.Create(op);
                custom = custom ?? new Dictionary<string, object>();
                custom[JsonPropertyNames.CustomChoices] = map;
            }

            string mask = parameter.Mask();

            if (!string.IsNullOrWhiteSpace(mask)) {
                custom = custom ?? new Dictionary<string, object>();
                custom[JsonPropertyNames.CustomMask] = mask;
            }

            if (Flags.SimpleDomainModel) {
                Extensions = RestUtils.GetExtensions(friendlyname: parameter.Name(),
                                                     description: parameter.Description(),
                                                     pluralName: null,
                                                     domainType: null,
                                                     isService: null,
                                                     hasParams: null,
                                                     optional: !parameter.IsMandatory(),
                                                     maxLength: parameter.MaxLength(),
                                                     pattern: parameter.Pattern(),
                                                     memberOrder: null,
                                                     customExtensions: custom,
                                                     returnType: parameter.Specification);
            }
            else {
                Extensions = MapRepresentation.Create();
            }
        }
 public bool DefaultTypeIsExplicit(INakedObjectSurface nakedObject)
 {
     return(nakedObjectActionParameter.GetDefaultType(((NakedObjectWrapper)nakedObject).WrappedNakedObject) == TypeOfDefaultValue.Explicit);
 }
 public INakedObjectSurface[] GetCompletions(INakedObjectSurface nakedObject, string autoCompleteParm)
 {
     return(nakedObjectActionParameter.GetCompletions(((NakedObjectWrapper)nakedObject).WrappedNakedObject, autoCompleteParm).Select(no => NakedObjectWrapper.Wrap(no, Surface, framework)).Cast <INakedObjectSurface>().ToArray());
 }
        public Tuple <INakedObjectSurface, string>[] GetChoicesAndTitles(INakedObjectSurface nakedObject, IDictionary <string, INakedObjectSurface> parameterNameValues)
        {
            var choices = GetChoices(nakedObject, parameterNameValues);

            return(choices.Select(c => new Tuple <INakedObjectSurface, string>(c, c.TitleString())).ToArray());
        }
Beispiel #36
0
 public INakedObjectSurface GetDefault(INakedObjectSurface nakedObject) {
     return NakedObjectWrapper.Wrap(nakedObjectActionParameter.GetDefault(((NakedObjectWrapper)nakedObject).WrappedNakedObject), Surface);
 }
Beispiel #37
0
 public IConsentSurface IsUsable(INakedObjectSurface nakedObject) {
     return new ConsentWrapper(action.IsUsable(NakedObjectsContext.Session, ((NakedObjectWrapper) nakedObject).WrappedNakedObject));
 }
Beispiel #38
0
 protected ParameterRepresentation(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter, RestControlFlags flags) : base(flags) {
     SetName(parameter);
     SetExtensions(req, nakedObject, parameter, flags);
     SetLinks(req, nakedObject, parameter);
     SetHeader(nakedObject);
 }
Beispiel #39
0
 public static object GetChoiceValue(HttpRequestMessage req, INakedObjectSurface item, INakedObjectAssociationSurface property, RestControlFlags flags) {
     return GetChoiceValue(item, new ChoiceRelType(property, new UriMtHelper(req, item)), flags);
 }
Beispiel #40
0
 public static object GetChoiceValue(HttpRequestMessage req, INakedObjectSurface item, INakedObjectActionParameterSurface parameter, RestControlFlags flags) {
     return GetChoiceValue(item, new ChoiceRelType(parameter, new UriMtHelper(req, item)), flags);
 }
 protected void SetHeader(INakedObjectSurface target)
 {
     SetEtag(target);
 }
Beispiel #42
0
 public static string SafeGetTitle(INakedObjectSurface no) {
     return no == null ? "" : no.TitleString();
 }
Beispiel #43
0
 public INakedObjectSurface GetNakedObject(INakedObjectSurface target) {
     INakedObject result = assoc.GetNakedObject(((NakedObjectWrapper) target).WrappedNakedObject);
     return NakedObjectWrapper.Wrap(result, Surface);
 }
Beispiel #44
0
 public static string SafeGetTitle(INakedObjectAssociationSurface property, INakedObjectSurface valueNakedObject) {
     return valueNakedObject == null ? "" : property.GetTitle(valueNakedObject);
 }
Beispiel #45
0
 public bool IsEager(INakedObjectSurface nakedObject) {
     return ((NakedObjectSpecificationWrapper) nakedObject.Specification).WrappedValue.ContainsFacet<IEagerlyFacet>() ||
            assoc.ContainsFacet<IEagerlyFacet>();
 }
Beispiel #46
0
 private void SetHeader(INakedObjectSurface target) {
     caching = CacheType.Transactional;
     SetEtag(target);
 }
Beispiel #47
0
 public Tuple<INakedObjectSurface, string>[] GetChoicesAndTitles(INakedObjectSurface target, IDictionary<string, INakedObjectSurface> parameterNameValues) {
     var choices = GetChoices(target, parameterNameValues);
     return choices.Select(c => new Tuple<INakedObjectSurface, string>(c, c.TitleString())).ToArray();
 }
Beispiel #48
0
 private void SetHeader(INakedObjectSurface target)
 {
     caching = CacheType.Transactional;
     SetEtag(target);
 }
Beispiel #49
0
 public int Count(INakedObjectSurface target) {
     if (IsCollection) {
         INakedObject result = assoc.GetNakedObject(((NakedObjectWrapper) target).WrappedNakedObject);
         return result.GetCollectionFacetFromSpec().AsQueryable(result).Count();
     }
     return 0;
 }
Beispiel #50
0
 public static bool IsTransient(this INakedObjectSurface nakedObjectSurface)
 {
     return(nakedObjectSurface.GetScalarProperty <bool>(ScalarProperty.IsTransient));
 }
Beispiel #51
0
 private static LinkRepresentation CreateDefaultLink(HttpRequestMessage req, INakedObjectActionParameterSurface parameter, INakedObjectSurface defaultNakedObject, string title, RestControlFlags flags) {
     return LinkRepresentation.Create(new DefaultRelType(parameter, new UriMtHelper(req, defaultNakedObject)), flags, new OptionalProperty(JsonPropertyNames.Title, title));
 }
Beispiel #52
0
 public static string TitleString(this INakedObjectSurface nakedObjectSurface)
 {
     return(nakedObjectSurface.GetScalarProperty <string>(ScalarProperty.TitleString));
 }
Beispiel #53
0
        public static ParameterRepresentation Create(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter, RestControlFlags flags) {
            var optionals = new List<OptionalProperty>();
            
            if (parameter.IsChoicesEnabled && !parameter.GetChoicesParameters().Any()) {
                INakedObjectSurface[] choices = parameter.GetChoices(nakedObject, null);
                object[] choicesArray = choices.Select(c => RestUtils.GetChoiceValue(req, c, parameter, flags)).ToArray();
                optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
            }

            if (parameter.DefaultTypeIsExplicit(nakedObject)) {
                INakedObjectSurface defaultNakedObject = parameter.GetDefault(nakedObject);
                if (defaultNakedObject != null) {
                    string title = defaultNakedObject.TitleString();
                    object value = RestUtils.ObjectToPredefinedType(defaultNakedObject.Object);
                    var isValue = defaultNakedObject.Specification.IsParseable() || (defaultNakedObject.Specification.IsCollection() && defaultNakedObject.ElementSpecification.IsParseable());
                    object defaultValue = isValue ? value : CreateDefaultLinks(req, parameter, defaultNakedObject, title, flags);

                    optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue));
                }
            }
                 
            if (optionals.Count == 0) {
                return new ParameterRepresentation(req, nakedObject, parameter, flags);
            }
            return CreateWithOptionals<ParameterRepresentation>(new object[] {req, nakedObject, parameter, flags}, optionals);
        }
Beispiel #54
0
 public static IDictionary <string, object> ExtensionData(this INakedObjectSurface nakedObjectSurface)
 {
     return(nakedObjectSurface.GetScalarProperty <IDictionary <string, object> >(ScalarProperty.ExtensionData));
 }
Beispiel #55
0
 private void SetHeader(INakedObjectSurface nakedObject) {
     SetEtag(nakedObject);
 }
Beispiel #56
0
        private LinkRepresentation CreateObjectLink(HttpRequestMessage req, INakedObjectSurface no) {
            var helper = new UriMtHelper(req, no);
            ObjectRelType rt = no.Specification.IsService() ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper);

            return LinkRepresentation.Create(rt, Flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(no)));
        }
 public INakedObjectSurface GetDefault(INakedObjectSurface nakedObject)
 {
     return(NakedObjectWrapper.Wrap(nakedObjectActionParameter.GetDefault(((NakedObjectWrapper)nakedObject).WrappedNakedObject), Surface, framework));
 }
Beispiel #58
0
 protected void SetHeader(INakedObjectSurface target) {
     SetEtag(target);
 }
 public ObjectContextSurface GetObject(INakedObjectSurface nakedObject) {
     return MapErrors(() => GetObjectContext(((NakedObjectWrapper) nakedObject).WrappedNakedObject).ToObjectContextSurface(this, framework));
 }
Beispiel #60
0
 public static object GetChoiceValue(INakedObjectSurface item, ChoiceRelType relType, RestControlFlags flags) {
     string title = SafeGetTitle(item);
     object value = ObjectToPredefinedType(item.Object);
     return item.Specification.IsParseable() ? value : LinkRepresentation.Create(relType, flags, new OptionalProperty(JsonPropertyNames.Title, title));
 }