Exemplo n.º 1
0
        /// <summary>
        /// The entry point of the application.
        /// </summary>
        /// <param name="args">The array of arguments passed in on the command line.</param>
        /// <exception cref="System.ArgumentNullException">command line arguments: args</exception>
        public static void Main(string[] args)
        {
            ConsoleArguments arg        = ConsoleArguments.Create(args);
            string           loaderData = arg.In;

            if (!File.Exists(loaderData))
            {
                Console.WriteLine(Resource.FileNotFound, loaderData);
                Environment.Exit(1);
            }

            IList <GatorData> sources = JsonConvert.DeserializeObject <IList <GatorData> >(
                File.ReadAllText(loaderData)
                );

            foreach (GatorData source in sources)
            {
                new Blender(
                    Loader.LoadParser(
                        source.Parser.AssemblyName,
                        source.Parser.ClassName,
                        source
                        ),
                    Loader.LoadListeners(source.Listeners),
                    Loader.LoadLogContent(source.Location)
                    ).Parse();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new "this" filled with parsed argument values and returns it.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>This class.</returns>
        /// <remarks>Comments above are taken directly from the Ookii SampleArguments.</remarks>
        public static ConsoleArguments Create(string[] args)
        {
            // Using a static creation function for a command line arguments class is not required, but it's a convenient
            // way to place all command-line related functionality in one place. To parse the arguments (eg. from the Main method)
            // you then only need to call this function.
            CommandLineParser consoleParser = new CommandLineParser(typeof(ConsoleArguments));

            // The ArgumentParsed event is used by this sample to stop parsing after the -Help argument is specified.
            consoleParser.ArgumentParsed += ArgumentParsed;
            try {
                // The Parse function returns null only when the ArgumentParsed event handler cancelled parsing.
                ConsoleArguments result = (ConsoleArguments)consoleParser.Parse(args);
                if (result != null)
                {
                    return(result);
                }
            } catch (CommandLineArgumentException ex) {
                // We use the LineWrappingTextWriter to neatly wrap console output.
                using (LineWrappingTextWriter writer = LineWrappingTextWriter.ForConsoleError()) {
                    // Tell the user what went wrong.
                    writer.WriteLine(ex.Message);
                    writer.WriteLine();
                }
            }

            // If we got here, we should print usage information to the console.
            // By default, aliases and default values are not included in the usage descriptions; for this sample, I do want to include them.
            WriteUsageOptions options = new WriteUsageOptions();

            options.IncludeDefaultValueInDescription = true;
            options.IncludeAliasInDescription        = true;
            // WriteUsageToConsole automatically uses a LineWrappingTextWriter to properly word-wrap the text.
            consoleParser.WriteUsageToConsole(options);

            return(null);
        }