Exemplo n.º 1
0
        private void SetExtensions(HttpRequestMessage req, IObjectFacade objectFacade, IActionParameterFacade parameter, RestControlFlags flags)
        {
            IDictionary <string, object> custom = parameter.ExtensionData;

            if (IsUnconditionalChoices(parameter))
            {
                Tuple <IObjectFacade, string>[] choices      = parameter.GetChoicesAndTitles(objectFacade, null);
                Tuple <object, string>[]        choicesArray = choices.Select(tuple => new Tuple <object, string>(RestUtils.GetChoiceValue(OidStrategy, 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(parameter.Name, parameter.Description, null, null, null, null, !parameter.IsMandatory, parameter.MaxLength, parameter.Pattern, null, custom, parameter.Specification, parameter.ElementType, OidStrategy);
            }
            else
            {
                Extensions = MapRepresentation.Create();
            }
        }
        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()));
        }
Exemplo n.º 3
0
        private void SetMembers(IMenuFacade menu, HttpRequestMessage req, List <LinkRepresentation> tempLinks)
        {
            var actionFacades = menu.MenuItems.SelectMany(i => GetMenuItem(i));

            InlineActionRepresentation[] actions = actionFacades.Select(a => InlineActionRepresentation.Create(OidStrategy, req, a.Item2, Flags)).ToArray();

            Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m));
        }
Exemplo n.º 4
0
        public ErrorRepresentation(Exception e) : base(RestControlFlags.DefaultFlags()) {
            Exception exception = GetInnermostException(e);
            Message = exception.Message;
            StackTrace = exception.StackTrace.Split('\n').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

            Links = new LinkRepresentation[] {};
            Extensions = new MapRepresentation();
        }
        public ErrorRepresentation(Exception e) : base(RestControlFlags.DefaultFlags())
        {
            Exception exception = GetInnermostException(e);

            Message    = exception.Message;
            StackTrace = exception.StackTrace.Split('\n').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

            Links      = new LinkRepresentation[] {};
            Extensions = new MapRepresentation();
        }
        private void SetMembers(ObjectContextSurface objectContext, HttpRequestMessage req, List <LinkRepresentation> tempLinks)
        {
            PropertyContextSurface[] visiblePropertiesAndCollections = objectContext.VisibleProperties;

            if (!Flags.BlobsClobs)
            {
                // filter any blobs and clobs
                visiblePropertiesAndCollections = visiblePropertiesAndCollections.Where(vp => !RestUtils.IsBlobOrClob(vp.Specification)).ToArray();
            }

            PropertyContextSurface[] visibleProperties = visiblePropertiesAndCollections.Where(p => !p.Property.IsCollection()).ToArray();

            if (!objectContext.Target.IsTransient() && visibleProperties.Any(p => p.Property.IsUsable(objectContext.Target).IsAllowed))
            {
                string[]           ids   = visibleProperties.Where(p => p.Property.IsUsable(objectContext.Target).IsAllowed&& !p.Property.IsInline()).Select(p => p.Id).ToArray();
                OptionalProperty[] props = ids.Select(s => new OptionalProperty(s, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))).ToArray();

                LinkRepresentation modifyLink = LinkRepresentation.Create(new ObjectRelType(RelValues.Update, new UriMtHelper(req, objectContext.Target))
                {
                    Method = RelMethod.Put
                }, Flags,
                                                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(props)));

                tempLinks.Add(modifyLink);
            }

            if (objectContext.Target.IsTransient())
            {
                KeyValuePair <string, object>[] ids = objectContext.Target.Specification.Properties.Where(p => !p.IsCollection() && !p.IsInline()).ToDictionary(p => p.Id, p => GetPropertyValue(req, p, objectContext.Target, Flags, true)).ToArray();
                OptionalProperty[] props            = ids.Select(kvp => new OptionalProperty(kvp.Key, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, kvp.Value)))).ToArray();

                var argMembers = new OptionalProperty(JsonPropertyNames.Members, MapRepresentation.Create(props));
                var args       = new List <OptionalProperty> {
                    argMembers
                };

                LinkRepresentation persistLink = LinkRepresentation.Create(new ObjectsRelType(RelValues.Persist, new UriMtHelper(req, objectContext.Target.Specification))
                {
                    Method = RelMethod.Post
                }, Flags,
                                                                           new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args.ToArray())));

                tempLinks.Add(persistLink);
            }

            InlineMemberAbstractRepresentation[] properties = visiblePropertiesAndCollections.Select(p => InlineMemberAbstractRepresentation.Create(req, p, Flags)).ToArray();

            InlineActionRepresentation[] actions = objectContext.Target.IsTransient() ? new InlineActionRepresentation[] {}
                : objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(req, a, Flags)).ToArray();


            IEnumerable <InlineMemberAbstractRepresentation> allMembers = properties.Union(actions);

            Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object)m));
        }
