示例#1
0
 /// <summary>
 /// Starts the plugin.
 /// </summary>
 /// <param name="config">The configuration object for this plugin</param>
 /// <param name="context">The context for this plugin</param>
 /// <returns>Always true</returns>
 public bool StartPlugin(Config config, IPluginContext context)
 {
     var path = Path.Combine(new FileInfo(this.GetType().Assembly.Location).DirectoryName, @"lib\Bass.Net");
     Bass.LoadMe(path);
     BassMix.LoadMe(path);
     Bass.BASS_PluginLoadDirectory(Path.Combine(path, "plugins"));
     _player = new Player();
     PluginManager.Register(_player);
     return true;
 }
示例#2
0
        /// <summary>
        /// Loads the plugins found in the given assembly
        /// </summary>
        /// <param name="assembly">The assembly to get the plugins from</param>
        /// <param name="config">Plugins config section</param>
        /// <param name="context">The plugin context to feed the plugin</param>
        static void LoadPlugins(Assembly assembly, Config config, IPluginContext context)
        {
            // Get reference to plugin interface
            Type pluginType = typeof(IPlugin);

            // Get the type which implements IPlugin
            var types = assembly.GetTypes().Where(p => pluginType.IsAssignableFrom(p) && p != pluginType);

            // No plugin found
            if (types.Count() == 0) {
                Logger.Log("No types found which implements IPlugin in assembly: " + assembly.FullName);
                return;
            }

            // Go through all plugins
            var thisAssembly = Assembly.GetExecutingAssembly();
            foreach (var type in types) {
                bool ok = true;
                IPlugin plugin;

                // Get the configuration
                Config pluginConfig = null;
                var name = type.Assembly == thisAssembly ? type.Name : type.Assembly.GetName().Name;
                bool disabled = false;
                if (config != null) {
                    pluginConfig = config.Sub(name);
                    if (pluginConfig != null)
                        disabled = pluginConfig.Contains("disabled");
                }

                // Do next if disabled
                if (disabled) continue;

                // Create instance of plugin
                try {
                    plugin = (IPlugin)Activator.CreateInstance(type);
                }
                catch (Exception e) {
                    Logger.Log("Cannot instantiate plugin: " + name + " : " + e.Message, Logger.LogLevel.Error);
                    continue;
                }

                // Boot the plugin
                ok = plugin.StartPlugin(pluginConfig, context);

                // Store plugin if successfull
                if (ok) {
                    PluginManager.Register(plugin);
                    Logger.Log("Plugin loaded: " + plugin.Name);
                }
                else {
                    Logger.Log("Start of plugin failed: " + name, Logger.LogLevel.Error);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Checks and initialises all the components for the application.
        /// </summary>
        static bool Init()
        {
            bool ok;

            // Set the error level
            Logger.Level = Logger.LogLevel.Info;

            // Loads all settings
            Config = LoadConfig();
            if (Config == null) return false;

            // Get port for the http server
            int httpPort = Config.Get("httpPort") ?? 80;

            // Get port for the websocket server
            int websocketPort = Config.Get("websocketPort") ?? 81;

            // Get the media detector polling interval
            int mediaPollingInterval = Config.Get("mediaPollingInterval") ?? 3000;

            // Load devices from config
            var devices = Config.Get("devices");
            if (devices is IEnumerable<JToken>)
                Devices.Device.Parse(devices as IEnumerable);

            // Init the server
            var server = new Server.ToucheeServer(httpPort, websocketPort);

            // Build plugin context
            IPluginContext pluginContext = new ToucheePluginContext(server);

            // Loads all plugins
            if (!LoadPlugins(pluginContext)) return false;

            // Kickstart WinLirc client
            var wlc = Devices.WinLirc.Client;

            // Init the library
            var library = Library.Instance;
            library.Init(server, mediaPollingInterval);

            // Start server
            if (!server.Start()) {
                Shutdown("Could not start server");
                return false;
            }

            // Show the form
            Logger.Log("Loading complete!", Logger.LogLevel.Info);
            var mainForm = new Forms.Main();
            Application.Run(mainForm);

            // Done
            return true;
        }
示例#4
0
        /// <summary>
        /// Starts the plugin.
        /// </summary>
        /// <param name="config">The configuration object for this plugin</param>
        /// <param name="context">The context for this plugin</param>
        /// <returns>True if the plugin was successfully started</returns>
        public bool StartPlugin(Config config, IPluginContext context) {
            Plugin.Config = config;
            Plugin.Context = context;

            // Add content provider
            ContentProvider = new ContentProvider();
            PluginManager.Register(ContentProvider);
            
            // Start the watcher
            Watcher = new Watcher();
            PluginManager.Register(Watcher);

            // Bind to watching event
            Watcher.StartedWatching += StartedWatching;

            return true;
        }
示例#5
0
        /// <summary>
        /// Starts the plugin.
        /// </summary>
        /// <param name="config">The configuration object for this plugin</param>
        /// <param name="context">The context for this plugin</param>
        /// <returns>True if the plugin was successfully started</returns>
        public bool StartPlugin(Config config, IPluginContext context)
        {
            // Get folders
            dynamic foldersConfig = config.Get("folders");
            IEnumerable<string> folders = foldersConfig is IList ? foldersConfig.Values<string>() : new string[0];

            // Get extensions
            dynamic trackExtensionsConfig = config.Get("extensions.tracks");
            TrackExtensions = trackExtensionsConfig is IList ? trackExtensionsConfig.Values<string>() : new string[0];
            dynamic playlistExtensionsConfig = config.Get("extensions.tracks");
            PlaylistExtensions = playlistExtensionsConfig is IList ? playlistExtensionsConfig.Values<string>() : new string[0];
            Extensions = TrackExtensions.Concat(PlaylistExtensions).ToArray();

            // Create the watcher and add folders to it
            Watcher = new MusicFileMediumWatcher();
            foreach(var f in folders)
                Watcher.AddLocalFolder(f);
            PluginManager.Register(Watcher);

            // Add content provider
            ContentProvider = new MusicContentProvider();
            PluginManager.Register(ContentProvider);

            // Add artwork provider
            ArtworkProvider = new MusicArtworkProvider();
            PluginManager.Register(ArtworkProvider);

            return true;
        }