Beispiel #1
0
        private IEnumerable <IConceptInfo> InitializeAlternativeInitializationConcepts(IEnumerable <IConceptInfo> parsedConcepts)
        {
            var stopwatch   = Stopwatch.StartNew();
            var newConcepts = AlternativeInitialization.InitializeNonparsableProperties(parsedConcepts, _logger);

            _performanceLogger.Write(stopwatch, "InitializeAlternativeInitializationConcepts (" + newConcepts.Count() + " new concepts created).");
            return(newConcepts);
        }
Beispiel #2
0
        private void ExpandMacroConcepts(DslContainer dslContainer)
        {
            var swTotal = Stopwatch.StartNew();
            var sw      = Stopwatch.StartNew();

            int iteration = 0;
            var iterationCreatedConcepts      = new List <IConceptInfo>();
            int lastNewConceptTime            = 0;
            var lastNewConceptTimeByIteration = new List <int>();
            var lastNewConceptTimeByMacro     = new Dictionary <string, int>();
            var recommendedMacroOrder         = _macroOrderRepository.Load().ToDictionary(m => m.EvaluatorName, m => m.EvaluatorOrder);
            var macroEvaluators         = ListMacroEvaluators(recommendedMacroOrder);
            var macroStopwatches        = macroEvaluators.ToDictionary(macro => macro.Name, macro => new Stopwatch());
            var createdTypesInIteration = new List <CreatedTypesInIteration>(dslContainer.Concepts.Count() * 5);

            _performanceLogger.Write(sw, "ExpandMacroConcepts initialization ("
                                     + macroEvaluators.Count + " evaluators, "
                                     + dslContainer.Concepts.Count() + " parsed concepts resolved, "
                                     + dslContainer.UnresolvedConceptsCount() + " unresolved).");

            do
            {
                iteration++;
                if (iteration > MacroIterationLimit)
                {
                    throw new DslSyntaxException(string.Format(
                                                     "Possible infinite loop detected with recursive macro concept {1}. Iteration limit ({0}) exceeded while expanding macro.",
                                                     MacroIterationLimit,
                                                     iterationCreatedConcepts.First().GetShortDescription()));
                }

                iterationCreatedConcepts.Clear();
                _logger.Trace("Expanding macro concepts, iteration {0}.", iteration);

                foreach (var macroEvaluator in macroEvaluators)
                {
                    macroStopwatches[macroEvaluator.Name].Start();
                    foreach (var conceptInfo in dslContainer.FindByType(macroEvaluator.Implements, macroEvaluator.ImplementsDerivations).ToList())
                    {
                        var macroCreatedConcepts = macroEvaluator.Evaluate(conceptInfo, dslContainer);
                        CsUtility.Materialize(ref macroCreatedConcepts);

                        if (macroCreatedConcepts != null && macroCreatedConcepts.Any())
                        {
                            _logger.Trace(() => "Evaluating macro " + macroEvaluator.Name + " on " + conceptInfo.GetShortDescription() + ".");

                            var aiCreatedConcepts = AlternativeInitialization.InitializeNonparsableProperties(macroCreatedConcepts, _logger);

                            var newUniqueConcepts = dslContainer.AddNewConceptsAndReplaceReferences(aiCreatedConcepts);
                            newUniqueConcepts.AddRange(dslContainer.AddNewConceptsAndReplaceReferences(macroCreatedConcepts));

                            _logger.Trace(() => LogCreatedConcepts(dslContainer, macroCreatedConcepts, newUniqueConcepts));

                            iterationCreatedConcepts.AddRange(newUniqueConcepts);

                            // Optimization analysis:
                            if (newUniqueConcepts.Count > 0)
                            {
                                lastNewConceptTimeByMacro[macroEvaluator.Name] = ++lastNewConceptTime;
                            }
                            createdTypesInIteration.AddRange(newUniqueConcepts.Select(nuc =>
                                                                                      new CreatedTypesInIteration {
                                Macro = macroEvaluator.Name, Created = nuc.BaseConceptInfoType().Name, Iteration = iteration
                            }));
                        }
                    }
                    macroStopwatches[macroEvaluator.Name].Stop();
                }

                lastNewConceptTimeByIteration.Add(lastNewConceptTime);

                _performanceLogger.Write(sw, "ExpandMacroConcepts iteration " + iteration + " ("
                                         + iterationCreatedConcepts.Count + " new concepts, "
                                         + dslContainer.UnresolvedConceptsCount() + " left unresolved).");
            } while (iterationCreatedConcepts.Count > 0);

            _evaluatorsOrderLogger.Trace(() => swTotal.Elapsed + "\r\n"
                                         + ReportLastEvaluationOrder(lastNewConceptTimeByMacro, lastNewConceptTimeByIteration));

            foreach (var macroStopwatch in macroStopwatches.OrderByDescending(msw => msw.Value.Elapsed.TotalSeconds).Take(5))
            {
                _performanceLogger.Write(macroStopwatch.Value, () => "ExpandMacroConcepts total time for " + macroStopwatch.Key + ".");
            }

            _logger.Trace(() => LogCreatedTypesInIteration(createdTypesInIteration));

            dslContainer.ReportErrorForUnresolvedConcepts();

            SaveMacroEvaluationOrder(lastNewConceptTimeByMacro);

            _performanceLogger.Write(swTotal, "ExpandMacroConcepts.");
        }