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

#2162 Edge device loose tags #2173

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public AWSDeviceThingProfile()
Name = att.Key,
Value = att.Value
})));

_ = CreateMap<IoTEdgeDevice, CreateThingRequest>()
.ForMember(dest => dest.ThingName, opts => opts.MapFrom(src => src.DeviceName))
.ForPath(dest => dest.AttributePayload.Attributes, opts => opts.MapFrom(src => src.Tags))
.ReverseMap();

_ = CreateMap<IoTEdgeDevice, UpdateThingRequest>()
.ForMember(dest => dest.ThingName, opts => opts.MapFrom(src => src.DeviceName))
.ForPath(dest => dest.AttributePayload.Attributes, opts => opts.MapFrom(src => src.Tags))
.ReverseMap();
}

private static MemoryStream EmptyPayload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class EdgeDeviceProfile : Profile
{
public EdgeDeviceProfile()
{
_ = CreateMap<EdgeDevice, EdgeDevice>();

_ = CreateMap<Twin, EdgeDevice>()
.ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.DeviceId))
.ForMember(dest => dest.Name, opts => opts.MapFrom(src => src.Tags["deviceName"]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AWSEdgeDevicesService : EdgeDevicesServiceBase, IEdgeDevicesService
private readonly IEdgeDeviceModelRepository deviceModelRepository;
private readonly IConfigService configService;
private readonly ConfigHandler configHandler;
private readonly IMapper mapper;

public AWSEdgeDevicesService(
ConfigHandler configHandler,
Expand All @@ -55,6 +56,8 @@ public AWSEdgeDevicesService(

this.unitOfWork = unitOfWork;
this.edgeDeviceRepository = edgeDeviceRepository;

this.mapper = mapper;
}

/// <summary>
Expand All @@ -73,15 +76,13 @@ public async Task<IoTEdgeDevice> CreateEdgeDevice(IoTEdgeDevice edgeDevice)
throw new InvalidOperationException($"Edge model '{edgeDevice.ModelId}' doesn't exist!");
}

var response = await this.awsExternalDevicesService.CreateDevice(new CreateThingRequest
{
ThingName = edgeDevice.DeviceName,
ThingTypeName = model.Name
});
var createThingRequest = this.mapper.Map<CreateThingRequest>(edgeDevice);
createThingRequest.ThingTypeName = model.Name;

var response = await this.awsExternalDevicesService.CreateDevice(createThingRequest);
edgeDevice.DeviceId = response.ThingId;
var result = await base.CreateEdgeDeviceInDatabase(edgeDevice);

var result = await base.CreateEdgeDeviceInDatabase(edgeDevice);
await this.unitOfWork.SaveAsync();

return result;
Expand All @@ -97,7 +98,8 @@ public async Task<IoTEdgeDevice> UpdateEdgeDevice(IoTEdgeDevice edgeDevice)
{
ArgumentNullException.ThrowIfNull(edgeDevice, nameof(edgeDevice));

_ = await this.awsExternalDevicesService.GetDevice(edgeDevice.DeviceName);
var updateThingRequest = this.mapper.Map<UpdateThingRequest>(edgeDevice);
_ = await this.awsExternalDevicesService.UpdateDevice(updateThingRequest);

var result = await UpdateEdgeDeviceInDatabase(edgeDevice);

Expand Down