/// <summary> /// Internal callback method that fired when twin json is changed on server side /// </summary> private async Task OnDesiredPropertiesUpdate(TwinCollection desiredProperties, object userContext) { try { Console.WriteLine("Desired property change:"); Console.WriteLine(JsonConvert.SerializeObject(desiredProperties)); //Checking that changed properties is related to blob extended properties if (desiredProperties[blobConfigPropertyName] != null) { var ts = desiredProperties[blobConfigPropertyName]["ts"].Value; string sasUri = desiredProperties[blobConfigPropertyName]["uri"].Value; if (string.IsNullOrWhiteSpace(sasUri)) { Console.WriteLine("Unable to apply blob update: uri is null or whitespace."); return; } if (ts <= lastTimestamp && string.Compare(sasUri, lastUri, true) == 0) { Console.WriteLine("Skipping blob update: for the same sas uri, the ts is less than or equal to the currently applied configuration."); return; } lastContent = await DownloadBlobAsync(sasUri); lastTimestamp = ts; lastUri = sasUri; BlobPropertyUpdatedArgs args = new BlobPropertyUpdatedArgs(); args.BlobContent = lastContent; args.DateTimeUpdated = ts; //Raise event OnBlobPropertyUpdatedEvent(args, this); //Notify IoT hub twin json file that we successfully download the extended blob file await NotifyIoTHubOfUpdatedBlob(sasUri, ts.ToString("o")); } } catch (AggregateException ex) { foreach (Exception exception in ex.InnerExceptions) { Console.WriteLine(); Console.WriteLine("Error when receiving desired property: {0}", exception); } } catch (Exception ex) { Console.WriteLine(); Console.WriteLine("Error when receiving desired property: {0}", ex.Message); } }
protected virtual void OnBlobPropertyUpdatedEvent(BlobPropertyUpdatedArgs e, object sender) { var BlobPropertyUpdatedEvent = this._BlobPropertyUpdatedEvent; if (BlobPropertyUpdatedEvent == null) { return; } BlobPropertyUpdatedEvent(e, sender); }