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
|
|
|
|
|
|
{
|
2026-03-02 10:48:30 +01: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() =>
|
2026-03-04 13:11:46 +01:00
|
|
|
|
(BeWoApp.AppSettings?.ShowAI ?? false) &&
|
2026-03-02 10:48:30 +01:00
|
|
|
|
(userRightType is null || BeWoApp.HasLoggedOnUserRight(userRightType.Value)) &&
|
2025-06-11 10:42:16 +02:00
|
|
|
|
(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
|
|
|
|
}
|
|
|
|
|
|
}
|