コード例 #1
0
        public void Execute(IJobExecutionContext context)
        {
            TechnicalFanCoil technicalFanCoil = new TechnicalFanCoil();

            var status = technicalFanCoil.GetStatus2();

            bool machineOn = false;

            if (status[1] != 0)
            {
                machineOn = true;
            }

            if (status[2] != 0)
            {
                machineOn = true;
            }

            if (machineOn)
            {
                technicalFanCoil.TurnOffMotor1();
                technicalFanCoil.TurnOffMotor2();

                var bot = new Telegram.Bot.Api("208761880:AAHxUZCc5z0g2dJDrgbbMEWk7r1t_IoKiAw");

                var    chatIds = RecieveReportForTechnicalFanCoilChatIds();
                string report  = "Fancoil automatically switched off.";

                foreach (var id in chatIds)
                {
                    bot.SendTextMessage(id, report);
                    bot.SendTextMessage(id, technicalFanCoil.GetStatus());
                }
            }
        }
コード例 #2
0
        private void ButtonRefreshClickedAsync()
        {
            try
            {
                TechnicalFanCoil      technicalFanCoil = new TechnicalFanCoil();
                Dictionary <int, int> status           = null;

                status = technicalFanCoil.GetStatus2();

                RunOnUiThread(() =>
                {
                    if (status == null)
                    {
                        return;
                    }


                    Thread thread = new Thread((() =>
                    {
                        buttonRefreshRunningThreads++;

                        Thread.Sleep(1000 * 60);

                        if (buttonRefreshRunningThreads > 1)
                        {
                            buttonRefreshRunningThreads--;
                            return;
                        }

                        RunOnUiThread(() =>
                        {
                            toggleButtonMotor1.Enabled = false;
                            toggleButtonMotor2.Enabled = false;
                            radioButtonMotor1Speed1.Enabled = false;
                            radioButtonMotor1Speed2.Enabled = false;
                            radioButtonMotor1Speed3.Enabled = false;
                            radioButtonMotor2Speed1.Enabled = false;
                            radioButtonMotor2Speed2.Enabled = false;
                            radioButtonMotor2Speed3.Enabled = false;

                            buttonSave.Enabled = false;

                            buttonRefreshRunningThreads--;
                        });
                    }));
                    thread.Start();


                    int motor1Status = status[1];
                    int motor2Status = status[2];

                    if (motor1Status == 0)
                    {
                        toggleButtonMotor1.Checked      = false;
                        radioButtonMotor1Speed1.Checked = false;
                        radioButtonMotor1Speed2.Checked = false;
                        radioButtonMotor1Speed3.Checked = false;
                    }
                    else if (motor1Status == 1)
                    {
                        toggleButtonMotor1.Checked      = true;
                        radioButtonMotor1Speed1.Checked = true;
                    }
                    else if (motor1Status == 2)
                    {
                        toggleButtonMotor1.Checked      = true;
                        radioButtonMotor1Speed2.Checked = true;
                    }
                    else if (motor1Status == 3)
                    {
                        toggleButtonMotor1.Checked      = true;
                        radioButtonMotor1Speed3.Checked = true;
                    }

                    if (motor2Status == 0)
                    {
                        toggleButtonMotor2.Checked      = false;
                        radioButtonMotor2Speed1.Checked = false;
                        radioButtonMotor2Speed2.Checked = false;
                        radioButtonMotor2Speed3.Checked = false;
                    }
                    else if (motor2Status == 1)
                    {
                        toggleButtonMotor2.Checked      = true;
                        radioButtonMotor2Speed1.Checked = true;
                    }
                    else if (motor2Status == 2)
                    {
                        toggleButtonMotor2.Checked      = true;
                        radioButtonMotor2Speed2.Checked = true;
                    }
                    else if (motor2Status == 3)
                    {
                        toggleButtonMotor2.Checked      = true;
                        radioButtonMotor2Speed3.Checked = true;
                    }

                    toggleButtonMotor1.Enabled = true;
                    toggleButtonMotor2.Enabled = true;

                    if (toggleButtonMotor1.Checked)
                    {
                        radioButtonMotor1Speed1.Enabled = true;
                        radioButtonMotor1Speed2.Enabled = true;
                        radioButtonMotor1Speed3.Enabled = true;
                    }

                    if (toggleButtonMotor2.Checked)
                    {
                        radioButtonMotor2Speed1.Enabled = true;
                        radioButtonMotor2Speed2.Enabled = true;
                        radioButtonMotor2Speed3.Enabled = true;
                    }


                    var values       = Login.GetValues(x => x.IsAuthorized);
                    int isAuthorized = 0;

                    if (values != null)
                    {
                        isAuthorized = values.Count;
                    }

                    if (isAuthorized > 0)
                    {
                        buttonSave.Enabled = true;
                    }

                    progressDialog.Dismiss();
                });
            }
            catch (SocketException ex)
            {
                RunOnUiThread(() =>
                {
                    progressDialog.Dismiss();

                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Network Error");
                    alert.SetMessage(ex.Message);
                    alert.SetPositiveButton("Ok", delegate(object o, DialogClickEventArgs args)
                    {
                        return;
                    });
                    alert.Create().Show();

                    buttonRefresh.Enabled = true;
                });
            }
            catch (Exception ex)
            {
                progressDialog.Dismiss();

                AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.SetTitle("Error");
                alert.SetMessage(ex.Message);
                alert.SetPositiveButton("Ok", delegate(object o, DialogClickEventArgs args)
                {
                    return;
                });
                alert.Create().Show();
            }
        }