Пример #1
0
        /// <summary>
        /// Runs the specified directory.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="pattern">The pattern.</param>
        /// <param name="generatorOptions">The generator options.</param>
        /// <returns>
        /// A list of output names.
        /// </returns>
        public static async Task <ConcurrentBag <string> > RunAsync(string directory, string pattern, GeneratorOptions?generatorOptions = null)
        {
            generatorOptions ??= GeneratorOptions.Default;
            using var progressReporter = new ProgressReporterFactory().Create(generatorOptions.ProgressReporter, generatorOptions.ProgressTextWriter);
            try
            {
                progressReporter.Start();
                directory = string.IsNullOrEmpty(directory)
                    ? Environment.CurrentDirectory
                    : Path.IsPathRooted(directory)
                        ? directory
                        : Path.Combine(Environment.CurrentDirectory, directory);
                var searchPattern       = string.IsNullOrEmpty(pattern) ? "*.gs.json" : pattern;
                var generatorDiscoverer = new SetupDiscoverer(new SetupFileFinder(), new JsonSetupProvider());
                var setupInfos          = await generatorDiscoverer.DiscoverAsync(directory, searchPattern).ConfigureAwait(false);

                var generatorRunnerFactory = new GeneratorRunnerFactory();
                var generatorRunner        = generatorRunnerFactory.Create(setupInfos);

                return(await generatorRunner.GenerateAsync(generatorOptions, new ProgressTracker <Report>(progressReporter)).ConfigureAwait(false));
            }
            catch (Exception)
            {
                progressReporter.Stop();
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Runs the asynchronous.
        /// </summary>
        /// <param name="setupsFactory">The setups factory.</param>
        /// <param name="generatorOptions">The generator options.</param>
        /// <returns>
        /// A list of output names.
        /// </returns>
        public static async Task <ConcurrentBag <string> > RunAsync(ISetupsFactory setupsFactory, GeneratorOptions?generatorOptions = null)
        {
            generatorOptions ??= GeneratorOptions.Default;
            using var progressReporter = new ProgressReporterFactory().Create(generatorOptions.ProgressReporter, generatorOptions.ProgressTextWriter);
            try
            {
                progressReporter.Start();
                var generatorRunnerFactory = new GeneratorRunnerFactory();
                var generatorRunner        = generatorRunnerFactory.Create((await setupsFactory.GetSetupsAsync().ConfigureAwait(false))
                                                                           .Select(x => new SetupInfo(setupsFactory.GetType().ToString(), x)));

                return(await generatorRunner.GenerateAsync(generatorOptions, new ProgressTracker <Report>(progressReporter)).ConfigureAwait(false));
            }
            catch (Exception)
            {
                progressReporter.Stop();
                throw;
            }
        }