Files
BeWoPlaner/BeWo/Core/Commands/CommandFactory.cs

37 lines
912 B
C#
Raw Permalink Normal View History

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;
namespace BeWo.Core.Commands
{
public static class CommandFactory
{
public static DelegateCommand GetAiViewCommand(Action openView, UserRightType? userRightType, Func<bool> additionalCheckup = null, bool? useCommandManager = null)
{
2025-06-11 10:42:16 +02:00
bool canExecute() =>
(BeWoApp.AppSettings?.ShowAI ?? false) &&
(userRightType is null || BeWoApp.HasLoggedOnUserRight(userRightType.Value)) &&
2025-06-11 10:42:16 +02:00
(additionalCheckup is null || additionalCheckup());
2025-08-11 12:52:19 +02:00
return new DelegateCommand(openView, () => CheckupSafe(canExecute), useCommandManager);
}
private static bool CheckupSafe(Func<bool> predicate)
{
try
{
return predicate();
}
catch (Exception ex)
{
return false;
}
}
}
}