public void InitializeChartFromTemplate(CurveChart chart, IEnumerable <DataColumn> dataColumns, CurveChartTemplate template, Func <DataColumn, string> curveNameDefinition = null, bool warnIfNumberOfCurvesAboveThreshold = false, bool propogateChartChangeEvent = true, int warningThreshold = Constants.DEFAULT_TEMPLATE_WARNING_THRESHOLD) { try { _allColumnsByPath = dataColumns.Select(x => new ColumnPath(x)).ToList(); _curveNameDefinition = curveNameDefinition ?? (x => x.Name); //Retrieve all possible curves for each curve template defined in the given template var curvesForTemplates = new Cache <CurveTemplate, TemplateToColumnsMatch>(x => x.CurveTemplate); template.Curves.Each(curveTemplate => curvesForTemplates.Add(allPossibleCurvesForTemplate(curveTemplate))); var bestTemplateForCurves = findBestTemplateForCurves(curvesForTemplates); //Ensure that the user wants to continue if the threshold is exceeded var numberOfCreatedColumns = bestTemplateForCurves.Sum(x => x.Count); if (numberOfCreatedColumns > warningThreshold && warnIfNumberOfCurvesAboveThreshold) { var shouldContinue = _dialogCreator.MessageBoxYesNo(Captions.NumberOfSelectedCurveWouldGoOverThreshold(numberOfCreatedColumns)); if (shouldContinue == ViewResult.No) { return; } } //Last but not least, update the chart updateChartFromTemplateWithMatchingCurves(chart, template, bestTemplateForCurves, propogateChartChangeEvent); } finally { _curveNameDefinition = null; _allColumnsByPath.Clear(); } }