Exemplo n.º 7
0
 private void SetExtensions(IObjectFacade objectFacade)
 {
     if (Flags.SimpleDomainModel)
     {
         Extensions = RestUtils.GetExtensions(objectFacade.Specification.SingularName, objectFacade.Specification.Description, objectFacade.Specification.PluralName, objectFacade.Specification.DomainTypeName(OidStrategy), objectFacade.Specification.IsService, null, null, null, null, null, GetCustomExtensions(objectFacade), null, null, OidStrategy);
     }
     else
     {
         Extensions = MapRepresentation.Create();
     }
 }
        private void SetLinks(HttpRequestMessage req, FilterFromInvokeContext context)
        {
            var uris = context.OtherSpecifications.Select(os => new DomainTypeRelType(new UriMtHelper(OidStrategy, req, os)).GetUri().AbsoluteUri).ToArray();

            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, SelfRelType,
                                          Flags,
                                          new OptionalProperty(JsonPropertyNames.Arguments,
                                                               MapRepresentation.Create(new OptionalProperty(context.ParameterId, uris.Select(uri =>
                                                                                                                                              MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href,
                                                                                                                                                                                            uri))).ToArray()))))
            };

            Links = tempLinks.ToArray();
        }
        private void SetLinks(HttpRequestMessage req, TypeActionInvokeContext context)
        {
            string uri = new DomainTypeRelType(new UriMtHelper(OidStrategy, req, context.OtherSpecification)).GetUri().AbsoluteUri;

            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, SelfRelType,
                                          Flags,
                                          new OptionalProperty(JsonPropertyNames.Arguments,
                                                               MapRepresentation.Create(new OptionalProperty(context.ParameterId,
                                                                                                             MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href,
                                                                                                                                                           uri))))))
            };

            Links = tempLinks.ToArray();
        }
        // custom extension for pagination 
        private void SetPagination(IObjectFacade list, RestControlFlags flags) {
            Pagination = new MapRepresentation();

            var totalCount = list.Count();
            var pageSize = flags.PageSize ;
            var page = flags.Page;
            var numPages = (int)Math.Round(totalCount / (decimal)pageSize + 0.5m);
            numPages = numPages == 0 ? 1 : numPages;

            var exts = new Dictionary<string, object> {
                {"page", page},
                {"pageSize", pageSize},
                {"numPages", numPages},
                {"totalCount", totalCount}
            };

            Pagination = RestUtils.CreateMap(exts);
        }
        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();
            }
        }
        // custom extension for pagination
        private void SetPagination(IObjectFacade list, RestControlFlags flags)
        {
            Pagination = new MapRepresentation();

            var totalCount = list.Count();
            var pageSize   = flags.PageSize;
            var page       = flags.Page;
            var numPages   = (int)Math.Round(totalCount / (decimal)pageSize + 0.5m);

            numPages = numPages == 0 ? 1 : numPages;

            var exts = new Dictionary <string, object> {
                { "page", page },
                { "pageSize", pageSize },
                { "numPages", numPages },
                { "totalCount", totalCount }
            };

            Pagination = RestUtils.CreateMap(exts);
        }
        private MapRepresentation CreateArguments(HttpRequestMessage req, ActionResultContextSurface actionResult)
        {
            var optionalProperties = new List <OptionalProperty>();

            foreach (ParameterContextSurface visibleParamContext in actionResult.ActionContext.VisibleParameters)
            {
                IRepresentation value;

                if (visibleParamContext.Specification.IsParseable())
                {
                    object proposedObj = visibleParamContext.ProposedNakedObject == null ? visibleParamContext.ProposedValue : visibleParamContext.ProposedNakedObject.Object;
                    object valueObj    = RestUtils.ObjectToPredefinedType(proposedObj);
                    value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueObj));
                }
                else if (visibleParamContext.Specification.IsCollection())
                {
                    if (visibleParamContext.ElementSpecification.IsParseable())
                    {
                        var proposedCollection = ((IEnumerable)(visibleParamContext.ProposedNakedObject == null ? visibleParamContext.ProposedValue : visibleParamContext.ProposedNakedObject.Object)).Cast <object>();
                        var valueObjs          = proposedCollection.Select(RestUtils.ObjectToPredefinedType).ToArray();
                        value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueObjs));
                    }
                    else
                    {
                        var refNos = visibleParamContext.ProposedNakedObject.ToEnumerable().Select(no => no).ToArray();
                        var refs   = refNos.Select(no => RefValueRepresentation.Create(new ObjectRelType(RelValues.Self, new UriMtHelper(req, no)), Flags)).ToArray();

                        value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, refs));
                    }
                }
                else
                {
                    var valueRef = RefValueRepresentation.Create(new ObjectRelType(RelValues.Self, new UriMtHelper(req, visibleParamContext.ProposedNakedObject)), Flags);
                    value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueRef));
                }

                optionalProperties.Add(new OptionalProperty(visibleParamContext.Id, value));
            }
            return(MapRepresentation.Create(optionalProperties.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();
     }
 }
 private void SetExtensions()
 {
     Extensions = new MapRepresentation();
 }
