Example #1
0
 public FubuSmartRequest(IRequestData data, IObjectConverter converter, IFubuRequest request)
     : base(data, converter)
 {
     _data = data;
     _converter = converter;
     _request = request;
 }
Example #2
0
 public static void Register(Type type, IObjectConverter converter)
 {
     lock (converters)
     {
         converters[type] = converter;
     }
 }
Example #3
0
 public ValidationService(IObjectFactory objectFactory, IObjectConverter objectConverter)
 {
     if (objectFactory == null)
     {
         throw new ArgumentNullException("objectFactory", "Object factory should not be null.");
     }
     if (objectConverter == null)
     {
         throw new ArgumentNullException("objectConverter", "Object converter should not be null.");
     }
     _objectFactory = objectFactory;
     _objectConverter = objectConverter;
 }
Example #4
0
 public static Options AddObjectConverter(this Options options, IObjectConverter objectConverter)
 {
     options.Interop.ObjectConverters.Add(objectConverter);
     return(options);
 }
Example #5
0
 public static void RegisterDefaultConverters(int order, IObjectConverter objectConverter)
 {
     _defaultObjectConverters.Add(order, objectConverter);
 }
Example #6
0
 public void RegisterConverter(int order, IObjectConverter objectConverter)
 {
     _currentObjectConverters.Add(order, objectConverter);
 }
Example #7
0
 public SmartRequest(IRequestData data, IObjectConverter converter, IFubuRequest request)
 {
     _data      = data;
     _converter = converter;
     _request   = request;
 }
Example #8
0
 public ObjectArrayObjectMapper(ReadWriteProperty <T> property,
                                IObjectConverter converter)
 {
     _property  = property;
     _converter = converter;
 }
 public GameMovementController(IExecuteMovementService executeMovementService,
                               IObjectConverter objectConverter)
 {
     _executeMovementService = executeMovementService;
     _objectConverter        = objectConverter;
 }
Example #10
0
 public ComplexTypeConverter(IObjectConverter converter)
     : base(converter)
 {
 }
 public AuthenticationController(ISecurityAuthenticationService securityAuthenticationService, IObjectConverter objectConverter, IConfiguration configuration)
 {
     this.securityAuthenticationService = securityAuthenticationService;
     this.objectConverter = objectConverter;
     this.configuration   = configuration;
 }
        private TResult ConvertResult <TResult>(object result)
        {
            IObjectConverter objectConverter = Component.Context.ObjectConverter;

            return((TResult)objectConverter.Convert(result, typeof(TResult)));
        }
Example #13
0
 public GetMovieDetailsCallStrategy(StrategyServices strategyServices, IQueryBuilder <string> queryBuilder, IObjectHandler <string, DetailedMovieResponseObject> objectHandler, IObjectConverter <DetailedMovieResponseObject, IMotionPictureData> objectConverter)
 {
     this.strategyServices = strategyServices;
     this.queryBuilder     = queryBuilder;
     this.objectHandler    = objectHandler;
     this.objectConverter  = objectConverter;
 }
 public bool Matches(Type type, IObjectConverter converter)
 {
     return(TypeDescriptor.GetConverter(type).CanConvertFrom(typeof(string)));
 }
 public bool Matches(Type type, IObjectConverter converter)
 {
     return(type.IsNullable());
 }
 public bool Matches(Type type, IObjectConverter converter)
 {
     return(type.IsEnum);
 }
