private void SetLinks(UriMtHelper helper) {
     Links = new List<LinkRepresentation> {
         LinkRepresentation.Create(OidStrategy , SelfRelType, Flags)
         // temp disable icons 
         //LinkRepresentation.Create(new IconRelType(helper), Flags) 
     }.ToArray();
 }
 protected MemberRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, RestControlFlags flags)
     : base(oidStrategy ,flags) {
     this.req = req;
     this.propertyContext = propertyContext;
     objectUri = new UriMtHelper(oidStrategy ,req, propertyContext);
     self = new MemberRelType(RelValues.Self, new UriMtHelper(oidStrategy , req, propertyContext));
 }
Exemple #3
0
 protected IList<LinkRepresentation> CreateLinks(HttpRequestMessage req, PropertyTypeContextSurface propertyContext) {
     var domainTypeUri = new UriMtHelper(req, propertyContext);
     return new List<LinkRepresentation> {
         LinkRepresentation.Create(SelfRelType, Flags),
         LinkRepresentation.Create(new DomainTypeRelType(RelValues.Up, domainTypeUri), Flags)
     };
 }
Exemple #4
0
 protected RelType(string name, UriMtHelper helper)
 {
     this.helper     = helper;
     Name            = name;
     Method          = RelMethod.Get;
     HasRelParameter = HasRelParameterSet.Contains(name);
 }
        public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
        {
            MediaTypeHeaderValue mediaType = UriMtHelper.GetJsonMediaType(helper.GetActionResultMediaType());

            helper.AddActionResultRepresentationParameter(mediaType, flags);
            return(mediaType);
        }
 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);
 }
 protected ObjectRepresentation(IOidStrategy oidStrategy, HttpRequestMessage req, ObjectContextFacade objectContext, RestControlFlags flags)
     : base(oidStrategy, flags) {
     var objectUri = new UriMtHelper(oidStrategy ,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);
 }
Exemple #8
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);
 }
 private object GetObjectByHref(string href, IFrameworkFacade facade, UriMtHelper helper, IOidStrategy oidStrategy) {
     string[] oids = helper.GetObjectId(href);
     if (oids != null) {
         // todo this is clunky 
         var oid =  facade.OidTranslator.GetOidTranslation(oids[0] + "/" + oids[1]);
         return facade.GetObject(oid).Target.GetDomainObject();
     }
     string typeName = helper.GetTypeId(href);
     return facade.GetDomainType(typeName);
 }
Exemple #10
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();
 }
Exemple #11
0
 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();
 }
Exemple #13
0
        private void SetLinks(HttpRequestMessage req, ParameterTypeContextSurface parameterTypeContext) {
            var domainTypeUri = new UriMtHelper(req, parameterTypeContext);

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

            Links = tempLinks.ToArray();
        }
Exemple #14
0
        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.ReturnType.ElementType)), Flags));
            }

            Links = tempLinks.ToArray();
        }
Exemple #15
0
        private static void CheckForRedirection(ContextSurface context, HttpRequestMessage req)
        {
            var ocs  = context as ObjectContextSurface;
            var arcs = context as ActionResultContextSurface;
            Tuple <string, string> redirected = (ocs != null ? ocs.Redirected : null) ?? (arcs != null && arcs.Result != null ? arcs.Result.Redirected : null);

            if (redirected != null)
            {
                Uri redirectAddress = new UriMtHelper(req).GetRedirectUri(req, redirected.Item1, redirected.Item2);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MovedPermanently)
                {
                    Headers = { Location = redirectAddress }
                });
            }
        }
Exemple #16
0
        public object GetValue(INakedObjectsSurface surface, UriMtHelper helper) {
            object[] items = internalValue.Select(iv => iv.GetValue(surface, helper)).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;
        }
