Exemple #1
0
        /// <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));
        }
Exemple #2
0
        /// <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)
        {
            Contract.Requires(dto != null);
            Contract.Requires(factory != null);
            Contract.Requires(culture != null);

            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));
        }
        private bool MarketMappingsMatch(MarketMappingCacheItem ci, MarketMappingDTO dto)
        {
            var isMatch = ci.MarketTypeId == dto.MarketTypeId && ci.MarketSubTypeId == dto.MarketSubTypeId;

            if (isMatch && ci.SportId != null)
            {
                isMatch = ci.SportId.Equals(dto.SportId);
            }

            if (isMatch && ci.ProducerIds != null)
            {
                isMatch = ci.ProducerIds.All(a => dto.ProducerIds.Contains(a));
            }

            if (isMatch && !string.IsNullOrEmpty(ci.ValidFor))
            {
                isMatch = ci.ValidFor.Equals(dto.ValidFor, StringComparison.InvariantCultureIgnoreCase);
            }

            return(isMatch);
        }
        /// <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));
        }