示例#1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;

            TryLoadController();

            // Attach event handlers
            controller.ConnectNotification    += OnControllerConnected;
            controller.DisconnectNotification += OnControllerDisconnected;

            viewModel = new ViewModel();

            controlWindow = new ControlWindow(viewModel);
            popupDial     = new PopupDial(viewModel);

            LoadEngines(controlWindow);

            #if DEBUG
            controlWindow.Show();
            #endif

            updateTimer          = new Timer(UPDATE_INTERVAL);
            updateTimer.Elapsed += updateTimer_Elapsed;
            updateTimer.Enabled  = controller.Connected;

            connectTimer          = new Timer(CONNECT_INTERVAL);
            connectTimer.Elapsed += connectTimer_Elapsed;
            connectTimer.Enabled  = !controller.Connected;

            ///// Tray Icon & Tray Menu /////

            trayIcon      = new WinForms.NotifyIcon();
            trayIcon.Text = "HexLight Controller";
            trayIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(
                System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name);
            trayIcon.Click  += trayIcon_Click;
            trayIcon.Visible = true;

            trayIcon.ContextMenu = new WinForms.ContextMenu(new[] {
                new WinForms.MenuItem("Control Panel", trayIcon_ControlPanel_Click),
                new WinForms.MenuItem("Settings", trayIcon_Settings_Click),
                new WinForms.MenuItem("Exit", trayIcon_Exit_Click),
            });
        }
示例#2
0
        /// <summary>
        /// Try and load all engines present
        /// </summary>
        private void LoadEngines(ControlWindow controlWindow)
        {
            var engineTypes = Engines.ListEngines();

            // Load engines & populate tabs
            foreach (var engineType in engineTypes)
            {
                string name = Engines.GetEngineName(engineType);

                // Try to load the engine
                HexEngine   engine = null;
                UserControl page   = null;
                try
                {
                    engine = Engines.LoadEngine(engineType);
                    page   = engine.GetControlPage();
                }
                catch (NotImplementedException)
                {
                    continue;
                }
                catch (Exception ex)
                {
                    string assyName = Plugins.GetAssemblyName(engineType);
                    if (assyName != null)
                    {
                        name += " (" + assyName + ")";
                    }

                    ExceptionDialog.ShowException(String.Format("Could not load {0}", name), ex, ExceptionSeverity.Error);
                    continue; // Ignore was pressed
                }

                // Add tab & page to the control window
                controlWindow.AddEngine(name, page, engine);
            }
        }