private IDictionary <string, object> GetCustomPropertyExtensions()
        {
            IDictionary <string, object> custom = propertyContext.Property.ExtensionData;

            if (IsUnconditionalChoices())
            {
                Tuple <IObjectFacade, string>[] choices      = propertyContext.Property.GetChoicesAndTitles(propertyContext.Target, null);
                Tuple <object, string>[]        choicesArray = choices.Select(tuple => new Tuple <object, string>(RestUtils.GetChoiceValue(OidStrategy, req, tuple.Item1, propertyContext.Property, 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 = propertyContext.Property.Mask;

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

            return(custom);
        }
Example #2
0
        public static OptionalProperty CreateArgumentProperty(HttpRequestMessage req, Tuple <string, INakedObjectSpecificationSurface> pnt, RestControlFlags flags)
        {
            var tempLinks = new List <LinkRepresentation>();

            if (flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.DescribedBy, new UriMtHelper(req, pnt.Item2)), flags));
            }

            return(new OptionalProperty(pnt.Item1, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object)),
                                                                            new OptionalProperty(JsonPropertyNames.Links, tempLinks.ToArray()))));
        }
        protected void AddChoicesCustomExtension()
        {
            if (AddChoices())
            {
                CustomExtensions = CustomExtensions ?? new Dictionary <string, object>();

                Tuple <IObjectFacade, string>[] choices      = PropertyContext.Property.GetChoicesAndTitles(PropertyContext.Target, null);
                Tuple <object, string>[]        choicesArray = choices.Select(tuple => new Tuple <object, string>(RestUtils.GetChoiceValue(OidStrategy, Req, tuple.Item1, PropertyContext.Property, Flags), tuple.Item2)).ToArray();

                OptionalProperty[] op  = choicesArray.Select(tuple => new OptionalProperty(tuple.Item2, tuple.Item1)).ToArray();
                MapRepresentation  map = MapRepresentation.Create(op);

                CustomExtensions[JsonPropertyNames.CustomChoices] = map;
            }
        }
        private LinkRepresentation CreatePromptLink()
        {
            var opts = new List <OptionalProperty>();

            if (propertyContext.Property.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, propertyContext.Property.AutoCompleteMinLength)));

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

            return(LinkRepresentation.Create(OidStrategy, new PromptRelType(new UriMtHelper(OidStrategy, req, propertyContext)), Flags, opts.ToArray()));
        }
Example #5
0
        public static IDictionary <string, object> AddRangeExtension(IFieldFacade field, IDictionary <string, object> customExtensions)
        {
            var range = field.Range;

            if (range != null)
            {
                customExtensions = customExtensions ?? new Dictionary <string, object>();

                var propertyType = field.Specification.GetUnderlyingType();

                object min;
                object max;

                if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
                {
                    var minDays = (double)range.Item1.ToType(typeof(double), null);
                    var maxDays = (double)range.Item2.ToType(typeof(double), null);

                    DateTime earliest = DateTime.Today.AddDays(minDays);
                    DateTime latest   = DateTime.Today.AddDays(maxDays);

                    min = ToDateFormatString(earliest);
                    max = ToDateFormatString(latest);
                }
                else
                {
                    min = range.Item1.ToType(propertyType, null);
                    max = range.Item2.ToType(propertyType, null);
                }

                OptionalProperty[] op  = { new OptionalProperty("min", min), new OptionalProperty("max", max) };
                MapRepresentation  map = MapRepresentation.Create(op);
                customExtensions[JsonPropertyNames.CustomRange] = map;
            }
            return(customExtensions);
        }
Example #6
0
        protected LinkRepresentation CreatePersistPromptLink()
        {
            var opts = new List <OptionalProperty>();

            var ids   = PropertyContext.Target.Specification.Properties.Where(p => !p.IsCollection && !p.IsInline).ToDictionary(p => p.Id, p => GetPropertyValue(OidStrategy, Req, p, PropertyContext.Target, Flags, true, UseDateOverDateTime())).ToArray();
            var props = ids.Select(kvp => new OptionalProperty(kvp.Key, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, kvp.Value)))).ToArray();

            var objectMembers = new OptionalProperty(JsonPropertyNames.PromptMembers, MapRepresentation.Create(props));

            if (PropertyContext.Property.IsAutoCompleteEnabled)
            {
                var searchTerm = new OptionalProperty(JsonPropertyNames.XRoSearchTerm, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))));
                var arguments  = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(objectMembers, searchTerm));

                var extensions = new OptionalProperty(JsonPropertyNames.Extensions, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.MinLength, PropertyContext.Property.AutoCompleteMinLength)));

                opts.Add(arguments);
                opts.Add(extensions);
            }
            else
            {
                var parms = PropertyContext.Property.GetChoicesParameters();
                var conditionalArguments = parms.Select(pnt => RestUtils.CreateArgumentProperty(OidStrategy, Req, pnt, Flags));
                var args = new List <OptionalProperty> {
                    objectMembers
                };
                args.AddRange(conditionalArguments);
                var arguments = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args.ToArray()));
                opts.Add(arguments);
            }

            return(LinkRepresentation.Create(OidStrategy, new PromptRelType(GetHelper())
            {
                Method = RelMethod.Put
            }, Flags, opts.ToArray()));
        }
Example #7
0
        protected virtual LinkRepresentation CreateActionLink()
        {
            var optionalProperties = parameterList.Select(pr => new OptionalProperty(pr.Name, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))).ToList();

            var method = GetRelMethod();

            return(LinkRepresentation.Create(OidStrategy, new InvokeRelType(new UriMtHelper(OidStrategy, Req, ActionContext))
            {
                Method = method
            }, Flags,
                                             new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(optionalProperties.ToArray()))));
        }
Example #8
0
 public static OptionalProperty CreateArgumentProperty(IOidStrategy oidStrategy, HttpRequestMessage req, Tuple <string, ITypeFacade> pnt, RestControlFlags flags)
 {
     return(new OptionalProperty(pnt.Item1, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object)),
                                                                     new OptionalProperty(JsonPropertyNames.Links, new LinkRepresentation[] {}))));
 }
Example #9
0
 public static MapRepresentation CreateMap(Dictionary <string, object> exts)
 {
     OptionalProperty[] parms = exts.Select(e => new OptionalProperty(e.Key, e.Value)).ToArray();
     return(MapRepresentation.Create(parms));
 }
 public MapRepresentation GetExtensions()
 {
     return(Flags.SimpleDomainModel ? GetExtensionsForSimple() : MapRepresentation.Create());
 }
 private LinkRepresentation CreateModifyLink()
 {
     return(LinkRepresentation.Create(OidStrategy, new MemberRelType(RelValues.Modify, new UriMtHelper(OidStrategy, req, propertyContext))
     {
         Method = RelMethod.Put
     }, Flags,
                                      new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))));
 }
Example #12
0
        private LinkRepresentation CreateActionLink()
        {
            List <OptionalProperty> optionalProperties = parameterList.Select(pr => new OptionalProperty(pr.Name, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))).ToList();

            RelMethod method = GetRelMethod();

            return(LinkRepresentation.Create(new InvokeRelType(new UriMtHelper(req, actionContext))
            {
                Method = method
            }, Flags,
                                             new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(optionalProperties.ToArray()))));
        }