-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Ali-YousefiTelori/develop
add Support for EasyMicroservices.UI.MauiComponents
- Loading branch information
Showing
23 changed files
with
782 additions
and
74 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/ApiBaseViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using EasyMicroservices.ServiceContracts; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.UI.Cores; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class ApiBaseViewModel : BaseViewModel | ||
{ | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <typeparam name="TResult"></typeparam> | ||
/// <param name="getServerResult"></param> | ||
/// <param name="onSuccess"></param> | ||
/// <param name="onError"></param> | ||
/// <returns></returns> | ||
public async virtual Task ExecuteApi<TResult>(Func<Task<object>> getServerResult, Func<TResult, Task> onSuccess, Func<Exception, Task> onError = default) | ||
{ | ||
try | ||
{ | ||
Busy(); | ||
var result = await getServerResult(); | ||
|
||
var response = result.ToContract<TResult>(); | ||
|
||
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(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="getServerResult"></param> | ||
/// <param name="onSuccess"></param> | ||
/// <param name="onError"></param> | ||
/// <returns></returns> | ||
public virtual async Task ExecuteApi(Func<Task<object>> getServerResult, Func<Task> onSuccess, Func<Exception, Task> 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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<Authors>EasyMicroservices</Authors> | ||
<IsPackable>true</IsPackable> | ||
<Version>0.0.0.9</Version> | ||
<Version>0.0.0.10</Version> | ||
<Description>Model View View Model</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>mvvm,mvpvm,modelview,modelviewviewmodel</PackageTags> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.UI.Cores.Interfaces; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IPage | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
Action OnLoadComplete { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
Action OnBackBottonPresssed { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="title"></param> | ||
/// <param name="cancel"></param> | ||
/// <param name="destruction"></param> | ||
/// <param name="buttons"></param> | ||
/// <returns></returns> | ||
Task<string> DisplayActionSheet(string title, string cancel, string destruction, params string[] buttons); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="title"></param> | ||
/// <param name="message"></param> | ||
/// <param name="cancel"></param> | ||
/// <returns></returns> | ||
Task DisplayAlert(string title, string message, string cancel); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="title"></param> | ||
/// <param name="message"></param> | ||
/// <param name="accept"></param> | ||
/// <param name="cancel"></param> | ||
/// <returns></returns> | ||
Task<bool> DisplayAlert(string title, string message, string accept, string cancel); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="title"></param> | ||
/// <param name="message"></param> | ||
/// <returns></returns> | ||
Task<string> DisplayPrompt(string title, string message); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IPushPageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace EasyMicroservices.UI.Cores.Interfaces; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IPushPageViewModel | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="data"></param> | ||
void SetResult(object data); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/Interfaces/IResponsibleViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.UI.Cores.Interfaces; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public interface IResponsibleViewModel | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<object> GetResult(); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
void Close(); | ||
} |
65 changes: 65 additions & 0 deletions
65
src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/NavigationManagerBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.UI.Cores; | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public abstract class NavigationManagerBase | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static NavigationManagerBase Current { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <typeparam name="TResponseData"></typeparam> | ||
/// <param name="pageName"></param> | ||
/// <param name="doClear"></param> | ||
/// <returns></returns> | ||
public abstract Task<TResponseData> PushAsync<TResponseData>(string pageName, bool doClear = false); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <typeparam name="TData"></typeparam> | ||
/// <typeparam name="TResponseData"></typeparam> | ||
/// <param name="data"></param> | ||
/// <param name="pageName"></param> | ||
/// <param name="doClear"></param> | ||
/// <returns></returns> | ||
public abstract Task<TResponseData> PushDataAsync<TData, TResponseData>(TData data, string pageName, bool doClear = false); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <typeparam name="TData"></typeparam> | ||
/// <param name="data"></param> | ||
/// <param name="pageName"></param> | ||
/// <param name="doClear"></param> | ||
/// <returns></returns> | ||
public abstract Task PushDataAsync<TData>(TData data, string pageName, bool doClear = false); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="pageName"></param> | ||
/// <param name="doClear"></param> | ||
/// <returns></returns> | ||
public abstract Task PushAsync(string pageName, bool doClear = false); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
public abstract Task PopAsync(); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <returns></returns> | ||
public abstract Task<(bool IsSusccess, Stream Stream, string FileName, string ContentType)> PickFile(); | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="url"></param> | ||
/// <returns></returns> | ||
public abstract Task<bool> OpenBrowser(string url); | ||
} |
Oops, something went wrong.