/// <summary>
        /// Initializes a new instance of the <see cref="InvariantMarketDescriptionCache"/> class
        /// </summary>
        /// <param name="cache">A <see cref="ObjectCache"/> used to store market descriptors</param>
        /// <param name="dataRouterManager">A <see cref="IDataRouterManager"/> used to fetch data</param>
        /// <param name="mappingValidatorFactory">A <see cref="IMappingValidatorFactory"/> used to construct <see cref="IMappingValidator"/> instances for market mappings</param>
        /// <param name="timer">The <see cref="ITimer"/> instance used to periodically fetch market descriptors</param>
        /// <param name="prefetchLanguages">A <see cref="IReadOnlyCollection{CultureInfo}"/> specifying the languages for which the data should be pre-fetched</param>
        /// <param name="cacheManager">A <see cref="ICacheManager"/> used to interact among caches</param>
        public VariantDescriptionListCache(ObjectCache cache,
                                           IDataRouterManager dataRouterManager,
                                           IMappingValidatorFactory mappingValidatorFactory,
                                           ITimer timer,
                                           IEnumerable <CultureInfo> prefetchLanguages,
                                           ICacheManager cacheManager)
            : base(cacheManager)
        {
            Guard.Argument(cache, nameof(cache)).NotNull();
            Guard.Argument(dataRouterManager, nameof(dataRouterManager)).NotNull();
            Guard.Argument(mappingValidatorFactory, nameof(mappingValidatorFactory)).NotNull();
            Guard.Argument(timer, nameof(timer)).NotNull();
            Guard.Argument(prefetchLanguages, nameof(prefetchLanguages)).NotNull();//.NotEmpty();
            if (!prefetchLanguages.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(prefetchLanguages));
            }

            _cache                   = cache;
            _dataRouterManager       = dataRouterManager;
            _mappingValidatorFactory = mappingValidatorFactory;
            _timer                   = timer;
            _prefetchLanguages       = new ReadOnlyCollection <CultureInfo>(prefetchLanguages.ToList());
            _timer.Elapsed          += OnTimerElapsed;
            _timer.Start();
        }
        /// <summary>
        /// Constructs and returns a <see cref="MarketDescriptionCacheItem"/> from the provided DTO
        /// </summary>
        /// <param name="dto">The <see cref="MarketDescriptionDTO"/> containing market description data.</param>
        /// <param name="factory">The <see cref="IMappingValidatorFactory"/> instance used to build market mapping validators .</param>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the provided DTO.</param>
        /// <param name="source">The source cache where <see cref="MarketDescriptionCacheItem"/> is built</param>
        /// <returns>The constructed <see cref="MarketDescriptionCacheItem"/>.</returns>
        /// <exception cref="InvalidOperationException">The cache item could not be build from the provided DTO</exception>
        public static MarketDescriptionCacheItem Build(MarketDescriptionDTO dto, IMappingValidatorFactory factory, CultureInfo culture, string source)
        {
            Guard.Argument(dto, nameof(dto)).NotNull();
            Guard.Argument(factory, nameof(factory)).NotNull();
            Guard.Argument(culture, nameof(culture)).NotNull();

            var names = new Dictionary <CultureInfo, string> {
                { culture, dto.Name }
            };
            var descriptions = string.IsNullOrEmpty(dto.Description)
                ? new Dictionary <CultureInfo, string>()
                : new Dictionary <CultureInfo, string> {
                { culture, dto.Description }
            };

            var outcomes = dto.Outcomes == null
                ? null
                : new ReadOnlyCollection <MarketOutcomeCacheItem>(dto.Outcomes.Select(o => new MarketOutcomeCacheItem(o, culture)).ToList());

            var mappings = dto.Mappings == null
                ? null
                : new ReadOnlyCollection <MarketMappingCacheItem>(dto.Mappings.Select(m => MarketMappingCacheItem.Build(m, factory, culture)).ToList());

            var specifiers = dto.Specifiers == null
                ? null
                : new ReadOnlyCollection <MarketSpecifierCacheItem>(dto.Specifiers.Select(s => new MarketSpecifierCacheItem(s)).ToList());

            var attributes = dto.Attributes == null
                ? null
                : new ReadOnlyCollection <MarketAttributeCacheItem>(dto.Attributes.Select(a => new MarketAttributeCacheItem(a)).ToList());

            var groups = dto.Groups == null ? null : new ReadOnlyCollection <string>(dto.Groups.ToList());

            return(new MarketDescriptionCacheItem(dto.Id, names, descriptions, dto.Variant, dto.OutcomeType, outcomes, mappings, specifiers, attributes, groups, culture, source));
        }
        public void Init()
        {
            _variantMemoryCache   = new MemoryCache("VariantCache");
            _invariantMemoryCache = new MemoryCache("InVariantCache");
            _variantsMemoryCache  = new MemoryCache("VariantsCache");
            //force markets to be loaded
            _timer = new TestTimer(false);
            _timer.FireOnce(TimeSpan.Zero);
            var specifiers = new ReadOnlyDictionary <string, string>(new Dictionary <string, string>
            {
                { "score", "1:1" }
            });

            _cacheManager      = new CacheManager();
            _dataRouterManager = new TestDataRouterManager(_cacheManager);

            _mappingValidatorFactory = new MappingValidatorFactory();

            _timer            = new TestTimer(true);
            _variantMdCache   = new VariantMarketDescriptionCache(_variantMemoryCache, _dataRouterManager, _mappingValidatorFactory, _cacheManager);
            _inVariantMdCache = new InvariantMarketDescriptionCache(_invariantMemoryCache, _dataRouterManager, _mappingValidatorFactory, _timer, TestData.Cultures, _cacheManager);
            _variantsMdCache  = new VariantDescriptionListCache(_variantsMemoryCache, _dataRouterManager, _mappingValidatorFactory, _timer, TestData.Cultures, _cacheManager);

            _nameProvider = new NameProvider(
                new MarketCacheProvider(_inVariantMdCache, _variantMdCache, _variantsMdCache),
                new Mock <IProfileCache>().Object,
                new Mock <INameExpressionFactory>().Object,
                new Mock <ISportEvent>().Object,
                41,
                specifiers,
                ExceptionHandlingStrategy.THROW
                );
        }
