Skip to content

Commit 288ee05

Browse files
author
zzzprojects
committed
Update to v1.4.10
Update to v1.4.10
1 parent 03d4c66 commit 288ee05

File tree

86 files changed

+2692
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2692
-100
lines changed

src/Z.EntityFramework.Plus.EF5.NET40/Audit/AuditConfiguration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System;
99
using System.Collections.Concurrent;
1010
using System.Collections.Generic;
11+
1112
#if EF5
1213
using System.Data.Entity;
1314
using System.Data.Objects;
@@ -47,6 +48,9 @@ public AuditConfiguration()
4748
#endif
4849
}
4950

51+
internal Func<Type, string> EntityNameFactory { get; set; }
52+
internal Func<Type, string, string> PropertyNameFactory { get; set; }
53+
5054
/// <summary>Gets or sets the audit entry factory.</summary>
5155
/// <value>The audit entry factory.</value>
5256
public Func<AuditEntryFactoryArgs, AuditEntry> AuditEntryFactory { get; set; }
@@ -133,6 +137,9 @@ public AuditConfiguration Clone()
133137
{
134138
var audit = new AuditConfiguration
135139
{
140+
EntityNameFactory = EntityNameFactory,
141+
PropertyNameFactory = PropertyNameFactory,
142+
136143
AuditEntryFactory = AuditEntryFactory,
137144
AuditEntryPropertyFactory = AuditEntryPropertyFactory,
138145
AutoSavePreAction = AutoSavePreAction,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Reflection;
3+
#if EFCORE
4+
using System.Linq;
5+
6+
#endif
7+
8+
namespace Z.EntityFramework.Plus
9+
{
10+
public partial class AuditConfiguration
11+
{
12+
public void DataAnnotationDisplayName()
13+
{
14+
EntityNameFactory = DataAnnotationEntityDisplayName;
15+
PropertyNameFactory = DataAnnotationPropertyDisplayName;
16+
}
17+
18+
internal string DataAnnotationEntityDisplayName(Type o)
19+
{
20+
#if EF5 || EF6
21+
var attributes = o.GetCustomAttributes(typeof(AuditDisplayAttribute), true);
22+
#elif EFCORE
23+
var attributes = o.GetTypeInfo().GetCustomAttributes(typeof (AuditDisplayAttribute), true).ToArray();
24+
#endif
25+
26+
if (attributes.Length > 0)
27+
{
28+
return ((AuditDisplayAttribute) attributes[0]).Name;
29+
}
30+
31+
return o.Name;
32+
}
33+
34+
internal string DataAnnotationPropertyDisplayName(Type o, string memberName)
35+
{
36+
try
37+
{
38+
MemberInfo member = o.GetProperty(memberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
39+
40+
if (member == null)
41+
{
42+
member = o.GetField(memberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
43+
}
44+
45+
if (member == null)
46+
{
47+
// Oops! member not found
48+
return memberName;
49+
}
50+
51+
#if EF5 || EF6
52+
var attributes = member.GetCustomAttributes(typeof(AuditDisplayAttribute), true);
53+
#elif EFCORE
54+
var attributes = member.GetCustomAttributes(typeof (AuditDisplayAttribute), true).ToArray();
55+
#endif
56+
57+
if (attributes.Length > 0)
58+
{
59+
return ((AuditDisplayAttribute) attributes[0]).Name;
60+
}
61+
62+
return member.Name;
63+
}
64+
catch (Exception)
65+
{
66+
// Could probably happen in case of an indexed property
67+
return memberName;
68+
}
69+
}
70+
}
71+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Reflection;
3+
4+
#if EF5
5+
using System.Data.Objects;
6+
7+
#elif EF6
8+
using System.Data.Entity.Core.Objects;
9+
10+
#elif EFCORE
11+
using System.Linq;
12+
13+
#endif
14+
15+
namespace Z.EntityFramework.Plus
16+
{
17+
public partial class AuditConfiguration
18+
{
19+
public void ExcludeDataAnnotation()
20+
{
21+
Exclude(o =>
22+
{
23+
#if EF5 || EF6
24+
var type = ObjectContext.GetObjectType(o.GetType());
25+
var attributes = type.GetCustomAttributes(typeof(AuditExcludeAttribute), true);
26+
#elif EFCORE
27+
var type = o.GetType();
28+
var attributes = type.GetTypeInfo().GetCustomAttributes(typeof (AuditExcludeAttribute), true).ToArray();
29+
#endif
30+
31+
return attributes.Length != 0;
32+
});
33+
34+
ExcludeIncludePropertyPredicates.Add((o, s) =>
35+
{
36+
try
37+
{
38+
#if EF5 || EF6
39+
var type = ObjectContext.GetObjectType(o.GetType());
40+
#elif EFCORE
41+
var type = o.GetType();
42+
#endif
43+
44+
MemberInfo member = type.GetProperty(s, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
45+
46+
if (member == null)
47+
{
48+
member = type.GetField(s, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
49+
}
50+
51+
if (member == null)
52+
{
53+
return null;
54+
}
55+
56+
#if EF5 || EF6
57+
var attributes = member.GetCustomAttributes(typeof (AuditExcludeAttribute), true);
58+
#elif EFCORE
59+
var attributes = member.GetCustomAttributes(typeof (AuditExcludeAttribute), true).ToArray();
60+
#endif
61+
62+
if (attributes.Length > 0)
63+
{
64+
return false;
65+
}
66+
67+
return null;
68+
}
69+
catch (Exception)
70+
{
71+
return null;
72+
}
73+
});
74+
}
75+
}
76+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Reflection;
3+
4+
#if EF5
5+
using System.Data.Objects;
6+
7+
#elif EF6
8+
using System.Data.Entity.Core.Objects;
9+
10+
#elif EFCORE
11+
using System.Linq;
12+
13+
#endif
14+
15+
namespace Z.EntityFramework.Plus
16+
{
17+
public partial class AuditConfiguration
18+
{
19+
public void IncludeDataAnnotation()
20+
{
21+
Include(o =>
22+
{
23+
#if EF5 || EF6
24+
var type = ObjectContext.GetObjectType(o.GetType());
25+
var attributes = type.GetCustomAttributes(typeof(AuditIncludeAttribute), true);
26+
#elif EFCORE
27+
var type = o.GetType();
28+
var attributes = type.GetTypeInfo().GetCustomAttributes(typeof (AuditIncludeAttribute), true).ToArray();
29+
#endif
30+
31+
return attributes.Length != 0;
32+
});
33+
34+
ExcludeIncludePropertyPredicates.Add((o, s) =>
35+
{
36+
try
37+
{
38+
#if EF5 || EF6
39+
var type = ObjectContext.GetObjectType(o.GetType());
40+
#elif EFCORE
41+
var type = o.GetType();
42+
#endif
43+
44+
MemberInfo member = type.GetProperty(s, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
45+
46+
if (member == null)
47+
{
48+
member = type.GetField(s, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
49+
}
50+
51+
if (member == null)
52+
{
53+
return null;
54+
}
55+
56+
#if EF5 || EF6
57+
var attributes = member.GetCustomAttributes(typeof(AuditIncludeAttribute), true);
58+
#elif EFCORE
59+
var attributes = member.GetCustomAttributes(typeof (AuditIncludeAttribute), true).ToArray();
60+
#endif
61+
62+
if (attributes.Length > 0)
63+
{
64+
return true;
65+
}
66+
67+
return null;
68+
}
69+
catch (Exception)
70+
{
71+
return null;
72+
}
73+
});
74+
}
75+
}
76+
}

src/Z.EntityFramework.Plus.EF5.NET40/Audit/AuditEntry.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public void Build(Audit parent, EntityEntry entry)
6969
{
7070
if (!entry.IsRelationship)
7171
{
72-
EntityTypeName = ObjectContext.GetObjectType(entry.Entity.GetType()).Name;
72+
EntityTypeName = parent.CurrentOrDefaultConfiguration.EntityNameFactory != null ?
73+
parent.CurrentOrDefaultConfiguration.EntityNameFactory(ObjectContext.GetObjectType(entry.Entity.GetType())) :
74+
ObjectContext.GetObjectType(entry.Entity.GetType()).Name;
7375
}
7476
}
7577

src/Z.EntityFramework.Plus.EF5.NET40/Audit/AuditEntryProperty.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
using System.ComponentModel.DataAnnotations;
1010
using System.ComponentModel.DataAnnotations.Schema;
1111

12+
#if EF5
13+
using System.Data.Objects;
14+
15+
#elif EF6
16+
using System.Data.Entity.Core.Objects;
17+
18+
#endif
19+
1220
namespace Z.EntityFramework.Plus
1321
{
1422
/// <summary>An audit entry property.</summary>
@@ -41,7 +49,15 @@ public void Build(AuditEntry parent, string relationName, string propertyName, o
4149

4250
if (PropertyName == null)
4351
{
44-
PropertyName = propertyName;
52+
#if EF5 || EF6
53+
PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null ?
54+
parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory(ObjectContext.GetObjectType(parent.Entry.Entity.GetType()), propertyName) :
55+
propertyName;
56+
#elif EFCORE
57+
PropertyName = parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory != null ?
58+
parent.Parent.CurrentOrDefaultConfiguration.PropertyNameFactory(parent.Entry.Entity.GetType(), propertyName) :
59+
propertyName;
60+
#endif
4561
}
4662

4763
if (RelationName == null)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace Z.EntityFramework.Plus
4+
{
5+
[AttributeUsage(AttributeTargets.All)]
6+
public class AuditDisplayAttribute : Attribute
7+
{
8+
public AuditDisplayAttribute(string name)
9+
{
10+
Name = name;
11+
}
12+
13+
public string Name { get; set; }
14+
}
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Z.EntityFramework.Plus
4+
{
5+
[AttributeUsage(AttributeTargets.All)]
6+
public class AuditExcludeAttribute : Attribute
7+
{
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Z.EntityFramework.Plus
4+
{
5+
[AttributeUsage(AttributeTargets.All)]
6+
public class AuditIncludeAttribute : Attribute
7+
{
8+
}
9+
}

src/Z.EntityFramework.Plus.EF5.NET40/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
[assembly: AssemblyCulture("")]
1919
[assembly: ComVisible(false)]
2020
[assembly: Guid("e4c2af73-caeb-4429-bcb6-0a359484e064")]
21-
[assembly: AssemblyVersion("1.4.9")]
22-
[assembly: AssemblyFileVersion("1.4.9")]
21+
[assembly: AssemblyVersion("1.4.10")]
22+
[assembly: AssemblyFileVersion("1.4.10")]

0 commit comments

Comments
 (0)