Exemplo n.º 1
0
        void connectTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
#if DEBUG
            (sender as Timer).Stop();
#endif
            if (controller != null)
            {
                try
                {
                    if (!controller.Connected)
                    {
                        controller.Connect();
                    }
                    (sender as Timer).Stop(); // Safety
                    return;
                }
                catch (ControllerConnectionException)
                {
                    // Ignore if we can't connect
                }
            }
#if DEBUG
            (sender as Timer).Start();
#endif
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the controller with the current settings,
        /// and attempt to connect
        /// </summary>
        private void LoadController()
        {
            var settings = HexLight.Properties.Settings.Default;

            // Get the class of the controller to use
            var controllerName = settings.Controller;

            if (controllerName == null || controllerName == "")
            {
                throw new ControllerConnectionException("No controller currently configured");
            }

            var controllerType = Controllers.GetControllerByName(controllerName);

            if (controllerType == null)
            {
                throw new ControllerConnectionException(String.Format("No controller found by name '{0}'", controllerName));
            }

            // Instantiate the controller and load any custom settings for it
            controller = Controllers.LoadController(settings, controllerType);

            // Attempt to connect (to validate the current settings)
            controller.Connect();
        }