public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) { MediaTypeHeaderValue mediaType = UriMtHelper.GetJsonMediaType(RepresentationTypes.List); Helper.AddListRepresentationParameter(mediaType, flags); return(mediaType); }
protected RelType(string name, UriMtHelper helper) { Helper = helper; Name = name; Method = RelMethod.Get; HasRelParameter = HasRelParameterSet.Contains(name); }
private void ValidateOutgoingJsonMediaType() { var contentType = Representation.GetContentType(); var headers = requestMessage.GetTypedHeaders(); var incomingParameters = headers.Accept.SelectMany(a => a.Parameters).ToList(); var incomingProfiles = incomingParameters.Where(nv => nv.Name.ToString() == "profile").Select(nv => nv.Value).Distinct().ToArray(); var outgoingProfiles = contentType != null?contentType.Parameters.Where(nv => nv.Name == "profile").Select(nv => nv.Value).Distinct().ToArray() : new StringSegment[] { }; 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 { var msg = DebugFilter(() => $"Failed outgoing json MT validation ic: {string.Join(',', incomingProfiles.ToArray())} og: {string.Join(',', outgoingProfiles.ToArray())}"); // outgoing profile not included in incoming profiles and not already an error so throw a 406 throw new ValidationException((int)HttpStatusCode.NotAcceptable, msg); } } }
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)); }
public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) { var mediaType = UriMtHelper.GetJsonMediaType(UriMtHelper.GetObjectMediaType()); Helper.AddObjectRepresentationParameter(mediaType, flags); return(mediaType); }
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); }
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); }
public static LinkRepresentation CreateTableRowValueLink(IObjectFacade no, ActionContextFacade actionContext, IOidStrategy oidStrategy, HttpRequestMessage req, RestControlFlags flags) { var columns = actionContext?.Action?.TableViewData?.Item2; var helper = new UriMtHelper(oidStrategy, req, no); ObjectRelType rt = no.Specification.IsService ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper); return(CreateTableRowValueLink(no, columns, rt, oidStrategy, req, flags)); }
private static void CheckForRedirection(IOidStrategy oidStrategy, ContextFacade context, HttpRequest req) { var ocs = context as ObjectContextFacade; var arcs = context as ActionResultContextFacade; var redirected = ocs?.Redirected ?? arcs?.Result?.Redirected; if (redirected != null) { var(serverName, oid) = redirected.Value; var redirectAddress = UriMtHelper.GetRedirectUri(req, serverName, oid); throw new RedirectionException(redirectAddress); } }
private static void CheckForRedirection(IOidStrategy oidStrategy, ContextFacade context, HttpRequestMessage req) { var ocs = context as ObjectContextFacade; var arcs = context as ActionResultContextFacade; Tuple <string, string> redirected = (ocs != null ? ocs.Redirected : null) ?? (arcs?.Result != null ? arcs.Result.Redirected : null); if (redirected != null) { Uri redirectAddress = new UriMtHelper(oidStrategy, req).GetRedirectUri(req, redirected.Item1, redirected.Item2); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MovedPermanently) { Headers = { Location = redirectAddress } }); } }
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; }
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 TypeActionInvokeRelType(string name, UriMtHelper helper) : base(name, helper) {}
public ListRelType(string name, string endPoint, UriMtHelper helper) : base(name, helper) { this.endPoint = endPoint; }
public static LinkRepresentation CreateTableRowValueLink(IObjectFacade no, ActionContextFacade actionContext, IOidStrategy oidStrategy, HttpRequestMessage req, RestControlFlags flags) { var columns = actionContext?.Action?.TableViewData?.Item2; var helper = new UriMtHelper(oidStrategy, req, no); ObjectRelType rt = no.Specification.IsService ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper); return CreateTableRowValueLink(no, columns, rt, oidStrategy, req, flags); }
public UserRelType(UriMtHelper helper) : base(RelValues.User, helper) {}
public CollectionValueRelType(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; Tuple<string, string> redirected = (ocs != null ? ocs.Redirected : null) ?? (arcs?.Result != null ? arcs.Result.Redirected : null); if (redirected != null) { Uri redirectAddress = new UriMtHelper(oidStrategy, req).GetRedirectUri(req, redirected.Item1, redirected.Item2); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.MovedPermanently) {Headers = {Location = redirectAddress}}); } }
public InvokeRelType(UriMtHelper helper) : base(RelValues.Invoke, helper) {}
public CollectionValueRelType(string name, UriMtHelper helper) : base(name, helper) {}
public ServiceRelType(string name, UriMtHelper helper) : base(name, helper) {}
public MenuRelType(UriMtHelper helper) : base(RelValues.Menu, helper) {}
public CollectionValueRelType(UriMtHelper helper) : base(RelValues.CollectionValue, helper) {}
public AttachmentRelType(UriMtHelper helper) : base(RelValues.Attachment, helper) {}
public VersionRelType(string name, UriMtHelper helper) : base(name, helper) {}
public VersionRelType(UriMtHelper helper) : base(RelValues.Version, helper) {}
public InvokeRelType(UriMtHelper helper) : base(RelValues.Invoke, helper) { }
public DomainTypeRelType(UriMtHelper helper) : base(RelValues.DomainType, helper) {}
public object GetValue(IFrameworkFacade facade, UriMtHelper helper, IOidStrategy oidStrategy) { return value; }
public DomainTypeRelType(string name, UriMtHelper helper) : base(name, helper) {}
public ServiceRelType(string name, UriMtHelper helper) : base(name, helper) { }
public PromptRelType(string name, UriMtHelper helper) : base(name, helper) { }
public PromptRelType(string name, UriMtHelper helper) : base(name, helper) {}
public object GetValue(IFrameworkFacade facade, UriMtHelper helper, IOidStrategy oidStrategy) { return GetObjectByHref(internalValue, facade, helper, oidStrategy); }
public CollectionValueRelType(UriMtHelper helper) : base(RelValues.CollectionValue, helper) { }
public ObjectRelType(string name, UriMtHelper helper) : base(name, helper) { }
public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) => UriMtHelper.GetJsonMediaType(RepresentationTypes.CollectionValue);
public UserRelType(string name, UriMtHelper helper) : base(name, helper) { }
public MemberRelType(UriMtHelper helper) : base(RelValues.Details, helper) { }
public HomePageRelType(string name, UriMtHelper helper) : base(name, helper) {}
public ServiceRelType(UriMtHelper helper) : base(RelValues.Service, helper) {}
protected RelType(string name, UriMtHelper helper) { Helper = helper; Name = name; Method = RelMethod.Get; HasRelParameter = HasRelParameterSet.Contains(name); }
public UserRelType(UriMtHelper helper) : base(RelValues.User, helper) { }
private ChoiceRelType(UriMtHelper helper) : base(RelValues.Choice, helper) { }
public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) { return(UriMtHelper.GetJsonMediaType(RepresentationTypes.User)); }
public ChoiceRelType(IActionParameterFacade parameter, UriMtHelper helper) : this(helper) { this.parameter = parameter; }
public ChoiceRelType(IAssociationFacade property, UriMtHelper helper) : this(helper) { member = property; }
public TypeActionRelType(UriMtHelper helper, string action) : this(RelValues.Invoke, helper, action) { }
public ActionResultRelType(string name, UriMtHelper helper) : base(name, helper) { }
public TypeActionRelType(string name, UriMtHelper helper, string action) : base(name, helper) { this.action = action; }
public override MediaTypeHeaderValue GetMediaType(RestControlFlags flags) { return(UriMtHelper.GetJsonMediaType(Helper.GetInvokeMediaType())); }
public MemberRelType(UriMtHelper helper) : base(RelValues.Details, helper) {}
public ActionResultRelType(string name, UriMtHelper helper) : base(name, helper) {}
public ListRelType(string name, string endPoint, UriMtHelper helper) : base(name, helper) => this.endPoint = endPoint;
public ServiceRelType(UriMtHelper helper) : base(RelValues.Service, helper) { }
public PromptRelType(UriMtHelper helper) : base(RelValues.Prompt, helper) {}
public VersionRelType(UriMtHelper helper) : base(RelValues.Version, helper) { }
protected LinkRepresentation CreateUpLink() { var helper = new UriMtHelper(OidStrategy, Req, ActionContext.Target); ObjectRelType parentRelType = ActionContext.Target.Specification.IsService ? new ServiceRelType(RelValues.Up, helper) : new ObjectRelType(RelValues.Up, helper); return LinkRepresentation.Create(OidStrategy, parentRelType, Flags); }
public MemberRelType(string name, UriMtHelper helper) : base(name, helper) {}
public VersionRelType(string name, UriMtHelper helper) : base(name, helper) { }