Skip to content

Commit

Permalink
fix #179
Browse files Browse the repository at this point in the history
  • Loading branch information
Sben65 committed Feb 6, 2022
1 parent b4f0ce9 commit 6a63f89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Placeholder="Please select the type"
Required="true"
AdornmentColor="Color.Primary">
<MudSelectItem Value="@("LoRa")">LoRa Device</MudSelectItem>
<MudSelectItem Value="@("LoRa Device")">LoRa Device</MudSelectItem>
<MudSelectItem Value="@("Other")">Other</MudSelectItem>
</MudSelect>
</MudItem>
Expand Down
46 changes: 29 additions & 17 deletions src/AzureIoTHub.Portal/Server/Controllers/GatewaysController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,37 @@ public GatewaysController(
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<GatewayListItem>))]
public async Task<IActionResult> Get()
{
// don't contain properties
IEnumerable<Twin> devicesWithoutProperties = await this.devicesService.GetAllEdgeDeviceWithTags();
// don't contain connected device
IEnumerable<Twin> edgeDevices = await this.devicesService.GetAllEdgeDevice();
try
{
// don't contain tags
IEnumerable<Twin> edgeDevices = await this.devicesService.GetAllEdgeDevice();

List<GatewayListItem> newGatewayList = new ();
int index = 0;
List<GatewayListItem> newGatewayList = new ();

newGatewayList.AddRange(edgeDevices.Select(deviceTwin => new GatewayListItem
{
DeviceId = deviceTwin.DeviceId,
Status = deviceTwin.Status?.ToString(),
Type = DeviceHelper.RetrieveTagValue(devicesWithoutProperties.ElementAt(index++), "purpose"),
NbDevices = DeviceHelper.RetrieveConnectedDeviceCount(deviceTwin)
}));
foreach (Twin deviceTwin in edgeDevices)
{
var twin = this.devicesService.GetDeviceTwin(deviceTwin.DeviceId).Result;

return this.Ok(newGatewayList);
if (twin != null)
{
GatewayListItem gateway = new ()
{
DeviceId = deviceTwin.DeviceId,
Status = deviceTwin.Status?.ToString(),
Type = DeviceHelper.RetrieveTagValue(twin, "purpose"),
NbDevices = DeviceHelper.RetrieveConnectedDeviceCount(deviceTwin)
};

newGatewayList.Add(gateway);
}
}

return this.Ok(newGatewayList);
}
catch (Exception e)
{
return this.BadRequest(e.Message);
}
}

/// <summary>
Expand All @@ -97,9 +111,7 @@ public async Task<IActionResult> Get(string deviceId)
Status = deviceTwin.Status?.ToString(),
EndPoint = this.configuration["IoTDPS:ServiceEndpoint"],
Scope = deviceTwin.DeviceScope,
Connection_state = deviceTwin.ConnectionState?.ToString(),
// we retrieve the symmetric Key
// SymmetricKey = DeviceHelper.RetrieveSymmetricKey(deviceTwin.DeviceId, this.devicesService.GetDpsAttestionMechanism().Result),
Connection_state = deviceTwin.ConnectionState.Value.ToString(),
// We retrieve the values of tags
Type = DeviceHelper.RetrieveTagValue(deviceTwin, "purpose"),
Environment = DeviceHelper.RetrieveTagValue(deviceTwin, "env"),
Expand Down

0 comments on commit 6a63f89

Please sign in to comment.