Ejemplo n.º 1
0
 /// <summary>
 /// Triggers the ValidatePath event.
 /// </summary>
 public virtual void CallValidatePath(ValidationArgs ea)
 {
     if (m_ValidatePath != null)
     {
         m_ValidatePath(this, ea);
     }
 }
Ejemplo n.º 2
0
        protected virtual void SaveCollection(SaveModeArgs obj)
        {
            obj.SetRow(_selectedItem);
            if (ViewService.ViewMode.Peek() == FormMode.SAVED)
            {
                var mode = ViewService.ViewMode.Pop();
                if (mode == FormMode.ADDMODE)
                {
                    AddToCollection(null);
                }
                //if we save then add

                return;
            }
            ValidationResult validation = ValidateVm();

            if (validation.IsValid)
            {
                if (!DataStoreContainsDuplicates(obj))
                {
                    if (ViewService.ViewMode.Peek() == FormMode.VALIDATION)
                    {
                        ViewService.ViewMode.Pop();
                    }
                    IsReadOnly = true;
                    VmData.Add(_selectedItem);
                    DoSave(obj);
                    //drop wip and then add saved

                    if (ViewService.ViewMode.Peek() == FormMode.SAVED)
                    {
                        ViewService.ViewMode.Pop();
                        ViewService.IsDirty = true;
                    }

                    if (ViewService.ViewMode.Peek() == FormMode.WIP)
                    {
                        ViewService.ViewMode.Pop();
                    }
                }

                else
                {
                    if (ViewService.ViewMode.Peek() != FormMode.WIP)
                    {
                        SendMessageBox("Duplicate Error Warning", "Duplicates not allowed");
                    }
                    IsReadOnly = false;
                }
            }
            else
            {
                var msg = new ValidationArgs();
                msg.Validation = validation.ErrorList;
                eventAggregator.GetEvent <ValidationArgsEvent>().Publish(msg);
            }
        }
Ejemplo n.º 3
0
        void FocusInvalidControl(ValidationArgs args)
        {
            Control control = args.Control as Control;

            if (control != null)
            {
                control.Focus();
            }
        }
Ejemplo n.º 4
0
        public void ValidatePath_ValidValidator_ValidatePathIsCalled()
        {
            ILinkerView     view      = MockRepository.GenerateMock <ILinkerView>();
            IPathValidation validator = MockRepository.GenerateMock <IPathValidation>();
            ValidationArgs  args      = new ValidationArgs("test");

            MainController controller = new MainController(view, validator, null, null, null);

            controller.ValidatePath(view, args);

            validator.AssertWasCalled(v => v.ValidPath(Arg <String> .Matches(s => s.Equals("test")), out Arg <String> .Out("").Dummy));
        }
        public List <Error> Validate(ValidationArgs args)
        {
            var result = new List <Error>();

            if (!string.IsNullOrWhiteSpace(args.Description) &&
                args.Description.Length > Validator.MaximumNumberOfCharacters)
            {
                result.Add(Error.With(nameof(args.Description), ErrorCodes.InvalidLength));
            }

            return(result);
        }
Ejemplo n.º 6
0
        public void ValidatePath(object sender, ValidationArgs e)
        {
            String errorMessage;

            if (_pathValidator.ValidPath(e.PathToValidate, out errorMessage))
            {
                e.Valid = true;
            }
            else
            {
                e.Valid       = false;
                e.ErrorMessge = errorMessage;
            }
        }
Ejemplo n.º 7
0
        public List <Error> Validate(ValidationArgs args)
        {
            var result = new List <Error>();

            if (string.IsNullOrWhiteSpace(args.Title))
            {
                result.Add(Error.With(nameof(args.Title), ErrorCodes.Required));
            }
            else if (args.Title.Length > Validator.MaximumNumberOfCharacters)
            {
                result.Add(Error.With(nameof(args.Title), ErrorCodes.InvalidLength));
            }

            return(result);
        }
Ejemplo n.º 8
0
        public ServiceExecutionResult Create(TodoCreationArgs todoCreationArgs)
        {
            var validationArgs = new ValidationArgs(todoCreationArgs.Title, todoCreationArgs.Description);
            var errors         = validator.Validate(validationArgs);

            if (errors.IsNotEmpty())
            {
                return(ServiceExecutionResult.WithErrors(errors));
            }

            var todo = new Create.Models.Todo(todoCreationArgs.Title, todoCreationArgs.Description);

            repository.Save(todo);

            return(ServiceExecutionResult.WithSucess());
        }
