public JavaScriptPlugin(string fileName) { PluginFile = fileName; _engine = new JintEngine(); _engine.AddPermission(new FileIOPermission(PermissionState.Unrestricted)); _engine.AllowClr = true; Properties = new PluginProperties(Path.GetFileName(PluginFile), PluginManager.PluginDirectoryPath); Properties.Load(); _engine.SetParameter("properties", Properties); _engine.SetParameter("plugindir", PluginManager.PluginDirectoryPath); _engine.SetFunction("WriteToConsole", new Action <object>(Console.WriteLine)); _engine.SetFunction("SubscribeToEvent", new Action <string, JsFunction>(SubscribeToEvent)); _engine.SetFunction("UnsubscribeFromEvent", new Action <string>(UnsubscribeFromEvent)); _engine.SetFunction("RegisterCommand", new Action <string, JsFunction>(RegisterCommand)); _engine.SetFunction("UnregisterCommand", new Action <string>(UnregisterCommand)); _engine.SetFunction("RegisterConsoleCommand", new Action <string, JsFunction>(RegisterConsoleCommand)); _engine.SetFunction("UnregisterConsoleCommand", new Action <string>(UnregisterConsoleCommand)); _engine.SetFunction("SendPacket", new Action <SharpStarClient, IPacket>(SendPacket)); _engine.SetFunction("SendClientPacketToAll", new Action <IPacket>(SendClientPacketToAll)); _engine.SetFunction("SendServerPacketToAll", new Action <IPacket>(SendServerPacketToAll)); _engine.SetFunction("GetPlayerClients", new Func <IClient[]>(GetPlayerClients)); _engine.SetFunction("GetServerClients", new Func <IClient[]>(GetServerClients)); _engine.SetFunction("ToArray", new Func <JsArray, object[]>(JsArrayToArray)); _registeredEvents = new Dictionary <string, JsFunction>(); _registeredCommands = new Dictionary <string, JsFunction>(); _registeredConsoleCommands = new Dictionary <string, JsFunction>(); }
void init() { PythonEngine.Inst.init(); jint = new JintEngine(); string absUserDir = Directory.GetCurrentDirectory() + "/Js"; jint.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, absUserDir)); //set some simple funcitons. Func <object, int> alert = delegate(object s) { MessageBox.Show(s.ToString()); return(0); }; Func <string, double, string, double[]> ema = delegate(string label, double days, string outLabel) { if (arrays.ContainsKey(label)) { double[] inputs = arrays[label]; double[] outputs = MathUtil.calcEMA(inputs, days); addArray(outLabel, outputs); return(outputs); } return(null); }; Func <string, string, string, double[]> diff = delegate(string label0, string label1, string outLabel) { if (arrays.ContainsKey(label0) && arrays.ContainsKey(label1)) { double[] inputs0 = arrays[label0]; double[] inputs1 = arrays[label1]; double[] outputs = MathUtil.calcDiff(inputs0, inputs1); addArray(outLabel, outputs); return(outputs); } return(null); }; //tell canvas to line Func <string, double, double, double, double, double, double, int> line = delegate(string label, double part, double r, double g, double b, double a, double thickness) { if (!arrays.ContainsKey(label)) { return(1); } Color c = new Color() { R = (byte)r, G = (byte)g, B = (byte)b, A = (byte)a }; canvas.addDrawingObj(label, arrays[label], (int)part, c, thickness, DrawingObjectType.Line); return(0); }; Func <string, double, double, double, double, double, double, int> zeroBars = delegate(string label, double part, double r, double g, double b, double a, double thickness) { if (!arrays.ContainsKey(label)) { return(1); } Color c = new Color() { R = (byte)r, G = (byte)g, B = (byte)b, A = (byte)a }; canvas.addDrawingObj(label, arrays[label], (int)part, c, thickness, DrawingObjectType.zVLines); return(0); }; ////kdj('close','high','low',9,'k','d','j'); Func <string, string, string, double, string, string, string, int> kdj = delegate(string close, string high, string low, double days, string k, string d, string j) { if (arrays.ContainsKey(close) && arrays.ContainsKey(high) && arrays.ContainsKey(low)) { double[] inputs0 = arrays[close]; double[] inputs1 = arrays[high]; double[] inputs2 = arrays[low]; double[] kArray; double[] dArray; double[] jArray; MathUtil.calcKDJ((int)days, inputs0, inputs1, inputs2, out kArray, out dArray, out jArray); addArray(k, kArray); addArray(d, dArray); addArray(j, jArray); return(0); } return(1); }; //draw candle line. Func <string, double, string, string, string, string, int> candleLine = delegate(string id, double part, string open, string close, string high, string low) { if (!arrays.ContainsKey(open) || !arrays.ContainsKey(close) || !arrays.ContainsKey(high) || !arrays.ContainsKey(low)) { return(1); } canvas.addKLineObj(id, (int)part, arrays[open], arrays[close], arrays[high], arrays[low]); return(0); }; Func <string, object, int> addConfig = delegate(string id, object value) { addConfigVal(id, value); return(0); }; Func <string, int> runScript = delegate(string scriptName) { runJsScript(scriptName); return(0); }; Func <string, double, string, double, double, double, double, double, int> vLines = delegate(string id, double part, string label, double r, double g, double b, double a, double thickness) { if (!arrays.ContainsKey(label)) { return(1); } Color c = new Color() { R = (byte)r, G = (byte)g, B = (byte)b, A = (byte)a }; // canvas.addDrawingObj(id, arrays[label], (int)part, c, thickness, DrawingObjectType.vLines); return(0); }; // Func <string, string, int> setDrawItemEventHandler = delegate(string id, string handlerName) { canvas.setDrawItemEventHandler(id, handlerName); return(0); }; jint.SetFunction("addConfig", addConfig); jint.SetFunction("runScript", runScript); jint.SetFunction("setDrawItemEventHandler", setDrawItemEventHandler); jint.SetFunction("alert", alert); jint.SetFunction("ema", ema); jint.SetFunction("kdj", kdj); jint.SetFunction("diff", diff); jint.SetFunction("line", line); jint.SetFunction("zeroBars", zeroBars); jint.SetFunction("candleLine", candleLine); jint.SetFunction("vLines", vLines); }
public void Initialize() { engine.AddPermission(new UIPermission(PermissionState.Unrestricted)); engine.AddPermission(new FileIOPermission(PermissionState.Unrestricted)); engine.AddPermission(new WebPermission(PermissionState.Unrestricted)); }