Skip to content

Commit

Permalink
Merge branch 'Development' into 'main'
Browse files Browse the repository at this point in the history
Blazor: Added basic components for Hio Cloud

See merge request tools/hio-dotnet!7
  • Loading branch information
fyziktom committed Jan 7, 2025
2 parents 43aa57b + 25669a9 commit 57c7993
Show file tree
Hide file tree
Showing 38 changed files with 1,306 additions and 43 deletions.
4 changes: 2 additions & 2 deletions hio-dotnet.APIs.HioCloudv2/CloudMessagesGrabberBase.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using hio_dotnet.APIs.HioCloudv2.Models;
using hio_dotnet.APIs.HioCloud.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2
namespace hio_dotnet.APIs.HioCloud
{
public abstract class CloudMessagesGrabberBase : ICloudMessagesGrabber
{
Expand Down
4 changes: 2 additions & 2 deletions hio-dotnet.APIs.HioCloudv2/CloudMessagesGrabbersHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using hio_dotnet.APIs.HioCloudv2.Models;
using hio_dotnet.APIs.HioCloud.Models;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2
namespace hio_dotnet.APIs.HioCloud
{
public class CloudMessagesGrabbersHandler
{
Expand Down
46 changes: 43 additions & 3 deletions hio-dotnet.APIs.HioCloudv2/HioCloudDriver.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using hio_dotnet.APIs.HioCloudv2.Models;
using hio_dotnet.APIs.HioCloud.Models;
using System.Data;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

namespace hio_dotnet.APIs.HioCloudv2
namespace hio_dotnet.APIs.HioCloud
{
public class HioCloudDriver
{
Expand Down Expand Up @@ -97,7 +97,15 @@ public async Task<string> GetAuthTokenAsync(string baseUrl, string email, string
var credentials = new { email = email, password = password };
var content = new StringContent(System.Text.Json.JsonSerializer.Serialize(credentials), Encoding.UTF8, "application/json");

var response = await httpClient.PostAsync("/v2/auth/login", content);
HttpResponseMessage? response = null;
try
{
response = await httpClient.PostAsync("/v2/auth/login", content);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
response.EnsureSuccessStatusCode();

var responseBody = await response.Content.ReadAsStringAsync();
Expand Down Expand Up @@ -508,6 +516,38 @@ private void CheckResponse(HttpResponseMessage? response)
}
}

/// <summary>
/// Get one specific message
/// </summary>
/// <param name="space_id">Guid of space</param>
/// <param name="message_id">Guid of message</param>
/// <returns>Message List</returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="Exception"></exception>
public async Task<HioCloudMessage?> GetMessage(Guid space_id,
Guid message_id)
{
using (var httpClient = GetHioClient())
{
var url = $"/v2/spaces/{space_id}/messages/{message_id}";

try
{
var response = await httpClient.GetAsync(url);
var cnt = response.Content.ReadAsStringAsync().Result;

CheckResponse(response);

var devices = System.Text.Json.JsonSerializer.Deserialize<HioCloudMessage?>(cnt);
return devices;
}
catch (HttpRequestException ex)
{
throw new Exception("An error occurred while fetching spaces data.", ex);
}
}
}

/// <summary>
/// Send downlink message to cloud to the specific device
/// This version will send message_body as string
Expand Down
4 changes: 2 additions & 2 deletions hio-dotnet.APIs.HioCloudv2/ICloudMessagesGrabber.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using hio_dotnet.APIs.HioCloudv2.Models;
using hio_dotnet.APIs.HioCloud.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2
namespace hio_dotnet.APIs.HioCloud
{
public interface ICloudMessagesGrabber
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public class CloudMessagesGrabberEventArgs
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/FilterLogicFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public static class FilterLogicFilters
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/HioCloudConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{

public class HioCloudConnector
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/HioCloudDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public static class HioCloudDefaults
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/HioCloudDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public class HioCloudDevice
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/HioCloudMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public class HioCloudMessage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public static class HioCloudMessageDirection
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/HioCloudMessageType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public static class HioCloudMessageType
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/HioCloudSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public class HioCloudSpace
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/HioCloudTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public class HioCloudTag
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/OrderByFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public static class OrderByFilter
{
Expand Down
2 changes: 1 addition & 1 deletion hio-dotnet.APIs.HioCloudv2/Models/SortByFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2.Models
namespace hio_dotnet.APIs.HioCloud.Models
{
public static class SortByFilters
{
Expand Down
4 changes: 2 additions & 2 deletions hio-dotnet.APIs.HioCloudv2/SimpleCloudMessageGrabber.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using hio_dotnet.APIs.HioCloudv2.Models;
using hio_dotnet.APIs.HioCloud.Models;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand All @@ -8,7 +8,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace hio_dotnet.APIs.HioCloudv2
namespace hio_dotnet.APIs.HioCloud
{
public class SimpleCloudMessageGrabber : CloudMessagesGrabberBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<RadzenPanelMenuItem Text="Home" Icon="home" Path="/" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Home", Position = TooltipPosition.Right }) )" />
<RadzenPanelMenuItem Text="Graph" Icon="monitoring" Path="/graph" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Counter", Position = TooltipPosition.Right }) )" />
<RadzenPanelMenuItem Text="Configs" Icon="manufacturing" Path="/configs" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Configs", Position = TooltipPosition.Right }) )" />
<RadzenPanelMenuItem Text="Cloud" Icon="cloud" Path="/hiocloud" MouseEnter="@(args => ShowTooltip(args, new TooltipOptions() { Text = "Cloud", Position = TooltipPosition.Right }) )" />
</RadzenPanelMenu>
</RadzenColumn>
</RadzenRow>
Expand Down
118 changes: 118 additions & 0 deletions hio-dotnet.Demos.HardwarioMonitor/Components/Pages/HioCloud.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
@using Services
@using hio_dotnet.UI.BlazorComponents.Radzen.CHESTER.HioCloud.Models
@using hio_dotnet.UI.BlazorComponents.Radzen.CHESTER.HioCloud

@page "/hiocloud"

@inject ConsoleService ConsoleService

<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center">
<!-- Loading overlay -->
@if (isBusy)
{
<RadzenCard Style="z-index: 3; text-align: center; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, .5)">
<div style="display: flex; justify-content: center; align-items: center; height: 100%; width: 100%;">
<RadzenProgressBarCircular ShowValue="true" Mode="ProgressBarMode.Indeterminate" Size="ProgressBarCircularSize.Medium">
<Template>Wait</Template>
</RadzenProgressBarCircular>
</div>
</RadzenCard>
}
</RadzenStack>

<RadzenLayout Style="height: 100%; grid-template-rows: 1fr; grid-template-columns: 1fr auto; grid-template-areas: 'rz-body rz-sidebar'">
<RadzenSidebar Style="padding: 5px;">
<HioCloudLoginButton OnLoggedIn="@OnLoggedInHandler" OnLoggingIn="OnLoggingInHandler" Style="margin-top: 5px; width: 100%;" />
</RadzenSidebar>
<RadzenBody>
<RadzenRow Style="height: 100%;">
<RadzenColumn Style="height: 100%;">

<RadzenRow>
<RadzenColumn Size="3">
<HioCloudTreeView @ref=hioCloudTreeViewRef OnOpenMessageRequest="@OnOpenMessageHandler"
OnOpenDeviceRequest="@OnOpenDeviceHandler"
OnOpenSpaceRequest="@OnOpenSpaceHandler"/>
</RadzenColumn>
<RadzenColumn Size="9">
<HioCloudTabs @ref=hioCloudTabsRef />
</RadzenColumn>
</RadzenRow>

</RadzenColumn>
</RadzenRow>
</RadzenBody>
</RadzenLayout>


@code {
private bool isBusy = false;
HioCloudTreeView? hioCloudTreeViewRef;
HioCloudTabs? hioCloudTabsRef;

protected override void OnInitialized()
{
base.OnInitialized();
}

public async Task Refresh()
{
await InvokeAsync(StateHasChanged);
}

public async Task OnLoggingInHandler(bool busy)
{
isBusy = busy;
}

public async Task OnLoggedInHandler(bool isLoggedIn)
{
isBusy = false;
if (hioCloudTreeViewRef != null)
{
await hioCloudTreeViewRef.GetSpaces();
}
}

public async Task OnOpenMessageHandler(Message msg)
{
if (hioCloudTabsRef != null)
{
await hioCloudTabsRef.AddTab(new OpenedTab()
{
Data = msg,
Type = OpenedTabType.Message,
Id = msg.Id,
Title = msg.Text
});
}
}

public async Task OnOpenDeviceHandler(Device device)
{
if (hioCloudTabsRef != null)
{
await hioCloudTabsRef.AddTab(new OpenedTab()
{
Data = device,
Type = OpenedTabType.Device,
Id = device.Id,
Title = device.Name
});
}
}

public async Task OnOpenSpaceHandler(Space space)
{
if (hioCloudTabsRef != null)
{
await hioCloudTabsRef.AddTab(new OpenedTab()
{
Data = space,
Type = OpenedTabType.Space,
Id = space.Id,
Title = space.Name
});
}
}
}
6 changes: 5 additions & 1 deletion hio-dotnet.Demos.HardwarioMonitor/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using hio_dotnet.Demos.HardwarioMonitor.Services;
using CommunityToolkit.Maui;
using hio_dotnet.Demos.HardwarioMonitor.Services;
using hio_dotnet.UI.BlazorComponents.Radzen.Services;
using Microsoft.Extensions.Logging;
using Radzen;
using System.Reflection;
Expand All @@ -13,6 +15,7 @@ public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Expand All @@ -21,6 +24,7 @@ public static MauiApp CreateMauiApp()
builder.Services.AddMauiBlazorWebView();
builder.Services.AddRadzenComponents();
builder.Services.AddScoped<ConsoleService>();
builder.Services.AddScoped<HioCloudService>();

#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
Expand Down
Loading

0 comments on commit 57c7993

Please sign in to comment.