private static bool PostEvent([MarshalAs(UnmanagedType.AnsiBStr)] 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); } if (!EventClasses.ContainsKey(classType)) { return(false); } List <IKodiEventConsumer> instances = EventClasses[classType]; foreach (IKodiEventConsumer instance in instances) { instance.TriggerEvent(ev); } return(true); }
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); }
public static bool DispatchEvent(KodiEventMessage e) { switch (e.Source) { case "Monitor": return(DispatchMonitorEvent(e)); case "Player": return(DispatchPlayerEvent(e)); default: throw new Exception(string.Format("Unknown event source {0}", e.Source)); } }
public bool TriggerEvent(KodiEventMessage e) { switch (e.Source) { case "onPlayBackEnded": PlayBackEnded?.Invoke(null, new EventArgs()); break; case "onPlayBackPaused": PlayBackPaused?.Invoke(null, new EventArgs()); break; case "onPlayBackResumed": PlayBackResumed?.Invoke(null, new EventArgs()); break; case "onPlayBackSeek": PlayBackSeek?.Invoke(null, new PlayBackSeekEventArgs(Convert.ToInt32(e.EventArgs[0]), Convert.ToInt32(e.EventArgs[1]))); break; case "onPlayBackSeekChapter": PlayBackSeekChapter?.Invoke(null, new PlayBackSeekChapterEventArgs(Convert.ToInt32(e.EventArgs[0]))); break; case "onPlayBackSpeedChanged": PlayBackSpeedChanged?.Invoke(null, new PlayBackSpeedChangedEventArgs(Convert.ToInt32(e.EventArgs[0]))); break; case "onPlayBackStarted": PlayBackStarted?.Invoke(null, new EventArgs()); break; case "onPlayBackStopped": PlayBackStopped?.Invoke(null, new EventArgs()); break; case "onQueueNextItem": QueueNextItem?.Invoke(null, new EventArgs()); break; default: PyConsole.WriteLine(string.Format("Unknown event '{0}' not handled", e.Source)); return(false); } return(true); }
public static bool DispatchPlayerEvent(KodiEventMessage e) { switch (e.Sender) { case "onPlayBackEnded": PlayBackEnded?.Invoke(e.Sender, new EventArgs()); break; case "onPlayBackPaused": PlayBackPaused?.Invoke(e.Sender, new EventArgs()); break; case "onPlayBackResumed": PlayBackResumed?.Invoke(e.Sender, new EventArgs()); break; case "onPlayBackSeek": PlayBackSeek?.Invoke(e.Sender, new PlayBackSeekEventArgs(int.Parse(e.EventArgs[0]), int.Parse(e.EventArgs[1]))); break; case "onPlayBackSeekChapter": PlayBackSeekChapter?.Invoke(e.Sender, new PlayBackSeekChapterEventArgs(int.Parse(e.EventArgs[0]))); break; case "onPlayBackSpeedChanged": PlayBackSpeedChanged?.Invoke(e.Sender, new PlayBackSpeedChangedEventArgs(int.Parse(e.EventArgs[0]))); break; case "onPlayBackStarted": PlayBackStarted?.Invoke(e.Sender, new EventArgs()); break; case "onPlayBackStopped": PlayBackStopped?.Invoke(e.Sender, new EventArgs()); break; case "onQueueNextItem": QueueNextItem?.Invoke(e.Sender, new EventArgs()); break; default: PyConsole.WriteLine(string.Format("Unknown event '{0}' not handled", e.Sender)); return(false); } return(true); }
private static bool PostEvent([MarshalAs(UnmanagedType.AnsiBStr)] string eventMessage) { KodiEventMessage ev = JsonConvert.DeserializeObject <KodiEventMessage>(eventMessage); Type classType = Type.GetType(ev.Source); if (classType != null && EventClasses.ContainsKey(classType)) { List <object> instances = EventClasses[classType]; foreach (object instance in instances) { var method = classType.GetMethod("onEvent", BindingFlags.NonPublic | BindingFlags.Instance); bool result = (bool)method.Invoke(instance, new object[] { ev }); } return(true); } else { return(Modules.Xbmc.GlobalEvents.DispatchEvent(ev)); } }
private bool onEvent(KodiEventMessage e) { switch (e.Sender) { case "onAbortRequested": AbortRequested?.Invoke(e.Sender, new EventArgs()); break; case "onCleanStarted": CleanStarted?.Invoke(e.Sender, new LibraryEventArgs(e.EventArgs[0])); break; case "onCleanFinished": CleanFinished?.Invoke(e.Sender, new LibraryEventArgs(e.EventArgs[0])); break; case "onDPMSActivated": DPMSActivated?.Invoke(e.Sender, new EventArgs()); break; case "onDPMSDeactivated": DPMSDeactivated?.Invoke(e.Sender, new EventArgs()); break; case "onDatabaseScanStarted": DatabaseScanStarted?.Invoke(e.Sender, new DatabaseEventArgs(e.EventArgs[0])); break; case "onDatabaseUpdated": DatabaseUpdated?.Invoke(e.Sender, new DatabaseEventArgs(e.EventArgs[0])); break; case "onNotification": Notification?.Invoke(e.Sender, new NotificationEventArgs( e.EventArgs[0], e.EventArgs[1], e.EventArgs[2] )); break; case "onScanStarted": ScanStarted?.Invoke(e.Sender, new LibraryEventArgs(e.EventArgs[0])); break; case "onScanFinished": ScanFinished?.Invoke(e.Sender, new LibraryEventArgs(e.EventArgs[0])); break; case "onScreensaverActivated": ScreensaverActivated?.Invoke(e.Sender, new EventArgs()); break; case "onScreensaverDeactivated": ScreensaverDeactivated?.Invoke(e.Sender, new EventArgs()); break; case "onSettingsChanged": SettingsChanged?.Invoke(e.Sender, new EventArgs()); break; default: PyConsole.WriteLine(string.Format("Unknown event '{0}' not handled", e.Sender)); return(false); } return(true); }