private SchemaTypeEntry GenerateForType(StructuredType structuredType) { string extends = null; var resourceTypeSpec = structuredType as ResourceType; IEnumerable<StructuredProperty> properties = structuredType.Properties; if (resourceTypeSpec == null || !resourceTypeSpec.IsUriBaseType) { if (structuredType.BaseType != null && structuredType.BaseType != typeof(object)) { extends = structuredType.BaseType.Name; var propsOfBaseType = new HashSet<string>(structuredType.BaseType.Properties.Select(x => x.Name)); properties = properties.Where(x => !propsOfBaseType.Contains(x.Name)); } } var typeName = structuredType.Name; var schemaTypeEntry = new SchemaTypeEntry { Extends = extends, Name = typeName, Properties = new SortedDictionary<string, SchemaPropertyEntry>(properties .Select(GenerateForProperty) .ToDictionary(x => x.Name, x => x)), // TODO: Expose IsAbstract on TypeSpec Abstract = structuredType.Type != null && structuredType.Type.IsAbstract, AllowedMethods = structuredType.AllowedMethods }; if (resourceTypeSpec != null) schemaTypeEntry.Uri = resourceTypeSpec.UrlRelativePath; return schemaTypeEntry; }
public override StructuredTypeDetails LoadStructuredTypeDetails(StructuredType structuredType) { if (IsAnonType(structuredType) || structuredType is QueryResultType) { return(new StructuredTypeDetails(structuredType, HttpMethod.Get, null, true, true, false)); } var ria = structuredType.DeclaredAttributes.OfType <ResourceInfoAttribute>().First(); var allMethods = (HttpMethod.Delete | HttpMethod.Get | HttpMethod.Patch | HttpMethod.Post | HttpMethod.Put); var allowedMethods = structuredType .DeclaredAttributes .OfType <AllowedMethodsAttribute>() .Select(x => (HttpMethod?)x.Methods) .FirstOrDefault() ?? allMethods; return(new StructuredTypeDetails(structuredType, allowedMethods, null, ria.IsValueObject, true, false)); }
public override IEnumerable <StructuredType> LoadSubTypes(StructuredType baseType) { return(TypeMap.Values.OfType <StructuredType>() .Where(x => x.BaseType == baseType) .SelectMany(x => x.SubTypes.Append(x)) .ToList()); }
public StructuredProperty(IStructuredTypeResolver typeResolver, PropertyInfo propertyInfo, StructuredType reflectedType) : base(typeResolver, propertyInfo, reflectedType) { this.structuredPropertyDetails = CreateLazy(() => typeResolver.LoadStructuredPropertyDetails(this)); }
private object Deserialize(StructuredType expectedBaseType, object patchedObject = null) { if (!Request.Body.CanSeek) { var memStream = new MemoryStream(); Request.Body.CopyTo(memStream); memStream.Seek(0, SeekOrigin.Begin); Request.Body = memStream; } if (Request.Body.Position != 0) { Request.Body.Seek(0, SeekOrigin.Begin); } using (var textReader = new StreamReader(Request.Body)) { var deserializer = Session.GetInstance <ITextDeserializer>(); var options = new DeserializeOptions() { Target = patchedObject, ExpectedBaseType = expectedBaseType, TargetNode = Node }; return(deserializer.Deserialize(textReader, options)); } }
private object BuildResourceInstance() { if (EdmObject == null) { return(null); } TypedEdmStructuredObject edmStructruredObject = EdmObject as TypedEdmStructuredObject; if (edmStructruredObject != null) { return(edmStructruredObject.Instance); } SelectExpandWrapper selectExpandWrapper = EdmObject as SelectExpandWrapper; if (selectExpandWrapper != null && selectExpandWrapper.UntypedInstance != null) { return(selectExpandWrapper.UntypedInstance); } Type clrType = EdmLibHelpers.GetClrType(StructuredType, EdmModel); if (clrType == null) { throw new InvalidOperationException(Error.Format(SRResources.MappingDoesNotContainResourceType, StructuredType.FullTypeName())); } object resource = Activator.CreateInstance(clrType); foreach (IEdmStructuralProperty property in StructuredType.StructuralProperties()) { object value; if (EdmObject.TryGetPropertyValue(property.Name, out value) && value != null) { if (value is SelectExpandWrapper) { // Skip the select expand property continue; } string propertyName = EdmLibHelpers.GetClrPropertyName(property, EdmModel); if (TypeHelper.IsCollection(value.GetType())) { DeserializationHelpers.SetCollectionProperty(resource, property, value, propertyName); } else { DeserializationHelpers.SetProperty(resource, propertyName, value); } } } return(resource); }
public PomonaQuery(StructuredType sourceType, StructuredType ofType = null) { if (sourceType == null) throw new ArgumentNullException(nameof(sourceType)); OrderByExpressions = new List<Tuple<LambdaExpression, SortOrder>>(); SourceType = sourceType; OfType = ofType ?? sourceType; DebugInfoKeys = new HashSet<string>(); }
public PomonaQuery(StructuredType sourceType, StructuredType ofType = null) { if (sourceType == null) { throw new ArgumentNullException(nameof(sourceType)); } OrderByExpressions = new List <Tuple <LambdaExpression, SortOrder> >(); SourceType = sourceType; OfType = ofType ?? sourceType; DebugInfoKeys = new HashSet <string>(); }
public StructuredTypeDetails(StructuredType type, HttpMethod allowedMethods, Action<object> onDeserialized, bool mappedAsValueObject, bool alwaysExpand, bool isAbstract) { this.type = type; AllowedMethods = allowedMethods; OnDeserialized = onDeserialized; MappedAsValueObject = mappedAsValueObject; this.type = type; AlwaysExpand = alwaysExpand; IsAbstract = isAbstract; }
private static TypeDescription[] GetItems() { TypeDescription _ret = new StructuredType() { Name = "StructuredTypeName", StructureKind = StructureKindEnum.Structure, Field = GetFields() }; TypeDescription _retEnum = new EnumeratedType() { Name = "EnumeratedTypeName", EnumeratedValues = GetEnumeratedValue() }; return(new TypeDescription[] { _ret, _retEnum }); }
public override StructuredTypeDetails LoadStructuredTypeDetails(StructuredType structuredType) { // TODO: Get allowed methods from filter var allowedMethods = HttpMethod.Get | (Filter.PatchOfTypeIsAllowed(structuredType) ? HttpMethod.Patch : 0) | (Filter.PostOfTypeIsAllowed(structuredType) ? HttpMethod.Post : 0) | (Filter.DeleteOfTypeIsAllowed(structuredType) ? HttpMethod.Delete : 0); var type = structuredType.Type; var details = new StructuredTypeDetails(structuredType, allowedMethods, Filter.GetOnDeserializedHook(type), Filter.TypeIsMappedAsValueObject(type), Filter.TypeIsMappedAsValueObject(type), Filter.GetTypeIsAbstract(type)); return(details); }
private object BuildResourceInstance() { if (EdmObject == null) { return(null); } TypedEdmStructuredObject edmStructruredObject = EdmObject as TypedEdmStructuredObject; if (edmStructruredObject != null) { return(edmStructruredObject.Instance); } Type clrType = EdmLibHelpers.GetClrType(StructuredType, EdmModel); if (clrType == null) { throw new InvalidOperationException(Error.Format(SRResources.MappingDoesNotContainEntityType, StructuredType.FullTypeName())); } object resource = Activator.CreateInstance(clrType); foreach (IEdmStructuralProperty property in StructuredType.StructuralProperties()) { object value; if (EdmObject.TryGetPropertyValue(property.Name, out value) && value != null) { if (value.GetType().IsCollection()) { DeserializationHelpers.SetCollectionProperty(resource, property, value, property.Name); } else { DeserializationHelpers.SetProperty(resource, property.Name, value); } } } return(resource); }
private SchemaTypeEntry GenerateForType(StructuredType structuredType) { string extends = null; var resourceTypeSpec = structuredType as ResourceType; IEnumerable <StructuredProperty> properties = structuredType.Properties; if (resourceTypeSpec == null || !resourceTypeSpec.IsUriBaseType) { if (structuredType.BaseType != null && structuredType.BaseType != typeof(object)) { extends = structuredType.BaseType.Name; var propsOfBaseType = new HashSet <string>(structuredType.BaseType.Properties.Select(x => x.Name)); properties = properties.Where(x => !propsOfBaseType.Contains(x.Name)); } } var typeName = structuredType.Name; var schemaTypeEntry = new SchemaTypeEntry { Extends = extends, Name = typeName, Properties = new SortedDictionary <string, SchemaPropertyEntry>(properties .Select(GenerateForProperty) .ToDictionary(x => x.Name, x => x)), // TODO: Expose IsAbstract on TypeSpec Abstract = structuredType.Type != null && structuredType.Type.IsAbstract, AllowedMethods = structuredType.AllowedMethods }; if (resourceTypeSpec != null) { schemaTypeEntry.Uri = resourceTypeSpec.UrlRelativePath; } return(schemaTypeEntry); }
public override StructuredTypeDetails LoadStructuredTypeDetails(StructuredType structuredType) { // TODO: Get allowed methods from filter var allowedMethods = HttpMethod.Get | (Filter.PatchOfTypeIsAllowed(structuredType) ? HttpMethod.Patch : 0) | (Filter.PostOfTypeIsAllowed(structuredType) ? HttpMethod.Post : 0) | (Filter.DeleteOfTypeIsAllowed(structuredType) ? HttpMethod.Delete : 0); var type = structuredType.Type; var details = new StructuredTypeDetails(structuredType, allowedMethods, Filter.GetOnDeserializedHook(type), Filter.TypeIsMappedAsValueObject(type), Filter.TypeIsMappedAsValueObject(type), Filter.GetTypeIsAbstract(type)); return details; }
public PomonaQuery TransformRequest(PomonaContext context, StructuredType rootType, int?defaultTop = null) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (rootType == null) { throw new ArgumentNullException(nameof(rootType)); } StructuredType ofType = null; if (context.Query["$oftype"].HasValue) { ofType = (StructuredType)this.typeMapper.FromType((string)context.Query["$oftype"]); } var query = new PomonaQuery(rootType, ofType); if (context.Query["$debug"].HasValue) { query.DebugInfoKeys = new HashSet <string>(((string)context.Query["$debug"]).ToLower().Split(',').Select(x => x.Trim())); } string filter = null; var top = defaultTop ?? 100; var skip = 0; if (context.Query["$totalcount"].HasValue && ((string)context.Query["$totalcount"]).ToLower() == "true") { query.IncludeTotalCount = true; } if (context.Query["$top"].HasValue) { top = int.Parse(context.Query["$top"]); } if (context.Query["$skip"].HasValue) { skip = int.Parse(context.Query["$skip"]); } if (context.Query["$filter"].HasValue) { filter = (string)context.Query["$filter"]; } ParseFilterExpression(query, filter); var selectSourceType = query.OfType.Type; if (context.Query["$groupby"].HasValue) { var groupby = (string)context.Query["$groupby"]; ParseGroupByExpression(query, groupby); selectSourceType = typeof(IGrouping <,>).MakeGenericType( query.GroupByExpression.ReturnType, selectSourceType); } if (context.Query["$projection"].HasValue) { var projectionString = (string)context.Query["$projection"]; query.Projection = projectionMap[projectionString]; QueryProjection projection; if (!projectionMap.TryGetValue(projectionString, out projection)) { throw new QueryParseException("\"" + projectionString + "\" is not a valid value for query parameter $projection", null, QueryParseErrorReason.UnrecognizedProjection, null); } query.Projection = projection; } else { query.Projection = QueryProjection.AsEnumerable; } if (context.Query["$select"].HasValue) { var select = (string)context.Query["$select"]; ParseSelect(query, select, selectSourceType); } if (context.Query["$orderby"].HasValue) { ParseOrderBy(query, (string)context.Query["$orderby"]); } query.Top = top; query.Skip = skip; if (context.Query["$expand"].HasValue) { // TODO: Translate expanded paths using TypeMapper query.ExpandedPaths = ((string)context.Query["$expand"]); } else { query.ExpandedPaths = string.Empty; } query.Url = context.Url; UpdateResultType(query); return(query); }
public virtual T Visit(StructuredType node) { Visit((VariableType)node); return(traverse(node.basetype)); }
public override bool Visit(StructuredType node) { Visit((VariableType)node); TraversePrint(node.basetype); return(true); }
public override IEnumerable <StructuredType> LoadSubTypes(StructuredType baseType) { return(this.typeNameMap.Values.OfType <StructuredType>()); }
private static void Compare(StructuredType source, StructuredType mirror) { Assert.AreEqual <StructureKindEnum>(source.StructureKind, mirror.StructureKind); CompareArrays <FieldType>(source.Field, mirror.Field, x => x.Name, CompareFieldType); }
private object Deserialize(StructuredType expectedBaseType, object patchedObject = null) { if (!Request.Body.CanSeek) { var memStream = new MemoryStream(); Request.Body.CopyTo(memStream); memStream.Seek(0, SeekOrigin.Begin); Request.Body = memStream; } if (Request.Body.Position != 0) Request.Body.Seek(0, SeekOrigin.Begin); using (var textReader = new StreamReader(Request.Body)) { var deserializer = Session.GetInstance<ITextDeserializer>(); var options = new DeserializeOptions() { Target = patchedObject, ExpectedBaseType = expectedBaseType, TargetNode = Node }; return deserializer.Deserialize(textReader, options); } }
public PomonaQuery TransformRequest(PomonaContext context, StructuredType rootType, int? defaultTop = null) { if (context == null) throw new ArgumentNullException(nameof(context)); if (rootType == null) throw new ArgumentNullException(nameof(rootType)); StructuredType ofType = null; if (context.Query["$oftype"].HasValue) ofType = (StructuredType)this.typeMapper.FromType((string)context.Query["$oftype"]); var query = new PomonaQuery(rootType, ofType); if (context.Query["$debug"].HasValue) { query.DebugInfoKeys = new HashSet<string>(((string)context.Query["$debug"]).ToLower().Split(',').Select(x => x.Trim())); } string filter = null; var top = defaultTop ?? 100; var skip = 0; if (context.Query["$totalcount"].HasValue && ((string)context.Query["$totalcount"]).ToLower() == "true") query.IncludeTotalCount = true; if (context.Query["$top"].HasValue) top = int.Parse(context.Query["$top"]); if (context.Query["$skip"].HasValue) skip = int.Parse(context.Query["$skip"]); if (context.Query["$filter"].HasValue) filter = (string)context.Query["$filter"]; ParseFilterExpression(query, filter); var selectSourceType = query.OfType.Type; if (context.Query["$groupby"].HasValue) { var groupby = (string)context.Query["$groupby"]; ParseGroupByExpression(query, groupby); selectSourceType = typeof(IGrouping<,>).MakeGenericType( query.GroupByExpression.ReturnType, selectSourceType); } if (context.Query["$projection"].HasValue) { var projectionString = (string)context.Query["$projection"]; query.Projection = projectionMap[projectionString]; QueryProjection projection; if (!projectionMap.TryGetValue(projectionString, out projection)) { throw new QueryParseException("\"" + projectionString + "\" is not a valid value for query parameter $projection", null, QueryParseErrorReason.UnrecognizedProjection, null); } query.Projection = projection; } else { query.Projection = QueryProjection.AsEnumerable; } if (context.Query["$select"].HasValue) { var select = (string)context.Query["$select"]; ParseSelect(query, select, selectSourceType); } if (context.Query["$orderby"].HasValue) ParseOrderBy(query, (string)context.Query["$orderby"]); query.Top = top; query.Skip = skip; if (context.Query["$expand"].HasValue) { // TODO: Translate expanded paths using TypeMapper query.ExpandedPaths = ((string)context.Query["$expand"]); } else query.ExpandedPaths = string.Empty; query.Url = context.Url; UpdateResultType(query); return query; }
public abstract IEnumerable<StructuredType> LoadSubTypes(StructuredType baseType);
public abstract StructuredTypeDetails LoadStructuredTypeDetails(StructuredType structuredType);
public override IEnumerable<StructuredType> LoadSubTypes(StructuredType baseType) { return TypeMap.Values.OfType<StructuredType>() .Where(x => x.BaseType == baseType) .SelectMany(x => x.SubTypes.Append(x)) .ToList(); }
/// <summary> /// Implements the constructor: StructuredType() /// Direct superclasses: global::MetaDslx.Soal.SoalType, global::MetaDslx.Soal.Declaration /// All superclasses: global::MetaDslx.Soal.SoalType, global::MetaDslx.Soal.Declaration, global::MetaDslx.Soal.NamedElement /// </summary> public virtual void StructuredType_StructuredType(StructuredType @this) { this.SoalType_SoalType(@this); this.Declaration_Declaration(@this); }