Ejemplo n.º 1
0
        public void Run(ParsedMessage message, AWatcherService service, t2sDbLibrary.IDBController controller)
        {
            String engineHash = null;

            Task LuaCodeTask = null;
            try
            {
                // Get to a clean state
                loadNewLuaEngine();

                // Register our plugin so we can call C# methods
                engineHash = LuaScriptingEngine.registerPlugin(this, message, service, controller, this.LuaEngine);

                Thread LuacodeThread = null;
                // Run the script
                LuaCodeTask = new Task(() =>
                {
                    LuacodeThread = Thread.CurrentThread;
                    RunLuaCode(this.LuaEngine, this.ScriptFileLoc);
                });
                LuaCodeTask.Start();

                bool finished = true;

                try
                {
                    if (!LuaCodeTask.Wait(LUADefinitions.MaxRunTime))
                    {
                        finished = false;

                        // Sorry Lua Code, gotta die now
                        LuacodeThread.Abort();
                    }
                }
                catch (AggregateException ex)
                {
                    if (ex.InnerExceptions.Count > 0)
                        throw ex.InnerExceptions[0];
                }

                if (!finished)
                    registerFailedRun(message, service, controller,
                        new LuaException("Lua script ran too long. Max runtime is: " + LUADefinitions.MaxRunTime.ToString()));
            }
            catch (LuaException ex)
            {
                registerFailedRun(message, service, controller, ex);
            }
            finally
            {
                if (engineHash != null)
                {
                    if (!LuaScriptingEngine.unregisterPlugin(engineHash))
                        Logger.LogMessage("LUAPlugin.Run: Couldn't unregister plugin! (" + this.PluginDAO.Name + ")", LoggerLevel.SEVERE);
                }
            }
        }
Ejemplo n.º 2
0
        private void registerFailedRun(ParsedMessage message, AWatcherService service, t2sDbLibrary.IDBController controller, Exception ex)
        {
            // Increment the error counter
            controller.IncrementPluginFailedAttemptCount(this.PluginDAO.PluginID);

            // Disable if above threshold
            int count = controller.GetPluginFailedAttemptCount(this.PluginDAO.PluginID);
            Logger.LogMessage(this.PluginDAO.Name + @": " + ex.Message, LoggerLevel.WARNING);
            if (count > LUADefinitions.DisablePluginAboveErrorCount)
            {
                controller.DisableGlobalPlugin(this.PluginDAO.PluginID);
                Logger.LogMessage(this.PluginDAO.Name + @": Plugin has been disabled", LoggerLevel.WARNING);
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("LUAPlugin.cs: ");
            sb.Append(this.PluginDAO.Name);
            sb.Append(" failed (count=");
            sb.Append(count);
            sb.Append("/");
            sb.Append(LUADefinitions.DisablePluginAboveErrorCount);
            sb.Append("): ");
            sb.Append(ex.Message);
            Logger.LogMessage(sb.ToString(), LoggerLevel.WARNING);

            // Message the user saying it failed
            Message failedMsg = new Message(new string[1] { message.Sender.PhoneEmail }, "");
            failedMsg.FullMessage = "Plugin " + this.PluginDAO.Name + " has failed to run. Please try again later.";
            service.SendMessage(failedMsg);
        }
Ejemplo n.º 3
0
 public void Run(ParsedMessage message, AWatcherService service, t2sDbLibrary.IDBController controller)
 {
     throw new NotImplementedException();
 }