public void Serialise( List <Spot> spots, List <SalesArea> prioritySalesAreas, IReadOnlyCollection <BreakWithProgramme> breaks, List <Campaign> campaigns, List <Demographic> demographics, List <BusinessType> businessTypes, List <Product> allProducts, List <Clash> allClashes, AgSpot agSpot, IFeatureManager featureManager) { ToAgSpot( spots, prioritySalesAreas, breaks, campaigns, demographics, businessTypes, allProducts, allClashes, agSpot, featureManager) .Serialize(Path.Combine(FolderName, Filename)); }
private static AgSpotsSerialization ToAgSpot( List <Spot> spots, List <SalesArea> salesAreas, IReadOnlyCollection <BreakWithProgramme> breaks, List <Campaign> campaigns, List <Demographic> demographics, List <BusinessType> businessTypes, List <Product> products, List <Clash> clashes, AgSpot agSpot, IFeatureManager featureManager) { var agSpots = new ConcurrentBag <AgSpot>(); Dictionary <string, SalesArea> salesAreasByName = SalesArea.IndexListByName(salesAreas); Dictionary <string, Campaign> campaignsByExternalId = Campaign.IndexListByExternalId(campaigns); Dictionary <string, bool> businessTypesInclusionSettings = businessTypes .ToDictionary(bt => bt.Code, bt => bt.IncludeConversionIndex); Dictionary <string, BreakWithProgramme> breaksWithProgrammeBySalesAreaAndExternalBreakRef = BreakWithProgramme.IndexListBySalesAreaAndExternalBreakRef(breaks); IImmutableDictionary <string, Product> productByExternalId = products.IndexListByExternalID(); IImmutableDictionary <string, Clash> clashByExternalRef = clashes.IndexListByExternalRef(); var clashRoots = ClashHelper.CalculateClashTopParents(clashByExternalRef); var threadSafeSpotsCollection = spots.ToImmutableList(); var includeNominalPrice = featureManager.IsEnabled(nameof(ProductFeature.NominalPrice)); var includePositionInBreak = featureManager.IsEnabled(nameof(ProductFeature.PositionInBreak)); _ = Parallel.ForEach(threadSafeSpotsCollection, spot => agSpots.Add( GetAgSpot( spot, threadSafeSpotsCollection, salesAreasByName, campaignsByExternalId, businessTypesInclusionSettings, breaksWithProgrammeBySalesAreaAndExternalBreakRef, productByExternalId, clashByExternalRef, demographics, agSpot.Clone(), includeNominalPrice, includePositionInBreak, clashRoots ) ) ); var serialization = new AgSpotsSerialization(); return(serialization.MapFrom(agSpots.ToList())); }