Пример #1
0
        private static LinkRepresentation CreateDefaultLink(IOidStrategy oidStrategy, HttpRequestMessage req, FieldFacadeAdapter parameter, IActionFacade action, IObjectFacade defaultNakedObject, string title, RestControlFlags flags)
        {
            var helper  = new UriMtHelper(oidStrategy, req, defaultNakedObject);
            var relType = new DefaultRelType(action.Id, parameter.Id, helper);

            return(LinkRepresentation.Create(oidStrategy, relType, flags, new OptionalProperty(JsonPropertyNames.Title, title)));
        }
Пример #2
0
        protected LinkRepresentation CreateUpLink()
        {
            var helper        = new UriMtHelper(OidStrategy, Req, ActionContext.Target);
            var parentRelType = ActionContext.Target.Specification.IsService ? new ServiceRelType(RelValues.Up, helper) : new ObjectRelType(RelValues.Up, helper);

            return(LinkRepresentation.Create(OidStrategy, parentRelType, Flags));
        }
        protected static object GetPropertyValue(IOidStrategy oidStrategy, HttpRequestMessage req, IAssociationFacade property, IObjectFacade target, RestControlFlags flags, bool valueOnly = false)
        {
            IObjectFacade valueNakedObject = property.GetValue(target);
            string        title            = RestUtils.SafeGetTitle(property, valueNakedObject);

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

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

            var helper    = new UriMtHelper(oidStrategy, 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(oidStrategy, valueNakedObject, req, flags)));
            }

            return(LinkRepresentation.Create(oidStrategy, new ValueRelType(property, helper), flags, optionals.ToArray()));
        }
Пример #4
0
        private LinkRepresentation CreateUpLink()
        {
            var           helper        = new UriMtHelper(req, actionContext.Target);
            ObjectRelType parentRelType = actionContext.Target.Specification.IsService() ? new ServiceRelType(RelValues.Up, helper) : new ObjectRelType(RelValues.Up, helper);

            return(LinkRepresentation.Create(parentRelType, Flags));
        }
Пример #5
0
        private LinkRepresentation CreateMenuLink(IOidStrategy oidStrategy, HttpRequestMessage req, IMenuFacade menu)
        {
            var helper = new UriMtHelper(oidStrategy, req, menu);
            var rt     = new MenuRelType(helper);

            return(LinkRepresentation.Create(oidStrategy, rt, Flags, new OptionalProperty(JsonPropertyNames.Title, menu.Name)));
        }
 protected MemberRepresentationStrategy(HttpRequestMessage req, PropertyContextSurface propertyContext, RestControlFlags flags) : base(flags)
 {
     this.req             = req;
     this.propertyContext = propertyContext;
     objectUri            = new UriMtHelper(req, propertyContext);
     self = new MemberRelType(RelValues.Self, new UriMtHelper(req, propertyContext));
 }
        private static RefValueRepresentation CreateObjectRef(IOidStrategy oidStrategy, HttpRequest req, IObjectFacade no, RestControlFlags flags)
        {
            var helper = new UriMtHelper(oidStrategy, req, no);
            var rt     = new ObjectRelType(RelValues.Element, helper);

            return(RefValueRepresentation.Create(oidStrategy, rt, flags));
        }
        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))));
        }
Пример #9
0
        private LinkRepresentation CreateObjectLink(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade no)
        {
            var           helper = new UriMtHelper(oidStrategy, req, no);
            ObjectRelType rt     = no.Specification.IsService ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper);

            return(LinkRepresentation.Create(oidStrategy, rt, Flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(no))));
        }
 protected MemberRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy, flags)
 {
     Req             = req;
     PropertyContext = propertyContext;
     objectUri       = new UriMtHelper(oidStrategy, req, propertyContext);
     self            = new MemberRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, propertyContext));
 }
 protected AbstractActionRepresentationStrategy(IOidStrategy oidStrategy, HttpRequest req, ActionContextFacade actionContext, RestControlFlags flags)
     : base(oidStrategy, flags)
 {
     Req           = req;
     ActionContext = actionContext;
     helper        = new UriMtHelper(oidStrategy, req, actionContext);
     self          = new MemberRelType(RelValues.Self, helper);
 }
Пример #12
0
 private void SetLinks(UriMtHelper helper)
 {
     Links = new List <LinkRepresentation> {
         LinkRepresentation.Create(SelfRelType, Flags)
         // temp disable icons
         //LinkRepresentation.Create(new IconRelType(helper), Flags)
     }.ToArray();
 }
