Ejemplo n.º 1
0
        public async Task ReportComponentPropertyAsync(string componentName, string propertyName, object propertyValue)
        {
            var twin = new TwinCollection();

            twin.AddComponentProperty(componentName, propertyName, propertyValue);
            await deviceClient.UpdateReportedPropertiesAsync(twin);
        }
Ejemplo n.º 2
0
        public async Task ReportComponentPropertyCollectionAsync(string componentName, Dictionary <string, object> properties)
        {
            var reported = new TwinCollection();

            foreach (var p in properties)
            {
                reported.AddComponentProperty(componentName, p.Key, p.Value);
            }
            await deviceClient.UpdateReportedPropertiesAsync(reported);
        }
Ejemplo n.º 3
0
        public async Task ReportPropertyAsync(string propertyName, object propertyValue)
        {
            this.logger.LogTrace("Reporting " + propertyName);
            var twin = new TwinCollection();

            if (isRootComponent)
            {
                twin[propertyName] = propertyValue;
            }
            else
            {
                twin.AddComponentProperty(this.componentName, propertyName, propertyValue);
            }
            await this.client.UpdateReportedPropertiesAsync(twin);
        }
        public void AddComponentPropAddsTheFlagIfNeeded()
        {
            TwinCollection collection = new TwinCollection();

            collection.AddComponentProperty("myComp", "myProp", 12.3);
            Assert.True(collection.Contains("myComp"));
            var comp = collection["myComp"] as JObject;

            Assert.True(comp.ContainsKey("__t"));
            Assert.True(comp.ContainsKey("myProp"));
            var prop = comp["myProp"];

            Assert.NotNull(prop);
            var propValue = prop["value"];

            Assert.Equal(12.3, propValue.Value <double>());
        }
        public void AddPropertyToAnExistingComponent()
        {
            string         json           = @"
      {
        tempSensor1: {
          __t: 'c',
          targetTemperature: {}
        }
      }";
            TwinCollection twinCollection = new TwinCollection(json);

            twinCollection.AddComponentProperty("tempSensor1", "newProperty", true);
            TwinCollection updatedCollection = new TwinCollection(twinCollection.ToJson());
            var            result            = twinCollection.GetPropertyValue <bool>("tempSensor1", "newProperty");

            Assert.True(result);
        }
Ejemplo n.º 6
0
        public async Task ReportPropertyCollectionAsync(Dictionary <string, object> properties)
        {
            var reported = new TwinCollection();

            foreach (var p in properties)
            {
                if (this.isRootComponent)
                {
                    reported[p.Key] = p.Value;
                }
                else
                {
                    reported.AddComponentProperty(this.componentName, p.Key, p.Value);
                }
            }

            await this.client.UpdateReportedPropertiesAsync(reported);
        }