Skip to content

Commit

Permalink
Added support for date range
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Jan 6, 2023
1 parent 90e3141 commit 5874209
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions NeuroSpeech.EntityAccessControl/BaseEntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ public async Task<IActionResult> InvokeAsync<T>(
where T : class
{
var q = db.FilteredQuery<T>();
var type = db.GetType();
options.Type = type;
var result = await MethodParser.Instance.Parse<T>(q, options);
return Serialize(result);
}
Expand Down
2 changes: 2 additions & 0 deletions NeuroSpeech.EntityAccessControl/Parser/LinqMethodOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public class LinqMethodOptions
public Action<string>? Trace { get; set; }
public CancellationToken CancelToken { get; set; }

internal Type Type { get; set; }

}
}
28 changes: 19 additions & 9 deletions NeuroSpeech.EntityAccessControl/Parser/MethodParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
Expand All @@ -26,25 +27,34 @@ private readonly ConcurrentDictionary<string, Task> cache

public async Task<LinqResult> Parse<T>(IQueryable<T> queryContext, LinqMethodOptions args)
{
var d = await Parse<T>(new CacheKeyBuilder(typeof(T), args.Methods));
var d = await Parse<T>(args);
return await d(queryContext, args);
}

public Task<LinqMethodDelegate<T>> Parse<T>(CacheKeyBuilder methods)
private Task<LinqMethodDelegate<T>> Parse<T>(LinqMethodOptions args)
{
var methods = new CacheKeyBuilder(typeof(T), args.Methods);
var key = methods.CacheKey;
return (Task<LinqMethodDelegate<T>>)cache.GetOrAdd(key, k => ParseQuery<T>(methods.Methods));
return (Task<LinqMethodDelegate<T>>)cache.GetOrAdd(key, k => ParseQuery<T>(args, methods.Methods));
}


private Task<LinqMethodDelegate<T>> ParseQuery<T>(List<LinqMethod> methods)
private Task<LinqMethodDelegate<T>> ParseQuery<T>(LinqMethodOptions args, List<LinqMethod> methods)
{
var list = new List<Assembly> {typeof(Queryable).Assembly,
typeof(Microsoft.EntityFrameworkCore.EF).Assembly,
typeof(QueryParser).Assembly,
typeof(RelationalQueryableExtensions).Assembly,
typeof(T).Assembly
};

if (!list.Contains(args.Type.Assembly))
{
list.Add(args.Type.Assembly);
}

var options = ScriptOptions.Default
.AddReferences(typeof(Queryable).Assembly,
typeof(Microsoft.EntityFrameworkCore.EF).Assembly,
typeof(QueryParser).Assembly,
typeof(RelationalQueryableExtensions).Assembly,
typeof(T).Assembly)
.AddReferences(list)
.WithOptimizationLevel(OptimizationLevel.Debug);

var type = typeof(T);
Expand Down

0 comments on commit 5874209

Please sign in to comment.