예제 #4
0
        public void Init()
        {
            _cacheManager      = new CacheManager();
            _dataRouterManager = new TestDataRouterManager(_cacheManager);

            _variantMemoryCache             = new MemoryCache("VariantCache");
            _invariantMemoryCache           = new MemoryCache("InVariantCache");
            _variantDescriptionsMemoryCache = new MemoryCache("VariantDescriptionListCache");

            _timer = new SdkTimer(_timerInterval, _timerInterval);
            _mappingValidatorFactory     = new MappingValidatorFactory();
            _inVariantMdCache            = new InvariantMarketDescriptionCache(_invariantMemoryCache, _dataRouterManager, _mappingValidatorFactory, _timer, TestData.Cultures, _cacheManager);
            _variantMdCache              = new VariantMarketDescriptionCache(_variantMemoryCache, _dataRouterManager, _mappingValidatorFactory, _cacheManager);
            _variantDescriptionListCache = new VariantDescriptionListCache(_variantDescriptionsMemoryCache, _dataRouterManager, _mappingValidatorFactory, _timer, TestData.Cultures, _cacheManager);

            var dataFetcher = new TestDataFetcher();

            var betStopReasonsCache = new NamedValueCache(new NamedValueDataProvider(FileHelper.FindFile("betstop_reasons.xml"), dataFetcher, "betstop_reason"), ExceptionHandlingStrategy.THROW);

            var bettingStatusCache = new NamedValueCache(new NamedValueDataProvider(FileHelper.FindFile("betting_status.xml"), dataFetcher, "betting_status"),
                                                         ExceptionHandlingStrategy.THROW);

            var namedValueProviderMock = new Mock <INamedValuesProvider>();

            namedValueProviderMock.Setup(x => x.BetStopReasons).Returns(betStopReasonsCache);
            namedValueProviderMock.Setup(x => x.BettingStatuses).Returns(bettingStatusCache);

            _validator = new FeedMessageValidator(
                new MarketCacheProvider(_inVariantMdCache, _variantMdCache, _variantDescriptionListCache),
                TestData.Culture,
                namedValueProviderMock.Object,
                TestProducerManager.Create());
        }
