Inheritance: ILoggerListener
Exemple #1
0
        private static int ExecSubCommand(string[] args)
        {
            var consoleLogListener = new ConsoleLogListener();
            var replayListener = new ReplayLogListener();
            replayListener.AddListener(consoleLogListener);
            Logger.RegisterListener(replayListener);

            CommandController controller = null;
            ISubCommand command;
            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command = controller.Create();
            }
            catch (System.IO.FileNotFoundException fe)
            {
                Logger.LogError(fe.Message);
                return 1;
            }
            catch (OptionParserException e)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return 1;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return 1;
            }

            if (!(command is ILoggable))
            {
                replayListener.Replay = false;
            }

            var context = new SubCommandRunningContext();
            try
            {
                command.Exec(context);
                return 0;
            }
            catch (DocfxException de)
            {
                Logger.LogError(de.Message);
                return 1;
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return 1;
            }
        }
Exemple #2
0
        private static int Main(string[] args)
        {
            try
            {
                var exitCode = 0;
                if (args.Length != 3 && args.Length != 4)
                {
                    PrintUsage();
                    return 1;
                }

                // Parse the basic arguments
                var rewriterToolArguments = ParseRewriterToolArgumentsFile(args[0], args[1], args[2]);
                if (rewriterToolArguments == null)
                {
                    return 1;
                }

                // Register logger
                var consoleLogListener = new ConsoleLogListener();
                var htmlLogFile = Path.Combine(rewriterToolArguments.AzureTransformArgumentsList.First().SourceDir, "log", "log.html");
                if (File.Exists(htmlLogFile))
                {
                    File.Delete(htmlLogFile);
                }
                var htmlLogListener = new HtmlLogListener(htmlLogFile);
                Logger.RegisterListener(consoleLogListener);
                Logger.RegisterListener(htmlLogListener);

                // Parse advanced migration parameters
                AzureFileInformationCollection azureFileInformationCollection = new AzureFileInformationCollection();
                if (args.Length == 4)
                {
                    azureFileInformationCollection.AzureVideoInfoMapping = AzureVideoHelper.ParseAzureVideoFile(args[3], rewriterToolArguments.IsMigration);
                }

                if (rewriterToolArguments.IsMigration)
                {
                    GenerateAzureFileInfoForMigration(args[0], rewriterToolArguments, args[2], azureFileInformationCollection);
                }
                else
                {
                    GenerateAzureFileInfo(args[0], rewriterToolArguments, args[2], azureFileInformationCollection);
                }

                foreach (var azureTransformArguments in rewriterToolArguments.AzureTransformArgumentsList)
                {
                    var p = new Program(rewriterToolArguments.IsMigration, azureTransformArguments.SourceDir, azureTransformArguments.DestDir, azureFileInformationCollection);
                    if (!p.CheckParameters())
                    {
                        continue;
                    }

                    var result = p.Rewrite();
                    if (result != 0)
                    {
                        exitCode = result;
                    }
                }
                return exitCode;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                return 1;
            }
            finally
            {
                Logger.Flush();
                Logger.UnregisterAllListeners();
            }
        }
Exemple #3
0
        private static int ExecSubCommand(string[] args)
        {
            var consoleLogListener = new ConsoleLogListener();
            var replayListener = new ReplayLogListener();
            replayListener.AddListener(consoleLogListener);
            Logger.RegisterListener(replayListener);

            CommandController controller = null;
            ISubCommand command;
            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command = controller.Create();
            }
            catch (System.IO.FileNotFoundException fe)
            {
                Logger.LogError(fe.Message);
                return 1;
            }
            catch (Exception e) when (e is OptionParserException || e is InvalidOptionException)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return 1;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return 1;
            }

            replayListener.Replay = command.AllowReplay;

            var context = new SubCommandRunningContext();
            try
            {
                ThreadPool.SetMinThreads(4, 4);
                using (new PerformanceScope("executing", LogLevel.Info))
                {
                    command.Exec(context);
                }

                return 0;
            }
            catch (DocumentException de)
            {
                Logger.LogError(de.Message);
                return 1;
            }
            catch (DocfxException de)
            {
                Logger.LogError(de.Message);
                return 1;
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return 1;
            }
        }