Esempio n. 1
0
 /// <summary>
 /// Adds a screen element to the the screen binder
 /// </summary>
 /// <param name="elementBinder">screen element to add</param>
 public void AddElement(IElementBinder <TObjectType> elementBinder)
 {
     _allElements.Add(elementBinder);
     elementBinder.Changed     += () => Changed();
     elementBinder.Changing    += () => Changing();
     elementBinder.ParentBinder = this;
 }
Esempio n. 2
0
        public override void InitializeBinding()
        {
            _screenBinder       = new ScreenBinder <IParameterDTO>();
            _valueElementBinder = _screenBinder.Bind(p => p.Value)
                                  .To(tbValue);

            _valueElementBinder.OnValueUpdating += (o, e) => ValueChanged(o, e.NewValue);

            _screenBinder.Bind(p => p.DisplayUnit)
            .To(cbUnit)
            .WithValues(p => p.AllUnits)
            .OnValueUpdating += (o, e) => UnitChanged(o, e.NewValue);

            _discreteValueElementBinder = _screenBinder.Bind(p => p.Value)
                                          .To(cbDiscreteValue)
                                          .WithValues(p => p.ListOfValues.Keys)
                                          .AndDisplays(p => p.ListOfValues);

            _discreteValueElementBinder.OnValueUpdating += (o, e) => ValueChanged(o, e.NewValue);

            _screenBinder.Changed += notifyChange;
            RegisterValidationFor(_screenBinder, () => Changing());

            tbValue.EnterMoveNextControl = true;
        }
Esempio n. 3
0
 protected override void Context()
 {
     _source           = new AnImplementation();
     _elementList      = new List <IElementBinder <IAnInterface> >();
     _element1         = A.Fake <IElementBinder <IAnInterface> >();
     _element2         = A.Fake <IElementBinder <IAnInterface> >();
     _validationEngine = A.Fake <IValidationEngine>();
     sut = new ScreenBinder <IAnInterface>(_elementList);
     sut.AddElement(_element1);
     sut.AddElement(_element2);
 }
Esempio n. 4
0
 public INotification GetValidationNotification(IElementBinder <TObject, TPropertyType> elementToValidate)
 {
     try
     {
         return(_validationEngine.Validate(elementToValidate.Source, elementToValidate.PropertyName, elementToValidate.GetValueFromControl()));
     }
     catch (Exception e)
     {
         return(new Notification(e.Message));
     }
 }
Esempio n. 5
0
        public void ValidateElementToScreen(IElementBinder <TObject, TPropertyType> elementToValidate)
        {
            var screenBinder = elementToValidate.ParentBinder;
            var notification = GetValidationNotification(elementToValidate);

            if (notification.HasError())
            {
                screenBinder.SetError(elementToValidate, notification.ErrorNotification);
            }
            else
            {
                screenBinder.ClearError(elementToValidate);
            }
        }
        protected override void Context()
        {
            _source       = A.Fake <IAnInterface>();
            _screenBinder = A.Fake <ScreenBinder <IAnInterface> >();

            _elementToValidate = A.Fake <IElementBinder <IAnInterface, string> >();
            A.CallTo(() => _elementToValidate.Source).Returns(_source);
            A.CallTo(() => _elementToValidate.PropertyName).Returns("FirstName");
            A.CallTo(() => _elementToValidate.GetValueFromControl()).Returns("Toto");
            _elementToValidate.ParentBinder = _screenBinder;

            _validationEngine = A.Fake <IValidationEngine>();
            sut = new ElementBinderValidator <IAnInterface, string>(_validationEngine);
        }
Esempio n. 7
0
 /// <summary>
 /// Removes the element binder from the screen binder. This should only be used in extrem scenarios
 /// This should be called before the bind methods
 /// </summary>
 /// <param name="elementBinder">Screen element to remove</param>
 public void Remove(IElementBinder <TObjectType> elementBinder)
 {
     _allElements.Remove(elementBinder);
 }
Esempio n. 8
0
 /// <summary>
 /// Sets error for the screen element given as parameter
 /// </summary>
 /// <param name="elementBinder">element for which the error provider should be set</param>
 /// <param name="errorMessage">Error message to be displayed by the error provider</param>
 public void SetError(IElementBinder <TObjectType> elementBinder, string errorMessage)
 {
     this.DoWithinLatch(() => OnValidationError(elementBinder.Control, errorMessage));
 }
Esempio n. 9
0
 /// <summary>
 /// Clears error for the screen element given as parameter
 /// </summary>
 /// <param name="elementBinder">element for which the error provider should be cleared</param>
 public void ClearError(IElementBinder <TObjectType> elementBinder)
 {
     this.DoWithinLatch(() => OnValidated(elementBinder.Control));
 }
Esempio n. 10
0
 public bool ElementHasError(IElementBinder <TObject, TPropertyType> elementToValidate)
 {
     return(GetValidationNotification(elementToValidate).HasError());
 }
 public static IElementBinder <TObjectType, TProperty> WithFormat <TObjectType, TProperty>
     (this IElementBinder <TObjectType, TProperty> elementBinder, Func <TProperty, string> format)
 {
     return(elementBinder.WithFormat(new DynamicFormatter <TProperty>(format)));
 }
 public static IElementBinder <TObjectType, TProperty> WithFormat <TObjectType, TProperty>
     (this IElementBinder <TObjectType, TProperty> elementBinder, Func <TObjectType, IFormatter <TProperty> > formatterProvider)
 {
     elementBinder.FormatterConfigurator = new FormatterConfigurator <TObjectType, TProperty>(formatterProvider);
     return(elementBinder);
 }
 public static IElementBinder <TObjectType, TProperty> WithFormat <TObjectType, TProperty>
     (this IElementBinder <TObjectType, TProperty> elementBinder, IFormatter <TProperty> formatter)
 {
     return(elementBinder.WithFormat(source => formatter));
 }