Пример #13
0
        protected IList <LinkRepresentation> CreateLinks(HttpRequestMessage req, PropertyTypeContextFacade propertyContext)
        {
            var domainTypeUri = new UriMtHelper(OidStrategy, req, propertyContext);

            return(new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, SelfRelType, Flags),
                LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.Up, domainTypeUri), Flags)
            });
        }
        protected ObjectRepresentation(HttpRequestMessage req, ObjectContextSurface objectContext, RestControlFlags flags) : base(flags)
        {
            var objectUri = new UriMtHelper(req, objectContext.Target);

            SetScalars(objectContext);
            SelfRelType = objectContext.Specification.IsService() ? new ServiceRelType(RelValues.Self, objectUri) : new ObjectRelType(RelValues.Self, objectUri);
            SetLinksAndMembers(req, objectContext);
            SetExtensions(objectContext.Target);
            SetHeader(objectContext);
        }
        protected MenuRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, IMenuFacade menu, RestControlFlags flags)
            : base(oidStrategy, flags)
        {
            var helper = new UriMtHelper(oidStrategy, req, menu);

            SetScalars(menu);
            SelfRelType = new MenuRelType(RelValues.Self, helper);
            SetLinksAndMembers(req, menu);
            SetExtensions(menu);
            SetHeader(menu);
        }
        private void SetLinks(HttpRequestMessage req, ParameterTypeContextFacade parameterTypeContext)
        {
            var domainTypeUri = new UriMtHelper(OidStrategy, req, parameterTypeContext);

            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, SelfRelType, Flags),
                LinkRepresentation.Create(OidStrategy, new TypeMemberRelType(RelValues.Up, domainTypeUri), Flags),
                LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(OidStrategy, req, parameterTypeContext.Parameter.Specification)), Flags)
            };

            Links = tempLinks.ToArray();
        }
Пример #17
0
        protected DomainTypeRepresentation(HttpRequestMessage req, INakedObjectSpecificationSurface spec, RestControlFlags flags) : base(flags)
        {
            var helper = new UriMtHelper(req, spec);

            SelfRelType = new DomainTypeRelType(RelValues.Self, helper);
            SetScalars(spec);
            SetLinks(helper);
            SetMembers(spec, req);
            SetTypeActions(spec, req);
            SetExtensions();
            SetHeader();
        }
        private object GetObjectByHref(string href, IFrameworkFacade facade, UriMtHelper helper, IOidStrategy oidStrategy)
        {
            string[] oids = helper.GetObjectId(href);
            if (oids != null)
            {
                var oid = facade.OidTranslator.GetOidTranslation(oids[0] + "/" + oids[1]);
                return(facade.GetObject(oid).Target?.Object);
            }
            string typeName = helper.GetTypeId(href);

            return(facade.GetDomainType(typeName));
        }
Пример #19
0
        private object GetObjectByHref(string href, INakedObjectsSurface surface, UriMtHelper helper)
        {
            string[] oids = helper.GetObjectId(href);
            if (oids != null)
            {
                var oid = new LinkObjectId(oids[0], oids[1]);
                return(surface.GetObject(oid).Target.Object);
            }
            string typeName = helper.GetTypeId(href);

            return(surface.GetDomainType(typeName));
        }
