Пример #1
0
        private void ReceiveSensorList(object _sensor_list, string attribute, string label)
        {
            Debug.Log("Receive sensor list " + attribute);
            JObject sensor_list = (JObject)_sensor_list;

            ThreadHelper.UI_Invoke(this, null, UISensorCheckboxList, (data) =>
            {
                autoObservableValues = new ObservableNumericValueCollection();
                foreach (var elem in (JObject)data["sensor_list"])
                {
                    if (!sensor_information.ContainsKey(elem.Key))
                    {
                        //string sensor_name = label + ": " + elem.Key;
                        string sensor_name = elem.Key;

                        sensor_information.Add(sensor_name, elem.Value.ToString());

                        UISensorCheckboxList.Items.Add(sensor_name);

                        if (DataReceiver.Observe)
                        {
                            AddParameterControlRow(new ObservedDataRow
                            {
                                name  = elem.Key,
                                value = ""
                            }
                                                   );

                            IObservableNumericValue o = autoObservableValues.AddWithType(elem.Key, elem.Value.ToString());
                            o.OnUpdate(ObservedValueChanged);
                        }
                    }
                }
                if (autoObservableValues.Count > 0)
                {
                    autoParamControlTemplate.SetCollection(autoObservableValues);
                    DataReceiver.SetObservableNumericValues(autoObservableValues);
                }
            }, new Hashtable {
                { "form", this },
                { "panel", null },
                { "control", UISensorCheckboxList },
                { "sensor_list", sensor_list }
            });
        }
        private void UITemplateSaveButton_Click(object sender, EventArgs e)
        {
            string name = UIParameterTemplateNameInput.Text;

            if (name.Length > 0)
            {
                using (LiteDatabase db = new LiteDatabase(db_path))
                {
                    ObservableNumericValueCollection          observedValues = Program.app.DataReceiver.ObservedValues;
                    LiteCollection <ParameterControlTemplate> collection     = db.GetCollection <ParameterControlTemplate>(collection_name);

                    if (UIParameterControlTemplateList.SelectedIndex == -1)
                    {
                        ParameterControlTemplate template = new ParameterControlTemplate(observedValues);
                        template.Name        = UIParameterTemplateNameInput.Text;
                        template.Description = UIParameterControlTemplateDescriptionInput.Text;

                        collection.Insert(template);
                    }
                    else
                    {
                        ParameterControlTemplate template = templateList[UIParameterControlTemplateList.SelectedIndex];
                        template.Name        = UIParameterTemplateNameInput.Text;
                        template.Description = UIParameterControlTemplateDescriptionInput.Text;
                        template.SetCollection(observedValues);

                        if (!collection.Update(template.Id, template))
                        {
                            Debug.Log("Update failed");
                        }
                        else
                        {
                            Debug.Log("Update OK");
                        }
                    }
                }

                Close();
            }
            else
            {
                MessageBox.Show("Cannot save, no name given");
            }
        }