Exemple #1
0
        private void MainFrm_Load(object sender, EventArgs e)
        {
            OptionsFrm options;

            try
            {
                if (Settings.Default.FirstTime)
                {
                    options = new OptionsFrm();

                    if (options.ShowDialog() != DialogResult.OK)
                    {
                        //connectToolStripMenuItem.Enabled = false;
                        return;
                    }

                    Settings.Default.IP        = options.Ip;
                    Settings.Default.Port      = options.Port;
                    Settings.Default.FirstTime = false;
                    Settings.Default.Save();
                }

                if (Settings.Default.GWType == GatewayType.Ethernet)
                {
                    gateway = new EthGateway(Settings.Default.IP, int.Parse(Settings.Default.Port), OpenSocketType.Command);
                }
                else
                {
                    gateway = new UsbGateway(Settings.Default.Port);
                }

                lighting   = new Lighting(gateway);
                automation = new Automation(gateway);
                scenarios  = new Scenarios(gateway);

                connectToolStripMenuItem.Enabled = false;

                gateway.ConnectionError += new EventHandler <OpenWebNetErrorEventArgs>(gateway_ConnectionError);
                gateway.Connected       += new EventHandler(gateway_Connected);
                gateway.MessageReceived += new EventHandler <OpenWebNetMessageEventArgs>(gateway_MessageReceived);
                gateway.Connect();
            }
            catch (Exception ex)
            {
#if DEBUG
                throw ex;
#endif

                MessageBox.Show("Error: " + ex.Message, "MyHomeShortcut", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        private void gatewayConfigurationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OptionsFrm options;

            options      = new OptionsFrm();
            options.Ip   = Settings.Default.IP;
            options.Port = Settings.Default.Port;
            options.Type = Settings.Default.GWType;

            if (options.ShowDialog() == DialogResult.OK)
            {
                Settings.Default.IP        = options.Ip;
                Settings.Default.Port      = options.Port;
                Settings.Default.GWType    = options.Type;
                Settings.Default.FirstTime = false;
                Settings.Default.Save();

                MessageBox.Show("The application will be restarted", "MyHomeShortcut", MessageBoxButtons.OK, MessageBoxIcon.Information);

                Application.Restart();
            }
        }