public static void LoadAll()
        {
            string path = Settings.GetRunningDirectory() + "plugins" +
                          Path.DirectorySeparatorChar;

            log.Info("Plugin path: " + path);

            if (!Directory.Exists(path))
            {
                return;
            }

            // cs plugins are background compiled, and loaded in the ui thread
            Task.Run(() =>
            {
                String[] csFiles = Directory.GetFiles(path, "*.cs");

                foreach (var csFile in csFiles)
                {
                    log.Info("Plugin: " + csFile);

                    try
                    {
                        //csharp 5 max

                        // create a compiler
                        var compiler = CodeGen.CreateCompiler();
                        // get all the compiler parameters
                        var parms = CodeGen.CreateCompilerParameters();
                        // compile the code into an assembly
                        var results = CodeGen.CompileCodeFile(compiler, parms, csFile);

                        InitPlugin(results?.CompiledAssembly);

                        if (results?.CompiledAssembly != null)
                        {
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }

                    try
                    {
                        // csharp 8
                        var ans = CodeGenRoslyn.BuildCode(csFile);

                        InitPlugin(ans);

                        continue;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }

                MainV2.instance.BeginInvokeIfRequired(() =>
                {
                    PluginInit();
                });
            });

            String[] files = Directory.GetFiles(path, "*.dll");
            foreach (var s in files)
            {
                Load(Path.Combine(Environment.CurrentDirectory, s));
            }

            PluginInit();
        }
Пример #2
0
        public static void LoadAll()
        {
            string path = Settings.GetRunningDirectory() + "plugins" +
                          Path.DirectorySeparatorChar;

            log.Info("Plugin path: " + path);

            if (!Directory.Exists(path))
            {
                return;
            }

            // cs plugins are background compiled, and loaded in the ui thread
            Task.Run(() =>
            {
                String[] csFiles = Directory.GetFiles(path, "*.cs");

                foreach (var csFile in csFiles)
                {
                    log.Info("Plugin: " + csFile);
                    //Check if it is disabled (moved out from the previous IF, to make it loggable)
                    if (DisabledPluginNames.Contains(Path.GetFileName(csFile).ToLower()))
                    {
                        log.InfoFormat("Plugin {0} is disabled in config.xml", Path.GetFileName(csFile));
                        continue;
                    }

                    //loadassembly: MissionPlanner.WebAPIs
                    var content = File.ReadAllText(csFile);

                    var matches = Regex.Matches(content, @"^\/\/loadassembly: (.*)$", RegexOptions.Multiline);
                    foreach (Match m in matches)
                    {
                        try
                        {
                            log.Info("Try load " + m.Groups[1].Value.Trim());
                            Assembly.Load(m.Groups[1].Value.Trim());
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex);
                        }
                    }

                    try
                    {
                        // csharp 8
                        var ans = CodeGenRoslyn.BuildCode(csFile);

                        InitPlugin(ans, Path.GetFileName(csFile));

                        continue;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }


                    try
                    {
                        //csharp 5 max

                        // create a compiler
                        var compiler = CodeGen.CreateCompiler();
                        // get all the compiler parameters
                        var parms = CodeGen.CreateCompilerParameters();
                        // compile the code into an assembly
                        var results = CodeGen.CompileCodeFile(compiler, parms, csFile);

                        InitPlugin(results?.CompiledAssembly, Path.GetFileName(csFile));

                        if (results?.CompiledAssembly != null)
                        {
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                }

                MainV2.instance.BeginInvokeIfRequired(() =>
                {
                    PluginInit();
                });
            });

            String[] files = Directory.GetFiles(path, "*.dll");
            foreach (var s in files)
            {
                Load(Path.Combine(Environment.CurrentDirectory, s));
            }

            InitPlugin(Assembly.GetAssembly(typeof(PluginLoader)), "self");

            PluginInit();
        }
Пример #3
0
        public static void LoadAll()
        {
            string path = Settings.GetRunningDirectory() + "plugins" +
                          Path.DirectorySeparatorChar;

            log.Info("Plugin path: " + path);

            if (!Directory.Exists(path))
            {
                return;
            }

            String[] csFiles = Directory.GetFiles(path, "*.cs");

            foreach (var csFile in csFiles)
            {
                log.Info("Plugin: " + csFile);
                try
                {
                    // csharp 8
                    var ans = CodeGenRoslyn.BuildCode(csFile);

                    InitPlugin(ans);

                    continue;
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }

                try
                {
                    //csharp 5 max

                    // create a compiler
                    var compiler = CodeGen.CreateCompiler();
                    // get all the compiler parameters
                    var parms = CodeGen.CreateCompilerParameters();
                    // compile the code into an assembly
                    var results = CodeGen.CompileCodeFile(compiler, parms, csFile);

                    InitPlugin(results?.CompiledAssembly);
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            }

            String[] files = Directory.GetFiles(path, "*.dll");
            foreach (var s in files)
            {
                Load(Path.Combine(Environment.CurrentDirectory, s));
            }

            for (Int32 i = 0; i < Plugins.Count; ++i)
            {
                lock (Plugins)
                {
                    Plugin p = Plugins.ElementAt(i);
                    try
                    {
                        if (!p.Loaded())
                        {
                            Plugins.RemoveAt(i);
                            --i;
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        Plugins.RemoveAt(i);
                        --i;
                    }
                }
            }
        }