mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
HTTP+Entity
This commit is contained in:
@ -32,6 +32,8 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore.Proxies;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Esyur.Proxy;
|
||||
using System.Linq;
|
||||
|
||||
namespace Esyur.Stores.EntityCore
|
||||
{
|
||||
@ -69,9 +71,12 @@ namespace Esyur.Stores.EntityCore
|
||||
}*/
|
||||
|
||||
|
||||
public AsyncReply<IResource> Get(string path)
|
||||
public async AsyncReply<IResource> Get(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var p = path.Split('/');
|
||||
var type = Options.Cache.Keys.Where(x => x.Name.ToLower() == p[0].ToLower()).FirstOrDefault();
|
||||
var id = Convert.ToInt32(p[1]);
|
||||
return DbContext.Find(type, id) as IResource;
|
||||
}
|
||||
|
||||
public async AsyncReply<bool> Put(IResource resource)
|
||||
@ -79,13 +84,22 @@ namespace Esyur.Stores.EntityCore
|
||||
return true;
|
||||
}
|
||||
|
||||
[Attribute]
|
||||
public EsyurExtensionOptions Options { get; set; }
|
||||
|
||||
[Attribute]
|
||||
public DbContext DbContext { get; set; }
|
||||
|
||||
public string Link(IResource resource)
|
||||
{
|
||||
var p = resource.GetType().GetProperty("Id");
|
||||
if (p != null)
|
||||
return this.Instance.Name + "/" + resource.GetType().Name + "/" + p.GetValue(resource);
|
||||
var type = ResourceProxy.GetBaseType(resource.GetType());
|
||||
|
||||
var id = Options.Cache[type].GetValue(resource);
|
||||
|
||||
if (id != null)
|
||||
return this.Instance.Name + "/" + type.Name + "/" + id.ToString();
|
||||
else
|
||||
return this.Instance.Name + "/" + resource.GetType().Name;
|
||||
return this.Instance.Name + "/" + type.Name;
|
||||
}
|
||||
|
||||
public bool Record(IResource resource, string propertyName, object value, ulong age, DateTime dateTime)
|
||||
|
@ -19,6 +19,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.1.2" />
|
||||
<PackageReference Include="System.Collections" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -32,11 +32,24 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Utilities;
|
||||
using Microsoft.EntityFrameworkCore.Proxies.Internal;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System.Reflection;
|
||||
using Esyur.Proxy;
|
||||
|
||||
namespace Esyur.Stores.EntityCore
|
||||
{
|
||||
public class EsyurExtensionOptions : IDbContextOptionsExtension
|
||||
{
|
||||
|
||||
public Dictionary<Type, PropertyInfo> Cache { get; } = new Dictionary<Type, PropertyInfo>();
|
||||
public void AddType(IEntityType type)
|
||||
{
|
||||
if (!Cache.ContainsKey(type.ClrType))
|
||||
Cache.Add(type.ClrType, type.FindPrimaryKey().Properties[0].PropertyInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private DbContextOptionsExtensionInfo _info;
|
||||
EntityStore _store;
|
||||
|
||||
@ -64,7 +77,6 @@ namespace Esyur.Stores.EntityCore
|
||||
throw new InvalidOperationException("");
|
||||
}
|
||||
}
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public EsyurExtensionOptions(EntityStore store)
|
||||
@ -76,7 +88,6 @@ namespace Esyur.Stores.EntityCore
|
||||
|
||||
private sealed class ExtensionInfo : DbContextOptionsExtensionInfo
|
||||
{
|
||||
private string _logFragment;
|
||||
|
||||
public ExtensionInfo(IDbContextOptionsExtension extension)
|
||||
: base(extension)
|
||||
@ -90,23 +101,11 @@ namespace Esyur.Stores.EntityCore
|
||||
|
||||
public override string LogFragment => "Esyur";
|
||||
|
||||
// => _logFragment ??= Extension.UseLazyLoadingProxies && Extension.UseChangeDetectionProxies
|
||||
// ? "using lazy-loading and change detection proxies "
|
||||
// : Extension.UseLazyLoadingProxies
|
||||
// ? "using lazy-loading proxies "
|
||||
//: Extension.UseChangeDetectionProxies
|
||||
//? "using change detection proxies "
|
||||
//: "";
|
||||
|
||||
public override long GetServiceProviderHashCode() => 2312;//541;//2922;// Extension.UseProxies ? : 0;
|
||||
public override long GetServiceProviderHashCode() => 2312;
|
||||
|
||||
public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
|
||||
{
|
||||
//debugInfo["Proxies:" + nameof(ProxiesExtensions.UseLazyLoadingProxies)]
|
||||
// = (Extension._useLazyLoadingProxies ? 541 : 0).ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
//debugInfo["Proxies:" + nameof(ProxiesExtensions.UseChangeDetectionProxies)]
|
||||
// = (Extension._useChangeDetectionProxies ? 541 : 0).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ namespace Esyur.Stores.EntityCore
|
||||
}
|
||||
|
||||
public static DbContextOptionsBuilder UseEsyur(this DbContextOptionsBuilder optionsBuilder,
|
||||
DbContext context,
|
||||
string name = null,
|
||||
IResource parent = null,
|
||||
IPermissionsManager manager = null
|
||||
@ -67,11 +68,14 @@ namespace Esyur.Stores.EntityCore
|
||||
)
|
||||
{
|
||||
var extension = optionsBuilder.Options.FindExtension<EsyurExtensionOptions>();
|
||||
|
||||
|
||||
if (extension == null)
|
||||
{
|
||||
|
||||
var store = Warehouse.New<EntityStore>(name, null, parent, manager);
|
||||
extension = new EsyurExtensionOptions(store);
|
||||
store.Options = extension;
|
||||
store.DbContext = context;
|
||||
}
|
||||
|
||||
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension);
|
||||
@ -82,6 +86,7 @@ namespace Esyur.Stores.EntityCore
|
||||
|
||||
public static DbContextOptionsBuilder<TContext> UseEsyur<TContext>(
|
||||
this DbContextOptionsBuilder<TContext> optionsBuilder,
|
||||
DbContext context,
|
||||
string name = null,
|
||||
IResource parent = null,
|
||||
IPermissionsManager manager = null)
|
||||
@ -95,6 +100,8 @@ namespace Esyur.Stores.EntityCore
|
||||
{
|
||||
var store = Warehouse.New<EntityStore>(name, null, parent, manager);
|
||||
extension = new EsyurExtensionOptions(store);
|
||||
store.Options = extension;
|
||||
store.DbContext = context;
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,7 +67,10 @@ namespace Esyur.Stores.EntityCore
|
||||
ILazyLoader loader,
|
||||
object[] constructorArguments)
|
||||
{
|
||||
var manager = options.Store.Instance.Managers.Count > 0 ? options.Store.Instance.Managers.First() : null;
|
||||
//var key = entityType.FindPrimaryKey();
|
||||
options.AddType(entityType);
|
||||
|
||||
var manager = options.Store.Instance.Managers.Count > 0 ? options.Store.Instance.Managers.First() : null;
|
||||
return Warehouse.New(entityType.ClrType, "", options.Store, null, manager);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user