Пример #1
0
        public static async Task <SystemModel> Build(IMapper mapper, FalconDbContext dbContext, bool includeData)
        {
            SystemModel result = new SystemModel();

            var users = await dbContext.Users.ToListAsync();

            var customers = await dbContext.Customers
                            .Include(c => c.Products).ThenInclude(c => c.Anchors)
                            .Include(c => c.Squads).ThenInclude(d => d.Members)
                            .ToListAsync();

            var journeys = await dbContext.Journeys.Include(c => c.FeatureMap).ToListAsync();

            var features = await dbContext.Features
                           .Include(c => c.Indicators)
                           .Include(c => c.Squads)
                           .ToListAsync();

            var sources = await dbContext.Sources.ToListAsync();

            var sourceItems = new List <SourceItemEntity>();

            if (includeData)
            {
                sourceItems = await dbContext.SourcesItems.ToListAsync();
            }

            var securityThreats = await dbContext.SecurityThreats.ToListAsync();

            var securityRisks = await dbContext.SecurityRisks.ToListAsync();

            var reliabilityThreats = await dbContext.ReliabilityThreats.ToListAsync();

            var reliabilityRisks = await dbContext.ReliabilityRisks.ToListAsync();

            SystemModelBuilder.PrepareData(users, customers,
                                           securityRisks, reliabilityRisks,
                                           journeys, features, sources, sourceItems);

            result.AddUsers(users);

            var securityThreatModels = mapper.Map <IEnumerable <SecurityThreatModel> >(securityThreats);

            result.AddSecurityThreats(securityThreatModels);

            var securityRiskModels = mapper.Map <IEnumerable <SecurityRiskModel> >(securityRisks);

            result.AddSecurityRisks(securityRiskModels);

            var reliabilityThreatModels = mapper.Map <IEnumerable <ReliabilityThreatModel> >(reliabilityThreats);

            result.AddReliabilityThreats(reliabilityThreatModels);

            var reliabilityRiskModels = mapper.Map <IEnumerable <ReliabilityRiskModel> >(reliabilityRisks);

            result.AddReliabilityRisks(reliabilityRiskModels);

            foreach (var customer in customers)
            {
                result.AddOrganization(customer);
                result.AddSquads(customer.Name, customer.Squads);
                result.AddProducts(customer.Name, customer.Products);

                foreach (var squad in customer.Squads)
                {
                    result.AddMembers(customer.Name, squad.Name, squad.Members);
                }
                foreach (var product in customer.Products)
                {
                    result.AddAnchors(customer.Name, product.Name, product.Anchors);
                    result.AddJourneys(customer.Name, product.Name, product.Journeys);
                    foreach (var journey in product.Journeys)
                    {
                        result.AddJourneyMaps(customer.Name, product.Name, journey.Name, journey.FeatureMap);
                    }
                    result.AddFeatures(customer.Name, product.Name, product.Features);
                    foreach (var feature in product.Features)
                    {
                        result.AddIndicator(customer.Name, product.Name, feature.Name, feature.Indicators);
                        result.AddSquadFeature(customer.Name, product.Name, feature.Name, feature.Squads);
                    }
                    result.AddSources(customer.Name, product.Name, product.Sources);
                    foreach (var source in product.Sources)
                    {
                        result.AddSourceItem(customer.Name, product.Name, source.Name, source.SourceItems);
                    }
                }
            }

            return(result);
        }