private void ButtonDeleteScript_Click(object sender, EventArgs e) { Log.Debug(TAG, "ButtonDeleteScript_Click"); CardTitle.Text = GetText(Resource.String.delete_script_card_title); CardSubtitle.Text = GetText(Resource.String.delete_script_card_sub_title); CardSubtitle.SetTextColor(Color.IndianRed); ScriptName.Enabled = false; ButtonOk.Enabled = false; ButtonOk.Text = GetText(Resource.String.ok_mute_button_with_remove_script); DeleteScript.Enabled = false; DeleteScript.SetTextColor(Color.Gray); DeleteScript.Click -= ButtonDeleteScript_Click; CommandsScript.Enabled = false; CommandsScript.SetTextColor(Color.Gray); CommandsScript.Click -= ButtonConfigScript_Click; AppCompatTextView appCompatTextView = new AppCompatTextView(this) { Text = GetText(Resource.String.footer_text_with_remove_script), TextSize = 15 }; appCompatTextView.SetTextColor(Color.Red); appCompatTextView.SetWidth(3); FooterLayout.AddView(appCompatTextView); AppCompatButton ButtonConfirmDeleteScript = new AppCompatButton(this) { Text = GetText(Resource.String.button_confirm_remove) }; ButtonConfirmDeleteScript.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); ButtonConfirmDeleteScript.SetTextColor(Color.DarkRed); ButtonConfirmDeleteScript.Click += new EventHandler((sender, eventArg) => { lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { ScriptModel script = db.Scripts.Find(scriptHardware.Id); db.Scripts.Remove(script); db.SaveChanges(); StartActivity(typeof(ScriptsListActivity)); } } }); FooterLayout.AddView(ButtonConfirmDeleteScript); }
private void ButtonStartScript_Click(object sender, EventArgs e) { string errMsg = ReadView(scriptHardware.Id); if (scriptHardware.Name != ScriptName.Text) { errMsg += $"{GetString(Resource.String.saving_is_required)}"; } if (!string.IsNullOrWhiteSpace(errMsg)) { errMsg += $"ButtonStartScript_Click - {errMsg}"; Log.Error(TAG, errMsg); using (LogsContext logs = new LogsContext()) { logs.AddLogRow(LogStatusesEnum.Error, errMsg, TAG); } CardSubtitle.Text = errMsg; CardSubtitle.SetTextColor(Color.Red); Toast.MakeText(this, errMsg, ToastLength.Short).Show(); return; } TaskModel task; lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { task = new TaskModel() { Name = "http trigger", TaskInitiatorType = TaskInitiatorsTypes.Manual, TaskInitiatorId = (sender as AppCompatButton).Id, ScriptId = scriptHardware.Id }; task.FinishedAt = task.CreatedAt; db.Tasks.Add(task); db.SaveChanges(); } } task.Script = scriptHardware; BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler(aForegroundService.RunScriptAction); bw.ProgressChanged += Bw_ProgressChanged; bw.RunWorkerCompleted += Bw_RunWorkerCompleted; bw.RunWorkerAsync(task); //Thread RunScriptThread = new Thread(aForegroundService.RunScriptAction) { IsBackground = false }; //RunScriptThread.Start(task); }
protected override void ButtonOk_Click(object sender, EventArgs e) { Log.Debug(TAG, "ButtonOk_Click"); string errMsg = ReadView(0); if (!string.IsNullOrWhiteSpace(errMsg)) { Log.Error(TAG, $"ButtonOk_Click - {errMsg}"); CardSubtitle.Text = errMsg; CardSubtitle.SetTextColor(Android.Graphics.Color.Red); Toast.MakeText(this, errMsg, ToastLength.Short).Show(); return; } CommandModel command = ReadFormToObject(new CommandModel() { ScriptId = ScriptId }); lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { if (db.Commands.Any(x => x.ScriptId == ScriptId)) { command.Ordering = db.Commands.Where(x => x.ScriptId == ScriptId).Max(x => x.Ordering) + 1; } else { command.Ordering = 1; } } } lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { db.Commands.Add(command); db.SaveChanges(); } } Intent intent = new Intent(this, typeof(CommandsListActivity)); intent.PutExtra(nameof(ScriptModel.Id), ScriptId); StartActivity(intent); }
protected override void ButtonOk_Click(object sender, EventArgs e) { Log.Debug(TAG, $"ButtonOk_Click"); string obj_id_tag = ButtonOk.Tag?.ToString() ?? "0"; int obj_id = 0; if (Regex.IsMatch(obj_id_tag, @"^\d+$")) { obj_id = int.Parse(obj_id_tag); } string errMsg = ReadView(obj_id); if (!string.IsNullOrWhiteSpace(errMsg)) { Log.Error(TAG, $"ButtonOk_Click - {errMsg}"); CardSubtitle.Text = errMsg; CardSubtitle.SetTextColor(Android.Graphics.Color.Red); Toast.MakeText(this, errMsg, ToastLength.Short).Show(); return; } ScriptModel scriptHardware = null; if (obj_id > 0) { lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { scriptHardware = db.Scripts.FirstOrDefault(x => x.Id == obj_id); } } scriptHardware.Name = ScriptName.Text.Trim(); } if (scriptHardware == null) { scriptHardware = new ScriptModel() { Name = ScriptName.Text }; } if (AutorunTrigger.Checked) { scriptHardware.TriggerPortId = Ports.Keys.ElementAt(PortTrigger.SelectedItemPosition); string[] statuses = Resources.GetStringArray(Resource.Array.script_trigger_port_states_array); string selectedPortStatus = statuses[StateTrigger.SelectedItemPosition]; if (selectedPortStatus == GetString(Resource.String.abc_capital_on)) { scriptHardware.TriggerPortState = true; } else if (selectedPortStatus == GetString(Resource.String.abc_capital_off)) { scriptHardware.TriggerPortState = false; } else { scriptHardware.TriggerPortState = null; } } lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { if (scriptHardware.Id > 0) { db.Scripts.Update(scriptHardware); } else { db.Scripts.Add(scriptHardware); } db.SaveChanges(); } } StartActivity(typeof(ScriptsListActivity)); }