예제 #5
0
        /// <summary>
        /// Constructs and returns a <see cref="MarketMappingCacheItem"/> from the provided DTO
        /// </summary>
        /// <param name="dto">The <see cref="MarketMappingDTO"/> containing mapping data</param>
        /// <param name="factory">The <see cref="IMappingValidatorFactory"/> used to construct mapping validator</param>
        /// <param name="culture">A <see cref="CultureInfo"/> </param>
        /// <returns>The constructed <see cref="MarketMappingCacheItem"/></returns>
        /// <exception cref="InvalidOperationException">The format of <see cref="MarketMappingDTO.ValidFor"/> is not correct</exception>
        public static MarketMappingCacheItem Build(MarketMappingDTO dto, IMappingValidatorFactory factory, CultureInfo culture)
        {
            Guard.Argument(dto, nameof(dto)).NotNull();
            Guard.Argument(factory, nameof(factory)).NotNull();

            return(string.IsNullOrEmpty(dto.ValidFor)
                ? new MarketMappingCacheItem(dto, null, culture)
                : new MarketMappingCacheItem(dto, factory.Build(dto.ValidFor), culture));
        }
        /// <summary>
        /// Constructs and returns a <see cref="MarketMappingCacheItem"/> from the provided DTO
        /// </summary>
        /// <param name="dto">The <see cref="MarketMappingDTO"/> containing mapping data</param>
        /// <param name="factory">The <see cref="IMappingValidatorFactory"/> used to construct mapping validator</param>
        /// <param name="culture">A <see cref="CultureInfo"/> </param>
        /// <returns>The constructed <see cref="MarketMappingCacheItem"/></returns>
        /// <exception cref="InvalidOperationException">The format of <see cref="MarketMappingDTO.ValidFor"/> is not correct</exception>
        public static MarketMappingCacheItem Build(MarketMappingDTO dto, IMappingValidatorFactory factory, CultureInfo culture)
        {
            Contract.Requires(dto != null);
            Contract.Requires(factory != null);

            return(string.IsNullOrEmpty(dto.ValidFor)
                ? new MarketMappingCacheItem(dto, null, culture)
                : new MarketMappingCacheItem(dto, factory.Build(dto.ValidFor), culture));
        }
