private CodeBuilder BuildCode <TPlugin>(IPluginsContainer <TPlugin> plugins, string tagOpen, string tagClose, IConceptCodeGenerator initialCodeGenerator) where TPlugin : IConceptCodeGenerator
        {
            var stopwatch = Stopwatch.StartNew();

            var codeBuilder = new CodeBuilder(tagOpen, tagClose);

            if (initialCodeGenerator != null)
            {
                initialCodeGenerator.GenerateCode(null, codeBuilder);
            }

            var conceptImplementations = _dslModel.GetTypes()
                                         .ToDictionary(conceptType => conceptType, conceptType => plugins.GetImplementations(conceptType).ToList());

            _performanceLogger.Write(stopwatch, $"Get implementations for {typeof(TPlugin).FullName}.");

            var implementationStopwatches = conceptImplementations.SelectMany(ci => ci.Value)
                                            .Select(plugin => plugin.GetType())
                                            .Distinct()
                                            .ToDictionary(pluginType => pluginType, pluginType => new Stopwatch());

            foreach (var conceptInfo in _dslModel.Concepts)
            {
                foreach (var plugin in conceptImplementations[conceptInfo.GetType()])
                {
                    try
                    {
                        var implementationStopwatch = implementationStopwatches[plugin.GetType()];
                        implementationStopwatch.Start();
                        plugin.GenerateCode(conceptInfo, codeBuilder);
                        implementationStopwatch.Stop();
                    }
                    catch (Exception e)
                    {
                        _logger.Info("Part of the source code that was generated before the exception was thrown is written in the trace log.");
                        _logger.Trace(() => codeBuilder.GenerateCode());
                        ExceptionsUtility.Rethrow(e);
                    }
                }
            }

            foreach (var imp in implementationStopwatches.OrderByDescending(i => i.Value.Elapsed.TotalSeconds).Take(3))
            {
                _performanceLogger.Write(imp.Value, () => $"{typeof(TPlugin).Name} total time for {imp.Key}.");
            }

            _performanceLogger.Write(stopwatch, $"Code generated for {typeof(TPlugin).FullName}.");
            return(codeBuilder);
        }
        public IDictionary <string, IAssemblySource> ExecutePluginsToFiles <TPlugin>(IPluginsContainer <TPlugin> plugins, string tagOpen, string tagClose, IConceptCodeGenerator initialCodeGenerator)
            where TPlugin : IConceptCodeGenerator
        {
            var codeBuilder = BuildCode(plugins, tagOpen, tagClose, initialCodeGenerator);

            return(codeBuilder.GeneratedCodeByFile
                   .ToDictionary(
                       codeFile => codeFile.Key,
                       codeFile => (IAssemblySource) new AssemblySource
            {
                GeneratedCode = codeFile.Value,
                RegisteredReferences = codeBuilder.RegisteredReferences
            }));
        }
        public IAssemblySource ExecutePlugins <TPlugin>(IPluginsContainer <TPlugin> plugins, string tagOpen, string tagClose, IConceptCodeGenerator initialCodeGenerator)
            where TPlugin : IConceptCodeGenerator
        {
            var codeBuilder = BuildCode(plugins, tagOpen, tagClose, initialCodeGenerator);

            return(new AssemblySource
            {
                GeneratedCode = codeBuilder.GenerateCode(),
                RegisteredReferences = codeBuilder.RegisteredReferences
            });
        }
Exemple #4
0
        public IDictionary <string, string> ExecutePluginsToFiles <TPlugin>(IPluginsContainer <TPlugin> plugins, string tagOpen, string tagClose, IConceptCodeGenerator initialCodeGenerator)
            where TPlugin : IConceptCodeGenerator
        {
            var codeBuilder = BuildCode(plugins, tagOpen, tagClose, initialCodeGenerator);

            return(codeBuilder.GeneratedCodeByFile);
        }
Exemple #5
0
        public string ExecutePlugins <TPlugin>(IPluginsContainer <TPlugin> plugins, string tagOpen, string tagClose, IConceptCodeGenerator initialCodeGenerator)
            where TPlugin : IConceptCodeGenerator
        {
            var codeBuilder = BuildCode(plugins, tagOpen, tagClose, initialCodeGenerator);

            return(codeBuilder.GenerateCode());
        }
Exemple #6
0
        public IAssemblySource ExecutePlugins <TPlugin>(IPluginsContainer <TPlugin> plugins, string tagOpen, string tagClose, IConceptCodeGenerator initialCodeGenerator)
            where TPlugin : IConceptCodeGenerator
        {
            var stopwatch = Stopwatch.StartNew();

            var codeBuilder = new CodeBuilder(tagOpen, tagClose);

            if (initialCodeGenerator != null)
            {
                initialCodeGenerator.GenerateCode(null, codeBuilder);
            }

            foreach (var conceptInfo in _dslModel.Concepts)
            {
                foreach (var plugin in plugins.GetImplementations(conceptInfo.GetType()))
                {
                    try
                    {
                        plugin.GenerateCode(conceptInfo, codeBuilder);
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex.ToString());
                        _logger.Error("Part of the source code that was generated before the exception was thrown is written in the trace log.");
                        _logger.Trace(codeBuilder.GeneratedCode);
                        throw;
                    }
                }
            }

            _performanceLogger.Write(stopwatch, "CodeGenerator: Code generated.");

            return(codeBuilder);
        }