SyncService + SyncPage added

This commit is contained in:
Iván Szabó
2025-02-06 14:46:31 +01:00
parent b5e5158f1e
commit b233347a7d
11 changed files with 159 additions and 25 deletions
+2
View File
@@ -6,11 +6,13 @@
xmlns:local="clr-namespace:WorkFlowCheck.MAUI" xmlns:local="clr-namespace:WorkFlowCheck.MAUI"
xmlns:security="clr-namespace:WorkFlowCheck.MAUI.Pages.Security" xmlns:security="clr-namespace:WorkFlowCheck.MAUI.Pages.Security"
xmlns:nfc="clr-namespace:WorkFlowCheck.MAUI.Pages.NFC" xmlns:nfc="clr-namespace:WorkFlowCheck.MAUI.Pages.NFC"
xmlns:system="clr-namespace:WorkFlowCheck.MAUI.Pages.System"
Shell.FlyoutBehavior="Disabled" Shell.FlyoutBehavior="Disabled"
Title="WorkFlowCheck.MAUI"> Title="WorkFlowCheck.MAUI">
<ShellContent Title="Home" ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" /> <ShellContent Title="Home" ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" />
<ShellContent Title="Login" ContentTemplate="{DataTemplate security:LoginPage}" Route="LoginPage" /> <ShellContent Title="Login" ContentTemplate="{DataTemplate security:LoginPage}" Route="LoginPage" />
<ShellContent Title="NFC Test" ContentTemplate="{DataTemplate nfc:NFCTestPage}" Route="NFCTestPage" /> <ShellContent Title="NFC Test" ContentTemplate="{DataTemplate nfc:NFCTestPage}" Route="NFCTestPage" />
<ShellContent Title="Sync data" ContentTemplate="{DataTemplate system:SyncPage}" Route="SyncPage" />
</Shell> </Shell>
+6
View File
@@ -31,6 +31,12 @@
SemanticProperties.Hint="Get user info" SemanticProperties.Hint="Get user info"
Clicked="OnButtonGetUser" Clicked="OnButtonGetUser"
HorizontalOptions="Fill" /> HorizontalOptions="Fill" />
<Button
x:Name="ButtonSync"
Text="Sync data"
SemanticProperties.Hint="Sync data"
Clicked="OnButtonSync"
HorizontalOptions="Fill" />
<Button <Button
x:Name="CounterBtn" x:Name="CounterBtn"
Text="Hahó II." Text="Hahó II."
+6 -1
View File
@@ -52,7 +52,12 @@ namespace WorkFlowCheck.MAUI
{ {
SecureStorage.Default.Remove("WFCUser"); SecureStorage.Default.Remove("WFCUser");
Shell.Current.GoToAsync("//LoginPage"); Shell.Current.GoToAsync("//LoginPage");
} }
private void OnButtonSync(object sender, EventArgs e)
{
Shell.Current.GoToAsync("//SyncPage");
}
} }
} }
@@ -2,11 +2,12 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.Security.LoginPage" x:Class="WorkFlowCheck.MAUI.Pages.Security.LoginPage"
Title="LoginPage"> Title="Bejelentkezés"
>
<StackLayout Padding="20" VerticalOptions="Center"> <StackLayout Padding="20" VerticalOptions="Center">
<Entry x:Name="UsernameEntry" Placeholder="Username" /> <Entry x:Name="UsernameEntry" Placeholder="Felhasználói név" />
<Entry x:Name="PasswordEntry" Placeholder="Password" IsPassword="True" Keyboard="Numeric"/> <Entry x:Name="PasswordEntry" Placeholder="PIN kód" IsPassword="True" Keyboard="Numeric"/>
<Button x:Name="LoginBtn" Text="Log In" Clicked="OnLoginClicked" /> <Button x:Name="LoginBtn" Text="Bejelentkezés" Clicked="OnLoginClicked" />
<ActivityIndicator x:Name="LoadingIndicator" <ActivityIndicator x:Name="LoadingIndicator"
IsRunning="False" IsRunning="False"
IsVisible="False" IsVisible="False"
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.System.SyncPage"
Title="SyncPage">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Button x:Name="SyncBtn" Text="Adat szinkronizálás" Clicked="OnSyncClicked" />
<ActivityIndicator x:Name="LoadingIndicator"
IsRunning="False"
IsVisible="False"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentPage>
@@ -0,0 +1,38 @@
using WorkFlowCheck.MAUI.Services;
namespace WorkFlowCheck.MAUI.Pages.System;
public partial class SyncPage : ContentPage
{
private ISyncService _syncService;
public SyncPage()
{
InitializeComponent();
_syncService = MauiProgram.ServiceProvider.GetRequiredService<ISyncService>();
}
private async void OnSyncClicked(object sender, EventArgs e)
{
LoadingIndicator.IsRunning = true;
LoadingIndicator.IsVisible = true;
try
{
await _syncService.SyncDatas();
}
catch (Exception)
{
throw;
}
LoadingIndicator.IsVisible = false;
LoadingIndicator.IsRunning = false;
}
protected override bool OnBackButtonPressed()
{
Shell.Current.GoToAsync("//MainPage");
return true;
}
}
@@ -0,0 +1,31 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkFlowCheck.MAUI.DataLayer;
namespace WorkFlowCheck.MAUI.Services
{
public class BaseService
{
public readonly HttpClient _httpClient;
public readonly AppDbContext _dbContext;
public readonly IConfiguration _configuration;
public BaseService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext)
{
_httpClient = httpClient;
_dbContext = dbContext;
_configuration = configuration;
var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
_httpClient.BaseAddress = new Uri(apiBaseUrl);
var apiKey = configuration["ApiKey"];
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
}
}
}
@@ -8,6 +8,7 @@ namespace WorkFlowCheck.MAUI.Services
{ {
public interface ISyncService public interface ISyncService
{ {
Task SyncDatas();
} }
} }
+46 -9
View File
@@ -1,22 +1,59 @@
using System; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.MAUI.DataLayer; using WorkFlowCheck.MAUI.DataLayer;
namespace WorkFlowCheck.MAUI.Services namespace WorkFlowCheck.MAUI.Services
{ {
public class SyncService: ISyncService public class SyncService : BaseService, ISyncService
{ {
private readonly HttpClient _httpClient; public SyncService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext) : base(httpClient, configuration, dbContext)
private readonly AppDbContext _dbContext;
public SyncService(HttpClient httpClient, AppDbContext dbContext)
{ {
_httpClient = httpClient;
_dbContext = dbContext;
} }
public async Task SyncDatas()
{
await SyncCheckPoints();
}
public async Task SyncCheckPoints()
{
try
{
// Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckPoints";
// HTTP GET kérés küldése
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<CheckPointListDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
var checkPointList = await _dbContext.CheckPoints.ToListAsync();
var missingItems = response.Data.CheckPointList.Where(f => !checkPointList.Any(s => s.Id == f.Id)).ToList();
foreach (var item in missingItems) {
}
}
}
}
catch (Exception ex)
{
// Hiba visszaadása
}
}
} }
} }
+3 -11
View File
@@ -10,23 +10,15 @@ using System.Threading.Tasks;
using WorkFlowCheck.Common.DTO; using WorkFlowCheck.Common.DTO;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
using WorkFlowCheck.MAUI.DataLayer;
namespace WorkFlowCheck.MAUI.Services namespace WorkFlowCheck.MAUI.Services
{ {
public class UserService : IUserService public class UserService : BaseService, IUserService
{ {
private readonly HttpClient _httpClient;
public UserDTO? CurrentUser { get; private set; } public UserDTO? CurrentUser { get; private set; }
public UserService(HttpClient httpClient, IConfiguration configuration) public UserService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext) : base(httpClient, configuration, dbContext)
{ {
_httpClient = httpClient;
var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
_httpClient.BaseAddress = new Uri(apiBaseUrl);
var apiKey = configuration["ApiKey"];
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
} }
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync() public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
{ {
@@ -86,6 +86,9 @@
<MauiXaml Update="Pages\Security\LoginPage.xaml"> <MauiXaml Update="Pages\Security\LoginPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Pages\System\SyncPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>