Exemple #17
0
        private static void CheckForRedirection(IOidStrategy oidStrategy, ContextFacade context, HttpRequestMessage req)
        {
            var    ocs  = context as ObjectContextFacade;
            var    arcs = context as ActionResultContextFacade;
            string url  = (ocs != null ? ocs.RedirectedUrl : null) ?? (arcs != null && arcs.Result != null ? arcs.Result.RedirectedUrl : null);

            if (url != null)
            {
                Uri redirectAddress = new UriMtHelper(oidStrategy, req).GetRedirectUri(req, url);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MovedPermanently)
                {
                    Headers = { Location = redirectAddress }
                });
            }
        }
Exemple #18
0
        private void ValidateOutgoingJsonMediaType()
        {
            var contentType = Representation.GetContentType();
            List <NameValueHeaderValue> incomingParameters = requestMessage.Headers.Accept.SelectMany(a => a.Parameters).ToList();

            string[] incomingProfiles = incomingParameters.Where(nv => nv.Name == "profile").Select(nv => nv.Value).Distinct().ToArray();
            string[] outgoingProfiles = contentType != null?contentType.Parameters.Where(nv => nv.Name == "profile").Select(nv => nv.Value).Distinct().ToArray() : new string[]
            {
            };

            if (incomingProfiles.Any() && outgoingProfiles.Any() && !outgoingProfiles.Intersect(incomingProfiles).Any())
            {
                if (outgoingProfiles.Contains(UriMtHelper.GetJsonMediaType(RepresentationTypes.Error).Parameters.First().Value))
                {
                    // outgoing error so even though incoming profiles does not include error representation return error anyway but with 406 code
                    HttpStatusCode = HttpStatusCode.NotAcceptable;
                }
                else
                {
                    // outgoing profile not included in incoming profiles and not already an error so throw a 406
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable));
                }
            }
        }
 public DefaultRelType(INakedObjectActionParameterSurface parameter, UriMtHelper helper)
     : this(helper) {
     this.parameter = parameter;
 }
 public PromptRelType(UriMtHelper helper) : base(RelValues.Prompt, helper) {}
 public MenuRelType(string name, UriMtHelper helper) : base(name, helper)
 {
 }
Exemple #22
0
 public ServiceRelType(UriMtHelper helper) : base(RelValues.Service, helper) {}
Exemple #23
0
 public TypeActionRelType(string name, UriMtHelper helper, string action)
     : base(name, helper)
 {
     this.action = action;
 }
 public CollectionValueRelType(UriMtHelper helper) : base(RelValues.CollectionValue, helper) {}
 public MenuRelType(UriMtHelper helper) : base(RelValues.Menu, helper) {}
 public UserRelType(UriMtHelper helper) : base(RelValues.User, helper)
 {
 }
 public MemberRelType(UriMtHelper helper) : base(RelValues.Details, helper) {}
Exemple #28
0
 public UserRelType(UriMtHelper helper) : base(RelValues.User, helper) {}
Exemple #29
0
        private void MapToRepresentation(Exception e, HttpRequestMessage req)
        {
            if (e is WithContextNOSException)
            {
                ArgumentsRepresentation.Format format = e is BadPersistArgumentsException ? ArgumentsRepresentation.Format.Full : ArgumentsRepresentation.Format.MembersOnly;
                RestControlFlags flags = e is BadPersistArgumentsException ? ((BadPersistArgumentsException)e).Flags : RestControlFlags.DefaultFlags();

                var contextNosException = e as WithContextNOSException;

                if (contextNosException.Contexts.Any(c => c.ErrorCause == Cause.Disabled || c.ErrorCause == Cause.Immutable))
                {
                    representation = NullRepresentation.Create();
                }
                else if (contextNosException.ContextSurface != null)
                {
                    representation = ArgumentsRepresentation.Create(req, contextNosException.ContextSurface, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else if (contextNosException.Contexts.Any())
                {
                    representation = ArgumentsRepresentation.Create(req, contextNosException.Contexts, format, flags, UriMtHelper.GetJsonMediaType(RepresentationTypes.BadArguments));
                }
                else
                {
                    representation = NullRepresentation.Create();
                }
            }
            else if (e is ResourceNotFoundNOSException ||
                     e is NotAllowedNOSException ||
                     e is PreconditionFailedNOSException ||
                     e is PreconditionHeaderMissingNOSException ||
                     e is NoContentNOSException)
            {
                representation = NullRepresentation.Create();
            }
            else
            {
                representation = ErrorRepresentation.Create(e);
            }
        }
 private DefaultRelType(UriMtHelper helper) : base(RelValues.Default, helper)
 {
 }
 public InvokeRelType(UriMtHelper helper) : base(RelValues.Invoke, helper)
 {
 }
 public AttachmentRelType(UriMtHelper helper) : base(RelValues.Attachment, helper)
 {
 }
 public ActionResultRelType(string name, UriMtHelper helper) : base(name, helper)
 {
 }
 public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
 {
     return(UriMtHelper.GetJsonMediaType(helper.GetTypeMemberMediaType()));
 }
Exemple #35
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)));
        }
