Skip to content

Commit

Permalink
Update GitHub with latest source
Browse files Browse the repository at this point in the history
Update GitHub with latest source
  • Loading branch information
JonathanMagnan committed Aug 8, 2024
1 parent 544ade2 commit ae0558d
Show file tree
Hide file tree
Showing 47 changed files with 763 additions and 191 deletions.
20 changes: 20 additions & 0 deletions src/shared/Z.EF.Plus.Audit.Shared/AuditConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#elif EF6
using System.Data.Entity;
using System.Data.Entity.Core.Objects;

#elif EFCORE
using Microsoft.EntityFrameworkCore;
Expand All @@ -34,6 +35,12 @@ public AuditConfiguration()

EntityValueFormatters = new List<Func<object, string, object, Func<object, object>>>();
ExcludeIncludeEntityPredicates = new List<Func<object, bool?>>();
#if EF5 || EF6
ExcludeIncludeByInstanceEntityPredicates = new List<Func<ObjectStateEntry, bool?>>();
#elif EFCORE
ExcludeIncludeByInstanceEntityPredicates = new List<Func<EntityEntry, bool?>>();
#endif

ExcludeIncludePropertyPredicates = new List<Func<object, string, bool?>>();

SoftAddedPredicates = new List<Func<object, bool>>();
Expand Down Expand Up @@ -72,6 +79,14 @@ public AuditConfiguration()
/// <value>A list of predicates to exclude or include entities.</value>
public List<Func<object, bool?>> ExcludeIncludeEntityPredicates { get; set; }

/// <summary>Gets or sets a list of predicates to exclude or include by instance entities.</summary>
/// <value>A list of predicates to exclude or include by instance entities.</value>
#if EF5 || EF6
public List<Func<ObjectStateEntry, bool?>> ExcludeIncludeByInstanceEntityPredicates { get; set; }
#elif EFCORE
public List<Func<EntityEntry, bool?>> ExcludeIncludeByInstanceEntityPredicates { get; set; }
#endif

/// <summary>Gets or sets a list of predicates to exclude or include properties.</summary>
/// <value>A list of predicates to exclude or include properties.</value>
public List<Func<object, string, bool?>> ExcludeIncludePropertyPredicates { get; set; }
Expand Down Expand Up @@ -179,6 +194,11 @@ public AuditConfiguration Clone()
IgnoreRelationshipDeleted = IgnoreRelationshipDeleted,
EntityValueFormatters = new List<Func<object, string, object, Func<object, object>>>(EntityValueFormatters),
ExcludeIncludeEntityPredicates = new List<Func<object, bool?>>(ExcludeIncludeEntityPredicates),
#if EF5 || EF6
ExcludeIncludeByInstanceEntityPredicates = new List<Func<ObjectStateEntry, bool?>>(ExcludeIncludeByInstanceEntityPredicates),
#elif EFCORE
ExcludeIncludeByInstanceEntityPredicates = new List<Func<EntityEntry, bool?>>(ExcludeIncludeByInstanceEntityPredicates),
#endif
ExcludeIncludePropertyPredicates = new List<Func<object, string, bool?>>(ExcludeIncludePropertyPredicates),
SoftAddedPredicates = new List<Func<object, bool>>(SoftAddedPredicates),
SoftDeletedPredicates = new List<Func<object, bool>>(SoftDeletedPredicates),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

using System;

#if EF5
using System.Data.Entity;
using System.Data.Objects;

#elif EF6
using System.Data.Entity;
using System.Data.Entity.Core.Objects;

#elif EFCORE
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;

#endif

