Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Support for EasyMicroservices.UI.MauiComponents #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading