示例#1
0
        public bool PassChatCommand(string command, IClient client, string[] args)
        {
            if (!Enabled)
            {
                return(false);
            }

            var cmd = _registeredCommands.SingleOrDefault(p => p.Key.Equals(command, StringComparison.OrdinalIgnoreCase));

            if (cmd.Value != null)
            {
                try
                {
                    _engine.CallFunction(cmd.Value, new object[] { client, command, args });

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Plugin {0} caused error: {1}", Path.GetFileName(PluginFile), ex.Message);
                }
            }

            return(false);
        }
示例#2
0
        public T CallFunction <T>(object function, params object[] arguments)
        {
            try
            {
                return(function is JsFunction
                           ? (T)engine.CallFunction((JsFunction)function, arguments)
                           : (T)engine.CallFunction((string)function, arguments));
            }
            catch (Exception ex)
            {
                WriteException(ex);
            }

            return(default(T));
        }
示例#3
0
        void initConfig()
        {
            if (configInited)
            {
                return;
            }

            execScript("./Js/config.js");
            try
            {
                jint.CallFunction("config");
                jint.CallFunction("init");
            }
            catch (Exception e)
            {
            }

            configInited = true;
        }
            public void Invoke(string methodName, object[] parameters)
            {
                var jint = new JintEngine();

                jint.DisableSecurity();
                jint.Visitor.Usings.CopyFrom(_extension._usings);
                jint.SetParameter("ExtensionHooks", _extension.Hooks);
                jint.Run(_extension._script);
                jint.CallFunction(methodName, parameters);
            }
示例#5
0
 private void Invoke(string func, params object[] obj)
 {
     try
     {
         Engine.CallFunction(func, obj);
     }
     catch (Exception ex)
     {
         Logger.LogError(string.Format("{0} Error invoking function {1} in {2} plugin.", brktname, func, Name));
         Logger.LogException(ex);
     }
 }
示例#6
0
        public static RavenJObject Transform(string transformScript, RavenJObject input)
        {
            if (jint == null)
            {
                throw new InvalidOperationException("Jint must be initialized.");
            }

            jint.ResetSteps();

            var jsObject            = ToJsObject(jint.Global, input);
            var jsObjectTransformed = jint.CallFunction("Transform", jsObject) as JsObject;

            return(jsObjectTransformed != null?ConvertReturnValue(jsObjectTransformed) : null);
        }
示例#7
0
 protected object Invoke(string name, params object[] args)
 {
     try
     {
         return(executor.CallFunction(name, args));
     }
     catch (NullReferenceException e)
     {
         return(null);
     }
     catch (InvalidCastException e)
     {
         return(null);
     }
 }
示例#8
0
 public object Invoke(string func, params object[] obj)
 {
     try
     {
         if (FunctionNames.Contains(func))
         {
             return(Engine.CallFunction(func, obj));
         }
     }
     catch (Exception ex)
     {
         Logger.LogError(string.Format("{0} Error invoking function {1} in {2} plugin.", brktname, func, Name));
         Logger.LogException(ex);
     }
     return(null);
 }
示例#9
0
        public Plugin(DirectoryInfo directory, string name, string code)
        {
            Name          = name;
            Code          = code;
            RootDirectory = directory;
            Timers        = new Dictionary <String, TimedEvent>();

            Engine = new JintEngine();
            Engine.AllowClr(true);

            InitGlobals();
            Engine.Run(code);
            try
            {
                Engine.CallFunction("On_PluginInit");
            }
            catch { }
        }
示例#10
0
        public override object Invoke(string method, params object[] args)
        {
            try {
                if (State == PluginState.Loaded && Globals.Contains(method))
                {
                    object result = null;

                    using (new Stopper(Name, method)) {
                        result = Engine.CallFunction(method, args);
                    }
                    return(result);
                }
                Logger.LogWarning($"[{GetType().Name}] Function: {method} not found in plugin: {Name}, or plugin is not loaded.");
                return(null);
            } catch (Exception ex) {
                string fileinfo = $"{GetType().Name}<{Name}>.{method}(){Environment.NewLine}";
                Logger.LogError(fileinfo + FormatException(ex));
                return(null);
            }
        }
示例#11
0
        /// <summary>
        /// Invoke the specified method and args.
        /// </summary>
        /// <param name="method">Method.</param>
        /// <param name="args">Arguments.</param>
        /// <param name="func">Func.</param>
        public override object Invoke(string func, params object[] args)
        {
            try
            {
                if (State == PluginState.Loaded && Globals.Contains(func))
                {
                    object result = (object)null;

                    using (new Stopper(Type + " " + Name, func))
                    {
                        result = Engine.CallFunction(func, args);
                    }

                    return(result);
                }
            }
            catch (Exception ex)
            {
                string fileinfo = "[Error] Failed to invoke: " + $"{Name}<{Type}>.{func}()" + Environment.NewLine;
                Logger.LogError(fileinfo + FormatException(ex));
            }
            return(null);
        }
示例#12
0
        /// <summary>
        /// Invoke the specified method and args.
        /// </summary>
        /// <param name="method">Method.</param>
        /// <param name="args">Arguments.</param>
        /// <param name="func">Func.</param>
        public override object Invoke(string func, params object[] args)
        {
            try {
                if (State == PluginState.Loaded && Globals.Contains(func))
                {
                    object result = (object)null;

                    using (new Stopper(Name, func)) {
                        result = Engine.CallFunction(func, args);
                    }
                    return(result);
                }
                else
                {
                    Logger.LogWarning("[Plugin] Function: " + func + " not found in plugin: " + Name + ", or plugin is not loaded.");
                    return(null);
                }
            } catch (Exception ex) {
                string fileinfo = (String.Format("{0}<{1}>.{2}()", Name, Type, func) + Environment.NewLine);
                Logger.LogError(fileinfo + FormatException(ex));
                return(null);
            }
        }
示例#13
0
 public void ShouldReturnDelegateForFunctions() {
     const string script = "var ccat=function (arg1,arg2){ return arg1+' '+arg2; }";
     JintEngine engine = new JintEngine().SetFunction("print", new Action<string>(Console.WriteLine));
     engine.Run(script);
     Assert.AreEqual("Nicolas Penin", engine.CallFunction("ccat", "Nicolas", "Penin"));
 }