示例#1
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);
        }
示例#2
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;
        }
示例#3
0
        /// <summary>
        /// Initialises the library
        /// </summary>
        /// <param name="mediaWatcherPollingInterval">The interval at which to look for modified media</param>
        public void Init(ToucheeServer server, int mediaWatcherPollingInterval)
        {
            _server = server;

            // Set retry period from config
            int period = Program.Config.Get("artwork.retryPeriod") ?? 2592000;
            _artworkRetryPeriod = new TimeSpan(0, 0, period);

            // Instantiate all available MediumWatchers
            // These watch the Medium instances and generate Containers
            _mediumWatchers = PluginManager.GetComponent<IMediumWatcher>().ToList();
            Medium.AfterCreate += Medium_AfterCreate;
            Medium.AfterDispose += Medium_BeforeDispose;

            // Watch for container changes
            Container.AfterSave += ContainersChanged;
            Container.AfterDispose += ContainersChanged;
            Container.ContentsChanged += ContainerContentsChanged;

            // Watch for device changes
            Device.AfterCreate += DevicesChanged;
            Device.AfterDispose += DevicesChanged;
            Device.AfterUpdate += DeviceChanged;

            // Init local and web media
            string localMediumName = Program.Config.Get("name", System.Environment.MachineName);
            LocalMedium.Init(localMediumName);
            string webCastsName = Program.Config.Get("webcastsName", "Webcasts");
            WebMedium.Init(webCastsName);

            // Instantiate all available MediaWatchers
            // These generate Medium instances
            PluginManager.Register(new DriveMediaWatcher());
            _mediaWatchers = PluginManager.GetComponent<IMediaWatcher>().ToList();

            // Start media detection
            _mediaWatchers.ForEach(w => w.Watch(mediaWatcherPollingInterval));
        }