While.PluginLoader.Load C# (CSharp) Method

Load() public method

public Load ( List pluginNames ) : void
pluginNames List
return void
        public void Load(List<string> pluginNames)
        {
            if (pluginNames.Count == 0) {
                return;
            }
            string path;
            path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
            path = Path.Combine(path, "plugins");
            path = Regex.Replace(path,@"^file\:(/|\\){1,2}", "");
            Console.WriteLine(path);
            if (!Directory.Exists(path)) {
                Console.Error.WriteLine("No plugins folder found, no plugins will be loaded!");
                return;
            }
            string[] files = Directory.GetFiles(path);
            foreach (string file in files) {
                if (file.ToLower().EndsWith(".dll")) {
                    LoadPluginTypes(pluginNames, file);
                }
            }

            //Check for missing plugins...
            foreach (string name in pluginNames) {
                bool found = false;
                foreach (ICompilerPlugin plugin in _loadedPlugins) {
                    if (plugin.Identifier == name) {
                        found = true;
                    }
                }
                if (!found) {
                    Console.Error.WriteLine("Failed to load plugin '{0}', it is not in any dll's in the plugins folder.", name);
                }
            }
        }

Usage Example

コード例 #1
0
        public static int Main(string[] args)
        {
            try {
                Version v = Assembly.GetExecutingAssembly().GetName().Version;
                string version = v.Major + "." + v.Minor + "." + v.Build;
                Console.WriteLine("While.NET Compiler v" + version);
                Console.WriteLine("Copyright (C) Einar Egilsson 2009. All rights reserved.");
                Console.WriteLine();

                CommandLineOptions options = new CommandLineOptions(args);
                if (options.Empty) {
                    System.Console.Error.WriteLine("ERROR: No inputs specified");
                    return 1;
                } else if (options.Help) {
                    System.Console.Error.WriteLine("Usage: wc.exe [options] filename");
                    CommandLineOptions.Print();
                    return 2;
                } else if (!options.ReadStdIn && !File.Exists(options.InputFilename)) {
                    System.Console.Error.WriteLine("ERROR: File '{0}' does not exist", options.InputFilename);
                    return 3;
                }

                Parser parser;
                if (options.ReadStdIn) {
                    //Passing the StdIn stream directly to the scanner doesn't work well
                    //so we do it this way instead
                    string source = Console.In.ReadToEnd();
                    StreamWriter writer = new StreamWriter(new MemoryStream());
                    writer.Write(source);
                    writer.Flush();
                    writer.BaseStream.Seek(0, SeekOrigin.Begin);
                    parser = new Parser(new Scanner(writer.BaseStream), options);
                } else {
                    parser = new Parser(new Scanner(new FileStream(options.InputFilename, FileMode.Open)), options);
                }
                parser.Parse();
                if (parser.errors.count > 0) {
                    return 1;
                }
                WhileProgram.SymbolTable.Clear();
                PluginLoader pluginLoader = new PluginLoader();
                pluginLoader.Load(options.Plugins);

                foreach (ICompilerPlugin plugin in pluginLoader.LoadedPlugins) {
                    Console.WriteLine("Executing the '{0}' plugin...", plugin.Name);
                    plugin.ProcessSyntaxTree(WhileProgram.Instance);
                }

                WhileProgram.Instance.Compile(options.OutputFilename);
                Console.WriteLine();
                Console.WriteLine("Compiled program to '{0}'", options.OutputFilename);
                return 0;
            } catch (Exception ex) {
                Console.Error.WriteLine("ERROR: " + ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                return 1;
            }
        }
All Usage Examples Of While.PluginLoader::Load