protected override void Act()
            {
                // simulate writing the data twice
                _templateWriter.WriteAsync(_templateWriterData, CancellationToken.None)
                .RunSynchronously();

                _templateWriter.WriteAsync(_templateWriterData, CancellationToken.None)
                .RunSynchronously();
            }
Esempio n. 2
0
        public async Task ProcessAsync(AssemblyData assemblyData, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _logger.Info($"Processing started for assembly: {assemblyData.AssemblyName} in folder: {assemblyData.Path}");

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var templateContext = _templateContextProvider.Create(assemblyData);

            foreach (var templateSet in _templateSetProvider.GetTemplatesByName(assemblyData.TemplateSet))
            {
                templateContext.With(templateSet);

                _logger.Debug($"Generating code for template {templateSet.Name}");

                var generator = _generatorProvider.GetGeneratorByDriverName(templateSet.Driver);

                if (generator != null)
                {
                    var templateStopwatch = new Stopwatch();
                    templateStopwatch.Start();

                    var model = generator.Generate(templateContext);

                    _logger.Debug($"Generating template data for template {templateSet.Name}");

                    string outputPath = Path.Combine(assemblyData.Path, templateSet.OutputPath);

                    var codeGenWriterData = new TemplateWriterData
                    {
                        TemplateSet = templateSet,
                        Model       = model,
                        OutputPath  = outputPath
                    };

                    _logger.Debug($"Writing template data for path {outputPath}");

                    await _templateWriter.WriteAsync(codeGenWriterData, cancellationToken)
                    .ConfigureAwait(false);

                    templateStopwatch.Stop();

                    _logger.Debug(
                        $"Code generation for template {templateSet.Name} completed in {templateStopwatch.Elapsed.ToString()}.");
                }
                else
                {
                    _logger.Debug($"TemplateSet model not found for {templateSet.Name}, skipping.");
                }
            }

            stopWatch.Stop();

            _logger.Info($"Processing complete for assembly: {assemblyData.AssemblyName} in {stopWatch.Elapsed.ToString()}.");
        }
Esempio n. 3
0
 public void Should_call_templateWriter_WriteAsync_once()
 => A.CallTo(() => _templateWriter.WriteAsync(A <TemplateWriterData> .That.IsNotNull(), CancellationToken.None))
 .MustHaveHappenedOnceExactly();