38 lines
948 B
C#
38 lines
948 B
C#
using BS.Shared;
|
|
using DevExpress.Mvvm;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static DevExpress.Mvvm.Native.Either;
|
|
|
|
namespace BeWo.Core.Commands
|
|
{
|
|
public static class CommandFactory
|
|
{
|
|
public static DelegateCommand GetAiViewCommand(Action openView, UserRightType userRightType, Func<bool> additionalCheckup = null, bool? useCommandManager = null)
|
|
{
|
|
bool canExecute() =>
|
|
BeWoAppInfo.IsInAiMode &&
|
|
(BeWoApp.AppSettings?.ModuleAiEnabled ?? BeWoApp.AppSettings?.ShowAI ?? false) &&
|
|
BeWoApp.HasLoggedOnUserRight(userRightType) &&
|
|
(additionalCheckup is null || additionalCheckup());
|
|
|
|
return new DelegateCommand(openView, () => CheckupSafe(canExecute), useCommandManager);
|
|
}
|
|
|
|
private static bool CheckupSafe(Func<bool> predicate)
|
|
{
|
|
try
|
|
{
|
|
return predicate();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|