Skip to content

Commit

Permalink
Merge pull request #12 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
add Support for EasyMicroservices.UI.MauiComponents
  • Loading branch information
Ali-YousefiTelori authored Dec 22, 2023
2 parents f46800d + baaa521 commit 70c993a
Show file tree
Hide file tree
Showing 23 changed files with 782 additions and 74 deletions.
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();
}
}
}
80 changes: 10 additions & 70 deletions src/CSharp/Cores/EasyMicroservices.UI.Cores.Mvvm/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,18 @@ public virtual bool IsBusy
_IsBusy = value;
OnBusyChanged?.Invoke(value);
OnPropertyChanged(nameof(IsBusy));
OnPropertyChanged(nameof(IsNotBusy));
}
}

/// <summary>
///
/// </summary>
public virtual bool IsNotBusy
{
get => !IsBusy;
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -133,75 +142,6 @@ public virtual void UnBusy()
IsBusy = false;
}

/// <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 DisplayFetchError(response.Error);
}
catch (Exception ex)
{
if (onError != null)
await onError(ex);
else
await DisplayError(ex.ToString());
}
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 DisplayFetchError(response.Error);
}
catch (Exception ex)
{
if (onError != null)
await onError(ex);
else
await DisplayError(ex.ToString());
}
finally
{
UnBusy();
}
}

/// <summary>
///
/// </summary>
Expand All @@ -217,7 +157,7 @@ public virtual Task OnError(Exception exception)
/// </summary>
/// <param name="errorContract"></param>
/// <returns></returns>
public virtual Task DisplayFetchError(ErrorContract errorContract)
public virtual Task DisplayServerError(ErrorContract errorContract)
{
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface IBusyViewModel : INotifyPropertyChanged
/// </summary>
/// <param name="errorContract"></param>
/// <returns></returns>
Task DisplayFetchError(ErrorContract errorContract);
Task DisplayServerError(ErrorContract errorContract);

/// <summary>
///
Expand Down
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);
}
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);
}
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();
}
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);
}
Loading

0 comments on commit 70c993a

Please sign in to comment.