Exemplo n.º 1
0
        public void Validate(string propertyName)
        {
            Base.Enumerations.ErrorLevel prevState = _RuleMap[propertyName].ErrorLevel;
            _RuleMap[propertyName].Update();
            if (prevState != _RuleMap[propertyName].ErrorLevel)
            {
                //a change occured.

                ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
                Base.Enumerations.ErrorLevel currState = _RuleMap[propertyName].ErrorLevel;

                //check if it is the biggest one.
                bool biggerErrorsExist = false;
                foreach (string s in _RuleMap.Keys)
                {
                    if (_RuleMap[s].ErrorLevel > currState)
                    {
                        biggerErrorsExist = true;
                    }
                }
                if (!biggerErrorsExist)
                {
                    if (currState == Base.Enumerations.ErrorLevel.Unassigned) _errorLevel = currState;
                    if (_errorLevel > Base.Enumerations.ErrorLevel.Unassigned)
                    {
                        _errorLevel = _errorLevel | currState;
                    }
                    else
                    {
                        _errorLevel = currState;
                    }
                }
                if ((currState ^ prevState) > 0) { NotifyPropertyChanged(nameof(HasErrors)); if (ErrorsAction is ViewModel.Interfaces.IDisplayToUI) { ((ViewModel.Interfaces.IDisplayToUI)ErrorsAction).IsEnabled = HasErrors; } }
            }
        }
Exemplo n.º 2
0
        public void Update()
        {
            _errors     = new List <string>();
            _errorLevel = Base.Enumerations.ErrorLevel.Unassigned;
            try
            {
                foreach (Rule r in _rules)
                {
                    if (!r.Expression())
                    {
                        _errors.Add(r.Message);
                        if (_errorLevel > Base.Enumerations.ErrorLevel.Unassigned)
                        {
                            _errorLevel = _errorLevel | r.ErrorLevel;
                        }
                        else
                        {
                            _errorLevel = r.ErrorLevel;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _errors.Add(e.Message);

                //NotifyPropertyChanged(nameof(Error));
                //if(HasError != prevState) { NotifyPropertyChanged(nameof(HasError)); }
            }
            //if (_Error != prevError) { NotifyPropertyChanged(nameof(Error)); }
            //if (HasError != prevState) { NotifyPropertyChanged(nameof(HasError)); }
        }
Exemplo n.º 3
0
 public static void Unsubscribe(Base.Interfaces.IRecieveMessages listener, Base.Enumerations.ErrorLevel filterLevel, System.Type senderFilterType, System.Type messageFilterType)
 {
     foreach (Base.Interfaces.IRecieveMessages s in _subscribers)
     {
         if (s == listener && s.FilterLevel == filterLevel && s.SenderTypeFilter == senderFilterType && s.MessageTypeFilter == messageFilterType)
         {
             _subscribers.Remove(s);
         }
     }
 }
Exemplo n.º 4
0
 public void Validate()
 {
     _Errors = new List<string>();
     Base.Enumerations.ErrorLevel prevErrorState = _errorLevel;
     _errorLevel = Base.Enumerations.ErrorLevel.Unassigned;
     foreach (string s in _RuleMap.Keys)
     {
         _RuleMap[s].Update();
         if (_RuleMap[s].ErrorLevel > Base.Enumerations.ErrorLevel.Unassigned)
         {
             if (_errorLevel > Base.Enumerations.ErrorLevel.Unassigned)
             {
                 _errorLevel = _RuleMap[s].ErrorLevel;
             }
             else
             {
                 _errorLevel = _errorLevel | _RuleMap[s].ErrorLevel;
             }
             _Errors.AddRange(_RuleMap[s].Errors);
         }
     }
     if (_errorLevel > Base.Enumerations.ErrorLevel.Unassigned)
     {
         //errors exist
         if (_errorLevel != prevErrorState)
         {
             Base.Enumerations.ErrorLevel changed = _errorLevel ^ prevErrorState;
             NotifyPropertyChanged(nameof(HasErrors));
             if (ErrorsAction is ViewModel.Interfaces.IDisplayToUI) { ((ViewModel.Interfaces.IDisplayToUI)ErrorsAction).IsEnabled = HasErrors; }
             foreach (Base.Enumerations.ErrorLevel e in Enum.GetValues(typeof(Base.Enumerations.ErrorLevel)))
             {
                 if ((changed & e) > 0)
                 {
                     if ((_errorLevel & e) > 0)
                     {
                         //turned on
                     }
                     else
                     {
                         //turned off
                     }
                 }
             }
         }
     }
     else
     {
         //no errors exist
         if (_errorLevel != prevErrorState)
         {
             NotifyPropertyChanged(nameof(HasErrors));//errors no longer exist
             if (ErrorsAction is ViewModel.Interfaces.IDisplayToUI) { ((ViewModel.Interfaces.IDisplayToUI)ErrorsAction).IsEnabled = HasErrors; }
         }
     }
 }
Exemplo n.º 5
0
 public DebuggingErrorMessage(string message, Base.Enumerations.ErrorLevel errorLevel, [System.Runtime.CompilerServices.CallerMemberNameAttribute] string memberName = "", [System.Runtime.CompilerServices.CallerFilePathAttribute] string filePath = "", [System.Runtime.CompilerServices.CallerLineNumberAttribute] int lineNo = 0) : base(message, errorLevel)
 {
     _callingMethod = memberName;
     _callingClass  = filePath.Split(new char[] { '\\' }).Last();
     _callingLine   = lineNo;
 }
 public TimeStampedErrorMessage(string message, Base.Enumerations.ErrorLevel errorLevel) : base(message, errorLevel)
 {
     _DateTime = DateTime.Now;
 }
Exemplo n.º 7
0
 public Rule(Func <bool> expr, string msg, Base.Enumerations.ErrorLevel errorLevel)
 {
     _expression = expr;
     _message    = msg;
     _errorLevel = errorLevel;
 }