コード例 #1
0
        public ErrorRepresentation(IOidStrategy oidStrategy, Exception e)
            : base(oidStrategy, 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();
        }
コード例 #2
0
        public ErrorRepresentation(IOidStrategy oidStrategy, Exception e)
            : base(oidStrategy, 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();
        }
コード例 #3
0
        private MapRepresentation CreateArguments(HttpRequest req, ActionResultContextFacade actionResult)
        {
            var optionalProperties = new List <OptionalProperty>();

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

                if (visibleParamContext.Specification.IsParseable)
                {
                    var proposedObj = visibleParamContext.ProposedObjectFacade == null ? visibleParamContext.ProposedValue : visibleParamContext.ProposedObjectFacade?.Object;
                    var valueObj    = proposedObj != null?RestUtils.ObjectToPredefinedType(proposedObj) : null;

                    value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueObj));
                }
                else if (visibleParamContext.Specification.IsCollection)
                {
                    if (visibleParamContext.ElementSpecification.IsParseable)
                    {
                        var proposedEnumerable = (visibleParamContext.ProposedObjectFacade == null
                            ? visibleParamContext.ProposedValue
                            : visibleParamContext.ProposedObjectFacade?.Object) as IEnumerable;

                        var proposedCollection = proposedEnumerable == null ? new object[] { } : proposedEnumerable.Cast <object>();

                        var valueObjs = proposedCollection.Select(i => RestUtils.ObjectToPredefinedType(i)).ToArray();
                        value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueObjs));
                    }
                    else
                    {
                        var refNos = visibleParamContext.ProposedObjectFacade.ToEnumerable().Select(no => no).ToArray();
                        var refs   = refNos.Select(no => RefValueRepresentation.Create(OidStrategy, new ObjectRelType(RelValues.Self, new UriMtHelper(OidStrategy, req, no)), Flags)).ToArray();

                        value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, refs));
                    }
                }
                else
                {
                    RefValueRepresentation valueRef = null;
                    if (visibleParamContext.ProposedObjectFacade != null)
                    {
                        valueRef = RefValueRepresentation.Create(OidStrategy, new ObjectRelType(RelValues.Self, new UriMtHelper(OidStrategy, req, visibleParamContext.ProposedObjectFacade)), Flags);
                    }

                    value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueRef));
                }

                optionalProperties.Add(new OptionalProperty(visibleParamContext.Id, value));
            }

            return(MapRepresentation.Create(optionalProperties.ToArray()));
        }
コード例 #4
0
        private void SetExtensions(HttpRequestMessage req, IObjectFacade objectFacade, FieldFacadeAdapter parameter, RestControlFlags flags)
        {
            IDictionary <string, object> custom = null;

            if (IsUnconditionalChoices(parameter))
            {
                custom = new Dictionary <string, object>();

                Tuple <IObjectFacade, string>[] choices      = parameter.GetChoicesAndTitles(objectFacade, null);
                Tuple <object, string>[]        choicesArray = choices.Select(tuple => new Tuple <object, string>(parameter.GetChoiceValue(OidStrategy, req, tuple.Item1, flags), tuple.Item2)).ToArray();

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

            string mask = parameter.Mask;

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

            var multipleLines = parameter.NumberOfLines;

            if (multipleLines > 1)
            {
                custom = custom ?? new Dictionary <string, object>();
                custom[JsonPropertyNames.CustomMultipleLines] = multipleLines;
            }

            custom = RestUtils.AddRangeExtension(parameter.AsField, custom);

            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,
                                                 dataType: parameter.DataType,
                                                 presentationHint: parameter.PresentationHint,
                                                 customExtensions: custom,
                                                 returnType: parameter.Specification,
                                                 elementType: parameter.ElementType,
                                                 oidStrategy: OidStrategy,
                                                 useDateOverDateTime: true);
        }
コード例 #5
0
        private void SetMembers(IMenuFacade menu, HttpRequestMessage req, List <LinkRepresentation> tempLinks)
        {
            var actionFacades = menu.MenuItems.SelectMany(i => GetMenuItem(i)).Where(af => IsVisibleAndUsable(af.Item2));

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

            var eq = new Eq();

            // todo fix distinct
            actions = actions.Distinct(eq).ToArray();

            Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m));
        }
