예제 #1
0
        public void Initialize()
        {
            Total = new UpdateSensor(ValueSensorUpdate);
            foreach (ISensor sensor in Hardware.Sensors)
            {
                switch (sensor.SensorType)
                {
                case SensorType.Load:
                    UsedPercentage = sensor;
                    break;

                case SensorType.Data:
                {
                    if (sensor.Name.StartsWith("Used"))
                    {
                        Used = sensor;
                    }
                    else if (sensor.Name.StartsWith("Avail"))
                    {
                        Available = sensor;
                    }
                    else
                    {
                        Jsoner.ObjectSaver.AddObject(sensor);
                    }
                }
                break;

                default:
                    Jsoner.ObjectSaver.AddObject(sensor);
                    break;
                }
            }
        }
예제 #2
0
 private void ValueSensorUpdate(UpdateSensor self)
 {
     if (Used != null && Available != null)
     {
         self.SensorType      = SensorType.Data;
         self.Value           = Used.Value + Available.Value;
         self.Min             = Used.Min + Available.Min;
         self.Max             = Used.Max + Available.Max;
         self.Name            = "Total Memory";
         self.Hardware        = Hardware;
         self.IsDefaultHidden = true;
     }
 }
        /// <summary>
        /// Update the SensorName and the Heartbeat info
        /// </summary>
        /// <param name="UpdateSensor">Update sensor model</param>
        /// <returns>Success/Failure</returns>
        public async Task <string> UpdateSensor(UpdateSensor UpdateSensor)
        {
            var retVal = "";

            retVal = await _sensorClient.SensorSetName(UpdateSensor.SensorID, UpdateSensor.SensorName);

            retVal = await _sensorClient.SensorSetThreshold(UpdateSensor.SensorID, UpdateSensor.MinimumThreshold, UpdateSensor.MaximumThreshold, 20);

            if (retVal == "Success")
            {
                retVal = await _sensorClient.SensorSetHeartbeat(UpdateSensor.SensorID, UpdateSensor.HeartBeat, UpdateSensor.HeartBeat);
            }

            return(retVal);
        }
예제 #4
0
        public void Sensor_CRUD_Positive()
        {
            // create
            Device      device        = null;
            Sensor      sensor        = null;
            Func <Task> asyncFunction = async() =>
            {
                device = await CreateDevice(Client);

                sensor = await CreateSensor(Client, device);
            };

            asyncFunction.ShouldNotThrow();
            sensor.Should().NotBeNull();

            // read
            asyncFunction = async() => sensor = await Client.ReadSensor(sensor.Id);

            asyncFunction.ShouldNotThrow();
            sensor.Should().NotBeNull();

            // read list
            IEnumerable <Sensor> sensors = null;

            asyncFunction = async() => sensors = await Client.ReadSensors(device.Id);

            asyncFunction.ShouldNotThrow();
            sensors.Should().NotBeNullOrEmpty();
            sensors.Any(x => x.Id == sensor.Id).Should().BeTrue();

            // update
            var update = new UpdateSensor(sensor)
            {
                Description = sensor.Description + "Updated",
                Tseoi       = 1,
            };

            asyncFunction = async() => sensor = await Client.UpdateSensor(device.DevKey, sensor.RemoteId, update);

            asyncFunction.ShouldNotThrow();
            sensor.Should().NotBeNull();
            sensor.Name.Should().Be(update.Name);
            sensor.Description.Should().Be(update.Description);
            sensor.Tseoi.Should().Be(update.Tseoi);

            // link list unlink
            Place place = null;
            Thing thing = null;

            asyncFunction = async() =>
            {
                place = await CreatePlace(Client);

                thing = await CreateThing(Client, place);

                await Client.LinkSensor(thing.Id, sensor.Id);

                sensors = await Client.ListSensors(thing.Id);

                await Client.UnlinkSensor(thing.Id, sensor.Id);
            };
            asyncFunction.ShouldNotThrow();
            sensors.Should().NotBeNullOrEmpty();
            sensors.Any(x => x.Id == sensor.Id).Should().BeTrue();

            // add data
            asyncFunction = async() =>
            {
                var data = CreateSensorData(new[] { sensor.RemoteId });
                await Client.AddSensorData(device.DevKey, data.Series);
            };
            asyncFunction.ShouldNotThrow();

            // read rule
            Rule rule = null;

            asyncFunction = async() => rule = await Client.ReadSensorRule(sensor.Id);

            asyncFunction.ShouldNotThrow();
            rule.Should().NotBeNull();

            // update rule
            var updatedRule = new UpdateRule(rule)
            {
                IsEnabled       = !rule.IsEnabled,
                Name            = rule.Name + " Updated",
                Description     = rule.Name + " Updated",
                IsIncremental   = !rule.IsIncremental,
                CheckGap        = !rule.CheckGap,
                LogInterval     = !rule.LogInterval,
                IndexToAbsolute = !rule.IndexToAbsolute,
                HasMinimumValue = !rule.HasMinimumValue,
                MinimumValue    = rule.MinimumValue - 1,
                HasMaximumValue = !rule.HasMaximumValue,
                MaximumValue    = rule.MaximumValue + 1
            };

            asyncFunction = async() => rule = await Client.UpdateSensorRule(sensor.Id, updatedRule);

            asyncFunction.ShouldNotThrow();
            rule.Should().NotBeNull();
            rule.IsEnabled.Should().Be(updatedRule.IsEnabled);
            rule.Name.Should().Be(updatedRule.Name);
            rule.Description.Should().Be(updatedRule.Description);
            rule.IsIncremental.Should().Be(updatedRule.IsIncremental);
            rule.CheckGap.Should().Be(updatedRule.CheckGap);
            rule.LogInterval.Should().Be(updatedRule.LogInterval);
            rule.IndexToAbsolute.Should().Be(updatedRule.IndexToAbsolute);
            rule.HasMinimumValue.Should().Be(updatedRule.HasMinimumValue);
            rule.MinimumValue.Should().Be(updatedRule.MinimumValue);
            rule.HasMaximumValue.Should().Be(updatedRule.HasMaximumValue);
            rule.MaximumValue.Should().Be(updatedRule.MaximumValue);

            // delete
            asyncFunction = async() =>
            {
                await Client.DeleteSensor(device.DevKey, sensor.RemoteId);

                await Client.DeleteThing(thing.Id);

                await Client.DeletePlace(place.Id);
            };
            asyncFunction.ShouldNotThrow();

            // read list
            asyncFunction = async() => sensors = await Client.ReadSensors(device.Id);

            asyncFunction.ShouldNotThrow();
            sensors.Should().BeNullOrEmpty();

            // delete device
            asyncFunction = async() => await Client.DeleteDevice(device.Id);

            asyncFunction.ShouldNotThrow();
        }