Example #17
0
 /// <summary>
 /// Adds a <see cref="IObjectConverter"/> instance to convert CLR types to <see cref="JsValue"/>
 /// </summary>
 public Options AddObjectConverter(IObjectConverter objectConverter)
 {
     _objectConverters.Add(objectConverter);
     return(this);
 }
        public Func <object, object> GetConverter(IObjectConverter context, Type sourceType, Type targetType)
        {
            // From DateTime
            if (sourceType == typeof(DateTime))
            {
                // DateTime to String
                if (targetType == typeof(string))
                {
                    return(source => ((DateTime)source).ToString());
                }

                var underlyingTargetType = targetType.IsNullableType() ? Nullable.GetUnderlyingType(targetType) : targetType;

                // DateTime to DateTimeOffset(Nullable)
                if (underlyingTargetType == typeof(DateTimeOffset))
                {
                    var defaultValue = targetType.IsNullableType() ? null : (object)default(DateTimeOffset);
                    return(source =>
                    {
                        try
                        {
                            return new DateTimeOffset((DateTime)source);
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            return defaultValue;
                        }
                    });
                }

                // DateTime to numeric
                if (DateTimeToTickConverter.TryGetValue(underlyingTargetType, out var converter))
                {
                    return(converter);
                }

                return(null);
            }

            // From DateTimeOffset
            if (sourceType == typeof(DateTimeOffset))
            {
                // DateTimeOffset to String
                if (targetType == typeof(string))
                {
                    return(source => ((DateTimeOffset)source).ToString());
                }

                var underlyingTargetType = targetType.IsNullableType() ? Nullable.GetUnderlyingType(targetType) : targetType;

                // DateTimeOffset to DateTime(Nullable)
                if (underlyingTargetType == typeof(DateTime))
                {
                    return(source => ((DateTimeOffset)source).DateTime);
                }

                // DateTimeOffset to numeric
                if (DateTimeOffsetToTickConverter.TryGetValue(underlyingTargetType, out var converter))
                {
                    return(converter);
                }

                return(null);
            }

            // From TimeSpan
            if (sourceType == typeof(TimeSpan))
            {
                // TimeSpan to String
                if (targetType == typeof(string))
                {
                    return(source => ((TimeSpan)source).ToString());
                }

                var underlyingTargetType = targetType.IsNullableType() ? Nullable.GetUnderlyingType(targetType) : targetType;

                // TimeSpan to numeric
                if (TimeSpanToTickConverter.TryGetValue(underlyingTargetType, out var converter))
                {
                    return(converter);
                }

                return(null);
            }

            // From string
            if (sourceType == typeof(string))
            {
                var underlyingTargetType = targetType.IsNullableType() ? Nullable.GetUnderlyingType(targetType) : targetType;

                // String to DateTime(Nullable)
                if (underlyingTargetType == typeof(DateTime))
                {
                    var defaultValue = targetType.IsNullableType() ? null : (object)default(DateTime);
                    return(source => DateTime.TryParse((string)source, out var result) ? result : defaultValue);
                }

                // String to DateTimeOffset(Nullable)
                if (underlyingTargetType == typeof(DateTimeOffset))
                {
                    var defaultValue = targetType.IsNullableType() ? null : (object)default(DateTimeOffset);
                    return(source => DateTimeOffset.TryParse((string)source, out var result) ? result : defaultValue);
                }

                // String to TimeSpan(Nullable)
                if (underlyingTargetType == typeof(TimeSpan))
                {
                    var defaultValue = targetType.IsNullableType() ? null : (object)default(TimeSpan);
                    return(source => TimeSpan.TryParse((string)source, out var result) ? result : defaultValue);
                }

                return(null);
            }

            // From Numeric to DateTime
            if (targetType == typeof(DateTime))
            {
                return(DateTimeFromTickConverter.TryGetValue(sourceType, out var converter) ? converter : null);
            }

            // From Numeric to DateTime?
            if (targetType == typeof(DateTime?))
            {
                return(NullableDateTimeFromTickConverter.TryGetValue(sourceType, out var converter) ? converter : null);
            }

            // From Numeric to DateTimeOffset
            if (targetType == typeof(DateTimeOffset))
            {
                return(DateTimeOffsetFromTickConverter.TryGetValue(sourceType, out var converter) ? converter : null);
            }

            // From Numeric to DateTime?
            if (targetType == typeof(DateTimeOffset?))
            {
                return(NullableDateTimeOffsetFromTickConverter.TryGetValue(sourceType, out var converter) ? converter : null);
            }

            // From Numeric to TimeSpan
            if (targetType == typeof(TimeSpan))
            {
                return(TimeSpanFromTickConverter.TryGetValue(sourceType, out var converter) ? converter : null);
            }

            // From Numeric to TimeSpan?
            if (targetType == typeof(TimeSpan?))
            {
                return(NullableTimeSpanFromTickConverter.TryGetValue(sourceType, out var converter) ? converter : null);
            }

            return(null);
        }
Example #19
0
 public ObjectCreator(IObjectConverter objectConverter, IObjectMapper objectMapper)
 {
     _objectConverter = objectConverter;
     _objectMapper    = objectMapper;
 }
Example #20
0
 public StrategyRunner(string strategyName)
 {
   this.objectConverter = Activator.CreateInstance(Type.GetType("OpenQuant.API.ObjectConverter, OpenQuant.API"), true) as IObjectConverter;
   this.strategyName = strategyName;
   this.Portfolio = PortfolioManager.Portfolios[strategyName] == null ? new FreeQuant.Instruments.Portfolio(strategyName) : PortfolioManager.Portfolios[strategyName];
   this.Portfolio.Clear();
 }
