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())); }
public static ParameterRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, IAssociationFacade assoc, ActionContextFacade actionContext, RestControlFlags flags) { var optionals = new List <OptionalProperty>(); if (assoc.IsChoicesEnabled != Choices.NotEnabled && !assoc.GetChoicesParameters().Any()) { IObjectFacade[] choices = assoc.GetChoices(objectFacade, null); object[] choicesArray = choices.Select(c => RestUtils.GetChoiceValue(oidStrategy, req, c, assoc, flags)).ToArray(); optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray)); } var adapter = new FieldFacadeAdapter(assoc); IObjectFacade defaultNakedObject = assoc.GetValue(objectFacade); if (defaultNakedObject != null) { string title = defaultNakedObject.TitleString; object value = RestUtils.ObjectToPredefinedType(defaultNakedObject.Object, true); var isValue = defaultNakedObject.Specification.IsParseable || (defaultNakedObject.Specification.IsCollection && defaultNakedObject.ElementSpecification.IsParseable); object defaultValue = isValue ? value : CreateDefaultLinks(oidStrategy, req, adapter, actionContext.Action, defaultNakedObject, title, flags); optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue)); } if (optionals.Count == 0) { return(new ParameterRepresentation(oidStrategy, req, objectFacade, adapter, flags)); } return(CreateWithOptionals <ParameterRepresentation>(new object[] { oidStrategy, req, objectFacade, adapter, flags }, optionals)); }
public MediaTypeHeaderValue GetAttachmentMediaType() { IObjectFacade no = assoc.GetValue(objectFacade); var attachment = no == null ? null : no.GetAttachment(); string mtv = attachment == null || string.IsNullOrWhiteSpace(attachment.MimeType) ? "" : attachment.MimeType; return(new MediaTypeHeaderValue(string.IsNullOrWhiteSpace(mtv) ? attachment.DefaultMimeType() : mtv)); }
protected string GetPropertyValueForEtag(IAssociationFacade property, IObjectFacade target) { IObjectFacade valueNakedObject = property.GetValue(target); if (valueNakedObject == null) { return(""); } if (property.Specification.IsParseable) { return(valueNakedObject.Object.ToString()); } return(OidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(target).Encode()); }
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())); }
public static ParameterRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, IAssociationFacade assoc, ActionContextFacade actionContext, RestControlFlags flags) { var optionals = new List<OptionalProperty>(); if (assoc.IsChoicesEnabled != Choices.NotEnabled && !assoc.GetChoicesParameters().Any()) { IObjectFacade[] choices = assoc.GetChoices(objectFacade, null); object[] choicesArray = choices.Select(c => RestUtils.GetChoiceValue(oidStrategy, req, c, assoc, flags)).ToArray(); optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray)); } var adapter = new FieldFacadeAdapter(assoc); IObjectFacade defaultNakedObject = assoc.GetValue(objectFacade); if (defaultNakedObject != null) { string title = defaultNakedObject.TitleString; object value = RestUtils.ObjectToPredefinedType(defaultNakedObject.Object, true); var isValue = defaultNakedObject.Specification.IsParseable || (defaultNakedObject.Specification.IsCollection && defaultNakedObject.ElementSpecification.IsParseable); object defaultValue = isValue ? value : CreateDefaultLinks(oidStrategy, req, adapter, actionContext.Action, defaultNakedObject, title, flags); optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue)); } if (optionals.Count == 0) { return new ParameterRepresentation(oidStrategy, req, objectFacade, adapter, flags); } return CreateWithOptionals<ParameterRepresentation>(new object[] { oidStrategy, req, objectFacade, adapter, flags }, optionals); }