Example #1
0
        private static int Main(string[] args)
        {
            ArgumentsLoader argumentsLoader = new ArgumentsLoader();

            argumentsLoader.Load(args);

            var log = argumentsLoader.Verbose ? OutputLog.FromWriter(Console.Out) : OutputLog.Empty();

            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => log.WriteLine("UnhandledException: {0}.", eventArgs.ExceptionObject);

            try
            {
                if (argumentsLoader.AreAllRequiredParametersSet)
                {
                    var task = new TransformationTask(
                        log,
                        argumentsLoader.SourceFilePath,
                        argumentsLoader.TransformFilePath,
                        argumentsLoader.PreserveWhitespace);

                    if (argumentsLoader.Indent)
                    {
                        task.Indent      = argumentsLoader.Indent;
                        task.IndentChars = argumentsLoader.IndentChars;
                    }

                    IDictionary <string, string> parameters = new Dictionary <string, string>();

                    if (!string.IsNullOrWhiteSpace(argumentsLoader.ParametersString))
                    {
                        var parser = new ParametersParser(log);
                        parser.ReadParameters(argumentsLoader.ParametersString, parameters);
                    }

                    if (!string.IsNullOrWhiteSpace(argumentsLoader.ParametersFile))
                    {
                        ParametersLoader.LoadParameters(argumentsLoader.ParametersFile, parameters);
                    }

                    task.SetParameters(parameters);

                    if (!task.Execute(argumentsLoader.DestinationFilePath))
                    {
                        return(4);
                    }
                }
                else
                {
                    ShowToolHelp();
                    return(1);
                }

                return(0);
            }
            catch (Exception e)
            {
                log.WriteLine("Unexpected exception: {0}.", e);
                return(4);
            }
        }
Example #2
0
        private static int Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
            var argumentsLoader = new ArgumentsLoader();

            if (!argumentsLoader.Load(args))
            {
                return(4);
            }

            OutputLog log = null;

            if (argumentsLoader.Verbose)
            {
                log = OutputLog.FromWriter(Console.Out, Console.Error);
            }
            else if (argumentsLoader.Quiet)
            {
                log = OutputLog.NoLogs();
            }
            else
            {
                log = OutputLog.ErrorOnly(Console.Error);
            }

            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => log.WriteErrorLine("UnhandledException: {0}.", eventArgs.ExceptionObject);

            try
            {
                if (argumentsLoader.AreAllRequiredParametersSet)
                {
                    var task = new TransformationTask(
                        log,
                        argumentsLoader.SourceFilePath,
                        argumentsLoader.TransformFilePath,
                        argumentsLoader.PreserveWhitespace);

                    if (argumentsLoader.Indent)
                    {
                        task.Indent      = argumentsLoader.Indent;
                        task.IndentChars = argumentsLoader.IndentChars;
                    }

                    if (argumentsLoader.DefaultEncoding != null)
                    {
                        task.DefaultEncoding = argumentsLoader.DefaultEncoding;
                    }

                    if (argumentsLoader.IgnoreMissingTransformation)
                    {
                        task.IgnoreMissingTransformation = true;
                    }

                    IDictionary <string, string> parameters = new Dictionary <string, string>();

                    if (!string.IsNullOrWhiteSpace(argumentsLoader.ParametersString))
                    {
                        var parser = new ParametersParser(log);
                        parser.ReadParameters(argumentsLoader.ParametersString, parameters);
                    }

                    if (!string.IsNullOrWhiteSpace(argumentsLoader.ParametersFile))
                    {
                        ParametersLoader.LoadParameters(argumentsLoader.ParametersFile, parameters);
                    }

                    task.SetParameters(parameters);

                    if (!task.Execute(argumentsLoader.DestinationFilePath, argumentsLoader.ForceParametersTask))
                    {
                        return(4);
                    }
                }
                else
                {
                    ShowToolHelp();
                    return(1);
                }

                return(0);
            }
            catch (Exception e)
            {
                log.WriteErrorLine("Unexpected exception: {0}.", e);
                return(4);
            }
        }