/** * Subgraph of a productionOrder includes: * - parent (StockExchangeDemand) if includeStockExchanges true * - childs (ProductionOrderBoms) * - childs of childs (StockExchangeProvider) if includeStockExchanges true */ private static List <IDemandOrProvider> CreateProductionOrderSubGraph( bool includeStockExchanges, ProductionOrder productionOrder, IAggregator aggregator) { List <IDemandOrProvider> demandOrProvidersOfProductionOrderSubGraph = new List <IDemandOrProvider>(); demandOrProvidersOfProductionOrderSubGraph.Add(productionOrder); if (includeStockExchanges) { Demands stockExchangeDemands = aggregator.GetAllParentDemandsOf(productionOrder); if (stockExchangeDemands.Count() > 1) { throw new MrpRunException( "A productionOrder can only have one parentDemand (stockExchangeDemand)."); } demandOrProvidersOfProductionOrderSubGraph.AddRange(stockExchangeDemands); foreach (var stockExchangeDemand in stockExchangeDemands) { Providers parentStockExchangeProviders = aggregator.GetAllParentProvidersOf(stockExchangeDemand); foreach (var parentStockExchangeProvider in parentStockExchangeProviders) { if (aggregator.GetAllChildDemandsOf(parentStockExchangeProvider).Count() == 1) { demandOrProvidersOfProductionOrderSubGraph.Add( parentStockExchangeProvider); } else { // stockExchangeProvider must stay } } } } Demands productionOrderBoms = aggregator.GetAllChildDemandsOf(productionOrder); demandOrProvidersOfProductionOrderSubGraph.AddRange(productionOrderBoms); if (includeStockExchanges) { foreach (var productionOrderBom in productionOrderBoms) { Providers stockExchangeProvider = aggregator.GetAllChildProvidersOf(productionOrderBom); if (stockExchangeProvider.Count() > 1) { throw new MrpRunException( "A ProductionOrderBom can only have one childProvider (stockExchangeProvider)."); } demandOrProvidersOfProductionOrderSubGraph.AddRange(stockExchangeProvider); } } return(demandOrProvidersOfProductionOrderSubGraph); }