Example #1
0
 public ResourceRegistry(ISchemaBuilder schemaBulder, IEnumerable <ResourceRegistryRegistration> registrations)
 {
     foreach (var registration in registrations)
     {
         Schemas.Add(registration.ResourceName, schemaBulder.BuildSchema(registration.Type));
         Types.Add(registration.ResourceName, registration.Type);
     }
 }
Example #2
0
 public virtual SchemaBuilderCaseResult BuildSchema(Type type, SchemaBuilderContext context)
 {
     if (type == typeof(IOrderEvent))
     {
         return(SchemaBuilderCaseResult.FromSchema(
                    new UnionSchema(new[]
         {
             schemaBuilder.BuildSchema <OrderCreationEvent>(context),
             schemaBuilder.BuildSchema <OrderLineItemModificationEvent>(context),
             schemaBuilder.BuildSchema <OrderCancellationEvent>(context),
         })));
     }
     else
     {
         return(SchemaBuilderCaseResult.FromException(
                    new UnsupportedTypeException(type, $"{nameof(OrderEventUnionSchemaBuilderCase)} can only be applied to the {typeof(IOrderEvent)} type.")));
     }
 }
Example #3
0
        /// <summary>
        /// Builds a map schema.
        /// </summary>
        /// <param name="resolution">
        /// A type resolution.
        /// </param>
        /// <param name="cache">
        /// A schema cache.
        /// </param>
        /// <returns>
        /// A <see cref="MapSchema" /> that matches the type resolution.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// Thrown when the resolution is not an <see cref="MapResolution" />.
        /// </exception>
        public override Schema BuildSchema(TypeResolution resolution, IDictionary <Type, Schema> cache)
        {
            if (!(resolution is MapResolution map))
            {
                throw new ArgumentException("The map case can only be applied to map resolutions.", nameof(resolution));
            }

            var schema = new MapSchema(SchemaBuilder.BuildSchema(map.ValueType, cache));

            cache.Add(map.Type, schema);

            return(schema);
        }
Example #4
0
        /// <summary>
        /// Builds an array schema.
        /// </summary>
        /// <param name="resolution">
        /// A type resolution.
        /// </param>
        /// <param name="cache">
        /// A schema cache.
        /// </param>
        /// <returns>
        /// An <see cref="ArraySchema" /> that matches the type resolution.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// Thrown when the resolution is not an <see cref="ArrayResolution" />.
        /// </exception>
        public override Schema BuildSchema(TypeResolution resolution, IDictionary <Type, Schema> cache)
        {
            if (!(resolution is ArrayResolution array))
            {
                throw new ArgumentException("The array case can only be applied to array resolutions.", nameof(resolution));
            }

            var schema = new ArraySchema(SchemaBuilder.BuildSchema(array.ItemType, cache));

            cache.Add(array.Type, schema);

            return(schema);
        }
Example #5
0
        /// <summary>
        /// Builds a record schema.
        /// </summary>
        /// <param name="resolution">
        /// A type resolution.
        /// </param>
        /// <param name="cache">
        /// A schema cache.
        /// </param>
        /// <returns>
        /// A <see cref="RecordSchema" /> that matches the type resolution.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// Thrown when the resolution is not an <see cref="RecordResolution" />.
        /// </exception>
        public override Schema BuildSchema(TypeResolution resolution, IDictionary <Type, Schema> cache)
        {
            if (!(resolution is RecordResolution record))
            {
                throw new ArgumentException("The record case can only be applied to record resolutions.", nameof(resolution));
            }

            var name = record.Namespace == null
                ? record.Name.Value
                : $"{record.Namespace.Value}.{record.Name.Value}";

            var schema = new RecordSchema(name);

            cache.Add(record.Type, schema);

            foreach (var field in record.Fields)
            {
                schema.Fields.Add(new RecordField(field.Name.Value, SchemaBuilder.BuildSchema(field.Type, cache)));
            }

            return(schema);
        }