示例#1
0
        public PowerGaugeCtrl(PowerConsumptionSensor sensor)
        {
            InitializeComponent();
            ToolTip          = sensor.Name;
            lbl_Name.Content = sensor.Name;
            this.sensor      = sensor;
            scale.Min        = (double)sensor.MinValue;
            scale.Max        = (double)sensor.MaxValue;

            try
            {
                model = HttpService.SensorList.First(item => item.Tag == sensor.Link);

                timer = new DispatcherTimer
                {
                    Interval = TimeSpan.FromSeconds(model.MinPollingIntervalInSeconds)
                };
                timer.Tick += Timer_Tick;
                timer.Start();
                FirstTick();
            }
            catch
            {
                needle.Background       = new SolidColorBrush(Colors.LightGray);
                numIndicator.Foreground = new SolidColorBrush(Colors.LightGray);
                label.Foreground        = new SolidColorBrush(Colors.LightGray);
                bar.Background          = new SolidColorBrush(Colors.LightGray);
            }
        }
        private void Submit(object param)
        {
            Sensor sensor;

            switch (SelectedItem)
            {
            case "Temperature":
                sensor = new TemperatureSensor(Name, Url, Description, Latitude, Longitude, Tracking, MinValue, MaxValue);
                break;

            case "Humidity":
                sensor = new HumiditySensor(Name, Url, Description, Latitude, Longitude, Tracking, MinValue, MaxValue);
                break;

            case "Electricity Consumption":
                sensor = new PowerConsumptionSensor(Name, Url, Description, Latitude, Longitude, Tracking, MinValue, MaxValue);
                break;

            case "Noise":
                sensor = new TemperatureSensor(Name, Url, Description, Latitude, Longitude, Tracking, MinValue, MaxValue);
                break;

            case "Window/Door":
                sensor = new WindowDoorSensor(Name, Url, Description, Latitude, Longitude, Tracking, Opened);
                break;

            default:
                sensor = null;
                break;
            }

            sensors.List.Add(sensor);
            UpdateXml(sensors);
        }
        private void Submit(object param)
        {
            Sensor sensor;

            CheckForBlanks();
            //check for errors
            if (ErrorCollection.Count == 0)
            {
                switch (SelectedItem)
                {
                case "Temperature":
                    sensor = new TemperatureSensor(Name, ToLinkWith.Tag, Description, Convert.ToDouble(Latitude),
                                                   Convert.ToDouble(Longitude), Tracking,
                                                   Convert.ToDecimal(MinValue), Convert.ToDecimal(MaxValue));
                    break;

                case "Humidity":
                    sensor = new HumiditySensor(Name, ToLinkWith.Tag, Description, Convert.ToDouble(Latitude),
                                                Convert.ToDouble(Longitude), Tracking,
                                                Convert.ToDecimal(MinValue), Convert.ToDecimal(MaxValue));
                    break;

                case "Electricity Consumption":
                    sensor = new PowerConsumptionSensor(Name, ToLinkWith.Tag, Description, Convert.ToDouble(Latitude),
                                                        Convert.ToDouble(Longitude), Tracking,
                                                        Convert.ToDecimal(MinValue), Convert.ToDecimal(MaxValue));
                    break;

                case "Noise":
                    sensor = new NoiseSensor(Name, ToLinkWith.Tag, Description, Convert.ToDouble(Latitude),
                                             Convert.ToDouble(Longitude), Tracking,
                                             Convert.ToDecimal(MinValue), Convert.ToDecimal(MaxValue));
                    break;

                case "Window/Door":
                    sensor = new WindowDoorSensor(Name, ToLinkWith.Tag, Description, Convert.ToDouble(Latitude),
                                                  Convert.ToDouble(Longitude), Tracking,
                                                  Open);
                    break;

                default:
                    sensor = null;
                    break;
                }

                sensors.List.Add(sensor);
                UpdateXml(sensors);
                Snackbar.Enqueue($"{sensor.Name} added");
                DialogHost.CloseDialogCommand.Execute(null, null);
            }
        }
示例#4
0
 private void CreateCopy(Sensor sensor1, ref Sensor sensor2)
 {
     if (sensor1 is HumiditySensor)
     {
         sensor2 = new HumiditySensor((HumiditySensor)sensor1);
     }
     else if (sensor1 is NoiseSensor)
     {
         sensor2 = new NoiseSensor((NoiseSensor)sensor1);
     }
     else if (sensor1 is PowerConsumptionSensor)
     {
         sensor2 = new PowerConsumptionSensor((PowerConsumptionSensor)sensor1);
     }
     else if (sensor1 is TemperatureSensor)
     {
         sensor2 = new TemperatureSensor((TemperatureSensor)sensor1);
     }
     else
     {
         sensor2 = new WindowDoorSensor((WindowDoorSensor)sensor1);
     }
 }