Example #21
0
 public SimplePropertyHandler(IObjectConverter converter, IDisplayFormatter formatter)
 {
     _converter = converter;
     _formatter = formatter;
 }
Example #22
0
 public ObjectMapper(IObjectConverter objectConverter)
 {
     this.objectConverter = objectConverter;
 }
 public MemoryStorageTransformer(IObjectConverter converter)
 {
     Converter = converter;
 }
Example #24
0
 public RequestHeaders(IObjectConverter converter, IObjectResolver resolver, AggregateDictionary dictionary)
 {
     _converter  = converter;
     _resolver   = resolver;
     _dictionary = dictionary;
 }
Example #25
0
        /// <summary>
        /// Creates an array of the given type from the given arguments
        /// </summary>
        /// <param name="type"></param>
        /// <param name="arguments"></param>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public static object CreateArray(Type type, object[] arguments, IContextObject ctx)
        {
            Type             elementType = type.GetElementType();
            IObjectConverter converter   = ctx.Registry.GetConverter(elementType);

            string failedConvert = $"Failed to convert '{string.Join(" ", arguments)}' to Type {type.Name}.";
            string failedCreate  = $"failed to create an instance of type {elementType.Name} from argument ";

            //Create the generic array of the required size
            Array array = (Array)Activator.CreateInstance(type, arguments.Length);

            for (int i = 0; i < array.Length; i++)
            {
                if (converter != null)
                {
                    //if we have a converter, use it
                    object conversion = converter.ConvertFromString(arguments[i].ToString(), ctx);

                    if (conversion == null)
                    {
                        throw new CommandParsingException(
                                  ParserFailReason.ParsingFailed,
                                  failedConvert,
                                  new Exception($"Conversion failed by '{converter.GetType().Name}.'")
                                  );
                    }

                    array.SetValue(conversion, i);
                    continue;
                }

                if (elementType == typeof(string))
                {
                    //strings are special, so have special treatment
                    array.SetValue(arguments[i], i);
                    continue;
                }

                if (elementType.GetTypeInfo().IsValueType)
                {
                    //value types can be created with a typeconverter
                    TypeConverter tc = TypeDescriptor.GetConverter(type.GetElementType());
                    try
                    {
                        //but a bad argument will throw an exception, so handle that
                        array.SetValue(tc.ConvertFrom(arguments[i]), i);
                    }
                    catch (Exception e)
                    {
                        throw new CommandParsingException(ParserFailReason.ParsingFailed, $"TypeConverter {failedCreate} '{arguments[i]}'.", e);
                    }
                }
                else
                {
                    //reference types need to be created with the Activator
                    try
                    {
                        //once again, bad arguments can throw an exception
                        object element = Activator.CreateInstance(elementType, arguments[i]);
                        array.SetValue(element, i);
                    }
                    catch (Exception e)
                    {
                        throw new CommandParsingException(ParserFailReason.ParsingFailed, $"Activator {failedCreate} '{arguments[i]}'.", e);
                    }
                }
            }

            return(array);
        }
 public ObjectObjectMapper(ReadWriteProperty <T> property, IObjectConverter converter)
 {
     _property      = property;
     _converter     = converter;
     _typeConverter = TypeDescriptor.GetConverter(property.Property.PropertyType);
 }
 public static object GetObject(this IObjectConverter converter, IDictionary <string, object> dictionary)
 {
     return(converter.GetObject(new DictionaryObjectValueProvider(dictionary)));
 }
Example #28
0
 public SmartRequest(IRequestData data, IObjectConverter converter)
 {
     _data      = data;
     _converter = converter;
 }
 // Matches any type deriving from DomainEntity
 // CanBeCastTo<> is an extension method in FubuCore as well
 public bool Matches(Type type, IObjectConverter converter)
 {
     return type.CanBeCastTo<DomainEntity>();
 }
Example #30
0
 // Matches any type deriving from DomainEntity
 // CanBeCastTo<> is an extension method in FubuCore as well
 public bool Matches(Type type, IObjectConverter converter)
 {
     return(type.CanBeCastTo <DomainEntity>());
 }
