Skip to content

Commit

Permalink
Fix #2942 - Add LoraWan service dependency before adding the http cli…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
kbeaugrand committed Apr 16, 2024
1 parent afdf9f2 commit 1004229
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace IoTHub.Portal.Infrastructure.Services
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using IoTHub.Portal.Application.Services;
Expand Down Expand Up @@ -38,9 +37,17 @@ public async Task<HttpResponseMessage> ExecuteLoRaDeviceMessage(string deviceId,
ArgumentNullException.ThrowIfNull(deviceId, nameof(deviceId));
ArgumentNullException.ThrowIfNull(commandDto, nameof(commandDto));

// Convert the hex frame to a byte array
var hexFrame = Enumerable.Range(0, commandDto.Frame.Length / 2)
.Select(x => Convert.ToByte(commandDto.Frame.Substring(x * 2, 2), 16))
.ToArray();

// Convert the byte array to a base64 string
var rawPayload = Convert.ToBase64String(hexFrame);

var body = new LoRaCloudToDeviceMessage
{
RawPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(commandDto.Frame)),
RawPayload = rawPayload,
Fport = commandDto.Port,
Confirmed = commandDto.Confirmed
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ namespace IoTHub.Portal.Infrastructure.Startup
using IoTHub.Portal.Models.v10.LoRaWAN;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Provisioning.Service;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Polly;
Expand Down Expand Up @@ -62,13 +60,13 @@ private static IServiceCollection AddLoRaWanSupport(this IServiceCollection serv
return services;
}

var transientHttpErrorPolicy = HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(c => c.StatusCode == HttpStatusCode.NotFound)
.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(100));
_ = services.AddTransient<ILoRaWanManagementService, LoRaWanManagementService>()
.AddTransient<IDeviceService<LoRaDeviceDetails>, LoRaWanDeviceService>();

_ = services.AddHttpClient("RestClient")
.AddPolicyHandler(transientHttpErrorPolicy);
var transientHttpErrorPolicy = HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(c => c.StatusCode == HttpStatusCode.NotFound)
.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(100));

_ = services.AddHttpClient<ILoRaWanManagementService, LoRaWanManagementService>((sp, client) =>
{
Expand Down Expand Up @@ -109,9 +107,8 @@ private static IServiceCollection ConfigureMappers(this IServiceCollection servi

private static IServiceCollection ConfigureServices(this IServiceCollection services)
{
return services.AddTransient<ILoRaWanManagementService, LoRaWanManagementService>()
.AddTransient<IDeviceService<DeviceDetails>, DeviceService>()
.AddTransient<IDeviceService<LoRaDeviceDetails>, LoRaWanDeviceService>();
return services
.AddTransient<IDeviceService<DeviceDetails>, DeviceService>();
}

private static IServiceCollection ConfigureHealthCheck(this IServiceCollection services)
Expand Down

0 comments on commit 1004229

Please sign in to comment.