/// <summary> /// Process CustomerName property updated. /// </summary> /// <param name="customerNameUpdate">information of property to be reported.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task SetCustomerNameAsync(DigitalTwinPropertyUpdate customerNameUpdate) { // code to consume customer value, currently just displaying on screen. string customerName = customerNameUpdate.PropertyDesired; Console.WriteLine($"Desired customer name = '{customerName}'."); Console.WriteLine($"Reported customer name = '{customerNameUpdate.PropertyReported}'."); Console.WriteLine($"Version is '{customerNameUpdate.DesiredVersion}'."); // report Completed var propertyReport = new Collection <DigitalTwinPropertyReport>(); propertyReport.Add(new DigitalTwinPropertyReport( customerNameUpdate.PropertyName, customerNameUpdate.PropertyDesired, new DigitalTwinPropertyResponse(customerNameUpdate.DesiredVersion, StatusCodeCompleted, "Processing Completed"))); await this.ReportPropertiesAsync(propertyReport).ConfigureAwait(false); Console.WriteLine("Sent completed status."); }
/// <summary> /// Callback on property updated. /// </summary> /// <param name="propertyUpdate">information regarding the property updated.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> protected override async Task OnPropertyUpdated(DigitalTwinPropertyUpdate propertyUpdate) { Console.WriteLine($"Received updates for property '{propertyUpdate.PropertyName}'"); switch (propertyUpdate.PropertyName) { case CustomerName: await this.SetCustomerNameAsync(propertyUpdate).ConfigureAwait(false); break; case Brightness: await this.SetBrightnessAsync(propertyUpdate).ConfigureAwait(false); break; default: Console.WriteLine($"Property name '{propertyUpdate.PropertyName}' is not handled."); break; } }
/// <summary> /// Process Brightness property updated. /// </summary> /// <param name="brightnessUpdate">information of property to be reported.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task SetBrightnessAsync(DigitalTwinPropertyUpdate brightnessUpdate) { // code to consume light brightness value, currently just displaying on screen string brightness = brightnessUpdate.PropertyDesired; long current = 0; Console.WriteLine($"Desired brightness = '{brightness}'."); Console.WriteLine($"Reported brightness = '{brightnessUpdate.PropertyReported}'."); Console.WriteLine($"Version is '{brightnessUpdate.DesiredVersion}'."); // report Pending var propertyReport = new Collection <DigitalTwinPropertyReport>(); propertyReport.Add(new DigitalTwinPropertyReport( brightnessUpdate.PropertyName, current.ToString(), new DigitalTwinPropertyResponse(brightnessUpdate.DesiredVersion, 102, "Processing Request"))); await this.ReportPropertiesAsync(propertyReport).ConfigureAwait(false); Console.WriteLine("Sent pending status for brightness property."); propertyReport.Clear(); // Pretend calling command to Sensor to update brightness await Task.Delay(5 * 1000).ConfigureAwait(false); // report Completed propertyReport.Add(new DigitalTwinPropertyReport( brightnessUpdate.PropertyName, brightnessUpdate.PropertyDesired, new DigitalTwinPropertyResponse( brightnessUpdate.DesiredVersion, StatusCodeCompleted, "Request completed"))); await this.ReportPropertiesAsync(propertyReport).ConfigureAwait(false); Console.WriteLine("Sent completed status for brightness property."); }