Skip to content

Commit

Permalink
added error notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
bigworld12 committed May 25, 2018
1 parent 1c13b8a commit a1a42d5
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions EZAppz.Core/Notifications/NotifyBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand All @@ -8,7 +9,7 @@
namespace EZAppz.Core
{

public abstract class NotifyBase : DescribableObject, INotifyBase
public abstract class NotifyBase : DescribableObject, INotifyBase, INotifyDataErrorInfo
{

internal protected class PropertyRelation
Expand All @@ -18,6 +19,45 @@ internal protected class PropertyRelation
public HashSet<Action> RelatedChangingActions { get; } = new HashSet<Action>();
}
private Dictionary<string, PropertyRelation> PropertyRelations { get; } = new Dictionary<string, PropertyRelation>();


private Dictionary<string, List<string>> Errors = new Dictionary<string, List<string>>();
public bool HasErrors => Errors.Any(x => x.Value.Count > 0);

public IEnumerable GetErrors(string propertyName)
{
if (Errors.TryGetValue(propertyName, out var l))
return l;
return null;
}
public void RaiseErrorChanged(string propertyName)
{
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
}
public void RaiseError(string error, [CallerMemberName] string prop = null)
{
if (Errors.ContainsKey(prop))
{
Errors[prop].Add(error);
}
else
{
Errors[prop] = new List<string>() { error };
}
RaiseErrorChanged(prop);
}
public void ClearErrors([CallerMemberName]string prop = null)
{
if (Errors.ContainsKey(prop))
{
Errors[prop].Clear();
}
}
public void ClearAllErrors()
{
Errors.Clear();
}

public NotifyBase(bool ImportFromReflection = false) : base(ImportFromReflection)
{
PropertyChanged += NotifyBase_PropertyChanged;
Expand Down Expand Up @@ -137,11 +177,13 @@ public void RaisePropertyChanging([CallerMemberName] string prop = null)
{
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(prop));
}


[field: NonSerialized]
public event PropertyChangingEventHandler PropertyChanging;
[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;
[field: NonSerialized]
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
}
}

0 comments on commit a1a42d5

Please sign in to comment.