Example #31
0
 public static void RegisterDefaultConverters(IObjectConverter objectConverter)
 {
     RegisterDefaultConverters(_defaultObjectConverters.Last().Key + 1, objectConverter);
 }
 public SearchTVSeriesCallStrategy(StrategyServices strategyServices, IQueryBuilder <string> queryBuilder, IObjectHandler <string, IResponseObject> objectHandler, IObjectConverter <ICollection <IResponseObject>, ICollection <IMotionPictureData> > objectConverter)
 {
     this.strategyServices = strategyServices;
     this.queryBuilder     = queryBuilder;
     this.objectHandler    = objectHandler;
     this.objectConverter  = objectConverter;
 }
Example #33
0
 public ValueObjectDictionaryObjectMapper(ReadWriteProperty <T> property, IObjectConverter valueConverter)
 {
     _property       = property;
     _valueConverter = valueConverter;
 }
Example #34
0
        /// <summary>
        /// Attempts to convert the arguments provided into objects of types required by the command executor
        /// </summary>
        /// <param name="ctx"></param>
        protected override void ConvertArgumentsToTypes(IContextObject ctx)
        {
            Objects = new List <object> {
                ctx
            };
            int index = 0;
            IEnumerable <object> arguments = Input.ObjectiveExplode();

            if (AdditionalArgs != null)
            {
                arguments = arguments.Concat(AdditionalArgs);
            }

            foreach (KeyValuePair <ParameterInfo, CommandParameterAttribute> kvp in ExecutorData.ParameterData)
            {
                //Get the number of arguments going in to the parameter
                int count = kvp.Value.Repetitions <= 0 ? arguments.Count() - index
                                                        : kvp.Value.Repetitions;

                if (index >= arguments.Count())
                {
                    //If we've used all our arguments, just add empty ones to satisfy the
                    //method signature for the command
                    Objects.Add(ObjectCreator.CreateDefaultObject(kvp.Key));
                    continue;
                }

                object[] args = arguments.ReadToArray(index, count);

                //If the provided object is already of the required type, add and continue
                if (count == 1 && args[0].GetType() == kvp.Key.ParameterType)
                {
                    Objects.Add(args[0]);
                    continue;
                }

                IObjectConverter converter = Registry.GetConverter(kvp.Key.ParameterType);
                if (converter == null)
                {
                    //Use the object creator to attempt a conversion
                    Objects.Add(ObjectCreator.CreateObject(kvp.Key.ParameterType, args, ctx));
                }
                else
                {
                    //Use a defined converter.
                    object conversion = count > 1 ? converter.ConvertFromArray((string[])args, ctx)
                                                  : converter.ConvertFromString(args[0].ToString(), ctx);

                    if (conversion == null)
                    {
                        throw new CommandParsingException(
                                  ParserFailReason.ParsingFailed,
                                  $"Type conversion failed: Failed to convert '{string.Join(" ", args)}' to Type '{ kvp.Key.ParameterType.Name }'.",
                                  new Exception($"Conversion failed in '{converter.GetType().Name}.{nameof(IObjectConverter.ConvertFromArray)}'")
                                  );
                    }

                    Objects.Add(conversion);
                }

                index += count;
            }
        }
Example #35
0
 public ObjectCreator(IObjectConverter objectConverter, IObjectMapper objectMapper)
 {
     this.objectConverter = objectConverter;
     this.objectMapper    = objectMapper;
 }
Example #36
0
 public ListTVSeriesByGenreCallStrategy(StrategyServices strategyServices, IQueryBuilder <string> queryBuilder, IObjectHandler <string, IResponseObject> objectHandler, IObjectConverter <ICollection <IResponseObject>, ICollection <IMotionPictureData> > objectConverter, GenreCollectionHandler genreCollection)
 {
     this.strategyServices = strategyServices;
     this.queryBuilder     = queryBuilder;
     this.objectHandler    = objectHandler;
     this.objectConverter  = objectConverter;
     this.genreCollection  = genreCollection;
 }
Example #37
0
 public FixtureLibrary(IObjectConverter converter)
 {
     _converter = converter;
 }
Example #38
0
 internal ApiCaller(HttpClient client, IObjectConverter objectConverter)
 {
     this.client          = client;
     this.objectConverter = objectConverter;
 }
Example #39
0
 /// <summary>
  /// Adds a <see cref="IObjectConverter"/> instance to convert CLR types to <see cref="JsValue"/>
 /// </summary>
 public Options AddObjectConverter(IObjectConverter objectConverter)
 {
     _objectConverters.Add(objectConverter);
     return this;
 }
 public ParametersModelBinder(IObjectConverter objectConverter)
 {
     _objectConverter = objectConverter;
 }