Exemple #1
0
        public void CreateConverterTest()
        {
            string     provider = "GoogleProvider";
            IConverter expected = new CsvConverter();
            IConverter actual;

            actual = _converterFactory.Create(provider);
            Assert.AreEqual(expected.ToString(), actual.ToString());
            Assert.AreNotSame(expected, actual);
        }
Exemple #2
0
        public void Create_GivenValueType_ShouldCreateValueTypeConverter(Type type)
        {
            CreateConverterFactory(type);

            _converterFactory
            .Create()
            .GetType()
            .GetGenericTypeDefinition()
            .Should()
            .Be(typeof(ValueTypeConverter <>));
        }
Exemple #3
0
        public JsonResult Index(InputInfo info)
        {
            if (info.Provider == null || info.Company == null)
            {
                return(null);
            }
            IEnumerable <Quote> quotes = new List <Quote>();

            try
            {
                var data = _providerFactory.Create(info.Provider).GetData(info.DateFrom, info.DateTo, info.Company);
                quotes = _converterFactory.Create(info.Provider).Convert(data);
            }
            catch (NullReferenceException exception)
            {
                Debug.WriteLine("{1} - {0}", exception.Message, exception.Data);
            }

            //var quotes = new List<Quote> {
            //    new Quote { Date = DateTime.Parse("11.06.2012"), Close = 29.09, High = 12.12, Low = 121.12, Open = 35.1, Volume = 1412412 },
            //    new Quote { Date = DateTime.Parse("10.06.2012"), Close = 29.09, High = 12.12, Low = 121.12, Open = 35.1, Volume = 1412412 },
            //    new Quote { Date = DateTime.Parse("09.06.2012"), Close = 29.09, High = 12.12, Low = 121.12, Open = 35.1, Volume = 1412412 },
            //};

            return(Json(quotes.Select(elem => new
            {
                Date = elem.Date.ToString("MMM dd, yyyy"),
                elem.Close,
                elem.High,
                elem.Low,
                elem.Open,
                elem.Volume
            })));
        }
 internal SimpleAmazonQueueService(IConfiguration configuration, IAmazonSQS amazonSqsClient, IConverterFactory converterFactory)
     : this()
 {
     _configuration   = configuration;
     _amazonSqsClient = amazonSqsClient;
     _converter       = converterFactory.Create();
 }
        /// <summary>
        /// Creates and initializes a converter. This takes care of nested types (recursive converter creation).
        /// </summary>
        /// <param name="factory">The converter factory to use. This must not be null.</param>
        /// <param name="type">The type for which to create the converter.</param>
        /// <param name="converterParameters">The constructor parameters for the new converter. This may be null.</param>
        /// <returns>The new converter.</returns>
        public static IConverter CreateConverter(IConverterFactory factory, Type type, object[] converterParameters)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            IConverter converter;

            lock (CURRENTLY_INITIALIZED_TYPES)
            {
                if (CURRENTLY_INITIALIZED_TYPES.TryGetValue(type, out converter))
                {
                    return(converter);
                }

                converter = factory.Create(type, converterParameters);
                if (!(converter is IConverterInitialization))
                {
                    return(converter);
                }

                CURRENTLY_INITIALIZED_TYPES[type] = converter;
            }
            try
            {
                ((IConverterInitialization)converter).InitializeConverter();
            }
            finally
            {
                lock (CURRENTLY_INITIALIZED_TYPES)
                    CURRENTLY_INITIALIZED_TYPES.Remove(type);
            }
            return(converter);
        }
Exemple #6
0
        public IActionResult ConvertTo([FromRoute] ConvertInputRequestModel request)
        {
            var converter = _converterFactory.Create(request.ConverterType);

            if (converter == null)
            {
                return(BadRequest());
            }

            try
            {
                var byteArr = _toByteArrayConverter.Convert(request.Input);
                var result  = converter.Convert(byteArr);
                return(Ok(result));
            }
            finally
            {
                _converterFactory.Release(converter);
            }
        }
        private static IConverter GetConverter(IConverterFactory factory, Type type, object[] converterParameters)
        {
            if (factory != null)
            {
                if (!factory.CanConvert(type))
                {
                    throw new Exception($"Converter factory {factory.GetType()} is not able to convert type '{type}'.");
                }

                IConverter converter = factory.Create(type, converterParameters);
                if (converter == null)
                {
                    throw new Exception($"{nameof(IConverterFactory.Create)} implementation of {factory.GetType()} did not return a converter for type {type}.");
                }

                return(converter);
            }

            return(ConverterRegistry.Get(type, converterParameters));
        }