public async Task SetPnPDesiredPropertyHandlerAsync <T>(string propertyName, OnDesiredPropertyFoundCallback callback, object ctx) { StatusCodes result = StatusCodes.NotImplemented; this.logger.LogTrace("Set Desired Handler for " + propertyName); await this.client.SetDesiredPropertyUpdateCallbackAsync(async (TwinCollection desiredProperties, object ctx2) => { this.logger.LogTrace($"Received desired updates [{desiredProperties.ToJson()}]"); T desiredPropertyValue; if (isRootComponent) { desiredPropertyValue = desiredProperties.GetPropertyValue <T>(propertyName); } else { desiredPropertyValue = desiredProperties.GetPropertyValue <T>(this.componentName, propertyName); } result = StatusCodes.Pending; await AckDesiredPropertyReadAsync(propertyName, desiredPropertyValue, StatusCodes.Pending, "update in progress", desiredProperties.Version); if (desiredPropertyValue != null) { callback(desiredPropertyValue); result = StatusCodes.Completed; await AckDesiredPropertyReadAsync(propertyName, desiredPropertyValue, StatusCodes.Completed, "update complete", desiredProperties.Version); this.logger.LogInformation($"Desired properties processed successfully"); } else { result = StatusCodes.Invalid; await AckDesiredPropertyReadAsync(propertyName, desiredPropertyValue, StatusCodes.Invalid, "invalid, empty value", desiredProperties.Version); this.logger.LogTrace($"Invalid desired properties processed "); } await Task.FromResult(result); }, this); }
public void SetDesiredPropertyUpdateCommandHandler(string componentName, OnDesiredPropertyFoundCallback callback) { desiredPropertyCallbacks.Add(componentName, callback); }