示例#1
0
        /// <summary>
        /// Returns RunModel for run
        /// </summary>
        /// <param name="run"></param>
        /// <param name="scenarioRepository"></param>
        /// <param name="passRepository"></param>
        /// <param name="tenantSettingsRepository"></param>
        /// <param name="allCampaigns"></param>
        /// <param name="functionalAreaRepository"></param>
        /// <returns></returns>
        public static RunModel MapToRunModel(Run run, IScenarioRepository scenarioRepository, IPassRepository passRepository,
                                             ITenantSettingsRepository tenantSettingsRepository, IMapper mapper,
                                             IAnalysisGroupRepository analysisGroupRepository,
                                             IFunctionalAreaRepository functionalAreaRepository = null,
                                             IScenarioCampaignMetricRepository scenarioCampaignMetricRepository = null,
                                             List <CampaignWithProductFlatModel> allCampaigns = null,
                                             List <Pass> passesFromDb = null, List <Scenario> scenariosFromDb = null)
        {
            // Get scenarios for run
            var scenarios = scenariosFromDb ?? scenarioRepository.FindByIds(run.Scenarios.Select(s => s.Id)).ToList();

            // Get passes for run
            var passes = passesFromDb ?? passRepository.FindByIds(scenarios.SelectMany(s => s.Passes).Select(p => p.Id).Distinct()).ToList();

            var analysisGroups = run.AnalysisGroupTargets.Any()
                ? analysisGroupRepository.GetByIds(run.AnalysisGroupTargets.Select(x => x.AnalysisGroupId).ToArray()).ToDictionary(x => x.Id)
                : new Dictionary <int, AnalysisGroupNameModel>();

            // Get default ScenarioId
            var defaultScenarioId = tenantSettingsRepository.GetDefaultScenarioId();

            if (run.RunStatus == RunStatus.NotStarted && allCampaigns != null && allCampaigns.Any())
            {
                // Since the run has not already started amend Run Scenarios
                // with CampaignPassPriorities for new Campaigns and remove
                // CampaignPassPriorities of deleted Campaigns
                CampaignPassPrioritiesServiceMapper.AmendCampaignPassPriorities(
                    scenarios,
                    passes,
                    allCampaigns,
                    passRepository,
                    mapper);
            }

            var runModel = mapper.Map <RunModel>(Tuple.Create(run, scenarios, passes, analysisGroups, defaultScenarioId));

            if (run.RunStatus == RunStatus.Complete)
            {
                ApplyFunctionalAreaFaultTypesToRunModel(runModel, run, functionalAreaRepository);
            }

            if (scenarioCampaignMetricRepository != null)
            {
                runModel.Scenarios.ForEach(s => ApplyKPIsToScenarioCampaigns(s, scenarioCampaignMetricRepository));
            }

            return(runModel);
        }