Exemple #1
0
        public CenterControl()
        {
            messageScheduler   = new MessageScheduler();
            serialPortDetector = new SerialPortDetector();
            profileContainer   = new ProfileContainer();

            if (!profileContainer.Load())
            {
                System.Windows.Forms.MessageBox.Show("錯誤"
                                                     , "無法開啟或重建" + GlobalSetting.ProfileLocation
                                                     , System.Windows.Forms.MessageBoxButtons.OK
                                                     , System.Windows.Forms.MessageBoxIcon.Error);
                throw new CannotUnloadAppDomainException();
            }

            serialPortDetector.PortsChanged += PortsChanged;
            form.VisibleChanged             += Form_VisibleChanged;
            messageScheduler.ProfileChanged += ProfileChanged;

            messageScheduler.handlers
                = MakeHandlers(profileContainer.jSONProfiles[profileContainer.ProfileIndex]);

            ScanPorts();

            notifyIcon.Visible = true;
            notifyIcon.Text    = "TinyKeyboard";
            notifyIcon.Click  += notifyIconClick;
            var cms = new System.Windows.Forms.MenuItem[1];

            cms[1] = new System.Windows.Forms.MenuItem("Exit", (sender, e) =>
            {
                System.Windows.Forms.Application.Exit();
            });
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(cms);
        }
        public CenterControl()
        {
            form = new Form1(new CenterControlGUIMessage(this));

            if (!System.IO.File.Exists(GlobalSetting.ProfileLocation))
            {
                profileContainer.Create();
                if (!profileContainer.Save())
                {
                    System.Windows.Forms.MessageBox.Show("錯誤"
                                                         , "重建" + GlobalSetting.ProfileLocation + "失敗"
                                                         , System.Windows.Forms.MessageBoxButtons.OK
                                                         , System.Windows.Forms.MessageBoxIcon.Error);
                    throw new CannotUnloadAppDomainException();
                }
            }

            else if (!profileContainer.Load())
            {
                System.Windows.Forms.MessageBox.Show("錯誤"
                                                     , GlobalSetting.ProfileLocation + "無法開啟或失敗"
                                                     , System.Windows.Forms.MessageBoxButtons.OK
                                                     , System.Windows.Forms.MessageBoxIcon.Error);
                throw new CannotUnloadAppDomainException();
            }

            serialPortDetector.PortsChanged += PortsChanged;
            messageScheduler.ProfileChanged += ProfileChanged;

            // Apply the default profile in the profile file
            messageScheduler.handlers
                = MakeHandlers(profileContainer.jSONProfiles[profileContainer.CurrentProfileIndex]);

            // Check if the device have connected before application start
            var truePortName = ScanPorts();

            if (truePortName != "")
            {
                SetSerialPortMessage(truePortName);
            }
        }