コード例 #1
0
        private GeneratedDataMigrationScripts ExecutePlugins()
        {
            var stopwatch = Stopwatch.StartNew();

            var codeBuilder = new DataMigrationScriptBuilder();

            foreach (var conceptInfo in _dslModel.Concepts)
            {
                foreach (var plugin in _plugins.GetImplementations(conceptInfo.GetType()))
                {
                    try
                    {
                        plugin.GenerateCode(conceptInfo, codeBuilder);
                    }
                    catch (Exception ex)
                    {
                        _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 new FrameworkException($"Error while generating data-migration script for '{conceptInfo.GetUserDescription()}'.", ex);
                    }
                }
            }

            _logger.Trace(codeBuilder.GeneratedCode);

            _performanceLogger.Write(stopwatch, "DataMigrationScriptGenerator: Scripts generated.");

            return(codeBuilder.GetDataMigrationScripts());
        }
コード例 #2
0
        public void Generate()
        {
            var stopwatch = Stopwatch.StartNew();

            var codeBuilder = new DataMigrationScriptBuilder();

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

            foreach (var conceptInfo in _dslModel.Concepts)
            {
                foreach (var plugin in conceptImplementations[conceptInfo.GetType()])
                {
                    try
                    {
                        plugin.GenerateCode(conceptInfo, codeBuilder);
                    }
                    catch (Exception ex)
                    {
                        _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());
                        throw new FrameworkException($"Error while generating data-migration script for '{conceptInfo.GetUserDescription()}'.", ex);
                    }
                }
            }

            _performanceLogger.Write(stopwatch, "Scripts generated.");

            string serializedConcepts = JsonConvert.SerializeObject(codeBuilder.GetDataMigrationScripts(), Formatting.Indented);

            File.WriteAllText(Path.Combine(_rhetosBuildEnvironment.GeneratedAssetsFolder, ConceptDataMigrationScriptsFileName), serializedConcepts, Encoding.UTF8);
        }