Skip to content

Commit

Permalink
#1924 Sync Iot Things
Browse files Browse the repository at this point in the history
- Fix for deletion at sync
- Remove unused references
  • Loading branch information
delager authored and kbeaugrand committed Jun 1, 2023
1 parent 110037d commit 4a3dddd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/AzureIoTHub.Portal.Infrastructure/Jobs/AWS/SyncThingsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace AzureIoTHub.Portal.Infrastructure.Jobs.AWS
{
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Amazon.IoT;
Expand Down Expand Up @@ -104,10 +105,14 @@ private async Task SyncThingsAsDevices()
await CreateOrUpdateThing(thing, deviceModel);
}

foreach (var item in (await this.deviceRepository.GetAllAsync()).Where(device => !things.Exists(x => x.ThingId == device.Id)))
foreach (var item in (await this.deviceRepository.GetAllAsync(
device => !things.Select(x => x.ThingId).Contains(device.Id),
default,
d => d.Tags,
d => d.Labels
)))
{
var deviceEntity = await this.deviceRepository.GetByIdAsync(item.Id, d => d.Tags, d => d.Labels);
this.deviceRepository.Delete(deviceEntity!.Id);
this.deviceRepository.Delete(item.Id);
}

await this.unitOfWork.SaveAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace AzureIoTHub.Portal.Infrastructure.Startup
{
using System.Net;
using Amazon;
using Amazon.GreengrassV2;
using Amazon.IoT;
Expand All @@ -20,7 +19,6 @@ namespace AzureIoTHub.Portal.Infrastructure.Startup
using AzureIoTHub.Portal.Infrastructure.Services.AWS;
using AzureIoTHub.Portal.Models.v10;
using Microsoft.Extensions.DependencyInjection;
using Prometheus;
using Quartz;

public static class AWSServiceCollectionExtension
Expand Down

0 comments on commit 4a3dddd

Please sign in to comment.