private void Initialize() { this.Bridge = KodiBridge.CreateBridgeInstance(); // If we're being started as a service, don't run addon specific tasks if (this.IsService) { PyConsole.WriteLine(string.Format("Starting as Service: {0}", this.BaseUrl)); return; } this.Handle = Convert.ToInt32((PythonInterop.EvalToResult("sys.argv[1]")).Value); this.Parameters = (PythonInterop.EvalToResult("sys.argv[2]")).Value; PyConsole.WriteLine(string.Format("BaseUrl: {0}, Handle: {1}, Parameters: {2}", this.BaseUrl, this.Handle, this.Parameters)); PyVariableManager.Reset(); // Instance of XbmcAddon this.Addon = new Addon(PluginId); // Settings accessor this.Settings = new KodiAddonSettings(this.Addon); //this.Monitor = new XbmcMonitor(); //string addonName = BaseUrl.Replace("plugin://", "").Replace("/", ""); }
public KodiAddon() { try { #if DEBUG ConsoleHelper.CreateConsole(); #endif // Clean the variables list from the previous run (we're in a new python instance so they don't exist anymore) Python.PyVariableManager.Initialize(); // Parse parameters this.BaseUrl = PythonInterop.EvalToResult("sys.argv[0]").Value; this.IsService = PythonInterop.EvalToResult("len(sys.argv) < 2").Value; // Initialize the Event Monitor //Modules.Xbmc.Events.Initialize(); // Set running addon KodiBridge.RunningAddon = this; // If we're being started as a service, don't run addon specific tasks if (this.IsService) { PyConsole.WriteLine(string.Format("Starting as Service: {0}", this.BaseUrl)); return; } this.Handle = int.Parse(PythonInterop.EvalToResult("sys.argv[1]").Value); this.Parameters = PythonInterop.EvalToResult("sys.argv[2]").Value; PyConsole.WriteLine(string.Format("BaseUrl: {0}, Handle: {1}, Parameters: {2}", this.BaseUrl, this.Handle, this.Parameters)); // Register routes for derived type RouteManager.RegisterRoutes(this.GetType()); } catch (Exception ex) { KodiBridge.SaveException(ex); } }
/// <summary> /// Handle a request by using the registered routes /// </summary> /// <param name="request">request URL</param> public static void HandleRequest(string request) { Uri url = new Uri(request); var qs = HttpUtility.ParseQueryString(url.Query); Console.WriteLine("URL IS " + request); string path = "/"; if (qs.AllKeys.Contains("action")) { path = RemoveTrailingSlash(qs["action"]); } PyConsole.WriteLine(string.Format("Checking route for '{0}'", path)); if (!Routes.ContainsKey(path)) { PyConsole.WriteLine(string.Format("Route not found for path '{0}'", path)); return; } Console.WriteLine("Going to call " + path); Routes[path](qs); }