Пример #20
0
        protected PromptRepresentation(IOidStrategy oidStrategy, ParameterContextFacade parmContext, HttpRequestMessage req, RestControlFlags flags)
            : base(oidStrategy, flags)
        {
            SetScalars(parmContext.Id);
            SetChoices(parmContext, req);
            SelfRelType = new PromptRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, parmContext));
            var           helper        = new UriMtHelper(oidStrategy, req, parmContext.Target);
            ObjectRelType parentRelType = parmContext.Target.Specification.IsService ? new ServiceRelType(RelValues.Up, helper) : new ObjectRelType(RelValues.Up, helper);

            SetLinks(req, parmContext.Completions.ElementType, parentRelType);
            SetExtensions();
            SetHeader(parmContext.Completions.IsListOfServices);
        }
        protected PromptRepresentation(ParameterContextSurface parmContext, ListContextSurface listContext, HttpRequestMessage req, RestControlFlags flags)
            : base(flags)
        {
            SetScalars(parmContext.Id);
            SetChoices(listContext, parmContext, req);
            SelfRelType = new PromptRelType(RelValues.Self, new UriMtHelper(req, parmContext));
            var           helper        = new UriMtHelper(req, parmContext.Target);
            ObjectRelType parentRelType = parmContext.Target.Specification.IsService() ? new ServiceRelType(RelValues.Up, helper) : new ObjectRelType(RelValues.Up, helper);

            SetLinks(req, listContext.ElementType, parentRelType);
            SetExtensions();
            SetHeader(listContext.IsListOfServices);
        }
        protected DomainTypeRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, ITypeFacade spec, RestControlFlags flags)
            : base(oidStrategy, flags)
        {
            var helper = new UriMtHelper(oidStrategy, req, spec);

            SelfRelType = new DomainTypeRelType(RelValues.Self, helper);
            SetScalars(spec);
            SetLinks(helper);
            SetMembers(spec, req);
            SetTypeActions(spec, req);
            SetExtensions();
            SetHeader();
        }
        private static object GetObjectByHref(string href, IFrameworkFacade facade, UriMtHelper helper, IOidStrategy oidStrategy)
        {
            var oids = UriMtHelper.GetObjectId(href);

            if (oids != null)
            {
                var oid = facade.OidTranslator.GetOidTranslation($"{oids.Value.type}/{oids.Value.key}");
                return(facade.GetObject(oid).Target?.Object);
            }

            var typeName = UriMtHelper.GetTypeId(href);

            return(facade.GetDomainType(typeName));
        }
        private void SetLinks(HttpRequestMessage req, ActionTypeContextSurface actionTypeContext)
        {
            var domainTypeUri = new UriMtHelper(req, actionTypeContext);
            var tempLinks     = new List <LinkRepresentation> {
                LinkRepresentation.Create(SelfRelType, Flags),
                LinkRepresentation.Create(new DomainTypeRelType(RelValues.Up, domainTypeUri), Flags),
                LinkRepresentation.Create(new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(req, actionTypeContext.ActionContext.Action.ReturnType)), Flags)
            };

            if (actionTypeContext.ActionContext.Action.ReturnType.IsCollection())
            {
                tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.ElementType, new UriMtHelper(req, actionTypeContext.ActionContext.Action.ElementType)), Flags));
            }

            Links = tempLinks.ToArray();
        }
        public object GetValue(IFrameworkFacade facade, UriMtHelper helper, IOidStrategy oidStrategy)
        {
            object[] items = internalValue.Select(iv => iv.GetValue(facade, helper, oidStrategy)).ToArray();

            if (items.Any())
            {
                Type[] types = items.Select(i => GetProxiedType(i.GetType())).ToArray();
                Type   type  = GetCommonBaseType(types, types.First());

                Type collType = typeof(List <>).MakeGenericType(type);
                var  coll     = (IList)Activator.CreateInstance(collType);

                Array.ForEach(items, i => coll.Add(i));
                return(coll);
            }
            return(null);
        }
        public static object GetPropertyValue(IOidStrategy oidStrategy, HttpRequest req, IAssociationFacade property, IObjectFacade target, RestControlFlags flags, bool valueOnly, bool useDateOverDateTime)
        {
            var valueNakedObject = property.GetValue(target);

            if (valueNakedObject == null)
            {
                return(null);
            }

            if (target.IsTransient && property.IsUsable(target).IsAllowed&& property.IsVisible(target) && property.IsSetToImplicitDefault(target))
            {
                return(null);
            }

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

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

            var title     = RestUtils.SafeGetTitle(property, valueNakedObject);
            var helper    = new UriMtHelper(oidStrategy, 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(oidStrategy, valueNakedObject, req, flags)));
            }

            return(LinkRepresentation.Create(oidStrategy, new ValueRelType(property, helper), flags, optionals.ToArray()));
        }
Пример #27
0
 public object GetValue(IFrameworkFacade facade, UriMtHelper helper, IOidStrategy oidStrategy)
 {
     return(internalValue);
 }
Пример #28
0
 public object GetValue(INakedObjectsSurface surface, UriMtHelper helper)
 {
     return(GetObjectByHref(internalValue, surface, helper));
 }
Пример #29
0
 public override MediaTypeHeaderValue GetContentType()
 {
     return(UriMtHelper.GetJsonMediaType(RepresentationTypes.Error));
 }
Пример #30
0
 public object GetValue(INakedObjectsSurface surface, UriMtHelper helper)
 {
     return(internalValue);
 }