namespace Z.EntityFramework.Plus
{
public partial class AuditConfiguration
{
/// <summary>Excludes (by entity entry) from the audit all entities which satisfy the predicate.</summary>
/// <param name="excludeEntityPredicate">The exclude entity predicate.</param>
/// <returns>An AuditConfiguration.</returns>
#if EF5 || EF6
public AuditConfiguration ExcludeByEntry(Func<ObjectStateEntry, bool> excludeEntityPredicate)
#elif EFCORE
public AuditConfiguration ExcludeByEntry(Func<EntityEntry, bool> excludeEntityPredicate)
#endif

{
ExcludeIncludeByInstanceEntityPredicates.Add(x => excludeEntityPredicate(x) ? (bool?) false : null);
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

using System;

namespace Z.EntityFramework.Plus
{
public partial class AuditConfiguration
{
/// <summary>Excludes (by entity instance) from the audit all entities which satisfy the predicate.</summary>
/// <param name="excludeEntityPredicate">The exclude entity predicate.</param>
/// <returns>An AuditConfiguration.</returns>
public AuditConfiguration ExcludeByInstance(Func<object, bool> excludeEntityPredicate)
{
ExcludeIncludeByInstanceEntityPredicates.Add(x => excludeEntityPredicate(x.Entity) ? (bool?)false : null);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace Z.EntityFramework.Plus
{
public partial class AuditConfiguration
{
/// <summary>Excludes from the audit all entities which satisfy the predicate.</summary>

/// <summary>Excludes (by entity type) from the audit all entities which satisfy the predicate.</summary>
/// <param name="excludeEntityPredicate">The exclude entity predicate.</param>
/// <returns>An AuditConfiguration.</returns>
public AuditConfiguration Exclude(Func<object, bool> excludeEntityPredicate)
Expand All @@ -20,7 +21,7 @@ public AuditConfiguration Exclude(Func<object, bool> excludeEntityPredicate)
return this;
}

/// <summary>Excludes from the audit all entities of 'T' type or entities which the type derive from 'T'.</summary>
/// <summary>Excludes (by entity type) from the audit all entities of 'T' type or entities which the type derive from 'T'.</summary>
/// <typeparam name="T">Generic type to exclude.</typeparam>
/// <returns>An AuditConfiguration.</returns>
public AuditConfiguration Exclude<T>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

using System;

#if EF5
using System.Data.Entity;
using System.Data.Objects;

#elif EF6
using System.Data.Entity;
using System.Data.Entity.Core.Objects;

#elif EFCORE
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;

#endif

namespace Z.EntityFramework.Plus
{
public partial class AuditConfiguration
{
/// <summary>Includes (by entity entry) from the audit all entities which satisfy the predicate.</summary>
/// <param name="includeEntityPredicate">The include entity predicate.</param>
/// <returns>An AuditConfiguration.</returns>
#if EF5 || EF6
public AuditConfiguration IncludeByEntry(Func<ObjectStateEntry, bool> includeEntityPredicate)
#elif EFCORE
public AuditConfiguration IncludeByEntry(Func<EntityEntry, bool> includeEntityPredicate)
#endif

{
ExcludeIncludeByInstanceEntityPredicates.Add(x => includeEntityPredicate(x) ? (bool?)true : null);
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.

using System;

namespace Z.EntityFramework.Plus
{
public partial class AuditConfiguration
{
/// <summary>Includes (by entity instance) from the audit all entities which satisfy the predicate.</summary>
/// <param name="includeEntityPredicate">The include entity predicate.</param>
/// <returns>An AuditConfiguration.</returns>
public AuditConfiguration IncludeByInstance(Func<object, bool> includeEntityPredicate)
{
ExcludeIncludeByInstanceEntityPredicates.Add(x => includeEntityPredicate(x.Entity) ? (bool?) true : null);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Z.EntityFramework.Plus
{
public partial class AuditConfiguration
{
/// <summary>Includes from the audit all entities which satisfy the predicate.</summary>
/// <summary>Includes (by entity type) from the audit all entities which satisfy the predicate.</summary>
/// <param name="includeEntityPredicate">The include entity predicate.</param>
/// <returns>An AuditConfiguration.</returns>
public AuditConfiguration Include(Func<object, bool> includeEntityPredicate)
Expand All @@ -20,7 +20,7 @@ public AuditConfiguration Include(Func<object, bool> includeEntityPredicate)
return this;
}

/// <summary>Includes from the audit all entities of 'T' type or entities which the type derive from 'T'.</summary>
/// <summary>Includes (by entity type) from the audit all entities of 'T' type or entities which the type derive from 'T'.</summary>
/// <typeparam name="T">Generic type to include.</typeparam>
/// <returns>An AuditConfiguration.</returns>
public AuditConfiguration Include<T>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public bool IsAuditedEntity(ObjectStateEntry entry)
public bool IsAuditedEntity(EntityEntry entry)
#endif
{
if (ExcludeIncludeEntityPredicates.Count == 0 || entry.Entity == null)
if (entry.Entity == null
|| (ExcludeIncludeEntityPredicates.Count == 0 && ExcludeIncludeByInstanceEntityPredicates.Count == 0))
{
return true;
}
Expand All @@ -54,6 +55,15 @@ public bool IsAuditedEntity(EntityEntry entry)
IsAuditedDictionary.TryAdd(key, value);
}

foreach(var excludeIncludeByInstanceEntityFunc in ExcludeIncludeByInstanceEntityPredicates)
{
var maybeIncluded = excludeIncludeByInstanceEntityFunc(entry);
if (maybeIncluded.HasValue)
{
value = maybeIncluded.Value;
}
}

return value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="SharedProjectFile_SccProperties">
<SharedProjectFile_ProjectGuid>{2ad53f92-e59b-4cba-b195-62918e6865fb}</SharedProjectFile_ProjectGuid>
<SharedProjectFile_SccProjectName>SAK</SharedProjectFile_SccProjectName>
<SharedProjectFile_SccAuxPath>SAK</SharedProjectFile_SccAuxPath>
<SharedProjectFile_SccLocalPath>SAK</SharedProjectFile_SccLocalPath>
<SharedProjectFile_SccProvider>SAK</SharedProjectFile_SccProvider>
<SharedProjectFile_SccProjectName></SharedProjectFile_SccProjectName>
<SharedProjectFile_SccAuxPath></SharedProjectFile_SccAuxPath>
<SharedProjectFile_SccLocalPath></SharedProjectFile_SccLocalPath>
<SharedProjectFile_SccProvider></SharedProjectFile_SccProvider>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
Expand All @@ -19,8 +19,12 @@
<Compile Include="$(MSBuildThisFileDirectory)Audit.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\DisplayNameDataAnnotation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\ExcludeByEntry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\ExcludeDataAnnotation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\ExcludeByInstance.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\ExcludeEntity.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\IncludeByEntry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\IncludeByInstance.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\MetaProperty.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\ExcludeProperty.cs" />
<Compile Include="$(MSBuildThisFileDirectory)AuditConfiguration\Format.cs" />
Expand Down
12 changes: 8 additions & 4 deletions src/shared/Z.EF.Plus.Audit.Shared/Z.EF.Plus.Audit.Shared.shproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
<PropertyGroup Label="Globals">
<ProjectGuid>6bfa5473-a429-4f9e-aa40-1387716de22d</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<SccProjectName>
</SccProjectName>
<SccProvider>
</SccProvider>
<SccAuxPath>
</SccAuxPath>
<SccLocalPath>
</SccLocalPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="SharedProjectFile_SccProperties">
<SharedProjectFile_ProjectGuid>{868b0e69-fb31-4d58-949c-fbf0f476d36c}</SharedProjectFile_ProjectGuid>
<SharedProjectFile_SccProjectName>SAK</SharedProjectFile_SccProjectName>
<SharedProjectFile_SccAuxPath>SAK</SharedProjectFile_SccAuxPath>
<SharedProjectFile_SccLocalPath>SAK</SharedProjectFile_SccLocalPath>
<SharedProjectFile_SccProvider>SAK</SharedProjectFile_SccProvider>
<SharedProjectFile_SccProjectName></SharedProjectFile_SccProjectName>
<SharedProjectFile_SccAuxPath></SharedProjectFile_SccAuxPath>
<SharedProjectFile_SccLocalPath></SharedProjectFile_SccLocalPath>
<SharedProjectFile_SccProvider></SharedProjectFile_SccProvider>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
<PropertyGroup Label="Globals">
<ProjectGuid>5b3fa372-a872-4ca1-b7c0-5352052ac75a</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<SccProjectName>
</SccProjectName>
<SccProvider>
</SccProvider>
<SccAuxPath>
</SccAuxPath>
<SccLocalPath>
</SccLocalPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="SharedProjectFile_SccProperties">
<SharedProjectFile_ProjectGuid>{f53c2b9e-ca23-4465-b14a-6f72c6100b71}</SharedProjectFile_ProjectGuid>
<SharedProjectFile_SccProjectName>SAK</SharedProjectFile_SccProjectName>
<SharedProjectFile_SccAuxPath>SAK</SharedProjectFile_SccAuxPath>
<SharedProjectFile_SccLocalPath>SAK</SharedProjectFile_SccLocalPath>
<SharedProjectFile_SccProvider>SAK</SharedProjectFile_SccProvider>
<SharedProjectFile_SccProjectName></SharedProjectFile_SccProjectName>
<SharedProjectFile_SccAuxPath></SharedProjectFile_SccAuxPath>
<SharedProjectFile_SccLocalPath></SharedProjectFile_SccLocalPath>
<SharedProjectFile_SccProvider></SharedProjectFile_SccProvider>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
<PropertyGroup Label="Globals">
<ProjectGuid>ce6171c3-84cc-4ae1-82d0-cdac97ef5ab2</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<SccProjectName>
</SccProjectName>
<SccProvider>
</SccProvider>
<SccAuxPath>
</SccAuxPath>
<SccLocalPath>
</SccLocalPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ public static IEnumerable<T> FromCache<T>(this IQueryable<T> query, MemoryCacheE
{
if (!QueryCacheManager.IsEnabled)
{
return query.AsNoTracking().ToList();
return QueryCacheManager.ResolveAsNoTracking(query).ToList();
}

var key = QueryCacheManager.GetCacheKey(query, tags);

object item;
if (!QueryCacheManager.Cache.TryGetValue(key, out item))
{
item = query.AsNoTracking().ToList();
item = QueryCacheManager.ResolveAsNoTracking(query).ToList();
item = QueryCacheManager.Cache.Set(key, item, options);
QueryCacheManager.AddCacheTag(key, tags);
QueryCacheManager.AddCacheTag(key,typeof(T).Name + QueryCacheManager.CacheTypeSuffix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ public static Task<IEnumerable<T>> FromCacheAsync<T>(this IQueryable<T> query, p
{
if (!QueryCacheManager.IsEnabled)
{
return await query.AsNoTracking().ToListAsync(cancellationToken).ConfigureAwait(false);
return await QueryCacheManager.ResolveAsNoTracking(query).ToListAsync(cancellationToken).ConfigureAwait(false);
}

var key = QueryCacheManager.GetCacheKey(query, tags, true);

object item;
if (!QueryCacheManager.Cache.TryGetValue(key, out item))
{
item = await query.AsNoTracking().ToListAsync(cancellationToken).ConfigureAwait(false);
item = await QueryCacheManager.ResolveAsNoTracking(query).ToListAsync(cancellationToken).ConfigureAwait(false);
item = QueryCacheManager.Cache.Set(key, item, options);
QueryCacheManager.AddCacheTag(key, tags);
QueryCacheManager.AddCacheTag(key, typeof(T).Name + QueryCacheManager.CacheTypeSuffix);
Expand Down
Loading

0 comments on commit ae0558d

Please sign in to comment.