예제 #7
0
        public MappingConfigurationValidationHelper(
            IMappingValidatorFactory mappingValidatorFactory,
            IPersistenceModelValidatorFactory persistenceModelValidatorFactory)
        {
            ArgumentUtility.CheckNotNull("mappingValidatorFactory", mappingValidatorFactory);
            ArgumentUtility.CheckNotNull("persistenceModelValidatorFactory", persistenceModelValidatorFactory);

            _mappingValidatorFactory          = mappingValidatorFactory;
            _persistenceModelValidatorFactory = persistenceModelValidatorFactory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VariantMarketDescriptionCache"/> class
        /// </summary>
        /// <param name="cache">A <see cref="MemoryCache"/> used to store market descriptors</param>
        /// <param name="dataRouterManager">A <see cref="IDataRouterManager"/> used to fetch data</param>
        /// <param name="mappingValidatorFactory">A <see cref="IMappingValidatorFactory"/> used to construct <see cref="IMappingValidator"/> instances for market mappings</param>
        /// <param name="cacheManager">A <see cref="ICacheManager"/> used to interact among caches</param>
        public VariantMarketDescriptionCache(MemoryCache cache,
                                             IDataRouterManager dataRouterManager,
                                             IMappingValidatorFactory mappingValidatorFactory,
                                             ICacheManager cacheManager)
            : base(cacheManager)
        {
            Guard.Argument(cache, nameof(cache)).NotNull();
            Guard.Argument(dataRouterManager, nameof(dataRouterManager)).NotNull();
            Guard.Argument(mappingValidatorFactory, nameof(mappingValidatorFactory)).NotNull();

            _cache                   = cache;
            _dataRouterManager       = dataRouterManager;
            _mappingValidatorFactory = mappingValidatorFactory;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VariantMarketDescriptionCache"/> class
        /// </summary>
        /// <param name="cache">A <see cref="ObjectCache"/> used to store market descriptors</param>
        /// <param name="dataRouterManager">A <see cref="IDataRouterManager"/> used to fetch data</param>
        /// <param name="mappingValidatorFactory">A <see cref="IMappingValidatorFactory"/> used to construct <see cref="IMappingValidator"/> instances for market mappings</param>
        /// <param name="cacheManager">A <see cref="ICacheManager"/> used to interact among caches</param>
        public VariantMarketDescriptionCache(ObjectCache cache,
                                             IDataRouterManager dataRouterManager,
                                             IMappingValidatorFactory mappingValidatorFactory,
                                             ICacheManager cacheManager)
            : base(cacheManager)
        {
            Contract.Requires(cache != null);
            Contract.Requires(dataRouterManager != null);
            Contract.Requires(mappingValidatorFactory != null);

            _cache                   = cache;
            _dataRouterManager       = dataRouterManager;
            _mappingValidatorFactory = mappingValidatorFactory;
        }
예제 #10
0
        public void Init()
        {
            _variantMemoryCache   = new MemoryCache("VariantCache");
            _invariantMemoryCache = new MemoryCache("InVariantCache");

            _cacheManager      = new CacheManager();
            _dataRouterManager = new TestDataRouterManager(_cacheManager);

            _mappingValidatorFactory = new MappingValidatorFactory();

            _timer            = new TestTimer(true);
            _variantMdCache   = new VariantMarketDescriptionCache(_variantMemoryCache, _dataRouterManager, _mappingValidatorFactory, _cacheManager);
            _inVariantMdCache = new InvariantMarketDescriptionCache(_invariantMemoryCache, _dataRouterManager, _mappingValidatorFactory, _timer, TestData.Cultures, _cacheManager);
        }
        /// <summary>
        /// Constructs and returns a <see cref="VariantDescriptionCacheItem"/> from the provided DTO
        /// </summary>
        /// <param name="dto">The <see cref="VariantDescriptionDTO"/> containing variant description data</param>
        /// <param name="factory">The <see cref="IMappingValidatorFactory"/> instance used to build market mapping validators</param>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the provided DTO</param>
        /// <param name="source">The source cache where <see cref="MarketDescriptionCacheItem"/> is built</param>
        /// <returns>The constructed <see cref="VariantDescriptionCacheItem"/></returns>
        /// <exception cref="InvalidOperationException">The cache item could not be build from the provided DTO</exception>
        public static VariantDescriptionCacheItem Build(VariantDescriptionDTO dto, IMappingValidatorFactory factory, CultureInfo culture, string source)
        {
            Contract.Requires(dto != null);
            Contract.Requires(factory != null);
            Contract.Requires(culture != null);

            var outcomes = dto.Outcomes == null
                ? null
                : new ReadOnlyCollection <MarketOutcomeCacheItem>(dto.Outcomes.Select(o => new MarketOutcomeCacheItem(o, culture)).ToList());

            var mappings = dto.Mappings == null
                ? null
                : new ReadOnlyCollection <MarketMappingCacheItem>(dto.Mappings.Select(m => MarketMappingCacheItem.Build(m, factory, culture)).ToList());

            return(new VariantDescriptionCacheItem(dto.Id, outcomes, mappings, culture, source));
        }
        /// <summary>
        /// Constructs and returns a <see cref="VariantDescriptionCacheItem"/> from the provided DTO
        /// </summary>
        /// <param name="dto">The <see cref="VariantDescriptionDTO"/> containing variant description data</param>
        /// <param name="factory">The <see cref="IMappingValidatorFactory"/> instance used to build market mapping validators</param>
        /// <param name="culture">A <see cref="CultureInfo"/> specifying the language of the provided DTO</param>
        /// <param name="source">The source cache where <see cref="MarketDescriptionCacheItem"/> is built</param>
        /// <returns>The constructed <see cref="VariantDescriptionCacheItem"/></returns>
        /// <exception cref="InvalidOperationException">The cache item could not be build from the provided DTO</exception>
        public static VariantDescriptionCacheItem Build(VariantDescriptionDTO dto, IMappingValidatorFactory factory, CultureInfo culture, string source)
        {
            Guard.Argument(dto, nameof(dto)).NotNull();
            Guard.Argument(factory, nameof(factory)).NotNull();
            Guard.Argument(culture, nameof(culture)).NotNull();

            var outcomes = dto.Outcomes == null
                ? null
                : new ReadOnlyCollection <MarketOutcomeCacheItem>(dto.Outcomes.Select(o => new MarketOutcomeCacheItem(o, culture)).ToList());

            var mappings = dto.Mappings == null
                ? null
                : new ReadOnlyCollection <MarketMappingCacheItem>(dto.Mappings.Select(m => MarketMappingCacheItem.Build(m, factory, culture)).ToList());

            return(new VariantDescriptionCacheItem(dto.Id, outcomes, mappings, culture, source));
        }
        public void Init()
        {
            _variantMarketDescriptionMemoryCache   = new MemoryCache("variantMarketDescriptionCache");
            _variantDescriptionMemoryCache         = new MemoryCache("variantDescriptionCache");
            _invariantMarketDescriptionMemoryCache = new MemoryCache("invariantMarketDescriptionCache");

            _cacheManager      = new CacheManager();
            _dataRouterManager = new TestDataRouterManager(_cacheManager);
            _producersProvider = new TestProducersProvider();

            _mappingValidatorFactory = new MappingValidatorFactory();

            _timer = new TestTimer(true);
            _variantMarketDescriptionCache   = new VariantMarketDescriptionCache(_variantMarketDescriptionMemoryCache, _dataRouterManager, _mappingValidatorFactory, _cacheManager);
            _variantDescriptionListCache     = new VariantDescriptionListCache(_variantDescriptionMemoryCache, _dataRouterManager, _mappingValidatorFactory, _timer, TestData.Cultures, _cacheManager);
            _invariantMarketDescriptionCache = new InvariantMarketDescriptionCache(_invariantMarketDescriptionMemoryCache, _dataRouterManager, _mappingValidatorFactory, _timer, TestData.Cultures, _cacheManager);

            _marketCacheProvider = new MarketCacheProvider(_invariantMarketDescriptionCache, _variantMarketDescriptionCache, _variantDescriptionListCache);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InvariantMarketDescriptionCache"/> class
        /// </summary>
        /// <param name="cache">A <see cref="MemoryCache"/> used to store market descriptors</param>
        /// <param name="dataRouterManager">A <see cref="IDataRouterManager"/> used to fetch data</param>
        /// <param name="mappingValidatorFactory">A <see cref="IMappingValidatorFactory"/> used to construct <see cref="IMappingValidator"/> instances for market mappings</param>
        /// <param name="timer">The <see cref="ITimer"/> instance used to periodically fetch market descriptors</param>
        /// <param name="prefetchLanguages">A <see cref="IReadOnlyCollection{CultureInfo}"/> specifying the languages for which the data should be pre-fetched</param>
        /// <param name="cacheManager">A <see cref="ICacheManager"/> used to interact among caches</param>
        public InvariantMarketDescriptionCache(MemoryCache cache,
                                               IDataRouterManager dataRouterManager,
                                               IMappingValidatorFactory mappingValidatorFactory,
                                               ITimer timer,
                                               IEnumerable <CultureInfo> prefetchLanguages,
                                               ICacheManager cacheManager)
            : base(cacheManager)
        {
            Guard.Argument(cache, nameof(cache)).NotNull();
            Guard.Argument(dataRouterManager, nameof(dataRouterManager)).NotNull();
            Guard.Argument(mappingValidatorFactory, nameof(mappingValidatorFactory)).NotNull();
            Guard.Argument(timer, nameof(timer)).NotNull();
            Guard.Argument(prefetchLanguages, nameof(prefetchLanguages)).NotNull().NotEmpty();


            _cache                   = cache;
            _dataRouterManager       = dataRouterManager;
            _mappingValidatorFactory = mappingValidatorFactory;
            _timer                   = timer;
            _prefetchLanguages       = new ReadOnlyCollection <CultureInfo>(prefetchLanguages.ToList());
            _timer.Elapsed          += OnTimerElapsed;
            _timer.Start();
        }
예제 #15
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="InvariantMarketDescriptionCache" /> class
        /// </summary>
        /// <param name="cache">A <see cref="MemoryCache" /> used to store market descriptors</param>
        /// <param name="dataRouterManager">A <see cref="IDataRouterManager" /> used to fetch data</param>
        /// <param name="mappingValidatorFactory">
        ///     A <see cref="IMappingValidatorFactory" /> used to construct
        ///     <see cref="IMappingValidator" /> instances for market mappings
        /// </param>
        /// <param name="timer">The <see cref="ITimer" /> instance used to periodically fetch market descriptors</param>
        /// <param name="prefetchLanguages">
        ///     A <see cref="IReadOnlyCollection{CultureInfo}" /> specifying the languages for which
        ///     the data should be pre-fetched
        /// </param>
        /// <param name="cacheManager">A <see cref="ICacheManager" /> used to interact among caches</param>
        public InvariantMarketDescriptionCache(MemoryCache cache,
                                               IDataRouterManager dataRouterManager,
                                               IMappingValidatorFactory mappingValidatorFactory,
                                               ITimer timer,
                                               IEnumerable <CultureInfo> prefetchLanguages,
                                               ICacheManager cacheManager)
            : base(cacheManager)
        {
            Contract.Requires(cache != null);
            Contract.Requires(dataRouterManager != null);
            Contract.Requires(mappingValidatorFactory != null);
            Contract.Requires(timer != null);
            Contract.Requires(prefetchLanguages != null && prefetchLanguages.Any());


            _cache                   = cache;
            _dataRouterManager       = dataRouterManager;
            _mappingValidatorFactory = mappingValidatorFactory;
            _timer                   = timer;
            _prefetchLanguages       = new ReadOnlyCollection <CultureInfo>(prefetchLanguages.ToList());
            _timer.Elapsed          += OnTimerElapsed;
            _timer.Start();
        }