public static ActionResultRepresentation Create(HttpRequestMessage req, ActionResultContextSurface actionResult, RestControlFlags flags) { if (actionResult.HasResult) { IRepresentation result; if (actionResult.Result == null) { result = null; } else if (actionResult.Specification.IsParseable()) { result = ScalarRepresentation.Create(actionResult.Result, req, flags); } else if (actionResult.Specification.IsObject()) { result = ObjectRepresentation.Create(actionResult.Result, req, flags); } else { result = ListRepresentation.Create(actionResult, req, flags); } return(CreateWithOptionals <ActionResultRepresentation>(new object[] { req, actionResult, flags }, new[] { new OptionalProperty(JsonPropertyNames.Result, result) })); } return(new ActionResultRepresentation(req, actionResult, flags)); }
protected ActionResultRepresentation(HttpRequestMessage req, ActionResultContextSurface actionResult, RestControlFlags flags) : base(flags) { SelfRelType = new ActionResultRelType(RelValues.Self, new UriMtHelper(req, actionResult.ActionContext)); SetResultType(actionResult); SetLinks(req, actionResult); SetExtensions(); SetHeader(); }
public RestSnapshot(ActionResultContextSurface actionResultContext, HttpRequestMessage req, RestControlFlags flags) : this(actionResultContext, req, true) { populator = () => { representation = ActionResultRepresentation.Create(req, actionResultContext, flags); SetHeaders(); }; }
private void SetLinks(HttpRequestMessage req, ActionResultContextSurface actionResult) { if (actionResult.ActionContext.Action.IsQueryOnly()) { Links = new[] { LinkRepresentation.Create(SelfRelType, Flags, new OptionalProperty(JsonPropertyNames.Arguments, CreateArguments(req, actionResult))) }; } else { Links = new LinkRepresentation[] {}; } }
private void SetResultType(ActionResultContextSurface actionResult) { if (actionResult.Specification.IsParseable()) { ResultType = ResultTypes.Scalar; } else if (actionResult.Specification.IsCollection()) { ResultType = ResultTypes.List; } else { ResultType = actionResult.Specification.IsVoid() ? ResultTypes.Void : ResultTypes.Object; } }
public ActionResultContextSurface ToActionResultContextSurface(INakedObjectsSurface surface) { var ac = new ActionResultContextSurface { Result = Result == null ? null : Result.ToObjectContextSurface(surface), ActionContext = ActionContext.ToActionContextSurface(surface), HasResult = HasResult }; if (Reason == null) { Reason = ActionContext.Reason; ErrorCause = ActionContext.ErrorCause; } return ToContextSurface(ac, surface); }
public ActionResultContextSurface ToActionResultContextSurface(INakedObjectsSurface surface, INakedObjectsFramework framework) { var ac = new ActionResultContextSurface { Result = Result == null ? null : Result.ToObjectContextSurface(surface, framework), ActionContext = ActionContext.ToActionContextSurface(surface, framework), HasResult = HasResult }; if (Reason == null) { Reason = ActionContext.Reason; ErrorCause = ActionContext.ErrorCause; } return(ToContextSurface(ac, surface, framework)); }
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())); }
public static ListRepresentation Create(ActionResultContextSurface actionResultContext, HttpRequestMessage req, RestControlFlags flags) { return(new ListRepresentation(actionResultContext.Result, req, flags, actionResultContext.ActionContext)); }