Ejemplo n.º 9
0
        void btnOK_Click(object sender, System.EventArgs e)
        {
            ValidationArgs args = new ValidationArgs();

            currentRecurrenceControl.ValidateValues(args);
            if (args.Valid)
            {
                args = new ValidationArgs();
                currentRecurrenceControl.CheckForWarnings(args);
                if (!args.Valid)
                {
                    DialogResult answer = MessageBox.Show(this, args.ErrorMessage,
                                                          Application.ProductName, MessageBoxButtons.OKCancel,
                                                          MessageBoxIcon.Question);
                    if (answer == DialogResult.OK)
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        if (args.Control != null)
                        {
                            ((Control)args.Control).Focus();
                        }
                    }
                }
                else
                {
                    // Apply changes to the appointment recurrence pattern.
                    controller.ApplyRecurrence(patternCopy);
                }
                // Apply changes to the original appointment.
                controller.ApplyChanges();
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(this, args.ErrorMessage, Application.ProductName,
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                if (args.Control != null)
                {
                    ((Control)args.Control).Focus();
                }
            }
        }
Ejemplo n.º 10
0
        private void OnValidation(ValidationArgs obj)
        {
            var sb = new StringBuilder();
            int i  = 0;

            while (i < obj.Validation.Count)
            {
                sb.Append(i + 1 + ".");
                sb.Append(obj.Validation[i].ErrorText);
                sb.Append(Environment.NewLine);
                i++;
            }
            var msg = new NotificationMessage();

            msg.Message = sb.ToString();
            msg.Title   = "Validation Error";
            RaiseNotification(msg);
        }
Ejemplo n.º 11
0
        private Boolean ValidateEditor(TextBox textBox)
        {
            var validEA = new ValidationArgs(textBox.Text);

            CallValidatePath(validEA);

            if (!validEA.Valid)
            {
                ErrorProvider.SetError(textBox, "Please enter a valid path");
                textBox.TextChanged += RealTimeValidation;
            }
            else
            {
                ErrorProvider.SetError(textBox, String.Empty);
                textBox.TextChanged -= RealTimeValidation;
            }

            return(validEA.Valid);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sets the validator instance.
        /// </summary>
        /// <param name="validator">The validator instance.</param>
        public void SetValidator(object validator)
        {
            if (validator == null)
            {
                throw new ArgumentNullException(nameof(validator));
            }

            Type gt = typeof(ValidatorBase <>).MakeGenericType(new Type[] { Type });

            if (!validator.GetType().GetTypeInfo().IsSubclassOf(gt))
            {
                throw new ArgumentException($"Validator '{Type.Name}' must be a subclass of '{gt.FullName}'.", nameof(validator));
            }

            _validator      = validator;
            _validateMI     = validator.GetType().GetMethod("Validate", new Type[] { Type, typeof(ValidationArgs) });
            _validationArgs = new ValidationArgs()
            {
                ShallowValidation = true
            };
        }
Ejemplo n.º 13
0
        public ServiceExecutionResult Update(TodoUpdatingArgs todoUpdatingArgs)
        {
            var validationArgs = new ValidationArgs(todoUpdatingArgs.Title, todoUpdatingArgs.Description);
            var errors         = validator.Validate(validationArgs);

            if (errors.IsNotEmpty())
            {
                return(ServiceExecutionResult.WithErrors(errors));
            }

            if (IsNotExistTodo(todoUpdatingArgs.Id))
            {
                return(ServiceExecutionResult.WithErrors(new List <Error> {
                    Error.With(nameof(todoUpdatingArgs.Id), ErrorCodes.NotFound)
                }));
            }

            var todo = findTodoRepository.FindById(todoUpdatingArgs.Id);

            todo.Update(validationArgs.Title, validationArgs.Description);
            updateTodoRepository.Update(todo);
            return(ServiceExecutionResult.WithSucess());
        }
Ejemplo n.º 14
0
        void OnOKButtonClick(object sender, RoutedEventArgs e)
        {
            if (edtEndDate.HasValidationError || edtEndTime.HasValidationError)
            {
                return;
            }
            ValidationArgs args = new ValidationArgs();

            SchedulerFormHelper.ValidateValues(this, args);
            if (!args.Valid)
            {
                DXMessageBox.Show(args.ErrorMessage, System.Windows.Forms.Application.ProductName, System.Windows.MessageBoxButton.OK, MessageBoxImage.Exclamation);
                FocusInvalidControl(args);
                return;
            }
            SchedulerFormHelper.CheckForWarnings(this, args);
            if (!args.Valid)
            {
                MessageBoxResult answer = DXMessageBox.Show(args.ErrorMessage, System.Windows.Forms.Application.ProductName, System.Windows.MessageBoxButton.OKCancel, MessageBoxImage.Question);
                if (answer == MessageBoxResult.Cancel)
                {
                    FocusInvalidControl(args);
                    return;
                }
            }
            if (!controller.IsConflictResolved())
            {
                DXMessageBox.Show(SchedulerLocalizer.GetString(SchedulerStringId.Msg_Conflict), System.Windows.Forms.Application.ProductName, System.Windows.MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            if (ShouldShowRecurrence)
            {
                RecurrenceVisualController.ApplyRecurrence();
            }
            Controller.ApplyChanges();
            CloseForm(true);
        }