public UpdateActionCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator,
            IActionValidator actionValidator,
            IRowVersionValidator rowVersionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}")
            .MustAsync((command, token) => NotBeAVoidedTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag is voided! Tag={command.TagId}")
            .MustAsync(BeAnExistingActionAsync)
            .WithMessage(command => "Tag and/or action doesn't exist!")
            .MustAsync((command, token) => NotBeAClosedActionAsync(command.ActionId, token))
            .WithMessage(command => $"Action is closed! Action={command.ActionId}")
            .Must(command => HaveAValidRowVersion(command.RowVersion))
            .WithMessage(command => $"Not a valid row version! Row version={command.RowVersion}");

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);
            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);
            async Task <bool> BeAnExistingActionAsync(UpdateActionCommand command, CancellationToken token)
            => await tagValidator.ExistsActionAsync(command.TagId, command.ActionId, token);
            async Task <bool> NotBeAClosedActionAsync(int actionId, CancellationToken token)
            => !await actionValidator.IsClosedAsync(actionId, token);

            bool HaveAValidRowVersion(string rowVersion)
            => rowVersionValidator.IsValid(rowVersion);
        }
Пример #2
0
        private static bool CanExecute(ActionId actionId)
        {
            if (!Enabled)
            {
                return(true);
            }

            foreach (ActionFlags flag in canExecuteFlags)
            {
                IAction action = GetAction(actionId);
                var     f      = flag & action.Flags;

                if (canExecuteCache.ContainsKey(f))
                {
                    return(canExecuteCache[f]);
                }

                IActionValidator validator    = GetValidator(f);
                string           error        = validator.Validate();
                bool             isCanExecute = string.IsNullOrWhiteSpace(error);
                canExecuteCache.Add(f, isCanExecute);

                if (!isCanExecute)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #3
0
        public UploadActionAttachmentCommandValidator(
            IProjectValidator projectValidator,
            ITagValidator tagValidator,
            IActionValidator actionValidator)
        {
            CascadeMode = CascadeMode.Stop;

            RuleFor(command => command)
            .MustAsync((command, token) => NotBeAClosedProjectForTagAsync(command.TagId, token))
            .WithMessage(command => $"Project for tag is closed! Tag={command.TagId}")
            .MustAsync((command, token) => NotBeAVoidedTagAsync(command.TagId, token))
            .WithMessage(command => $"Tag is voided! Tag={command.TagId}")
            .MustAsync(BeAnExistingActionAsync)
            .WithMessage(command => "Tag and/or action doesn't exist!")
            .MustAsync((command, token) => NotBeAClosedActionAsync(command.ActionId, token))
            .WithMessage(command => $"Action is closed! Action={command.ActionId}")
            .MustAsync((command, token) => NotHaveAttachmentWithFilenameAsync(command.ActionId, command.FileName, token))
            .WithMessage(command => $"Action already has an attachment with filename {command.FileName}! Please rename file or choose to overwrite")
            .When(c => !c.OverwriteIfExists, ApplyConditionTo.CurrentValidator);

            async Task <bool> NotBeAClosedProjectForTagAsync(int tagId, CancellationToken token)
            => !await projectValidator.IsClosedForTagAsync(tagId, token);
            async Task <bool> NotBeAVoidedTagAsync(int tagId, CancellationToken token)
            => !await tagValidator.IsVoidedAsync(tagId, token);
            async Task <bool> NotHaveAttachmentWithFilenameAsync(int actionId, string fileName, CancellationToken token)
            => !await actionValidator.AttachmentWithFilenameExistsAsync(actionId, fileName, token);
            async Task <bool> BeAnExistingActionAsync(UploadActionAttachmentCommand command, CancellationToken token)
            => await tagValidator.ExistsActionAsync(command.TagId, command.ActionId, token);
            async Task <bool> NotBeAClosedActionAsync(int actionId, CancellationToken token)
            => !await actionValidator.IsClosedAsync(actionId, token);
        }
Пример #4
0
 public TableRobot(IActionValidator actionValidator)
 {
     if (actionValidator == null)
     {
         throw new ArgumentNullException("actionValidator missing");
     }
     this._actionValidator = actionValidator;
 }
Пример #5
0
 public AccountsController(IUsersRepository usersRepository, IActionsRepository actionsRepository,
                           IAccountsService accountsService, IActionValidator actionValidator,
                           ICryptographyService cryptographyService)
 {
     _usersRepository     = usersRepository;
     _actionsRepository   = actionsRepository;
     _accountsService     = accountsService;
     _actionValidator     = actionValidator;
     _cryptographyService = cryptographyService;
 }
 public CSharpDocumentProcessor(object documentContent, int selectedLineNumber) : this(documentContent, selectedLineNumber, new FunctionBasedActionValidator())
 {
     _validator = new FunctionBasedActionValidator()
                  .WithFunctionList("jump", new List <Func <int, bool> > {
         (selectedLine) => DoesNodeOrReturnNodeContainBatisNamespace()
     })
                  .WithFunctionList("rename", new List <Func <int, bool> >
     {
         (selectedLine) => DoesNodeOrReturnNodeContainBatisNamespace() && IsAnyNodeLiteralStringExpression()
     });
 }
Пример #7
0
 public XmlDocumentProcessor(object documentContent, int selectedLineNumber) : this(documentContent, selectedLineNumber, new FunctionBasedActionValidator())
 {
     _validator = new FunctionBasedActionValidator()
                  .WithFunctionList("jump", new List <Func <int, bool> >
     {
         (selectionLineNum) => !XmlStringLine.IsIgnored(GetLineText(selectionLineNum + 1)),
         (selectionLineNum) => _parser.XmlNamespace == Constants.BatisConstants.XmlMapConstants.XmlNamespace,
         (selectionLineNum) => _parser.HasSelectedLineValidQuery(selectionLineNum + 1)
     })
                  .WithFunctionList("rename", new List <Func <int, bool> >());
 }
Пример #8
0
        public static void Execute(ActionId actionId)
        {
#if DEBUG
            Log.Logger.DebugFormat("Action Execute = {0}", actionId);
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
#endif
            try
            {
                IAction action = GetAction(actionId);

                foreach (ActionFlags flag in executeFlags)
                {
                    var f = flag & action.Flags;
                    IActionValidator validator = GetValidator(f);
                    string           error     = validator.Validate();

                    if (!string.IsNullOrWhiteSpace(error))
                    {
                        MessageDialog.Warn(error);
                        return;
                    }
                }

                action.Execute();
#if DEBUG
                sw.Stop();
                Log.Logger.DebugFormat("Action Completed = {0}, {1}", actionId, sw.Elapsed);
#endif
            }
            catch (AggregateException ex)
            {
                ex.Flatten();

                foreach (var e in ex.InnerExceptions)
                {
                    Log.Logger.Warn(e);
                }

                MessageDialog.Error(ex.InnerException.Message);
            }
            catch (InvalidOperationException ex)
            {
                Log.Logger.Warn(ex);
                MessageDialog.Warn(ex.Message);
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex);
                MessageDialog.Error(ex.Message);
            }
        }
Пример #9
0
        private static IActionValidator GetValidator(ActionFlags flag)
        {
            if (validators.ContainsKey(flag))
            {
                return(validators[flag]);
            }

            Type             t         = ActionValidatorAttribute.GetActionValidatorType(flag);
            IActionValidator validator = (IActionValidator)Activator.CreateInstance(t);

            validators.Add(flag, validator);

            return(validator);
        }
Пример #10
0
 public void Setup()
 {
     ActionValidator = new ActionValidator();
 }
 public CSharpDocumentProcessor(object documentContent, int selectedLineNumber, IActionValidator validator)
 {
     _documentContent    = (Document)documentContent;
     _selectedLineNumber = selectedLineNumber;
     _validator          = validator;
 }
Пример #12
0
 public ActionProcessor(BoardGame game)
 {
     _game      = game;
     _validator = new ActionValidator(game);
 }
Пример #13
0
 public void AddValidator(IActionValidator validator)
 {
     validators.Add(validator);
 }
Пример #14
0
 /// <summary>
 ///     Ctor
 /// </summary>
 public ActionsController(IActionsService actionsService, IActionValidator actionValidator)
 {
     _actionsService  = actionsService;
     _actionValidator = actionValidator;
 }