Exemplo n.º 16
0
 private void SetExtensions() {
     Extensions = new MapRepresentation();
 }
Exemplo n.º 17
0
 private void SetTypeActions(INakedObjectSpecificationSurface spec, HttpRequestMessage req)
 {
     TypeActions = new[] {
         LinkRepresentation.Create(new TypeActionRelType(new UriMtHelper(req, spec), WellKnownIds.IsSubtypeOf), Flags,
                                   new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSubtypeOf),
                                   new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),
         LinkRepresentation.Create(new TypeActionRelType(new UriMtHelper(req, spec), WellKnownIds.IsSupertypeOf), Flags,
                                   new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSupertypeOf),
                                   new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object)))))))
     };
 }
        private void SetExtensions(HttpRequestMessage req, IObjectFacade objectFacade, IActionParameterFacade parameter, RestControlFlags flags) {
            IDictionary<string, object> custom = parameter.ExtensionData;

            if (IsUnconditionalChoices(parameter)) {
                Tuple<IObjectFacade, string>[] choices = parameter.GetChoicesAndTitles(objectFacade, null);
                Tuple<object, string>[] choicesArray = choices.Select(tuple => new Tuple<object, string>(RestUtils.GetChoiceValue(OidStrategy ,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(parameter.Name, parameter.Description, null, null, null, null, !parameter.IsMandatory, parameter.MaxLength, parameter.Pattern, null, custom, parameter.Specification, parameter.ElementType, OidStrategy);
            }
            else {
                Extensions = MapRepresentation.Create();
            }
        }
        private void SetMembers(ObjectContextFacade objectContext, HttpRequestMessage req, List<LinkRepresentation> tempLinks) {
            PropertyContextFacade[] visiblePropertiesAndCollections = objectContext.VisibleProperties;

            if (!Flags.BlobsClobs) {
                // filter any blobs and clobs 
                visiblePropertiesAndCollections = visiblePropertiesAndCollections.Where(vp => !RestUtils.IsBlobOrClob(vp.Specification)).ToArray();
            }

            PropertyContextFacade[] visibleProperties = visiblePropertiesAndCollections.Where(p => !p.Property.IsCollection).ToArray();

            if (!objectContext.Target.IsTransient && visibleProperties.Any(p => p.Property.IsUsable(objectContext.Target).IsAllowed)) {
                string[] ids = visibleProperties.Where(p => p.Property.IsUsable(objectContext.Target).IsAllowed && !p.Property.IsInline).Select(p => p.Id).ToArray();
                OptionalProperty[] props = ids.Select(s => new OptionalProperty(s, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof (object))))).ToArray();

                LinkRepresentation modifyLink = LinkRepresentation.Create(OidStrategy, new ObjectRelType(RelValues.Update, new UriMtHelper(OidStrategy ,req, objectContext.Target)) {Method = RelMethod.Put}, Flags,
                    new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(props)));

                tempLinks.Add(modifyLink);
            }

            if (objectContext.Target.IsTransient) {
                KeyValuePair<string, object>[] ids = objectContext.Target.Specification.Properties.Where(p => !p.IsCollection && !p.IsInline).ToDictionary(p => p.Id, p => GetPropertyValue(OidStrategy ,req, p, objectContext.Target, Flags, true)).ToArray();
                OptionalProperty[] props = ids.Select(kvp => new OptionalProperty(kvp.Key, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, kvp.Value)))).ToArray();

                var argMembers = new OptionalProperty(JsonPropertyNames.Members, MapRepresentation.Create(props));
                var args = new List<OptionalProperty> {argMembers};

                LinkRepresentation persistLink = LinkRepresentation.Create(OidStrategy, new ObjectsRelType(RelValues.Persist, new UriMtHelper(OidStrategy, req, objectContext.Target.Specification)) { Method = RelMethod.Post }, Flags,
                    new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args.ToArray())));

                tempLinks.Add(persistLink);
            }

            InlineMemberAbstractRepresentation[] properties = visiblePropertiesAndCollections.Select(p => InlineMemberAbstractRepresentation.Create(OidStrategy ,req, p, Flags)).ToArray();

            InlineActionRepresentation[] actions = objectContext.Target.IsTransient ? new InlineActionRepresentation[] {}
                : objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(OidStrategy ,req, a, Flags)).ToArray();


            IEnumerable<InlineMemberAbstractRepresentation> allMembers = properties.Union(actions);

            Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object) m));
        }