Exemple #36
0
 public CollectionValueRelType(string name, UriMtHelper helper) : base(name, helper)
 {
 }
 public CollectionValueRelType(string name, UriMtHelper helper) : base(name, helper) {}
 public TypeMemberRelType(string name, UriMtHelper helper) : base(name, helper) {}
 public MenuRelType(string name, UriMtHelper helper) : base(name, helper) { }
 public ChoiceRelType(INakedObjectAssociationSurface property, UriMtHelper helper) : this(helper) {
     member = property;
 }
Exemple #41
0
 public ServiceRelType(string name, UriMtHelper helper) : base(name, helper) {}
        private static void CheckForRedirection(IOidStrategy oidStrategy, ContextFacade context, HttpRequestMessage req) {
            var ocs = context as ObjectContextFacade;
            var arcs = context as ActionResultContextFacade;
            string url = (ocs != null ? ocs.RedirectedUrl : null) ?? (arcs != null && arcs.Result != null ? arcs.Result.RedirectedUrl : null);

            if (url != null) {
                Uri redirectAddress = new UriMtHelper(oidStrategy, req).GetRedirectUri(req, url);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MovedPermanently) {Headers = {Location = redirectAddress}});
            }
        }
Exemple #43
0
 public TypeActionRelType(UriMtHelper helper, string action) : this(RelValues.Invoke, helper, action)
 {
 }
Exemple #44
0
 public PromptRelType(UriMtHelper helper) : base(RelValues.Prompt, helper)
 {
 }
 public PromptRelType(string name, UriMtHelper helper) : base(name, helper) {}
Exemple #46
0
 public PromptRelType(string name, UriMtHelper helper) : base(name, helper)
 {
 }
 public ParamTypeRelType(UriMtHelper helper) : base(RelValues.ActionParam, helper)
 {
 }
 public TypeActionInvokeRelType(string name, UriMtHelper helper) : base(name, helper)
 {
 }
Exemple #49
0
 public ListRelType(string name, string endPoint, UriMtHelper helper)
     : base(name, helper) {
     this.endPoint = endPoint;
 }
 public ParamTypeRelType(string name, UriMtHelper helper) : base(name, helper)
 {
 }
 public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
 {
     return(UriMtHelper.GetJsonMediaType(RepresentationTypes.User));
 }
 public IconRelType(UriMtHelper helper) : base(RelValues.Icon, helper) {}
 public TypeMemberRelType(string name, UriMtHelper helper) : base(name, helper)
 {
 }
 public TypesRelType(UriMtHelper helper) : base(RelValues.DomainTypes, helper) {}
Exemple #55
0
 public CollectionValueRelType(UriMtHelper helper) : base(RelValues.CollectionValue, helper)
 {
 }
 private ChoiceRelType(UriMtHelper helper) : base(RelValues.Choice, helper)
 {
 }
Exemple #57
0
        public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags)
        {
            MediaTypeHeaderValue mediaType = UriMtHelper.GetJsonMediaType(RepresentationTypes.CollectionValue);

            return(mediaType);
        }
 public ChoiceRelType(IAssociationFacade property, UriMtHelper helper) : this(helper) {
     member = property;
 }
Exemple #59
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);
 }
 public ChoiceRelType(IActionParameterFacade parameter, UriMtHelper helper)
     : this(helper) {
     this.parameter = parameter;
 }