Exemple #1
0
        protected async void DoAction(object sender, EventArgs e)
        {
            try
            {
                TxtStatus.Text = "";
                var btn  = sender as Button;
                var tipe = btn.CommandName;
                switch (tipe)
                {
                case "Monster":
                    await iot.InvokeMethod("BMCSecurityBot", "PlaySound", new string[] { "monster.mp3" });

                    break;

                case "Scream":
                    await iot.InvokeMethod("BMCSecurityBot", "PlaySound", new string[] { "scream.mp3" });

                    break;

                case "Tornado":
                    await iot.InvokeMethod("BMCSecurityBot", "PlaySound", new string[] { "tornado.mp3" });

                    break;

                case "Police":
                    await iot.InvokeMethod("BMCSecurityBot", "PlaySound", new string[] { "police.mp3" });

                    break;

                case "LEDON":
                    await iot.InvokeMethod("BMCSecurityBot", "ChangeLED", new string[] { "RED" });

                    break;

                case "LEDOFF":
                    await iot.InvokeMethod("BMCSecurityBot", "TurnOffLED", new string[] { "" });

                    break;

                case "Emergency":
                {
                    var datas = DeviceData.GetAllDevices().Where(x => x.Name.Contains("WC") || x.Name.Contains("Tamu")).Select(x => x.IP).ToList();

                    await iot.InvokeMethod("BMCSecurityBot", "Emergency", datas.ToArray());
                }
                break;

                case "DEVICEON":
                {
                    //string DeviceID = $"Device{btn.CommandArgument}IP";
                    string URL = $"http://{btn.CommandArgument}/cm?cmnd=Power%20On";
                    await iot.InvokeMethod("BMCSecurityBot", "OpenURL", new string[] { URL });
                }
                break;

                case "DEVICEOFF":
                {
                    //string DeviceID = $"Device{btn.CommandArgument}IP";
                    string URL = $"http://{btn.CommandArgument}/cm?cmnd=Power%20Off";
                    await iot.InvokeMethod("BMCSecurityBot", "OpenURL", new string[] { URL });
                }
                break;

                case "CCTVStatus":
                    await iot.InvokeMethod("CCTV_Watcher", "CCTVStatus", new string[] { btn.CommandArgument });

                    break;

                case "CCTVUpdateTime":
                    var interval = string.IsNullOrEmpty(TxtInterval.Text) ? "10" : TxtInterval.Text;
                    await iot.InvokeMethod("CCTV_Watcher", "CCTVUpdateTime", new string[] { interval });

                    break;

                case "Relay1":
                    await iot.InvokeMethod2("bmc/hidroponic/control", "Relay1", new string[] { btn.CommandArgument });

                    break;

                case "Relay2":
                    await iot.InvokeMethod2("bmc/hidroponic/control", "Relay2", new string[] { btn.CommandArgument });

                    break;

                case "WaterIn":
                    await iot.InvokeMethod("BMCSecurityBot", "OpenURL", new string[] { btn.CommandArgument });

                    break;

                case "WaterOut":
                    await iot.InvokeMethod("BMCSecurityBot", "OpenURL", new string[] { btn.CommandArgument });

                    break;

                case "RelayAqua1":
                    await iot.InvokeMethod2("bmc/aquaponic/control", "Relay1", new string[] { btn.CommandArgument });

                    break;

                case "RelayAqua2":
                    await iot.InvokeMethod2("bmc/aquaponic/control", "Relay2", new string[] { btn.CommandArgument });

                    break;

                case "DraineageOn":
                    // neck
                    //await iot.InvokeMethod3("bmc/autodrainage/relay16", "on");
                    //await iot.InvokeMethod3("bmc/autodrainage/relay15", "off");

                    // mouth
                    if (DrainRelay1.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay1", "on");
                    }
                    if (DrainRelay2.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay2", "on");
                    }
                    if (DrainRelay3.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay3", "on");
                    }
                    if (DrainRelay4.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay4", "on");
                    }
                    if (DrainRelay5.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay5", "on");
                    }
                    if (DrainRelay6.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay6", "on");
                    }
                    if (DrainRelay7.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay7", "on");
                    }
                    if (DrainRelay8.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay8", "on");
                    }
                    if (DrainRelay9.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay9", "on");
                    }
                    if (DrainRelay10.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay10", "on");
                    }
                    if (DrainRelay11.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay11", "on");
                    }
                    if (DrainRelay12.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay12", "on");
                    }
                    if (DrainRelay13.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay13", "on");
                    }
                    if (DrainRelay14.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay14", "on");
                    }
                    break;

                case "DraineageOff":
                    // neck
                    await iot.InvokeMethod3("bmc/autodrainage/relay16", "off");

                    // mouth
                    if (DrainRelay1.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay1", "off");
                    }
                    if (DrainRelay2.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay2", "off");
                    }
                    if (DrainRelay3.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay3", "off");
                    }
                    if (DrainRelay4.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay4", "off");
                    }
                    if (DrainRelay5.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay5", "off");
                    }
                    if (DrainRelay6.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay6", "off");
                    }
                    if (DrainRelay7.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay7", "off");
                    }
                    if (DrainRelay8.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay8", "off");
                    }
                    if (DrainRelay9.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay9", "off");
                    }
                    if (DrainRelay10.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay10", "off");
                    }
                    if (DrainRelay11.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay11", "off");
                    }
                    if (DrainRelay12.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay12", "off");
                    }
                    if (DrainRelay13.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay13", "off");
                    }
                    if (DrainRelay14.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay14", "off");
                    }
                    break;

                case "DraineageFillOn":
                    // neck
                    await iot.InvokeMethod3("bmc/autodrainage/relay16", "off");

                    await iot.InvokeMethod3("bmc/autodrainage/relay15", "on");

                    // mouth
                    if (DrainRelay1.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay1", "on");
                    }
                    if (DrainRelay2.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay2", "on");
                    }
                    if (DrainRelay3.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay3", "on");
                    }
                    if (DrainRelay4.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay4", "on");
                    }
                    if (DrainRelay5.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay5", "on");
                    }
                    if (DrainRelay6.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay6", "on");
                    }
                    if (DrainRelay7.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay7", "on");
                    }
                    if (DrainRelay8.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay8", "on");
                    }
                    if (DrainRelay9.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay9", "on");
                    }
                    if (DrainRelay10.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay10", "on");
                    }
                    if (DrainRelay11.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay11", "on");
                    }
                    if (DrainRelay12.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay12", "on");
                    }
                    if (DrainRelay13.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay13", "on");
                    }
                    if (DrainRelay14.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay14", "on");
                    }
                    break;

                case "DraineageFillOff":
                    // neck
                    await iot.InvokeMethod3("bmc/autodrainage/relay15", "off");

                    // mouth
                    if (DrainRelay1.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay1", "off");
                    }
                    if (DrainRelay2.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay2", "off");
                    }
                    if (DrainRelay3.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay3", "off");
                    }
                    if (DrainRelay4.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay4", "off");
                    }
                    if (DrainRelay5.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay5", "off");
                    }
                    if (DrainRelay6.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay6", "off");
                    }
                    if (DrainRelay7.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay7", "off");
                    }
                    if (DrainRelay8.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay8", "off");
                    }
                    if (DrainRelay9.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay9", "off");
                    }
                    if (DrainRelay10.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay10", "off");
                    }
                    if (DrainRelay11.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay11", "off");
                    }
                    if (DrainRelay12.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay12", "off");
                    }
                    if (DrainRelay13.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay13", "off");
                    }
                    if (DrainRelay14.Checked)
                    {
                        iot.InvokeMethod3("bmc/autodrainage/relay14", "off");
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                TxtStatus.Text = "ERROR:" + ex.Message + "_" + ex.StackTrace;
            }
        }