예제 #1
0
        private void ExecuteAction(Action action)
        {
            string where;

            try
            {
                if (!gateway.IsConnectedToGateway)
                {
                    MessageBox.Show("MyHomeShortcut isn't connected to the gateway...Check IP and Port", "MyHomeShortcut", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (action == null)
                {
                    return;
                }

                if (action.What == WHAT.None || action.Who == WHO.None || string.IsNullOrEmpty(action.Where) && !string.IsNullOrEmpty(action.Command))
                {
                    gateway.SendData(action.Command);
                    return;
                }

                where = action.Where;

                switch (action.What)
                {
                case WHAT.LightON:
                    lighting.LightON(where);
                    break;

                case WHAT.LightOFF:
                    lighting.LightOFF(where);
                    break;

                case WHAT.DimmerUp:
                    lighting.DimmerUp(where);
                    break;

                case WHAT.DimmerDown:
                    lighting.DimmerDown(where);
                    break;

                case WHAT.AutomationUp:
                    automation.Up(where);
                    break;

                case WHAT.AutomationDown:
                    automation.Down(where);
                    break;

                case WHAT.AutomationStop:
                    automation.Stop(where);
                    break;

                case WHAT.ScenariosON:
                    scenarios.Activate(Settings.Default.ScenariosCentralUnitWhere, int.Parse(where));
                    break;

                case WHAT.ScenariosOFF:
                    scenarios.Deactivate(Settings.Default.ScenariosCentralUnitWhere, int.Parse(where));
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "MyHomeShortcut", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }