Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix/#1421_-_Unable to delete device in database when the device did not exist in IoTHub #1499

Merged
merged 5 commits into from
Nov 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/AzureIoTHub.Portal.Server/Jobs/SyncEdgeDeviceJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public async Task Execute(IJobExecutionContext context)

private async Task SyncEdgeDevices()
{
foreach (var twin in await GetTwinDevices())
var deviceTwins = await GetTwinDevices();

foreach (var twin in deviceTwins)
{
var deviceModel = await this.edgeDeviceModelRepository.GetByIdAsync(twin.Tags[ModelId]?.ToString() ?? string.Empty);

Expand All @@ -80,6 +82,14 @@ private async Task SyncEdgeDevices()
await CreateOrUpdateDevice(twin);
}

foreach (var item in this.edgeDeviceRepository.GetAll())
{
if (!deviceTwins.Exists(x => x.DeviceId == item.Id))
{
this.edgeDeviceRepository.Delete(item.Id);
}
}
Fixed Show fixed Hide fixed

await this.unitOfWork.SaveAsync();
}

Expand Down