Exemplo n.º 1
0
        public int Run()
        {
            try {
                // Create the Settings object
                //this.Settings = new KodiAddonSettings();

                // If we have routes, invoke the request handler
                if (Router.Routes.Count > 0)
                {
                    Router.HandleRequest(this.BaseUrl + this.Parameters);
                }
                int result = this.PluginMain();

                return(result);
            } catch (Exception ex) {
                // This takes the exception and stores it, not allowing it to bubble up
                KodiBridge.SaveException(ex);
                return(1);
            } finally {
                KodiBridge.SetRunningAddon(null, null);

                if (!IsPersistent)
                {
                    KodiBridge.ScheduleAddonTermination(BaseUrl);
                }

                /*
                 * When we get here, we have already returned from PluginMain
                 * tell Python that we are done (TODO: Wait for threads here)
                 * */
                KodiBridge.StopRPC();
            }
        }
Exemplo n.º 2
0
        private void BeforeReturn()
        {
            KodiBridge.SetRunningAddon(null);

            if (!IsPersistent)
            {
                KodiBridge.ScheduleAddonTermination(BaseUrl);
            }

            /*
             * tell Python that we are done (TODO: Wait for threads here)
             * */
            Bridge.StopRPC(IsPersistent == false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new addon instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enableDebug">Enables or disabled the debugging console (works on windows only)</param>
        /// <param name="persist">Whether or not to reuse a previous addon instance</param>
        /// <returns></returns>
        public static T GetInstance <T>(bool enableDebug = false, bool persist = false) where T : KodiAddon
        {
            if (enableDebug)
            {
                ConsoleHelper.CreateConsole();
            }

            string BaseUrl = PythonInterop.EvalToResult("sys.argv[0]").Value;

            T instance = null;

            if (persist)
            {
                T previousInstance = (T)KodiBridge.GetPersistentAddon(BaseUrl);
                if (previousInstance != null)
                {
                    Console.WriteLine("REUSING PREVIOUS INSTANCE");
                    instance = previousInstance;
                }
            }

            if (instance == null)
            {
                instance = (T)Activator.CreateInstance(typeof(T));
                if (persist)
                {
                    KodiBridge.RegisterPersistentAddon(BaseUrl, instance);
                }
            }

            instance.DebugEnabled = enableDebug;
            instance.IsPersistent = persist;

            // Set running addon
            KodiBridge.SetRunningAddon(instance);

            // Initialize addon fields.
            // If the addon is persistent, it updates fields that might have changed
            instance.Initialize();

            return(instance);
        }