private void Controllers_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            int hardware_id = ParentActivity.Hardwares.Keys.ElementAt(e.Position);

            if (Command != null && Command.Execution != hardware_id)
            {
                CommandText.Text = Command.ExecutionParametr;
                Controllers.SetSelection(ParentActivity.Hardwares.Keys.ToList().IndexOf(Command.Execution));
                return;
            }
            Command = null;

            ParentActivity.command_executer_id = hardware_id;
            HardwareModel hw = null;

            if (ParentActivity.command_executer_id > 0)
            {
                lock (DatabaseContext.DbLocker)
                {
                    using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                    {
                        hw = db.Hardwares.Find(ParentActivity.command_executer_id);
                    }
                }
            }
            if (hw == null)
            {
                Log.Error(TAG, $"{ParentActivity.GetString(Resource.String.err_selected_device_was_not_found_title)} - ControllerCommand_SpinnerItemSelected({ParentActivity.command_executer_id}) - Position:{e.Position}");
            }
            else
            {
                Log.Debug(TAG, $"ControllerCommand_SpinnerItemSelected(hw:{hw}) - Position:{e.Position}");
            }
        }
Beispiel #2
0
        protected override bool Setup()
        {
            _ProgressDialog = ProgressDialog.Show(ParentActivity, "",
                                                  ParentActivity.GetString(Utils.Resource.String.progress_message));

            return(true);
        }
        public void ControllerSelect(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            int hardware_id = ParentActivity.Hardwares.Keys.ElementAt(e.Position);

            if (Command != null)
            {
                PortModel port = null;
                lock (DatabaseContext.DbLocker)
                {
                    using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                    {
                        port = db.Ports.FirstOrDefault(x => x.Id == Command.Execution);
                    }
                }
                if (port.HardwareId != hardware_id)
                {
                    Controllers.SetSelection(ParentActivity.Hardwares.Keys.ToList().IndexOf(port.HardwareId));
                    return;
                }
            }

            PortsList = new Dictionary <int, string>();

            HardwareModel hw = null;

            if (hardware_id > 0)
            {
                lock (DatabaseContext.DbLocker)
                {
                    using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase))
                    {
                        hw = db.Hardwares.Include(x => x.Ports).FirstOrDefault(x => x.Id == hardware_id);
                    }
                }
            }
            if (hw == null)
            {
                Log.Error(TAG, $"{ParentActivity.GetString(Resource.String.err_selected_device_was_not_found_title)}; ControllerSelect(); hardware_id:{hardware_id}; Position:{e.Position};");
                return;
            }
            else
            {
                Log.Debug(TAG, $"ControllerSelect(); for command; hw:{hw}; Position:{e.Position};");
            }
            hw.Ports.ForEach(portHardware => { PortsList.Add(portHardware.Id, portHardware.ToString()); });
            //
            ArrayAdapter <string> adapterPorts = new ArrayAdapter <string>(ParentActivity, Android.Resource.Layout.SimpleSpinnerItem, PortsList.Values.ToList());

            adapterPorts.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            Ports.Adapter = adapterPorts;
        }
        public void StateSelect(object sender, AdapterView.ItemSelectedEventArgs e)
        {
            string selected_state = ParentActivity.Resources.GetStringArray(Resource.Array.script_trigger_port_states_array)[e.Position];

            Log.Debug(TAG, $"StateSelect(); for command; selected_state:{selected_state}; Position:{e.Position};");

            if (selected_state == ParentActivity.GetString(Resource.String.abc_capital_on))
            {
                ParentActivity.command_executer_parameter = true;
            }
            else if (selected_state == ParentActivity.GetString(Resource.String.abc_capital_off))
            {
                ParentActivity.command_executer_parameter = false;
            }
            else
            {
                ParentActivity.command_executer_parameter = null;
            }
        }