public static bool PostEvent([MarshalAs(UnmanagedType.LPStr)] string eventMessage) { KodiEventMessage ev = JsonConvert.DeserializeObject <KodiEventMessage>(eventMessage); Type classType; switch (ev.Sender) { case "Monitor": classType = typeof(XbmcMonitor); break; case "Player": classType = typeof(XbmcPlayer); break; default: return(false); } KodiBridgeInstance bridge = RunningAddon.Bridge; if (!bridge.EventClasses.ContainsKey(classType)) { return(false); } bridge.EventClasses[classType].All((kevc) => { kevc.TriggerEvent(ev); return(true); }); return(true); }
private static bool CommonInit() { AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper; SetPythonCulture(); GlobalStaticBridge = CreateBridgeInstance(); return(true); }
public static PythonEvalReply Eval(string code) { PythonEvalMessage msg = new PythonEvalMessage { Code = code }; KodiBridgeInstance bridge = KodiBridge.RunningAddon?.Bridge ?? KodiBridge.GlobalStaticBridge; string replyString = bridge.SendMessage(msg); Console.Error.WriteLine(replyString); PythonEvalReply reply = JsonConvert.DeserializeObject <PythonEvalReply>(replyString); if (reply.ExitCode == 1) { throw new InvalidOperationException($"eval of '{code}' failed: '{reply.Error}'"); } return(reply); }