コード例 #6
0
        private void SetLinks(HttpRequest req, TypeActionInvokeContext context)
        {
            var 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();
        }
コード例 #7
0
        private void SetMembers(IMenuFacade menu, HttpRequest req)
        {
            ActionContextFacade SetMenuId(ActionContextFacade action)
            {
                action.MenuId = menu.Id;
                return(action);
            }

            var actionFacades = menu.MenuItems.SelectMany(i => GetMenuItem(i)).Where(af => IsVisibleAndUsable(af.action)).ToArray();

            var actions = actionFacades.Select(a => InlineActionRepresentation.Create(OidStrategy, req, SetMenuId(a.action), Flags)).ToArray();

            var actionComparer = new ActionComparer();

            actions = actions.Distinct(actionComparer).ToArray();

            Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m));
        }
        // custom extension for pagination 
        private void SetPagination(IObjectFacade list, RestControlFlags flags, ActionContextFacade actionContext) {
            Pagination = new MapRepresentation();

            var totalCount = list.Count();
            var pageSize = PageSize(flags, actionContext);
            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> {
                {JsonPropertyNames.Page, page},
                {JsonPropertyNames.PageSize, pageSize},
                {JsonPropertyNames.NumPages, numPages},
                {JsonPropertyNames.TotalCount, totalCount}
            };

            Pagination = RestUtils.CreateMap(exts);
        }
コード例 #9
0
        // custom extension for pagination
        private void SetPagination(IObjectFacade list, RestControlFlags flags, ActionContextFacade actionContext)
        {
            Pagination = new MapRepresentation();

            var totalCount = list.Count();
            var pageSize   = PageSize(flags, actionContext);
            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> {
                { JsonPropertyNames.Page, page },
                { JsonPropertyNames.PageSize, pageSize },
                { JsonPropertyNames.NumPages, numPages },
                { JsonPropertyNames.TotalCount, totalCount }
            };

            Pagination = RestUtils.CreateMap(exts);
        }
コード例 #10
0
        private LinkRepresentation CreatePromptLink(HttpRequest req, IObjectFacade objectFacade, FieldFacadeAdapter parameter)
        {
            var opts = new List <OptionalProperty>();

            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
            {
                var parms     = parameter.GetChoicesParameters();
                var args      = parms.Select(tuple => RestUtils.CreateArgumentProperty(OidStrategy, req, tuple, Flags)).ToArray();
                var arguments = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args));
                opts.Add(arguments);
            }

            return(LinkRepresentation.Create(OidStrategy, new PromptRelType(parameter.GetHelper(OidStrategy, req, objectFacade)), Flags, opts.ToArray()));
        }
 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));
 }
コード例 #12
0
 private void SetExtensions()
 {
     Extensions = new MapRepresentation();
 }
コード例 #13
0
 private void SetExtensions() {
     Extensions = new MapRepresentation();
 }
コード例 #14
0
 private void SetExtensions() => Extensions = MapRepresentation.Create();
コード例 #15
0
        private void SetOptionalCapabilities(IDictionary <string, string> capabilitiesMap)
        {
            var properties = capabilitiesMap.Select(kvp => new OptionalProperty(kvp.Key, kvp.Value)).ToArray();

            OptionalCapabilities = MapRepresentation.Create(properties);
        }
コード例 #16
0
 private void SetExtensions() {
     Extensions = MapRepresentation.Create();
 }
コード例 #17
0
        private void SetMembers(ObjectContextFacade objectContext, HttpRequest req, List <LinkRepresentation> tempLinks)
        {
            var visiblePropertiesAndCollections = objectContext.VisibleProperties;

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

            var visibleProperties = visiblePropertiesAndCollections.Where(p => !p.Property.IsCollection).ToArray();

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

                var helper = GetHelper(OidStrategy, req, objectContext);

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

                tempLinks.Add(modifyLink);
            }

            if (IsProtoPersistent(objectContext.Target))
            {
                var ids = objectContext.Target.Specification.Properties.Where(p => !p.IsCollection && !p.IsInline).ToDictionary(p => p.Id, p => {
                    var useDate = p.IsDateOnly;
                    return(GetPropertyValue(OidStrategy, req, p, objectContext.Target, Flags, true, useDate));
                }).ToArray();
                var 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
                };

                var 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);
            }

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

            ActionContextFacade[] visibleActions;

            if (IsProtoPersistent(objectContext.Target))
            {
                visibleActions = new ActionContextFacade[] { };
            }
            else if (IsForm(objectContext.Target))
            {
                visibleActions = objectContext.VisibleActions.Where(af => af.Action.ParameterCount == 0).ToArray();
            }
            else
            {
                visibleActions = FilterLocallyContributedActions(objectContext.VisibleActions, visiblePropertiesAndCollections.Where(p => p.Property.IsCollection).ToArray());
            }

            var actions = visibleActions.Select(a => InlineActionRepresentation.Create(OidStrategy, req, a, Flags)).ToArray();

            var allMembers = properties.Union(actions);

            Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object)m));
        }
