public async Task SaveDeploymentHistory(string tenantId, DeploymentServiceModel deploymentModel, Twin deviceTwin) { CosmosOperations storageClient = await CosmosOperations.GetClientAsync(); TwinServiceModel previousTwin = await this.GetPreviousFirmwareReportedProperties(tenantId, deviceTwin.DeviceId); var deviceTwinServiceModel = new TwinServiceModel(deviceTwin); DeploymentHistoryModel modelToSave = new DeploymentHistoryModel { DeploymentId = deploymentModel.Id, DeploymentName = deploymentModel.Name, DeviceId = deviceTwin.DeviceId, PreviousFirmwareTwin = previousTwin, LastUpdatedDateTimeUtc = DateTime.UtcNow, Twin = deviceTwinServiceModel, }; var value = JsonConvert.SerializeObject( modelToSave, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, }); await storageClient.SaveDocumentAsync(string.Format(DeploymentHistoryCollection, deviceTwin.DeviceId), deploymentModel.Id, new ValueServiceModel() { Data = value }, this.GenerateCollectionLink(tenantId), Guid.NewGuid()); }
public DeviceServiceModel( string etag, string id, int c2DMessageCount, DateTime lastActivity, bool connected, bool enabled, bool isEdgeDevice, DateTime lastStatusUpdated, TwinServiceModel twin, AuthenticationMechanismServiceModel authentication, string ioTHubHostName) { this.Etag = etag; this.Id = id; this.C2DMessageCount = c2DMessageCount; this.LastActivity = lastActivity; this.Connected = connected; this.Enabled = enabled; this.IsEdgeDevice = isEdgeDevice; this.LastStatusUpdated = lastStatusUpdated; this.Twin = twin; this.IoTHubHostName = ioTHubHostName; this.Authentication = authentication; }
private async Task SaveModuleTwin(string tenantId, string deploymentId, TwinServiceModel moduleTwin) { CosmosOperations storageClient = await CosmosOperations.GetClientAsync(); var value = JsonConvert.SerializeObject( moduleTwin, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, }); await storageClient.SaveDocumentAsync(string.Format(DeploymentEdgeModulePropertiesCollection, deploymentId), $"{moduleTwin.DeviceId}-{this.RemoveSpecialCharacters(moduleTwin.ModuleId)}", new ValueServiceModel() { Data = value }, this.GenerateCollectionLink(tenantId)); }