2025-06-10 16:15:34 +02:00
|
|
|
|
using BS.Shared;
|
|
|
|
|
|
using DevExpress.Mvvm;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2025-06-11 10:42:16 +02:00
|
|
|
|
using static DevExpress.Mvvm.Native.Either;
|
2025-06-10 16:15:34 +02:00
|
|
|
|
|
|
|
|
|
|
namespace BeWo.Core.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class CommandFactory
|
|
|
|
|
|
{
|
2025-08-11 12:52:19 +02:00
|
|
|
|
public static DelegateCommand GetAiViewCommand(Action openView, UserRightType userRightType, Func<bool> additionalCheckup = null, bool? useCommandManager = null)
|
2025-06-10 16:15:34 +02:00
|
|
|
|
{
|
2025-06-11 10:42:16 +02:00
|
|
|
|
bool canExecute() =>
|
2025-11-28 13:16:18 +01:00
|
|
|
|
userRightType != UserRightType.AiModuleView2 &&
|
2025-08-11 12:52:19 +02:00
|
|
|
|
BeWoAppInfo.IsInAiMode &&
|
2025-06-23 12:29:57 +02:00
|
|
|
|
(BeWoApp.AppSettings?.ModuleAiEnabled ?? false) &&
|
2025-06-11 10:42:16 +02:00
|
|
|
|
BeWoApp.HasLoggedOnUserRight(userRightType) &&
|
|
|
|
|
|
(additionalCheckup is null || additionalCheckup());
|
2025-06-11 10:06:25 +02:00
|
|
|
|
|
2025-08-11 12:52:19 +02:00
|
|
|
|
return new DelegateCommand(openView, () => CheckupSafe(canExecute), useCommandManager);
|
2025-06-23 12:33:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static bool CheckupSafe(Func<bool> predicate)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return predicate();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-06-11 10:06:25 +02:00
|
|
|
|
}
|
2025-06-10 16:15:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|