コード例 #18
0
        private LinkRepresentation[] CreateIsOfTypeLinks(HttpRequest req, ObjectContextFacade objectContext)
        {
            var spec = objectContext.Target.Specification;

            return(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.Value, 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.Value, null, typeof(object)))))))
            });
        }
コード例 #19
0
        private void SetActions(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequest req, RestControlFlags flags)
        {
            var actions = objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(oidStrategy, req, a, flags)).ToArray();

            Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m));
        }
        private void SetExtensions(HttpRequestMessage req, IObjectFacade objectFacade, FieldFacadeAdapter parameter, RestControlFlags flags) {
            IDictionary<string, object> custom = null;

            if (IsUnconditionalChoices(parameter)) {
                custom = new Dictionary<string, object>();

                Tuple<IObjectFacade, string>[] choices = parameter.GetChoicesAndTitles(objectFacade, null);
                Tuple<object, string>[] choicesArray = choices.Select(tuple => new Tuple<object, string>(parameter.GetChoiceValue(OidStrategy, req, tuple.Item1, flags), tuple.Item2)).ToArray();

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

            string mask = parameter.Mask;

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

            var multipleLines = parameter.NumberOfLines;

            if (multipleLines > 1) {
                custom = custom ?? new Dictionary<string, object>();
                custom[JsonPropertyNames.CustomMultipleLines] = multipleLines;
            }

            custom = RestUtils.AddRangeExtension(parameter.AsField, custom);

            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,
                                                  dataType: parameter.DataType,
                                                  presentationHint: parameter.PresentationHint,
                                                  customExtensions: custom,
                                                  returnType: parameter.Specification,
                                                  elementType: parameter.ElementType,
                                                  oidStrategy: OidStrategy,
                                                  useDateOverDateTime: true);
        }
コード例 #21
0
 private void SetOptionalCapabilities(IDictionary<string, string> capabilitiesMap) {
     OptionalProperty[] properties = capabilitiesMap.Select(kvp => new OptionalProperty(kvp.Key, kvp.Value)).ToArray();
     OptionalCapabilities = MapRepresentation.Create(properties);
 }
コード例 #22
0
 private void SetExtensions(IMenuFacade menu)
 {
     Extensions = MapRepresentation.Create();
 }
コード例 #23
0
        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 (!IsProtoPersistent(objectContext.Target) && !IsForm(objectContext.Target) && 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();

                var helper = GetHelper(OidStrategy, req, objectContext);

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

                tempLinks.Add(modifyLink);
            }

            if (IsProtoPersistent(objectContext.Target)) {
                KeyValuePair<string, object>[] ids = objectContext.Target.Specification.Properties.Where(p => !p.IsCollection && !p.IsInline).ToDictionary(p => p.Id, p => {

                    var useDate = p.IsDateOnly;
                    return GetPropertyValue(OidStrategy, req, p, objectContext.Target, Flags, true, useDate);
                }).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, false)).ToArray();

            ActionContextFacade[] visibleActions;

            if (IsProtoPersistent(objectContext.Target)) {
                visibleActions = new ActionContextFacade[] {};
            }
            else if (IsForm(objectContext.Target)) {
                visibleActions = objectContext.VisibleActions.Where(af => af.Action.ParameterCount == 0).ToArray();
            }
            else {
                visibleActions = FilterLocallyContributedActions(objectContext.VisibleActions, visiblePropertiesAndCollections.Where(p => p.Property.IsCollection).ToArray());
            }

            InlineActionRepresentation[] actions = 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));
        }