From 4cbea824eb5fb6a9f5906d6edf1cbeed2aec06f8 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Fri, 22 Dec 2023 14:38:34 +0330 Subject: [PATCH 1/3] Add new structure of base view models --- .../ApiBaseViewModel.cs | 81 ++++++++++ .../BaseViewModel.cs | 80 ++------- .../Commands/BaseCommand.cs | 2 +- .../Commands/TaskBaseCommand.cs | 2 +- .../EasyMicroservices.UI.Cores.Mvvm.csproj | 2 +- .../Interfaces/IBusyViewModel.cs | 2 +- .../Interfaces/IPage.cs | 53 ++++++ .../Interfaces/IPushPageViewModel.cs | 12 ++ .../Interfaces/IResponsibleViewModel.cs | 21 +++ .../NavigationManagerBase.cs | 65 ++++++++ .../PageBaseViewModel.cs | 153 ++++++++++++++++++ .../PushPageBaseViewModel.cs | 34 ++++ .../PushPageResponsibleBaseViewModel.cs | 30 ++++ .../ResponsibleBaseViewModel.cs | 72 +++++++++ 14 files changed, 535 insertions(+), 74 deletions(-) create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPushPageViewModel.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IResponsibleViewModel.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/NavigationManagerBase.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PageBaseViewModel.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PushPageBaseViewModel.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PushPageResponsibleBaseViewModel.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ResponsibleBaseViewModel.cs diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs new file mode 100644 index 0000000..6388462 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs @@ -0,0 +1,81 @@ +using EasyMicroservices.ServiceContracts; +using System; +using System.Threading.Tasks; + +namespace EasyMicroservices.UI.Cores; + +/// +/// +/// +public class ApiBaseViewModel : BaseViewModel +{ + + /// + /// + /// + /// + /// + /// + /// + /// + public async virtual Task ExecuteApi(Func> getServerResult, Func onSuccess, Func onError = default) + { + try + { + Busy(); + var result = await getServerResult(); + + var response = result.ToContract(); + + if (response.IsSuccess) + await onSuccess(response); + else + await DisplayServerError(response.Error); + } + catch (Exception ex) + { + if (onError != null) + await onError(ex); + else + await OnError(ex); + } + finally + { + UnBusy(); + } + } + + /// + /// + /// + /// + /// + /// + /// + public virtual async Task ExecuteApi(Func> getServerResult, Func onSuccess, Func onError = default) + { + try + { + Busy(); + var result = await getServerResult(); + + var response = result.ToContract(); + + if (response.IsSuccess) + await onSuccess(); + else + await DisplayServerError(response.Error); + } + catch (Exception ex) + { + if (onError != null) + await onError(ex); + else + await OnError(ex); + } + finally + { + UnBusy(); + } + } +} diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/BaseViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/BaseViewModel.cs index 2625f9d..2f92c49 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/BaseViewModel.cs +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/BaseViewModel.cs @@ -100,9 +100,18 @@ public virtual bool IsBusy _IsBusy = value; OnBusyChanged?.Invoke(value); OnPropertyChanged(nameof(IsBusy)); + OnPropertyChanged(nameof(IsNotBusy)); } } + /// + /// + /// + public virtual bool IsNotBusy + { + get => !IsBusy; + } + /// /// /// @@ -133,75 +142,6 @@ public virtual void UnBusy() IsBusy = false; } - /// - /// - /// - /// - /// - /// - /// - /// - public async virtual Task ExecuteApi(Func> getServerResult, Func onSuccess, Func onError = default) - { - try - { - Busy(); - var result = await getServerResult(); - - var response = result.ToContract(); - - if (response.IsSuccess) - await onSuccess(response); - else - await DisplayFetchError(response.Error); - } - catch (Exception ex) - { - if (onError != null) - await onError(ex); - else - await DisplayError(ex.ToString()); - } - finally - { - UnBusy(); - } - } - - /// - /// - /// - /// - /// - /// - /// - public virtual async Task ExecuteApi(Func> getServerResult, Func onSuccess, Func onError = default) - { - try - { - Busy(); - var result = await getServerResult(); - - var response = result.ToContract(); - - if (response.IsSuccess) - await onSuccess(); - else - await DisplayFetchError(response.Error); - } - catch (Exception ex) - { - if (onError != null) - await onError(ex); - else - await DisplayError(ex.ToString()); - } - finally - { - UnBusy(); - } - } - /// /// /// @@ -217,7 +157,7 @@ public virtual Task OnError(Exception exception) /// /// /// - public virtual Task DisplayFetchError(ErrorContract errorContract) + public virtual Task DisplayServerError(ErrorContract errorContract) { return Task.CompletedTask; } diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Commands/BaseCommand.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Commands/BaseCommand.cs index 7a5b43b..15800ca 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Commands/BaseCommand.cs +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Commands/BaseCommand.cs @@ -86,7 +86,7 @@ public virtual void Execute(object parameter) } catch (InvalidResultOfMessageContractException ex) { - _busyViewModel?.DisplayFetchError(ex.MessageContract.Error); + _busyViewModel?.DisplayServerError(ex.MessageContract.Error); } catch (Exception ex) { diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Commands/TaskBaseCommand.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Commands/TaskBaseCommand.cs index 882e16a..2a05006 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Commands/TaskBaseCommand.cs +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Commands/TaskBaseCommand.cs @@ -87,7 +87,7 @@ async Task InternalExecute(object parameter) } catch (InvalidResultOfMessageContractException ex) { - _busyViewModel?.DisplayFetchError(ex.MessageContract.Error); + _busyViewModel?.DisplayServerError(ex.MessageContract.Error); } catch (Exception ex) { diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj index ec0db2e..2b8912f 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/EasyMicroservices.UI.Cores.Mvvm.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.9 + 0.0.0.10 Model View View Model EasyMicroservices@gmail.com mvvm,mvpvm,modelview,modelviewviewmodel diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IBusyViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IBusyViewModel.cs index 292289c..7022894 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IBusyViewModel.cs +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IBusyViewModel.cs @@ -40,7 +40,7 @@ public interface IBusyViewModel : INotifyPropertyChanged /// /// /// - Task DisplayFetchError(ErrorContract errorContract); + Task DisplayServerError(ErrorContract errorContract); /// /// diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs new file mode 100644 index 0000000..10a0424 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace EasyMicroservices.UI.Cores.Interfaces; +/// +/// +/// +public interface IPage +{ + /// + /// + /// + Action OnLoadComplete { get; set; } + /// + /// + /// + Action OnBackBottonPresssed { get; set; } + /// + /// + /// + /// + /// + /// + /// + /// + Task DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons); + /// + /// + /// + /// + /// + /// + /// + Task DisplayAlert(string title, string message, string cancel); + /// + /// + /// + /// + /// + /// + /// + /// + Task DisplayAlert(string title, string message, string accept, string cancel); + /// + /// + /// + /// + /// + /// + Task DisplayPrompt(string title, string message); +} diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPushPageViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPushPageViewModel.cs new file mode 100644 index 0000000..08d943c --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPushPageViewModel.cs @@ -0,0 +1,12 @@ +namespace EasyMicroservices.UI.Cores.Interfaces; +/// +/// +/// +public interface IPushPageViewModel +{ + /// + /// + /// + /// + void SetResult(object data); +} \ No newline at end of file diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IResponsibleViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IResponsibleViewModel.cs new file mode 100644 index 0000000..d552cc6 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IResponsibleViewModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace EasyMicroservices.UI.Cores.Interfaces; +/// +/// +/// +public interface IResponsibleViewModel +{ + /// + /// + /// + /// + Task GetResult(); + /// + /// + /// + void Close(); +} diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/NavigationManagerBase.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/NavigationManagerBase.cs new file mode 100644 index 0000000..a71e238 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/NavigationManagerBase.cs @@ -0,0 +1,65 @@ +using System.IO; +using System.Threading.Tasks; + +namespace EasyMicroservices.UI.Cores; +/// +/// +/// +public abstract class NavigationManagerBase +{ + /// + /// + /// + public static NavigationManagerBase Current { get; set; } + + /// + /// + /// + /// + /// + /// + /// + public abstract Task PushAsync(string pageName, bool doClear = false); + /// + /// + /// + /// + /// + /// + /// + /// + /// + public abstract Task PushDataAsync(TData data, string pageName, bool doClear = false); + /// + /// + /// + /// + /// + /// + /// + /// + public abstract Task PushDataAsync(TData data, string pageName, bool doClear = false); + /// + /// + /// + /// + /// + /// + public abstract Task PushAsync(string pageName, bool doClear = false); + /// + /// + /// + /// + public abstract Task PopAsync(); + /// + /// + /// + /// + public abstract Task<(bool IsSusccess, Stream Stream, string FileName, string ContentType)> PickFile(); + /// + /// + /// + /// + /// + public abstract Task OpenBrowser(string url); +} diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PageBaseViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PageBaseViewModel.cs new file mode 100644 index 0000000..5276f20 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PageBaseViewModel.cs @@ -0,0 +1,153 @@ +using EasyMicroservices.ServiceContracts; +using EasyMicroservices.UI.Cores.Interfaces; +using System; +using System.Linq; +using System.Threading.Tasks; + +namespace EasyMicroservices.UI.Cores; +/// +/// +/// +public class PageBaseViewModel : ApiBaseViewModel +{ + IPage _Page; + /// + /// + /// + public IPage Page + { + get + { + return _Page; + } + set + { + _Page = value; + Page.OnLoadComplete = OnLoadComplete; + } + } + + /// + /// + /// + public virtual void OnLoadComplete() + { + + } + + /// + /// + /// + /// + /// + /// + /// + /// + public async Task<(bool IsSelected, string SelectedItem)> DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons) + { + var res = await Page.DisplayActionSheet(title, cancel, destruction, buttons); + if (buttons != null && buttons.Contains(res)) + return (true, res); + return (false, res); + } + + /// + /// + /// + /// + /// + /// + /// + public async Task<(bool IsSelected, TEnum SelectedItem)> DisplayEnumActionSheet(string title, params string[] skipItems) + where TEnum : struct, Enum + { + var unusedEnums = new string[] + { + "None","Default","All","Other","Unknown","Nothing" + }; + if (skipItems != null) + unusedEnums = unusedEnums.Concat(skipItems).ToArray(); + var items = Enum.GetNames(typeof(TEnum)); + items = items.Where(x => !unusedEnums.Contains(x)).ToArray(); + var res = await Page.DisplayActionSheet(title, "Close", null, items); + if (items.Contains(res)) + return (true, (TEnum)Enum.Parse(typeof(TEnum),res)); + return (false, default); + } + + /// + /// + /// + /// + /// + /// + /// + public Task DisplayAlert(string title, string message, string cancel) + { + return Page.DisplayAlert(title, message, cancel); + } + + /// + /// + /// + /// + /// + /// + /// + /// + public Task DisplayQuestion(string title, string message, string accept = "Yes", string cancel = "No") + { + return Page.DisplayAlert(title, message, accept, cancel); + } + + /// + /// + /// + /// + /// + /// + public Task DisplayPrompt(string title, string message) + { + return Page.DisplayPrompt(title, message); + } + + /// + /// + /// + /// + /// + public override Task DisplayError(string message) + { + return Page.DisplayAlert("Error", message, "Ok"); + } + + /// + /// + /// + /// + /// + public override Task OnError(Exception exception) + { + return DisplayError(exception.ToString()); + } + + /// + /// + /// + /// + /// + public override Task DisplayServerError(ErrorContract errorContract) + { + return Page.DisplayAlert("Server Error", $"{errorContract?.FailedReasonType}{Environment.NewLine}{errorContract?.Message}{Environment.NewLine}{errorContract?.Details}{Environment.NewLine}{errorContract?.StackTrace}", "Ok"); + } + + /// + /// + /// + /// + /// + public Task DisplayValidationAlert(string message) + { + return Page.DisplayAlert("Data is not valid", message, "Ok"); + } +} diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PushPageBaseViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PushPageBaseViewModel.cs new file mode 100644 index 0000000..f5f3165 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PushPageBaseViewModel.cs @@ -0,0 +1,34 @@ +using EasyMicroservices.UI.Cores.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace EasyMicroservices.UI.Cores; +/// +/// +/// +/// +public abstract class PushPageBaseViewModel : PageBaseViewModel, IPushPageViewModel +{ + /// + /// + /// + public TData Data { get; set; } + + /// + /// + /// + /// + public void SetResult(object data) + { + Data = (TData)data; + OnPropertyChanged(nameof(Data)); + OnDataInitialized(Data); + } + + /// + /// + /// + /// + public abstract void OnDataInitialized(TData data); +} \ No newline at end of file diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PushPageResponsibleBaseViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PushPageResponsibleBaseViewModel.cs new file mode 100644 index 0000000..1a424f3 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/PushPageResponsibleBaseViewModel.cs @@ -0,0 +1,30 @@ +using EasyMicroservices.UI.Cores.Interfaces; + +namespace EasyMicroservices.UI.Cores; +/// +/// +/// +public abstract class PushPageResponsibleBaseViewModel : ResponsibleBaseViewModel, IPushPageViewModel +{ + /// + /// + /// + public TRequestData Data { get; set; } + + /// + /// + /// + /// + public void SetResult(object data) + { + Data = (TRequestData)data; + OnPropertyChanged(nameof(Data)); + OnDataInitialized(Data); + } + + /// + /// + /// + /// + public abstract void OnDataInitialized(TRequestData data); +} diff --git a/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ResponsibleBaseViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ResponsibleBaseViewModel.cs new file mode 100644 index 0000000..4cfc815 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ResponsibleBaseViewModel.cs @@ -0,0 +1,72 @@ +using EasyMicroservices.UI.Cores.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace EasyMicroservices.UI.Cores; +/// +/// +/// +/// +public class ResponsibleBaseViewModel : PageBaseViewModel, IResponsibleViewModel +{ + TaskCompletionSource TaskCompletionSource { get; set; } = new TaskCompletionSource(); + /// + /// + /// + /// + public Task WaitForResult() + { + return TaskCompletionSource.Task; + } + + /// + /// + /// + /// + public void SetData(TData data) + { + TaskCompletionSource.TrySetResult(data); + } + + /// + /// + /// + /// + public async Task GetResult() + { + return await TaskCompletionSource.Task; + } + + /// + /// + /// + public void Close() + { + if (TaskCompletionSource.Task.IsCompleted) + return; + TaskCompletionSource.TrySetResult(default); + } + + /// + /// + /// + /// + public Task PopAsync() + { + SetData(default); + return NavigationManagerBase.Current.PopAsync(); + } + + /// + /// + /// + /// + /// + public Task PopDataAsync(TData data) + { + SetData(data); + return NavigationManagerBase.Current.PopAsync(); + } +} From ad20a1763225a6a749c20a4a4dd6dfd1a0b880e1 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Fri, 22 Dec 2023 14:57:54 +0330 Subject: [PATCH 2/3] add Support for EasyMicroservices.UI.MauiComponents --- .../EasyMicroservices.UI.MauiComponents.sln | 56 ++++++++++++ .../Design/Pages/EasyContentPage.cs | 30 +++++++ ...EasyMicroservices.UI.MauiComponents.csproj | 34 ++++++++ .../Navigations/DefaultNavigationManager.cs | 87 +++++++++++++++++++ .../Platforms/Android/PlatformClass1.cs | 6 ++ .../Platforms/MacCatalyst/PlatformClass1.cs | 6 ++ .../Platforms/Tizen/PlatformClass1.cs | 7 ++ .../Platforms/Windows/PlatformClass1.cs | 6 ++ .../Platforms/iOS/PlatformClass1.cs | 6 ++ 9 files changed, 238 insertions(+) create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents.sln create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Design/Pages/EasyContentPage.cs create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Navigations/DefaultNavigationManager.cs create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Android/PlatformClass1.cs create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/MacCatalyst/PlatformClass1.cs create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Tizen/PlatformClass1.cs create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Windows/PlatformClass1.cs create mode 100644 src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/iOS/PlatformClass1.cs diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents.sln b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents.sln new file mode 100644 index 0000000..fdf33fd --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents.sln @@ -0,0 +1,56 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34309.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyMicroservices.UI.MauiComponents", "EasyMicroservices.UI.MauiComponents\EasyMicroservices.UI.MauiComponents.csproj", "{07394D18-C9B5-41F1-A70D-AC07B66A2918}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application-Layer", "Application-Layer", "{78B06757-B39E-461F-AD9E-50C375CF2FC5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EasyMicroservices.UI.Cores.Mvvm", "..\Cores\EasyMicroservices.UI.Cores.Mvvm\EasyMicroservices.UI.Cores.Mvvm.csproj", "{C0F2A7F9-9CBE-4191-974E-0E903183DBA3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Debug|x64.ActiveCfg = Debug|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Debug|x64.Build.0 = Debug|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Debug|x86.ActiveCfg = Debug|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Debug|x86.Build.0 = Debug|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Release|Any CPU.Build.0 = Release|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Release|x64.ActiveCfg = Release|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Release|x64.Build.0 = Release|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Release|x86.ActiveCfg = Release|Any CPU + {07394D18-C9B5-41F1-A70D-AC07B66A2918}.Release|x86.Build.0 = Release|Any CPU + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Debug|x64.ActiveCfg = Debug|x64 + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Debug|x64.Build.0 = Debug|x64 + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Debug|x86.ActiveCfg = Debug|x86 + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Debug|x86.Build.0 = Debug|x86 + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Release|Any CPU.Build.0 = Release|Any CPU + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Release|x64.ActiveCfg = Release|x64 + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Release|x64.Build.0 = Release|x64 + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Release|x86.ActiveCfg = Release|x86 + {C0F2A7F9-9CBE-4191-974E-0E903183DBA3}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {07394D18-C9B5-41F1-A70D-AC07B66A2918} = {78B06757-B39E-461F-AD9E-50C375CF2FC5} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {67F91600-7A5C-46C1-B9AF-A0F4B809A48E} + EndGlobalSection +EndGlobal diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Design/Pages/EasyContentPage.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Design/Pages/EasyContentPage.cs new file mode 100644 index 0000000..b0ca13f --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Design/Pages/EasyContentPage.cs @@ -0,0 +1,30 @@ +using EasyMicroservices.UI.Cores.Interfaces; + +namespace EasyMicroservices.UI.MauiComponents.Design.Pages; + +public class EasyContentPage : ContentPage, IPage +{ + public EasyContentPage() + { + Loaded += CustomContentPage_Loaded; + } + + private void CustomContentPage_Loaded(object sender, EventArgs e) + { + OnLoadComplete?.Invoke(); + } + + public Action OnBackBottonPresssed { get; set; } + public Action OnLoadComplete { get; set; } + + protected override bool OnBackButtonPressed() + { + OnBackBottonPresssed?.Invoke(); + return base.OnBackButtonPressed(); + } + + public async Task DisplayPrompt(string title, string message) + { + return await DisplayPromptAsync(title, message); + } +} \ No newline at end of file diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj new file mode 100644 index 0000000..75ffb50 --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj @@ -0,0 +1,34 @@ + + + + net7.0-android;net7.0-ios;net7.0-maccatalyst;net8.0-android;net8.0-ios;net8.0-maccatalyst; + $(TargetFrameworks);net7.0-windows10.0.19041.0;net8.0-windows10.0.19041.0 + + + true + true + enable + + 11.0 + 13.1 + 21.0 + 10.0.17763.0 + 10.0.17763.0 + 6.5 + + + + + + + + + + + + + + + + + diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Navigations/DefaultNavigationManager.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Navigations/DefaultNavigationManager.cs new file mode 100644 index 0000000..73e4e09 --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Navigations/DefaultNavigationManager.cs @@ -0,0 +1,87 @@ +using EasyMicroservices.UI.Cores; +using EasyMicroservices.UI.Cores.Interfaces; +using System.Collections.Concurrent; + +namespace EasyMicroservices.UI.MauiComponents.Navigations; +public class DefaultNavigationManager : NavigationManagerBase +{ + readonly INavigation _navigation; + public DefaultNavigationManager(INavigation navigation) + { + _navigation = navigation; + } + + ConcurrentDictionary Pages { get; set; } = new ConcurrentDictionary(); + public override Task PopAsync() + { + return _navigation.PopAsync(); + } + + public override Task PushAsync(string pageName, bool doClear = false) + { + return PushDataAsync(default, pageName, doClear); + } + + public override async Task PushDataAsync(TData data, string pageName, bool doClear = false) + { + if (!Pages.TryGetValue(pageName, out IPage findPage)) + throw new Exception($"Page {pageName} not found, did you register it?"); + Page page = findPage as Page; + if (page == null) + throw new NotImplementedException($"Page {pageName} is not inherit Page!"); + var ipage = page as IPage; + if (page.BindingContext is PageBaseViewModel pageBaseViewModel && ipage != null) + pageBaseViewModel.Page = ipage; + if (doClear) + await _navigation.PopAsync(); + await _navigation.PushAsync(page); + if (page.BindingContext is IPushPageViewModel pushViewModel) + pushViewModel.SetResult(data); + if (page.BindingContext is IResponsibleViewModel responsibleViewModel) + { + if (ipage != null) + ipage.OnBackBottonPresssed = responsibleViewModel.Close; + var result = await responsibleViewModel.GetResult(); + if (result != null && result is TResponseData responseData) + return responseData; + return default; + } + return default; + } + + public override Task PushDataAsync(TData data, string pageName, bool doClear = false) + { + return PushDataAsync(data, pageName, doClear); + } + + public override async Task PushAsync(string pageName, bool doClear = false) + { + await PushAsync(pageName, doClear); + } + + public override async Task<(bool IsSusccess, Stream Stream, string FileName, string ContentType)> PickFile() + { + try + { + var result = await FilePicker.Default.PickAsync(new PickOptions() + { + PickerTitle = "Please select a Word file", + }); + if (result != null) + { + return (true, await result.OpenReadAsync(), result.FileName, result.ContentType); + } + } + catch (Exception ex) + { + // The user canceled or something went wrong + } + + return default; + } + + public override Task OpenBrowser(string url) + { + return Browser.OpenAsync(url, BrowserLaunchMode.SystemPreferred); + } +} \ No newline at end of file diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Android/PlatformClass1.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Android/PlatformClass1.cs new file mode 100644 index 0000000..15c7956 --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Android/PlatformClass1.cs @@ -0,0 +1,6 @@ +namespace EasyMicroservices.UI.MauiComponents; + +// All the code in this file is only included on Android. +public class PlatformClass1 +{ +} diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/MacCatalyst/PlatformClass1.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/MacCatalyst/PlatformClass1.cs new file mode 100644 index 0000000..628548b --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/MacCatalyst/PlatformClass1.cs @@ -0,0 +1,6 @@ +namespace EasyMicroservices.UI.MauiComponents; + +// All the code in this file is only included on Mac Catalyst. +public class PlatformClass1 +{ +} diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Tizen/PlatformClass1.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Tizen/PlatformClass1.cs new file mode 100644 index 0000000..a8ab613 --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Tizen/PlatformClass1.cs @@ -0,0 +1,7 @@ +using System; + +namespace EasyMicroservices.UI.MauiComponents; +// All the code in this file is only included on Tizen. +public class PlatformClass1 +{ +} \ No newline at end of file diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Windows/PlatformClass1.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Windows/PlatformClass1.cs new file mode 100644 index 0000000..8779364 --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/Windows/PlatformClass1.cs @@ -0,0 +1,6 @@ +namespace EasyMicroservices.UI.MauiComponents; + +// All the code in this file is only included on Windows. +public class PlatformClass1 +{ +} diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/iOS/PlatformClass1.cs b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/iOS/PlatformClass1.cs new file mode 100644 index 0000000..215bd0f --- /dev/null +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/Platforms/iOS/PlatformClass1.cs @@ -0,0 +1,6 @@ +namespace EasyMicroservices.UI.MauiComponents; + +// All the code in this file is only included on iOS. +public class PlatformClass1 +{ +} From baaa521e8501bf798953a9431cdd887a21f941de Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Fri, 22 Dec 2023 15:02:39 +0330 Subject: [PATCH 3/3] clean pack --- .../EasyMicroservices.UI.MauiComponents.csproj | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj index 75ffb50..251a76c 100644 --- a/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj +++ b/src/CSharp/MauiComponents/EasyMicroservices.UI.MauiComponents/EasyMicroservices.UI.MauiComponents.csproj @@ -15,6 +15,15 @@ 10.0.17763.0 10.0.17763.0 6.5 + AnyCPU;x64;x86 + EasyMicroservices + true + 0.0.0.1 + Maui easy and light components + EasyMicroservices@gmail.com + maui,ui,component,components + https://github.com/EasyMicroservices/UICores + latest