Exemplo n.º 20
0
 private void SetOptionalCapabilities(IDictionary <string, string> capabilitiesMap)
 {
     OptionalProperty[] properties = capabilitiesMap.Select(kvp => new OptionalProperty(kvp.Key, kvp.Value)).ToArray();
     OptionalCapabilities = MapRepresentation.Create(properties);
 }
 private void SetOptionalCapabilities(IDictionary<string, string> capabilitiesMap) {
     OptionalProperty[] properties = capabilitiesMap.Select(kvp => new OptionalProperty(kvp.Key, kvp.Value)).ToArray();
     OptionalCapabilities = MapRepresentation.Create(properties);
 }
        private void SetTypeActions(ITypeFacade spec, HttpRequestMessage req)
        {
            TypeActions = new[] {
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSubtypeOf), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSubtypeOf),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSupertypeOf), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSupertypeOf),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),

                // extensions to 1.1 spec
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.FilterSubtypesFrom), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.FilterSubtypesFrom),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubTypes, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.FilterSupertypesFrom), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.FilterSupertypesFrom),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperTypes, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object)))))))
            };
        }
Exemplo n.º 23
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();
            }
        }
 private void SetExtensions() {
     Extensions = MapRepresentation.Create();
 }
 private void SetActions(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags)
 {
     InlineActionRepresentation[] actions = objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(oidStrategy, req, a, flags)).ToArray();
     Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m));
 }
Exemplo n.º 26
0
 private void SetExtensions()
 {
     Extensions = MapRepresentation.Create();
 }
        private void SetMembers(IMenuFacade menu, HttpRequestMessage req, List<LinkRepresentation> tempLinks) {
            var actionFacades = menu.MenuItems.SelectMany(i => GetMenuItem(i));

            InlineActionRepresentation[] actions = actionFacades.Select(a => InlineActionRepresentation.Create(OidStrategy, req, a.Item2, Flags)).ToArray();

            Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object) m));
        }