public void ParserByNewParser() { byte[] message = new MessageBuilder().AddRaw("35=D|53=10|44=145|55=ABC|").Build(); // Create a property mapper and map types to be parsed. SubPropertySetterFactory is responsible creating the actual property setters. var propertyMapper = new TagToPropertyMapper(new SubPropertySetterFactory()); propertyMapper.Map <Order>(); // Create the composite property setter. CompositePropertySetter is the delegator of the sub property setters. var compositeSetter = new CompositePropertySetter(); // Create a validator collection to have all default validators var validators = new ValidatorCollection(IntegerToFixConverter.Instance); // Passing empty options var options = new MessageParserOptions(); // Create MessageParser, passing dependencies var parser = new MessageParser(propertyMapper, compositeSetter, validators, options); Order order = parser.Parse <Order>(message); Console.WriteLine($"Order {order.Symbol} - Px {order.Price}, Qty {order.Quantity}"); }
/// <summary> /// Sets message parsing options to configure the <see cref="RapideFix.Parsers.IMessageParser{TOutput, TData}"/> instances built by ParserBuilder. /// </summary> /// <returns>The builder instance.</returns> public ParserBuilder <TOutput> SetOptions(MessageParserOptions options) { if (_options != null) { throw new ArgumentException("Options already set"); } _options = options ?? throw new ArgumentNullException(nameof(options)); return(this); }
/// <summary> /// Creates an IMessageParser object. /// </summary> /// <typeparam name="TInput">The input type of the data.</typeparam> /// <param name="options">Custom <c>MessageParserOptions</c> to this instance of the IMessageParser built.</param> /// <returns>A message parser.</returns> public IMessageParser <TOutput, TInput> Build <TInput>(MessageParserOptions options) where TInput : struct { var subPropertySetterFactory = _subPropertySetterFactory ?? new SubPropertySetterFactory(); var propertyMapper = _propertyMapper ?? new TagToPropertyMapper(subPropertySetterFactory); var propertySetter = _propertySetter ?? new CompositePropertySetter(); var validator = _validator ?? new ValidatorCollection(IntegerToFixConverter.Instance); return(Build <TInput>(propertyMapper, propertySetter, validator, options)); }
public MessageParser( ITagToPropertyMapper tagToPropertyMapper, IPropertySetter compositeSetter, IValidator validators, MessageParserOptions options ) { _propertyMapper = tagToPropertyMapper ?? throw new ArgumentNullException(nameof(tagToPropertyMapper)); _compositeSetter = compositeSetter ?? throw new ArgumentNullException(nameof(compositeSetter)); _validators = validators ?? throw new ArgumentNullException(nameof(validators)); _options = options ?? throw new ArgumentNullException(nameof(options)); _messageContext = new FixMessageContext(); }
public TypedStringMessageParser( ITagToPropertyMapper tagToPropertyMapper, ITypedPropertySetter typedPropertySetter, IValidator validators, MessageParserOptions options ) { _propertyMapper = tagToPropertyMapper ?? throw new ArgumentNullException(nameof(tagToPropertyMapper)); _typedPropertySetter = typedPropertySetter ?? throw new ArgumentNullException(nameof(typedPropertySetter)); _options = options ?? throw new ArgumentNullException(nameof(options)); _messageContext = new FixMessageContext(); _propertyMapper.Map <TTarget>(); _isValueType = typeof(TTarget).IsValueType; }
/// <summary> /// Creates an IMessageParser object. /// </summary> /// <typeparam name="TInput">The input type of the data.</typeparam> /// <param name="propertyMapper">Custom <c>ITagToPropertyMapper</c> to this instance of the IMessageParser built.</param> /// <param name="propertySetter">Custom <c>ITypedPropertySetter</c> to this instance of the IMessageParser built.</param> /// <param name="validatorCollection">Custom <c>IValidator</c> to this instance of the IMessageParser built.</param> /// <param name="options">Custom <c>MessageParserOptions</c> to this instance of the IMessageParser built.</param> /// <returns>A message parser.</returns> public IMessageParser <TOutput, TInput> Build <TInput>(ITagToPropertyMapper propertyMapper, ITypedPropertySetter propertySetter, IValidator validatorCollection, MessageParserOptions options) { if (propertyMapper == null) { throw new ArgumentNullException(nameof(propertyMapper)); } if (propertySetter == null) { throw new ArgumentNullException(nameof(propertySetter)); } if (validatorCollection == null) { throw new ArgumentNullException(nameof(validatorCollection)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } propertyMapper.Map <TOutput>(); if (typeof(TInput) == typeof(char)) { return((IMessageParser <TOutput, TInput>) new TypedStringMessageParser <TOutput>(propertyMapper, propertySetter, validatorCollection, options)); } if (typeof(TInput) == typeof(byte)) { if (typeof(TOutput) == typeof(object)) { return((IMessageParser <TOutput, TInput>) new MessageParser(propertyMapper, propertySetter, validatorCollection, options)); } else { return((IMessageParser <TOutput, TInput>) new TypedMessageParser <TOutput>(propertyMapper, propertySetter, validatorCollection, options)); } } throw new NotSupportedException("Input type is not supported"); }