Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine();
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: extutil <option> [<extension>]");                //just name of the extension, not a path(it looks to defined Extension directory)
                Console.WriteLine("  Options:\n");
                Console.WriteLine("  -e  Lists errors that occured during extension loading and startup.\n");
                Console.WriteLine("  -m  Lists loaded extensions.\n");
                Console.WriteLine("  -f  Lists functions in all loaded extensions or");
                Console.WriteLine("      in a particular <extension>.\n");
                Console.WriteLine("  -c  Lists classes in all loaded extensions or");
                Console.WriteLine("      in a particular <extension>.\n");
                Console.WriteLine("  -w  Generates managed wrappers for all available extensions or");
                Console.WriteLine("      for a particular <extension> (need not be loaded).");
                return;
            }

            if (args.Length >= 2)
            {
                args[1] = args[1].ToLower();
                if (args[1].EndsWith(".dll"))
                {
                    args[1] = args[1].Substring(0, args[1].Length - 4);
                }
            }

            switch (args[0])
            {
            case "-e":
            {
                ICollection errors;
                try
                {
                    errors = Externals.GetStartupErrors();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to get error list.");
                    Console.WriteLine(e.ToString());
                    return;
                }

                if (errors != null && errors.Count > 0)
                {
                    Console.WriteLine("Startup errors:");
                    foreach (string item in errors)
                    {
                        Console.WriteLine(item);
                    }
                }
                else
                {
                    Console.WriteLine("No errors.");
                }
            }
            break;

            case "-m":
            {
                Console.WriteLine("Loaded extensions:");
                DoForAllExtensions(new Callback(Console.WriteLine));
                break;
            }

            case "-f":
            {
                if (args.Length >= 2)
                {
                    ListFunctions(args[1]);
                }
                else
                {
                    DoForAllExtensions(new Callback(ListFunctions));
                }
                break;
            }

            case "-c":
            {
                if (args.Length >= 2)
                {
                    ListClasses(args[1]);
                }
                else
                {
                    DoForAllExtensions(new Callback(ListClasses));
                }
                break;
            }

            case "-w":
            {
                if (args.Length >= 2)
                {
                    GenerateWrapper(args[1]);
                }
                else
                {
                    DoForAllAvailableExtensions(new Callback(GenerateWrapper));
                }
                break;
            }

            default:
                Console.WriteLine("Unknown option: " + args[0]);
                break;
            }

#if DEBUG
            Console.Write("Press Enter to close this window ...");
            Console.ReadLine();
#endif
        }