Пример #1
0
        public int Run()
        {
            var logger = LoggerFactory.Create(b => b.AddConsole())
                         .CreateLogger("AistDoc");

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory());

            Console.WriteLine($"Reading config: {ConfigPath} ...");
            try {
                builder.AddJsonFile(ConfigPath);
            }
            catch (FileNotFoundException ex) {
                throw ex;
            }


            try {
                var startTime     = DateTime.UtcNow;
                var configuration = builder.Build();

                var aistantSettings = configuration.GetSection("aistant").Get <AistantSettings>();

                IArticlePublisher publisher = null;
                if (_outputOp.HasValue())
                {
                    publisher = new FileArticlePublisher(_outputOp.Value(), logger);
                }
                else
                {
                    publisher = new AistantArticlePublisher(aistantSettings, logger);
                }

                var mode = configuration["source:mode"]?.ToString();

                IDocGenerator generator;
                if (mode == "typescript")
                {
                    generator = new TypeScriptDocGenerator(configuration);
                }
                else
                {
                    generator = new CSharpDocGenerator(configuration, logger, _outputOp.Value());
                }

                var articleCount = generator.Generate(publisher);

                logger.LogInformation("Done! " + $"{articleCount} documents added or updated");
                logger.LogInformation("Time Elapsed : " + (DateTime.UtcNow - startTime));
                Thread.Sleep(100);
            }
            catch (Exception ex) {
                logger.LogCritical(ex.Message);

                Thread.Sleep(100);

                return(-1);
            }

            return(0);
        }
Пример #2
0
        static void Main(string[] args)
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            Console.WriteLine($"aistdoc utility {assembly.GetName().Version.ToString()} (c) Aistant 2018");
            Console.WriteLine("Current folder: " + Directory.GetCurrentDirectory());

            var loggerFactory = new LoggerFactory();
            var logger        = loggerFactory.AddConsole()
                                .CreateLogger("AistDoc");


            var startTime = DateTime.UtcNow;

            try {
                var dest = Directory.GetCurrentDirectory();

                var result = ReadArgs(args);
                if (!result)
                {
                    return;
                }

                var builder = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory());

                if (string.IsNullOrEmpty(_configFilePath))
                {
                    GenerateDefaultConfig("aistdoc.json", "cs");
                    throw new FileNotFoundException("Config file is required");
                }

                Console.WriteLine($"Reading config: {_configFilePath} ...");
                try {
                    builder.AddJsonFile(_configFilePath);
                }
                catch (FileNotFoundException ex) {
                    GenerateDefaultConfig(_configFilePath, "cs");
                    throw ex;
                }

                var configuration = builder.Build();

                var aistantSettings = configuration.GetSection("aistant").Get <AistantSettings>();

                IArticleSaver saver = null;
                if (!string.IsNullOrEmpty(_outputPath))
                {
                    saver = new FileSaver(_outputPath, logger);
                }
                else
                {
                    saver = new AistantSaver(aistantSettings, logger);
                }

                var mode = configuration["source:mode"].ToString();

                IDocGenerator generator;
                if (mode == "typescript")
                {
                    generator = new TypeScriptDocGenerator(configuration);
                }
                else
                {
                    generator = new CSharpDocGenerator(configuration, logger, _outputPath);
                }

                var articleCount = generator.Generate(saver);

                logger.LogInformation("Done! " + $"{articleCount} documents added or updated");
            }
            catch (Exception ex) {
                logger.LogCritical(ex.Message);
            }

            logger.LogInformation("Time Elapsed : " + (DateTime.UtcNow - startTime));
            Thread.Sleep(100);
        }