Esempio n. 1
0
 public void InitializePlugins()
 {
     foreach (var pluginHost in LoadedPlugins.Where(lp => lp.Enabled))
     {
         foreach (var plugin in pluginHost.PluginHost.Plugins)
         {
             plugin.Initialize();
         }
     }
 }
Esempio n. 2
0
        public async void RunPlugins(PluginTypes types, Board board, Thread thread, Response response, Session session)
        {
            var targetPlugin = LoadedPlugins.Where(x => (x.PluginType & types) == types &&
                                                   x.IsEnabled &&
                                                   x.Valid &&
                                                   x.ActivatedBoards.Contains(board.BoardKey))
                               .OrderBy(x => x.Priority);

            foreach (var item in targetPlugin)
            {
                try
                {
                    await item.Script.RunAsync(new ZerochSharpPlugin(board, thread, response, types,
                                                                     item.BoardSetting?[board.BoardKey] as dynamic, session));
                }
                catch (CompilationErrorException ex)
                {
                    Console.WriteLine("Error in plugin running.");
                    Console.WriteLine(ex.Message);
                    var plugin = LoadedPlugins.FirstOrDefault(x => x.PluginPath == item.PluginPath);
                    if (plugin == null)
                    {
                        throw new InvalidOperationException();
                    }

                    plugin.Valid = false;
                    await SavePluginInfo();

                    Console.WriteLine($"Plugin {item.PluginName} is disabled.");
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("error in running plugin", e);
                }
            }
        }