Beispiel #1
0
        // This method updates local state and should be called only after acquiring edgeHubConfigLock
        async Task <Option <EdgeHubConfig> > PatchDesiredProperties(TwinCollection baseline, TwinCollection patch)
        {
            LastDesiredStatus      lastDesiredStatus;
            Option <EdgeHubConfig> edgeHubConfig;

            try
            {
                string desiredPropertiesJson = JsonEx.Merge(baseline, patch, true);
                this.lastDesiredProperties = Option.Some(new TwinCollection(desiredPropertiesJson));
                var desiredPropertiesPatch = JsonConvert.DeserializeObject <EdgeHubDesiredProperties>(desiredPropertiesJson);
                edgeHubConfig     = Option.Some(this.configParser.GetEdgeHubConfig(desiredPropertiesPatch));
                lastDesiredStatus = new LastDesiredStatus(200, string.Empty);
                Events.PatchConfigSuccess();
            }
            catch (Exception ex)
            {
                lastDesiredStatus = new LastDesiredStatus(400, $"Error while parsing desired properties - {ex.Message}");
                edgeHubConfig     = Option.None <EdgeHubConfig>();
                Events.ErrorPatchingDesiredProperties(ex);
            }

            await this.UpdateReportedProperties(patch.Version, lastDesiredStatus);

            return(edgeHubConfig);
        }
Beispiel #2
0
 public ReportedProperties(
     VersionInfo versionInfo, string schemaVersion,
     long?lastDesiredVersion, LastDesiredStatus lastDesiredStatus,
     IDictionary <string, DeviceConnectionStatus> clients
     )
 {
     this.SchemaVersion      = schemaVersion;
     this.LastDesiredVersion = lastDesiredVersion;
     this.LastDesiredStatus  = lastDesiredStatus;
     this.Clients            = clients;
     this.VersionInfo        = versionInfo ?? VersionInfo.Empty;
 }
Beispiel #3
0
 Task UpdateReportedProperties(long desiredVersion, LastDesiredStatus desiredStatus)
 {
     try
     {
         var           edgeHubReportedProperties = new ReportedProperties(this.versionInfo, desiredVersion, desiredStatus);
         var           twinCollection            = new TwinCollection(JsonConvert.SerializeObject(edgeHubReportedProperties));
         Core.IMessage reportedPropertiesMessage = this.twinCollectionMessageConverter.ToMessage(twinCollection);
         return(this.twinManager.UpdateReportedPropertiesAsync(this.id, reportedPropertiesMessage));
     }
     catch (Exception ex)
     {
         Events.ErrorUpdatingLastDesiredStatus(ex);
         return(Task.CompletedTask);
     }
 }
Beispiel #4
0
        // This method updates local state and should be called only after acquiring edgeHubConfigLock
        async Task <Option <EdgeHubConfig> > PatchDesiredProperties(TwinCollection baseline, TwinCollection patch)
        {
            LastDesiredStatus      lastDesiredStatus;
            Option <EdgeHubConfig> edgeHubConfig;

            try
            {
                string desiredPropertiesJson = JsonEx.Merge(baseline, patch, true);
                var    desiredProperties     = new TwinCollection(desiredPropertiesJson);
                Events.LogDesiredPropertiesAfterPatch(desiredProperties);
                if (!this.CheckIfManifestSigningIsEnabled(desiredProperties))
                {
                    Events.ManifestSigningIsNotEnabled();
                }
                else
                {
                    Events.ManifestSigningIsEnabled();
                    if (this.ExtractHubTwinAndVerify(desiredProperties))
                    {
                        Events.VerifyTwinSignatureSuceeded();
                    }
                    else
                    {
                        Events.VerifyTwinSignatureFailed();
                        lastDesiredStatus = new LastDesiredStatus(400, "Twin Signature Verification failed");
                        return(Option.None <EdgeHubConfig>());
                    }
                }

                this.lastDesiredProperties = Option.Some(new TwinCollection(desiredPropertiesJson));
                edgeHubConfig     = Option.Some(this.configParser.GetEdgeHubConfig(desiredPropertiesJson));
                lastDesiredStatus = new LastDesiredStatus(200, string.Empty);
                Events.PatchConfigSuccess();
            }
            catch (Exception ex)
            {
                lastDesiredStatus = new LastDesiredStatus(400, $"Error while parsing desired properties - {ex.Message}");
                edgeHubConfig     = Option.None <EdgeHubConfig>();
                Events.ErrorPatchingDesiredProperties(ex);
            }

            await this.UpdateReportedProperties(patch.Version, lastDesiredStatus);

            return(edgeHubConfig);
        }
Beispiel #5
0
 // When reporting last desired version/status, send empty map of clients so that the patch doesn't touch the
 // existing values. If we send a null, it will clear out the existing clients.
 public ReportedProperties(VersionInfo versionInfo, long lastDesiredVersion, LastDesiredStatus lastDesiredStatus)
     : this(versionInfo, CurrentSchemaVersion, lastDesiredVersion, lastDesiredStatus, EmptyConnectionStatusesDictionary)
 {
 }