/// <summary> /// Extracts schema info from <paramref name="type"/>. /// </summary> /// <param name="context"></param> /// <param name="type"></param> /// <param name="schema"></param> private static void ExtractSchemaFromTypeDefinition(IMansionContext context, ITypeDefinition type, Schema schema) { // check if this type has a table declaration TypeTableDescriptor tableDescriptor; if (type.TryGetDescriptor(out tableDescriptor)) { var table = tableDescriptor.Create(context, type); // add the table to schema schema.Add(table); } // check if the type has property table declaration foreach (var property in type.Properties) { PropertyTableDescriptor propertyTableDescriptor; if (!property.TryGetDescriptor(out propertyTableDescriptor)) continue; // create the table propertyTableDescriptor.Create(context, schema, property); } }
/// <summary> /// Gets the <see cref="ColumnSchema"/> of <paramref name="type"/>. /// </summary> /// <param name="context">The request context.</param> /// <param name="type">The <see cref="ITypeDefinition" /> of the type from which to get the column scheme.</param> /// <returns>Returns the <see cref="ColumnSchema"/>.</returns> public static ColumnSchema GetSchema(IMansionContext context, ITypeDefinition type) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (type == null) throw new ArgumentNullException("type"); // get the schema descriptor ColumnSchemaDescriptor descriptor; if (!type.TryGetDescriptor(out descriptor)) throw new InvalidOperationException(string.Format("The type '{0}' does not provide a schema", type.Name)); return descriptor.GetSchema(context); }
/// <summary> /// Maps the given <paramref name="type"/> in <paramref name="typeMapping"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="definition">The <see cref="IndexDefinition"/>.</param> /// <param name="type">The <see cref="ITypeDefinition"/>.</param> /// <param name="typeMapping">The <see cref="TypeMapping"/>.</param> private static void MapType(IMansionContext context, IndexDefinition definition, ITypeDefinition type, TypeMapping typeMapping) { // map the type descriptor, if any TypeMapping.TypeMappingDescriptor descriptor; if (type.TryGetDescriptor(out descriptor)) descriptor.UpdateMapping(context, typeMapping); // map all the properties of this type MapProperties(context, type, typeMapping); // map all the analysis components defined on this type MapAnalysisComponents(context, type, definition); // loop over all the children of this type foreach (var childType in type.GetChildTypes(context)) { // clone the parent mapping, children should include the properties of the parent var childMapping = typeMapping.Clone(childType); // map the the child MapType(context, definition, childType, childMapping); } // append the mapping to the index definition definition.Add(typeMapping); }