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()); } } }
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(); } }
private void buttonSaveClickedAsync() { try { Dictionary <int, int> dic = new Dictionary <int, int>(); MotorStatus motor1 = MotorStatus.Off; MotorStatus motor2 = MotorStatus.Off; if (!toggleButtonMotor1.Checked) { motor1 = MotorStatus.Off; } else if (radioButtonMotor1Speed1.Checked) { motor1 = MotorStatus.Speed1; } else if (radioButtonMotor1Speed2.Checked) { motor1 = MotorStatus.Speed2; } else if (radioButtonMotor1Speed3.Checked) { motor1 = MotorStatus.Speed3; } if (!toggleButtonMotor2.Checked) { motor2 = MotorStatus.Off; } else if (radioButtonMotor2Speed1.Checked) { motor2 = MotorStatus.Speed1; } else if (radioButtonMotor2Speed2.Checked) { motor2 = MotorStatus.Speed2; } else if (radioButtonMotor2Speed3.Checked) { motor2 = MotorStatus.Speed3; } SetStatusWrapper wrapper = new SetStatusWrapper(); wrapper.Motor1 = motor1; wrapper.Motor2 = motor2; var login = Login.GetValues(x => x.IsAuthorized).FirstOrDefault(); wrapper.SessionKey = login.SessionKey; TechnicalFanCoil technicalFanCoil = new TechnicalFanCoil(); bool result = technicalFanCoil.SetStatus(wrapper); ButtonRefreshClickedAsync(); //RunOnUiThread(() => //{ // buttonSave.Enabled = true; //}); progressDialog.Dismiss(); } catch (Exception ex) { //RunOnUiThread(() => //{ // buttonSave.Enabled = true; // buttonRefresh.Enabled = true; //}); 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(); } }