UI javítás + beküldés, képméretezés
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.MAUI.Handlers
|
||||||
|
{
|
||||||
|
public class ProgressableStreamContent : HttpContent
|
||||||
|
{
|
||||||
|
private readonly Stream _stream;
|
||||||
|
private readonly int _bufferSize;
|
||||||
|
private readonly Action<long, long> _progress;
|
||||||
|
|
||||||
|
public ProgressableStreamContent(Stream stream, int bufferSize, Action<long, long> progress)
|
||||||
|
{
|
||||||
|
_stream = stream;
|
||||||
|
_bufferSize = bufferSize;
|
||||||
|
_progress = progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
|
||||||
|
{
|
||||||
|
var buffer = new byte[_bufferSize];
|
||||||
|
long totalBytesRead = 0;
|
||||||
|
int bytesRead;
|
||||||
|
|
||||||
|
while ((bytesRead = await _stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
||||||
|
{
|
||||||
|
await stream.WriteAsync(buffer, 0, bytesRead);
|
||||||
|
totalBytesRead += bytesRead;
|
||||||
|
_progress(totalBytesRead, _stream.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool TryComputeLength(out long length)
|
||||||
|
{
|
||||||
|
length = _stream.Length;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,13 +2,19 @@
|
|||||||
<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.MainPage"
|
x:Class="WorkFlowCheck.MAUI.MainPage"
|
||||||
Title="Főmenü">
|
Title="Főmenü"
|
||||||
|
BackgroundColor="#f0f0f0">
|
||||||
|
|
||||||
<Grid RowDefinitions="Auto, * , Auto" Padding="30,0">
|
<Grid RowDefinitions="Auto, * , Auto" Padding="30,0">
|
||||||
|
|
||||||
<ScrollView Grid.Row="1">
|
<ScrollView Grid.Row="1"
|
||||||
|
Padding="25">
|
||||||
<VerticalStackLayout Spacing="25">
|
<VerticalStackLayout Spacing="25">
|
||||||
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
|
<Frame BorderColor="Gray"
|
||||||
|
Padding="5"
|
||||||
|
CornerRadius="10"
|
||||||
|
Margin="1"
|
||||||
|
HasShadow="True">
|
||||||
<VerticalStackLayout>
|
<VerticalStackLayout>
|
||||||
<Label Text="Alapműveletek" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
<Label Text="Alapműveletek" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
<Button
|
<Button
|
||||||
@@ -31,7 +37,11 @@
|
|||||||
HorizontalOptions="Fill" />
|
HorizontalOptions="Fill" />
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
</Frame>
|
</Frame>
|
||||||
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
|
<Frame BorderColor="Gray"
|
||||||
|
Padding="5"
|
||||||
|
Margin="1"
|
||||||
|
CornerRadius="10"
|
||||||
|
HasShadow="True">
|
||||||
<VerticalStackLayout>
|
<VerticalStackLayout>
|
||||||
<Label Text="Ellenőrzés" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
<Label Text="Ellenőrzés" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
<Button
|
<Button
|
||||||
@@ -46,7 +56,12 @@
|
|||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
<Frame Grid.Row="2" BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
|
<Frame Grid.Row="2"
|
||||||
|
BorderColor="Gray"
|
||||||
|
CornerRadius="10"
|
||||||
|
Padding="5"
|
||||||
|
Margin="1"
|
||||||
|
HasShadow="True">
|
||||||
<Button
|
<Button
|
||||||
x:Name="LogoutBtn" Margin="5"
|
x:Name="LogoutBtn" Margin="5"
|
||||||
BackgroundColor="DarkRed"
|
BackgroundColor="DarkRed"
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
x:Class="WorkFlowCheck.MAUI.Pages.BaseStock.CheckPointsPage"
|
x:Class="WorkFlowCheck.MAUI.Pages.BaseStock.CheckPointsPage"
|
||||||
Title="Ellenőrzési pontok">
|
Title="Ellenőrzési pontok">
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
|
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
|
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
|
||||||
<Button
|
<Button
|
||||||
x:Name="ButtonSync" Margin="5"
|
x:Name="ButtonSync" Margin="5"
|
||||||
Text="Adatok szinkronizálása"
|
Text="Adatok szinkronizálása"
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public partial class CheckPointsPage : ContentPage
|
|||||||
private async Task LoadCheckPoints()
|
private async Task LoadCheckPoints()
|
||||||
{
|
{
|
||||||
IsRefreshing = true;
|
IsRefreshing = true;
|
||||||
await _syncService.SyncDatas();
|
//await _syncService.SyncDatas();
|
||||||
CheckPointsList.ItemsSource = await _baseStockService.GetAllCheckPoints();
|
CheckPointsList.ItemsSource = await _baseStockService.GetAllCheckPoints();
|
||||||
IsRefreshing = false;
|
IsRefreshing = false;
|
||||||
OnPropertyChanged(nameof(IsRefreshing));
|
OnPropertyChanged(nameof(IsRefreshing));
|
||||||
@@ -72,8 +72,38 @@ public partial class CheckPointsPage : ContentPage
|
|||||||
Shell.Current.GoToAsync("//BaseStockPage");
|
Shell.Current.GoToAsync("//BaseStockPage");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private void OnButtonSync(object sender, EventArgs e)
|
private async void OnButtonSync(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_syncService.SyncCheckPointsUp();
|
IsRefreshing = true;
|
||||||
|
ButtonSync.IsEnabled = false;
|
||||||
|
|
||||||
|
progressLabel.Text = "Szinkronizálás indítása...";
|
||||||
|
progressBar.Progress = 0;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await _syncService.SyncCheckPoints_Up((percentage, infostring) =>
|
||||||
|
{
|
||||||
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
|
{
|
||||||
|
progressBar.Progress = percentage / 100;
|
||||||
|
progressLabel.Text = $"{infostring}: {percentage:0.00}%";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
progressLabel.Text = "Szinkronizálás befejezve!";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
progressLabel.Text = $"Hiba történt: {ex.Message}";
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ButtonSync.IsEnabled = true;
|
||||||
|
IsRefreshing = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,16 @@
|
|||||||
<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.CheckList.CheckListPage"
|
x:Class="WorkFlowCheck.MAUI.Pages.CheckList.CheckListPage"
|
||||||
Title="Ellenőrzések">
|
Title="Ellenőrzések"
|
||||||
<Grid RowDefinitions="*,*" Padding="30,0">
|
BackgroundColor="#f0f0f0">
|
||||||
|
<Grid RowDefinitions="*,*" Padding="30,30">
|
||||||
<ScrollView Grid.Row="0">
|
<Frame Grid.Row="0"
|
||||||
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
|
BorderColor="Gray"
|
||||||
|
Padding="5"
|
||||||
|
Margin="1"
|
||||||
|
CornerRadius="10"
|
||||||
|
HasShadow="True">
|
||||||
|
<ScrollView >
|
||||||
<VerticalStackLayout>
|
<VerticalStackLayout>
|
||||||
<Label Text="Megkezdett ellenőrzések" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
<Label Text="Megkezdett ellenőrzések" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
<CollectionView x:Name="CheckList">
|
<CollectionView x:Name="CheckList">
|
||||||
@@ -29,10 +34,16 @@
|
|||||||
</CollectionView.ItemTemplate>
|
</CollectionView.ItemTemplate>
|
||||||
</CollectionView>
|
</CollectionView>
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
</Frame>
|
</ScrollView>
|
||||||
</ScrollView>
|
</Frame>
|
||||||
<ScrollView Grid.Row="1">
|
|
||||||
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
|
<Frame Grid.Row="1"
|
||||||
|
BorderColor="Gray"
|
||||||
|
Padding="5"
|
||||||
|
Margin="1"
|
||||||
|
CornerRadius="10"
|
||||||
|
HasShadow="True">
|
||||||
|
<ScrollView>
|
||||||
<VerticalStackLayout>
|
<VerticalStackLayout>
|
||||||
<Label Text="Új ellenőrzés" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
<Label Text="Új ellenőrzés" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
<CollectionView x:Name="CheckListTemplate">
|
<CollectionView x:Name="CheckListTemplate">
|
||||||
@@ -55,8 +66,8 @@
|
|||||||
</CollectionView.ItemTemplate>
|
</CollectionView.ItemTemplate>
|
||||||
</CollectionView>
|
</CollectionView>
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
</Frame>
|
</ScrollView>
|
||||||
</ScrollView>
|
</Frame>
|
||||||
<Grid BackgroundColor="#80000000"
|
<Grid BackgroundColor="#80000000"
|
||||||
IsVisible="{Binding IsLoading}"
|
IsVisible="{Binding IsLoading}"
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
|
|||||||
@@ -3,14 +3,17 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="WorkFlowCheck.MAUI.Pages.CheckList.CheckListWorkPage"
|
x:Class="WorkFlowCheck.MAUI.Pages.CheckList.CheckListWorkPage"
|
||||||
xmlns:templateselectors="clr-namespace:WorkFlowCheck.MAUI.TemplateSelectors"
|
xmlns:templateselectors="clr-namespace:WorkFlowCheck.MAUI.TemplateSelectors"
|
||||||
xmlns:local="clr-namespace:WorkFlowCheck.MAUI.Pages.CheckList"
|
xmlns:local="clr-namespace:WorkFlowCheck.MAUI.Pages.CheckList"
|
||||||
|
BackgroundColor="#f0f0f0"
|
||||||
Title="">
|
Title="">
|
||||||
<Grid>
|
<Grid>
|
||||||
<StackLayout Padding="20">
|
<StackLayout Padding="20">
|
||||||
|
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Default" HorizontalOptions="Center" />
|
||||||
|
<ProgressBar x:Name="progressBar" WidthRequest="450" HeightRequest="30" />
|
||||||
<Label Text="Ellenőrzési feladatok" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
<Label Text="Ellenőrzési feladatok" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
<Frame BorderColor="Gray" Padding="1" Margin="2" HasShadow="True" CornerRadius="2">
|
<Frame BorderColor="Gray" Padding="1" Margin="2" HasShadow="True" CornerRadius="2">
|
||||||
<CollectionView x:Name="CheckPointCheckListRows"
|
<CollectionView x:Name="CheckPointCheckListRows"
|
||||||
HeightRequest="615"
|
HeightRequest="555"
|
||||||
ItemsSource="{Binding CheckListRows}"
|
ItemsSource="{Binding CheckListRows}"
|
||||||
ItemTemplate="{StaticResource AnswerTemplateSelector}">
|
ItemTemplate="{StaticResource AnswerTemplateSelector}">
|
||||||
<CollectionView.EmptyView>
|
<CollectionView.EmptyView>
|
||||||
@@ -27,8 +30,8 @@
|
|||||||
<ColumnDefinition Width="200" />
|
<ColumnDefinition Width="200" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<Button Text="Mentés" Command="{Binding SaveCommand}" Grid.Column="0"/>
|
<Button x:Name="saveButton" Text="Mentés" Command="{Binding SaveCommand}" Grid.Column="0"/>
|
||||||
<Button Text="Beküldés" Command="{Binding SendCommand}" Grid.Column="2" Background="DarkRed" TextColor="Yellow"/>
|
<Button x:Name="sendButton" Text="Beküldés" Command="{Binding SendCommand}" Grid.Column="2" Background="DarkRed" TextColor="Yellow"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<Grid BackgroundColor="#80000000"
|
<Grid BackgroundColor="#80000000"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using WorkFlowCheck.MAUI.Services.Interfaces;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Pages.CheckList;
|
namespace WorkFlowCheck.MAUI.Pages.CheckList;
|
||||||
@@ -49,16 +49,52 @@ public partial class CheckListWorkPage : ContentPage
|
|||||||
private async void OnSend()
|
private async void OnSend()
|
||||||
{
|
{
|
||||||
IsLoading = true;
|
IsLoading = true;
|
||||||
|
sendButton.IsEnabled = false;
|
||||||
|
saveButton.IsEnabled = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
OnSave();
|
OnSave();
|
||||||
await _syncService.SyncCheckListHeaderUp(_checkListHeaderId);
|
|
||||||
|
|
||||||
|
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
var result = await _syncService.SyncCheckListHeader_Up(_checkListHeaderId, (percentage, infostring) =>
|
||||||
|
{
|
||||||
|
// Direkt UI frissítés
|
||||||
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
|
{
|
||||||
|
progressBar.Progress = percentage / 100;
|
||||||
|
progressLabel.Text = $"{infostring}: {percentage:0.00}%";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
if (Navigation.ModalStack.Count > 0)
|
||||||
|
{
|
||||||
|
await Shell.Current.Navigation.PopModalAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Application.Current.MainPage.DisplayAlert("Hiba", result.Error, "OK");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
progressLabel.Text = "Szinkronizálás befejezve!";
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await Application.Current.MainPage.DisplayAlert("Hiba", ex.Message, "OK");
|
await Application.Current.MainPage.DisplayAlert("Hiba", ex.Message, "OK");
|
||||||
|
sendButton.IsEnabled = true;
|
||||||
|
saveButton.IsEnabled = true;
|
||||||
}
|
}
|
||||||
IsLoading = false;
|
finally
|
||||||
|
{
|
||||||
|
IsLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private async void OnSave()
|
private async void OnSave()
|
||||||
{
|
{
|
||||||
@@ -105,11 +141,28 @@ public partial class CheckListWorkPage : ContentPage
|
|||||||
var photo = await MediaPicker.CapturePhotoAsync();
|
var photo = await MediaPicker.CapturePhotoAsync();
|
||||||
if (photo != null)
|
if (photo != null)
|
||||||
{
|
{
|
||||||
|
//using var stream = await photo.OpenReadAsync();
|
||||||
|
//using var ms = new MemoryStream();
|
||||||
|
//await stream.CopyToAsync(ms);
|
||||||
|
//byte[] photoBytes = ms.ToArray();
|
||||||
|
|
||||||
using var stream = await photo.OpenReadAsync();
|
using var stream = await photo.OpenReadAsync();
|
||||||
using var ms = new MemoryStream();
|
using var originalBitmap = SKBitmap.Decode(stream);
|
||||||
await stream.CopyToAsync(ms);
|
|
||||||
byte[] photoBytes = ms.ToArray();
|
int newWidth = 500;
|
||||||
checkListRowDTO.Photo = photoBytes;
|
int newHeight = (int)(originalBitmap.Height * ((double)newWidth / originalBitmap.Width));
|
||||||
|
|
||||||
|
using var surface = SKSurface.Create(new SKImageInfo(newWidth, newHeight));
|
||||||
|
using var canvas = surface.Canvas;
|
||||||
|
|
||||||
|
var sourceRect = new SKRect(0, 0, originalBitmap.Width, originalBitmap.Height);
|
||||||
|
var destRect = new SKRect(0, 0, newWidth, newHeight);
|
||||||
|
canvas.DrawBitmap(originalBitmap, sourceRect, destRect);
|
||||||
|
|
||||||
|
using var resizedImage = surface.Snapshot();
|
||||||
|
using var data = resizedImage.Encode(SKEncodedImageFormat.Jpeg, 100);
|
||||||
|
|
||||||
|
checkListRowDTO.Photo = data.ToArray();
|
||||||
|
|
||||||
await _checkListService.UpdateCheckListRow(checkListRowDTO);
|
await _checkListService.UpdateCheckListRow(checkListRowDTO);
|
||||||
await LoadCheckPointCheckListRows();
|
await LoadCheckPointCheckListRows();
|
||||||
@@ -148,6 +201,7 @@ public partial class CheckListWorkPage : ContentPage
|
|||||||
|
|
||||||
IsLoading = false;
|
IsLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public class BindableRadioButton : RadioButton
|
public class BindableRadioButton : RadioButton
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,13 +29,14 @@ public partial class LoginPage : ContentPage
|
|||||||
if (response != null && response.IsSuccess)
|
if (response != null && response.IsSuccess)
|
||||||
{
|
{
|
||||||
_userService.SetCurrentUser(response.Data);
|
_userService.SetCurrentUser(response.Data);
|
||||||
await _syncService.SyncDatas();
|
|
||||||
|
//await _syncService.SyncDatas();
|
||||||
|
|
||||||
var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data);
|
var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data);
|
||||||
await SecureStorage.Default.SetAsync("WFCUser", "wFCUser");
|
await SecureStorage.Default.SetAsync("WFCUser", "wFCUser");
|
||||||
await SecureStorage.Default.SetAsync("AuthToken", response.Data.JwtToken);
|
await SecureStorage.Default.SetAsync("AuthToken", response.Data.JwtToken);
|
||||||
|
|
||||||
await Shell.Current.GoToAsync("//MainPage");
|
await Shell.Current.GoToAsync("//SyncPage");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,13 +2,37 @@
|
|||||||
<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.System.SyncPage"
|
x:Class="WorkFlowCheck.MAUI.Pages.System.SyncPage"
|
||||||
Title="Adatok szinkronizálása">
|
Title="Adatok szinkronizálása"
|
||||||
<VerticalStackLayout>
|
BackgroundColor="#f0f0f0">
|
||||||
<Button x:Name="SyncBtn" Text="Adat szinkronizálás" Clicked="OnSyncClicked" Margin="10,10,10,10" />
|
<ScrollView>
|
||||||
<ActivityIndicator x:Name="LoadingIndicator"
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Frame
|
||||||
|
Grid.Row="1"
|
||||||
|
BorderColor="Gray"
|
||||||
|
CornerRadius="20"
|
||||||
|
Padding="30"
|
||||||
|
Margin="1"
|
||||||
|
HasShadow="True"
|
||||||
|
HorizontalOptions="Center"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
WidthRequest="{OnPlatform Android=350, iOS=350, WinUI=400, MacCatalyst=400}"
|
||||||
|
MaximumWidthRequest="500">
|
||||||
|
<VerticalStackLayout Margin="10,10,10,0">
|
||||||
|
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
|
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
|
||||||
|
<Button x:Name="SyncBtn" Text="Adat szinkronizálás" Clicked="OnSyncClicked" Margin="10,10,10,10" />
|
||||||
|
<ActivityIndicator x:Name="LoadingIndicator"
|
||||||
IsRunning="False"
|
IsRunning="False"
|
||||||
IsVisible="False"
|
IsVisible="False"
|
||||||
VerticalOptions="Center"
|
VerticalOptions="Center"
|
||||||
HorizontalOptions="Center" />
|
HorizontalOptions="Center" />
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
|
</Frame>
|
||||||
|
</Grid>
|
||||||
|
</ScrollView>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
@@ -13,22 +13,52 @@ public partial class SyncPage : ContentPage
|
|||||||
|
|
||||||
private async void OnSyncClicked(object sender, EventArgs e)
|
private async void OnSyncClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
SyncBtn.IsEnabled = false;
|
||||||
LoadingIndicator.IsRunning = true;
|
LoadingIndicator.IsRunning = true;
|
||||||
LoadingIndicator.IsVisible = true;
|
LoadingIndicator.IsVisible = true;
|
||||||
|
progressLabel.Text = "Szinkronizálás indítása...";
|
||||||
|
progressBar.Progress = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _syncService.SyncDatas();
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await _syncService.SyncDatas((percentage, infostring) =>
|
||||||
|
{
|
||||||
|
// Direkt UI frissítés
|
||||||
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
|
{
|
||||||
|
progressBar.Progress = percentage / 100;
|
||||||
|
progressLabel.Text = $"{infostring}: {percentage:0.00}%";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
progressLabel.Text = "Szinkronizálás befejezve!";
|
||||||
|
await Shell.Current.GoToAsync("//MainPage");
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
progressLabel.Text = $"Hiba történt: {ex.Message}";
|
||||||
throw;
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
SyncBtn.IsEnabled = true;
|
||||||
|
LoadingIndicator.IsVisible = false;
|
||||||
|
LoadingIndicator.IsRunning = false;
|
||||||
}
|
}
|
||||||
LoadingIndicator.IsVisible = false;
|
|
||||||
LoadingIndicator.IsRunning = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SimulateLongRunningTask(IProgress<double> progress)
|
||||||
|
{
|
||||||
|
int totalSteps = 50;
|
||||||
|
for (int i = 1; i <= totalSteps; i++)
|
||||||
|
{
|
||||||
|
await Task.Delay(100); // Szimulált hosszú mûvelet
|
||||||
|
double percentage = (double)i / totalSteps * 100;
|
||||||
|
progress.Report(percentage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnBackButtonPressed()
|
protected override bool OnBackButtonPressed()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
|
|
||||||
public async Task<List<CheckListHeaderDTO>> GetCheckLists(int userId)
|
public async Task<List<CheckListHeaderDTO>> GetCheckLists(int userId)
|
||||||
{
|
{
|
||||||
await _syncService.SyncDatas();
|
//await _syncService.SyncDatas();
|
||||||
|
|
||||||
var retVal = new List<CheckListHeaderDTO>();
|
var retVal = new List<CheckListHeaderDTO>();
|
||||||
try
|
try
|
||||||
@@ -106,7 +106,7 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
|
|
||||||
public async Task<List<CheckListTemplateHeaderDTO>> GetCheckListTemplates(int userId)
|
public async Task<List<CheckListTemplateHeaderDTO>> GetCheckListTemplates(int userId)
|
||||||
{
|
{
|
||||||
await _syncService.SyncDatas();
|
//await _syncService.SyncDatas();
|
||||||
|
|
||||||
var retVal = new List<CheckListTemplateHeaderDTO>();
|
var retVal = new List<CheckListTemplateHeaderDTO>();
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -7,14 +7,17 @@ using WorkFlowCheck.Common.DTO;
|
|||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Services.Interfaces
|
namespace WorkFlowCheck.MAUI.Services.Interfaces
|
||||||
{
|
{
|
||||||
public interface ISyncService
|
public interface ISyncService
|
||||||
{
|
{
|
||||||
Task SyncDatas();
|
Task SyncDatas(Action<double, string> reportProgress);
|
||||||
Task SyncCheckPointsDown();
|
Task SyncCheckPoints_Down(Action<double, string> reportProgress);
|
||||||
Task SyncCheckPointsUp();
|
Task SyncCheckPoints_Up(Action<double, string> reportProgress);
|
||||||
Task SyncLocations();
|
Task SyncLocations_Down(Action<double, string> reportProgress);
|
||||||
Task SyncEquipments();
|
Task SyncEquipments_Down(Action<double, string> reportProgress);
|
||||||
|
|
||||||
Task SyncCheckListHeaderUp(int Id);
|
Task SyncCheckListTemplates_Down(Action<double, string> reportProgress);
|
||||||
|
|
||||||
|
Task SyncCheckListHeader_Down(Action<double, string> reportProgress);
|
||||||
|
Task<ApiResponseDTO<string>> SyncCheckListHeader_Up(int Id, Action<double, string> reportProgress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
using AutoMapper;
|
using Android.Health.Connect.DataTypes.Units;
|
||||||
|
using AutoMapper;
|
||||||
|
using Java.Net;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
|
using System.Text;
|
||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
using WorkFlowCheck.MAUI.DataLayer;
|
using WorkFlowCheck.MAUI.DataLayer;
|
||||||
using WorkFlowCheck.MAUI.DataLayer.Entities;
|
using WorkFlowCheck.MAUI.DataLayer.Entities;
|
||||||
|
using WorkFlowCheck.MAUI.Handlers;
|
||||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||||
using Location = WorkFlowCheck.MAUI.DataLayer.Entities.Location;
|
using Location = WorkFlowCheck.MAUI.DataLayer.Entities.Location;
|
||||||
|
|
||||||
@@ -18,30 +22,27 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
{
|
{
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
}
|
}
|
||||||
public async Task SyncDatas()
|
public async Task SyncDatas(Action<double, string> reportProgress)
|
||||||
{
|
{
|
||||||
await SyncCheckPointsDown();
|
await SyncCheckPoints_Down(reportProgress);
|
||||||
await SyncLocations();
|
await SyncLocations_Down(reportProgress);
|
||||||
await SyncEquipments();
|
await SyncEquipments_Down(reportProgress);
|
||||||
await SyncCheckListTemplates();
|
await SyncCheckListTemplates_Down(reportProgress);
|
||||||
await SyncCheckList();
|
await SyncCheckListHeader_Down(reportProgress);
|
||||||
}
|
}
|
||||||
public async Task SyncCheckPointsDown()
|
public async Task SyncCheckPoints_Down(Action<double, string> reportProgress)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PrepareAuthenticatedRequestAsync();
|
|
||||||
// Az API végpont meghatározása
|
|
||||||
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckPoints";
|
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckPoints";
|
||||||
|
var responseList = DownloadDataAsync<CheckPointDTO>(endpoint, reportProgress).Result;
|
||||||
|
|
||||||
// HTTP GET kérés küldése
|
if (responseList != null)
|
||||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckPointDTO>>>(endpoint);
|
|
||||||
if (response != null)
|
|
||||||
{
|
{
|
||||||
if (response.IsSuccess)
|
if (responseList.IsSuccess)
|
||||||
{
|
{
|
||||||
var entityList = await _dbContext.CheckPoints.ToListAsync();
|
var entityList = await _dbContext.CheckPoints.ToListAsync();
|
||||||
var missingItems = response.Data.Where(f => !entityList.Any(s => s.Id == f.Id)).ToList();
|
var missingItems = responseList.Data.Where(f => !entityList.Any(s => s.Id == f.Id)).ToList();
|
||||||
|
|
||||||
var mappedMissingItems = _mapper.Map<List<CheckPoint>>(missingItems);
|
var mappedMissingItems = _mapper.Map<List<CheckPoint>>(missingItems);
|
||||||
|
|
||||||
@@ -52,49 +53,14 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Hiba visszaadása
|
Console.WriteLine($"Hiba történt: {ex.Message}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task SyncCheckPointsUp()
|
public async Task SyncCheckPoints_Up(Action<double, string> reportProgress)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PrepareAuthenticatedRequestAsync();
|
|
||||||
// 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<List<CheckPointDTO>>>(endpoint);
|
|
||||||
if (response != null)
|
|
||||||
{
|
|
||||||
if (response.IsSuccess)
|
|
||||||
{
|
|
||||||
var entityList = await _dbContext.CheckPoints.ToListAsync();
|
|
||||||
var missingItems = response.Data.Where(f => !entityList.Any(s => s.Id == f.Id & s.Code == f.Code)).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var checkPointListDTO = _mapper.Map<List<CheckPointDTO>>(missingItems);
|
|
||||||
|
|
||||||
foreach (var item in checkPointListDTO)
|
|
||||||
{
|
|
||||||
var entity = await _dbContext.CheckPoints.Where(w => w.Id == item.Id).FirstOrDefaultAsync();
|
|
||||||
if (entity != null)
|
|
||||||
{
|
|
||||||
item.ShortName = entity.ShortName;
|
|
||||||
item.Code = entity.Code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllCheckPoint";
|
|
||||||
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, checkPointListDTO))
|
|
||||||
{
|
|
||||||
httpResponseMessage.EnsureSuccessStatusCode();
|
|
||||||
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
||||||
response = JsonConvert.DeserializeObject<ApiResponseDTO<List<CheckPointDTO>>>(jsonString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -102,22 +68,19 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SyncLocations()
|
public async Task SyncLocations_Down(Action<double, string> reportProgress)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PrepareAuthenticatedRequestAsync();
|
|
||||||
// Az API végpont meghatározása
|
|
||||||
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllLocations";
|
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllLocations";
|
||||||
|
var responseList = DownloadDataAsync<LocationDTO>(endpoint, reportProgress).Result;
|
||||||
|
|
||||||
// HTTP GET kérés küldése
|
if (responseList != null)
|
||||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<LocationDTO>>>(endpoint);
|
|
||||||
if (response != null)
|
|
||||||
{
|
{
|
||||||
if (response.IsSuccess)
|
if (responseList.IsSuccess)
|
||||||
{
|
{
|
||||||
var entityList = await _dbContext.Locations.ToListAsync();
|
var entityList = await _dbContext.Locations.ToListAsync();
|
||||||
var missingItems = response.Data.Where(f => !entityList.Any(s => s.Id == f.Id)).ToList();
|
var missingItems = responseList.Data.Where(f => !entityList.Any(s => s.Id == f.Id)).ToList();
|
||||||
|
|
||||||
var mappedMissingItems = _mapper.Map<List<Location>>(missingItems);
|
var mappedMissingItems = _mapper.Map<List<Location>>(missingItems);
|
||||||
|
|
||||||
@@ -132,22 +95,19 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task SyncEquipments()
|
public async Task SyncEquipments_Down(Action<double, string> reportProgress)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PrepareAuthenticatedRequestAsync();
|
|
||||||
// Az API végpont meghatározása
|
|
||||||
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllEquipments";
|
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllEquipments";
|
||||||
|
var responseList = DownloadDataAsync<LocationDTO>(endpoint, reportProgress).Result;
|
||||||
|
|
||||||
// HTTP GET kérés küldése
|
if (responseList != null)
|
||||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<EquipmentDTO>>>(endpoint);
|
|
||||||
if (response != null)
|
|
||||||
{
|
{
|
||||||
if (response.IsSuccess)
|
if (responseList.IsSuccess)
|
||||||
{
|
{
|
||||||
var entityList = await _dbContext.Locations.ToListAsync();
|
var entityList = await _dbContext.Locations.ToListAsync();
|
||||||
var missingItems = response.Data.Where(f => !entityList.Any(s => s.Id == f.Id)).ToList();
|
var missingItems = responseList.Data.Where(f => !entityList.Any(s => s.Id == f.Id)).ToList();
|
||||||
|
|
||||||
var mappedMissingItems = _mapper.Map<List<Equipment>>(missingItems);
|
var mappedMissingItems = _mapper.Map<List<Equipment>>(missingItems);
|
||||||
|
|
||||||
@@ -162,23 +122,20 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task SyncCheckListTemplates()
|
public async Task SyncCheckListTemplates_Down(Action<double, string> reportProgress)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PrepareAuthenticatedRequestAsync();
|
|
||||||
// Az API végpont meghatározása
|
|
||||||
var userId = _userService.GetCurrentUser()?.Id;
|
var userId = _userService.GetCurrentUser()?.Id;
|
||||||
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListTemplateHeader/{userId}";
|
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListTemplateHeader/{userId}";
|
||||||
|
var responseList = DownloadDataAsync<CheckListTemplateHeaderDTO>(endpoint, reportProgress).Result;
|
||||||
|
|
||||||
// HTTP GET kérés küldése
|
if (responseList != null)
|
||||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>>(endpoint);
|
|
||||||
if (response != null)
|
|
||||||
{
|
{
|
||||||
if (response.IsSuccess)
|
if (responseList.IsSuccess)
|
||||||
{
|
{
|
||||||
var checkListTemplateHeaderList = await _dbContext.CheckListTemplateHeaders.ToListAsync();
|
var checkListTemplateHeaderList = await _dbContext.CheckListTemplateHeaders.ToListAsync();
|
||||||
var missingItems = response.Data.Where(f => !checkListTemplateHeaderList.Any(s => s.Id == f.Id)).ToList();
|
var missingItems = responseList.Data.Where(f => !checkListTemplateHeaderList.Any(s => s.Id == f.Id)).ToList();
|
||||||
|
|
||||||
var missingCheckListTemplateHeaders = _mapper.Map<List<CheckListTemplateHeader>>(missingItems);
|
var missingCheckListTemplateHeaders = _mapper.Map<List<CheckListTemplateHeader>>(missingItems);
|
||||||
|
|
||||||
@@ -193,70 +150,44 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task SyncCheckList()
|
|
||||||
|
|
||||||
|
public async Task SyncCheckListHeader_Down(Action<double, string> reportProgress)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PrepareAuthenticatedRequestAsync();
|
|
||||||
if (_userService == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Az API végpont meghatározása
|
|
||||||
var userId = _userService.GetCurrentUser()?.Id;
|
var userId = _userService.GetCurrentUser()?.Id;
|
||||||
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListHeader/{userId}";
|
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListHeader/{userId}";
|
||||||
|
var responseList = DownloadDataAsync<CheckListHeaderDTO>(endpoint, reportProgress).Result;
|
||||||
|
|
||||||
// HTTP GET kérés küldése
|
if (responseList != null && responseList.IsSuccess)
|
||||||
|
|
||||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListHeaderDTO>>>(endpoint);
|
|
||||||
if (response != null)
|
|
||||||
{
|
{
|
||||||
if (response.IsSuccess)
|
var checkListHeaderList = await _dbContext.CheckListHeaders.ToListAsync();
|
||||||
|
var missingItems = responseList.Data
|
||||||
|
.Where(f => !checkListHeaderList.Any(s => s.GuidNumber == f.GuidNumber))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var missingCheckListHeaders = _mapper.Map<List<CheckListHeader>>(missingItems);
|
||||||
|
_dbContext.CheckListHeaders.AddRange(missingCheckListHeaders);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
foreach (var item in missingItems)
|
||||||
{
|
{
|
||||||
var checkListHeaderList = await _dbContext.CheckListHeaders.ToListAsync();
|
double itemPercentage = (double)i / missingItems.Count * 100;
|
||||||
var missingItems = response.Data.Where(f => !checkListHeaderList.Any(s => s.GuidNumber == f.GuidNumber)).ToList();
|
reportProgress(itemPercentage, "Adatbázis szinkronizáció..."); // Közvetlen progress jelentés
|
||||||
|
i++;
|
||||||
var missingCheckListHeaders = _mapper.Map<List<CheckListHeader>>(missingItems);
|
|
||||||
|
|
||||||
_dbContext.CheckListHeaders.AddRange(missingCheckListHeaders);
|
|
||||||
await _dbContext.SaveChangesAsync();
|
|
||||||
|
|
||||||
foreach (var item in missingItems)
|
|
||||||
{
|
|
||||||
var checkListHeaderDTO = item as CheckListHeaderDTO;
|
|
||||||
|
|
||||||
foreach (var checkListRowDTO in checkListHeaderDTO.CheckListRowDTO)
|
|
||||||
{
|
|
||||||
var checkListRow = _dbContext.CheckListRows.Where(w => w.GuidNumber == checkListRowDTO.GuidNumber).FirstOrDefault();
|
|
||||||
var isAdd = false;
|
|
||||||
if (checkListRow == null)
|
|
||||||
{
|
|
||||||
isAdd = true;
|
|
||||||
checkListRow = new CheckListRow();
|
|
||||||
checkListRow.CheckListHeaderId = checkListHeaderDTO.Id;
|
|
||||||
}
|
|
||||||
checkListRow.Answer = checkListRowDTO.Answer;
|
|
||||||
checkListRow.CheckListTemplateRowId = checkListRowDTO.CheckListTemplateRowId;
|
|
||||||
checkListRow.GuidNumber = checkListRowDTO.GuidNumber;
|
|
||||||
checkListRow.Photo = checkListRowDTO.Photo;
|
|
||||||
|
|
||||||
if (isAdd) _dbContext.CheckListRows.Add(checkListRow);
|
|
||||||
await _dbContext.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Hiba visszaadása
|
Console.WriteLine($"Hiba történt: {ex.Message}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public async Task<ApiResponseDTO<string>> SyncCheckListHeader_Up(int Id, Action<double, string> reportProgress)
|
||||||
public async Task SyncCheckListHeaderUp(int Id)
|
|
||||||
{
|
{
|
||||||
|
var retVal = new ApiResponseDTO<string>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PrepareAuthenticatedRequestAsync();
|
await PrepareAuthenticatedRequestAsync();
|
||||||
@@ -268,21 +199,74 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
var checkListHeaderDTO = _mapper.Map<CheckListHeaderDTO>(checkListHeader);
|
var checkListHeaderDTO = _mapper.Map<CheckListHeaderDTO>(checkListHeader);
|
||||||
|
|
||||||
|
|
||||||
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateCheckListHeader";
|
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateCheckListHeader";
|
||||||
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, checkListHeaderDTO))
|
|
||||||
|
var json = JsonConvert.SerializeObject(checkListHeaderDTO);
|
||||||
|
var jsonBytes = Encoding.UTF8.GetBytes(json);
|
||||||
|
var jsonStream = new MemoryStream(jsonBytes);
|
||||||
|
|
||||||
|
var progressContent = new ProgressableStreamContent(jsonStream, 8192, (uploaded, total) =>
|
||||||
|
{
|
||||||
|
double percentage = (double)uploaded / total * 100;
|
||||||
|
reportProgress(percentage, "Beküldés...");
|
||||||
|
});
|
||||||
|
|
||||||
|
progressContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
||||||
|
|
||||||
|
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsync(endpoint, progressContent))
|
||||||
{
|
{
|
||||||
httpResponseMessage.EnsureSuccessStatusCode();
|
httpResponseMessage.EnsureSuccessStatusCode();
|
||||||
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||||
var response = JsonConvert.DeserializeObject<ApiResponseDTO<CheckListHeaderDTO>>(jsonString);
|
retVal = JsonConvert.DeserializeObject<ApiResponseDTO<string>>(jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Hiba visszaadása
|
retVal.IsSuccess = false;
|
||||||
|
retVal.Errors.Add(ex.Message);
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ApiResponseDTO<List<T>>> DownloadDataAsync<T>(string endpoint, Action<double, string> reportProgress)
|
||||||
|
{
|
||||||
|
await PrepareAuthenticatedRequestAsync();
|
||||||
|
|
||||||
|
using var response = await _httpClient.GetAsync(endpoint, HttpCompletionOption.ResponseHeadersRead);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
using var stream = await response.Content.ReadAsStreamAsync();
|
||||||
|
using var memoryStream = new MemoryStream();
|
||||||
|
|
||||||
|
var buffer = new byte[8192];
|
||||||
|
long totalRead = 0;
|
||||||
|
int bytesRead;
|
||||||
|
int chunkCounter = 0;
|
||||||
|
|
||||||
|
while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
||||||
|
{
|
||||||
|
await memoryStream.WriteAsync(buffer, 0, bytesRead);
|
||||||
|
totalRead += bytesRead;
|
||||||
|
chunkCounter++;
|
||||||
|
|
||||||
|
// Gyakori progress frissítés
|
||||||
|
if (chunkCounter % 5 == 0) // 5 blokk után
|
||||||
|
{
|
||||||
|
double estimatedProgress = Math.Min((double)totalRead / (8192 * 100) * 100, 99);
|
||||||
|
reportProgress(estimatedProgress, "Letöltés ...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Végső progress 100%-ra állítása
|
||||||
|
reportProgress(100, "Letöltés ... kész!");
|
||||||
|
|
||||||
|
memoryStream.Position = 0;
|
||||||
|
var jsonString = Encoding.UTF8.GetString(memoryStream.ToArray());
|
||||||
|
|
||||||
|
// Generikus deszerializálás
|
||||||
|
var responseList = JsonConvert.DeserializeObject<ApiResponseDTO<List<T>>>(jsonString);
|
||||||
|
return responseList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,8 @@
|
|||||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
|
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
|
||||||
|
<PackageReference Include="SkiaSharp" Version="3.116.1" />
|
||||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user