mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
1.4.5
This commit is contained in:
parent
128972bb74
commit
a96ddf602f
@ -11,7 +11,7 @@
|
||||
<PackageProjectUrl>http://www.esyur.com</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/esyur/esyur-dotnet/</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Version>1.2.9</Version>
|
||||
<Version>1.3.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -24,21 +24,24 @@ namespace Esyur.Stores.MongoDB
|
||||
IMongoDatabase database;
|
||||
IMongoCollection<BsonDocument> resourcesCollection;
|
||||
|
||||
//List<IResource> storeParents = new List<IResource>();
|
||||
//List<IResource> storeChildren = new List<IResource>();
|
||||
|
||||
//string collectionName;
|
||||
//string dbName;
|
||||
|
||||
Dictionary<string, WeakReference> resources = new Dictionary<string, WeakReference>();
|
||||
|
||||
|
||||
public long Count
|
||||
[ResourceEvent]
|
||||
public event ResourceEventHanlder ResourceAdded;
|
||||
|
||||
[ResourceEvent]
|
||||
public event ResourceEventHanlder ResourceRemoved;
|
||||
|
||||
[ResourceProperty]
|
||||
public virtual int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourcesCollection.CountDocuments(x => true);
|
||||
}// resources.Count; }
|
||||
return (int)resourcesCollection.CountDocuments(x => true);
|
||||
}
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
@ -73,6 +76,7 @@ namespace Esyur.Stores.MongoDB
|
||||
return true;
|
||||
}
|
||||
|
||||
[ResourceFunction]
|
||||
public bool Remove(IResource resource)
|
||||
{
|
||||
var objectId = resource.Instance.Attributes["objectId"].ToString();
|
||||
@ -81,9 +85,15 @@ namespace Esyur.Stores.MongoDB
|
||||
this.database.DropCollection("record_" + objectId);
|
||||
resourcesCollection.DeleteOne(filter);
|
||||
|
||||
ResourceRemoved?.Invoke(resource);
|
||||
|
||||
Instance.Modified("Count");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AsyncReply<T> Fetch<T>(string id) where T : IResource
|
||||
{
|
||||
|
||||
@ -304,6 +314,10 @@ namespace Esyur.Stores.MongoDB
|
||||
|
||||
PutResource(resource).Wait();
|
||||
|
||||
ResourceAdded?.Invoke(resource);
|
||||
|
||||
Instance.Modified("Count");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -773,6 +787,8 @@ namespace Esyur.Stores.MongoDB
|
||||
public bool Modify(IResource resource, string propertyName, object value, ulong age, DateTime dateTime)
|
||||
{
|
||||
|
||||
if (resource == this)
|
||||
return true;
|
||||
|
||||
var objectId = resource.Instance.Attributes["objectId"].ToString();
|
||||
|
||||
|
28
Esyur.Stores.MongoDB/MongoDBStoreGeneric.cs
Normal file
28
Esyur.Stores.MongoDB/MongoDBStoreGeneric.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Esyur.Core;
|
||||
using Esyur.Data;
|
||||
using Esyur.Proxy;
|
||||
using Esyur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Esyur.Stores.MongoDB
|
||||
{
|
||||
public class MongoDBStore<T> : MongoDBStore where T:IResource
|
||||
{
|
||||
[ResourceFunction]
|
||||
public T Create(string name, Structure values)
|
||||
{
|
||||
return Warehouse.New<T>(name, this, null, null, null, null, values);
|
||||
}
|
||||
|
||||
[ResourceFunction]
|
||||
public async AsyncReply<IResource[]> Slice(int index, int limit)
|
||||
{
|
||||
var list = await this.Instance.Children<IResource>();
|
||||
return list.Skip(index).Take(limit).ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
@ -9,7 +9,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Esiur\Esiur.csproj" />
|
||||
<ProjectReference Include="..\Esyur\Esyur.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -90,6 +90,8 @@ namespace Esyur.Core
|
||||
Add(r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public AsyncBag()
|
||||
{
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<PackageLicenseUrl>https://github.com/Esyur/Esyur-dotnet/blob/master/LICENSE</PackageLicenseUrl>
|
||||
<PackageProjectUrl>http://www.esyur.com</PackageProjectUrl>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>1.4.3</Version>
|
||||
<Version>1.4.5</Version>
|
||||
<RepositoryUrl>https://github.com/esyur/esyur-dotnet</RepositoryUrl>
|
||||
<Authors>Ahmed Kh. Zamil</Authors>
|
||||
<AssemblyVersion>1.3.1.0</AssemblyVersion>
|
||||
|
@ -286,7 +286,7 @@ namespace Esyur.Net.HTTP
|
||||
//base.Send(fd);
|
||||
|
||||
|
||||
using (var fs = new FileStream(filename, FileMode.Open))
|
||||
using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
|
||||
var buffer = new byte[5000];
|
||||
|
@ -179,6 +179,7 @@ namespace Esyur.Net
|
||||
//if (!connected)
|
||||
// return;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (sock != null)
|
||||
|
@ -113,18 +113,43 @@ namespace Esyur.Proxy
|
||||
var getInstance = resourceType.GetTypeInfo().GetProperty("Instance").GetGetMethod();
|
||||
|
||||
|
||||
//g.Emit(OpCodes.Ldarg_0);
|
||||
//g.Emit(OpCodes.Ldarg_1);
|
||||
//g.Emit(OpCodes.Call, pi.GetSetMethod());
|
||||
//g.Emit(OpCodes.Nop);
|
||||
|
||||
//g.Emit(OpCodes.Ldarg_0);
|
||||
//g.Emit(OpCodes.Call, getInstance);
|
||||
//g.Emit(OpCodes.Ldstr, pi.Name);
|
||||
//g.Emit(OpCodes.Call, modifyMethod);
|
||||
//g.Emit(OpCodes.Nop);
|
||||
|
||||
//g.Emit(OpCodes.Ret);
|
||||
|
||||
Label exitMethod = g.DefineLabel();
|
||||
Label callModified = g.DefineLabel();
|
||||
|
||||
g.Emit(OpCodes.Ldarg_0);
|
||||
g.Emit(OpCodes.Ldarg_1);
|
||||
g.Emit(OpCodes.Call, pi.GetSetMethod());
|
||||
g.Emit(OpCodes.Nop);
|
||||
//g.Emit(OpCodes.Nop);
|
||||
|
||||
g.Emit(OpCodes.Nop);
|
||||
g.Emit(OpCodes.Ldarg_0);
|
||||
g.Emit(OpCodes.Call, getInstance);
|
||||
g.Emit(OpCodes.Dup);
|
||||
|
||||
g.Emit(OpCodes.Brtrue_S, callModified);
|
||||
|
||||
g.Emit(OpCodes.Pop);
|
||||
g.Emit(OpCodes.Br_S, exitMethod);
|
||||
|
||||
g.MarkLabel(callModified);
|
||||
|
||||
g.Emit(OpCodes.Ldstr, pi.Name);
|
||||
g.Emit(OpCodes.Call, modifyMethod);
|
||||
g.Emit(OpCodes.Nop);
|
||||
|
||||
g.MarkLabel(exitMethod);
|
||||
g.Emit(OpCodes.Ret);
|
||||
propertyBuilder.SetSetMethod(builder);
|
||||
|
||||
|
@ -816,10 +816,10 @@ namespace Esyur.Resource
|
||||
Type t = ResourceProxy.GetBaseType(resource);
|
||||
|
||||
#if NETSTANDARD
|
||||
var events = t.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
var events = t.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
|
||||
#else
|
||||
var events = t.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
var events = t.GetEvents(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
#endif
|
||||
|
||||
foreach (var evt in events)
|
||||
|
@ -140,14 +140,14 @@ namespace Esyur.Resource.Template
|
||||
|
||||
|
||||
#if NETSTANDARD
|
||||
PropertyInfo[] propsInfo = type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
EventInfo[] eventsInfo = type.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
MethodInfo[] methodsInfo = type.GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
PropertyInfo[] propsInfo = type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
EventInfo[] eventsInfo = type.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
MethodInfo[] methodsInfo = type.GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Instance); // | BindingFlags.DeclaredOnly);
|
||||
|
||||
#else
|
||||
PropertyInfo[] propsInfo = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
EventInfo[] eventsInfo = type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
MethodInfo[] methodsInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
PropertyInfo[] propsInfo = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
EventInfo[] eventsInfo = type.GetEvents(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
MethodInfo[] methodsInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
|
||||
#endif
|
||||
|
||||
//byte currentIndex = 0;
|
||||
|
@ -58,6 +58,8 @@ namespace Esyur.Resource
|
||||
|
||||
public static KeyList<string, Func<IStore>> Protocols { get; } = getSupportedProtocols();
|
||||
|
||||
private static Regex urlRegex = new Regex(@"^(?:([\S]*)://([^/]*)/?)");
|
||||
|
||||
|
||||
static KeyList<string, Func<IStore>> getSupportedProtocols()
|
||||
{
|
||||
@ -106,7 +108,7 @@ namespace Esyur.Resource
|
||||
public static async AsyncReply<bool> Open()
|
||||
{
|
||||
|
||||
foreach(var rk in resources)
|
||||
foreach (var rk in resources)
|
||||
{
|
||||
IResource r;
|
||||
if (rk.Value.TryGetTarget(out r))
|
||||
@ -351,32 +353,39 @@ namespace Esyur.Resource
|
||||
|
||||
// Should we create a new store ?
|
||||
|
||||
if (path.Contains("://"))
|
||||
if (urlRegex.IsMatch(path))
|
||||
{
|
||||
var url = path.Split(new string[] { "://" }, 2, StringSplitOptions.None);
|
||||
var hostname = url[1].Split(new char[] { '/' }, 2)[0];
|
||||
var pathname = string.Join("/", url[1].Split(new char[] { '/' }).Skip(1));
|
||||
|
||||
//if (path.Contains("://"))
|
||||
//{
|
||||
var url = urlRegex.Split(path);
|
||||
//var url = path.Split(new string[] { "://" }, 2, StringSplitOptions.None);
|
||||
//var hostname = url[1].Split(new char[] { '/' }, 2)[0];
|
||||
//var pathname = string.Join("/", url[1].Split(new char[] { '/' }).Skip(1));
|
||||
|
||||
|
||||
if (Protocols.ContainsKey(url[0]))
|
||||
if (Protocols.ContainsKey(url[1]))
|
||||
{
|
||||
var handler = Protocols[url[0]];
|
||||
var handler = Protocols[url[1]];
|
||||
|
||||
var store = handler();
|
||||
Put(store, hostname, null, parent, null, 0, manager, attributes);
|
||||
Put(store, url[2], null, parent, null, 0, manager, attributes);
|
||||
|
||||
|
||||
store.Trigger(ResourceTrigger.Open).Then(x => {
|
||||
store.Trigger(ResourceTrigger.Open).Then(x =>
|
||||
{
|
||||
|
||||
warehouseIsOpen = true;
|
||||
|
||||
if (pathname.Length > 0 && pathname != "")
|
||||
store.Get(pathname).Then(r => {
|
||||
if (url[3].Length > 0 && url[3] != "")
|
||||
store.Get(url[3]).Then(r =>
|
||||
{
|
||||
rt.Trigger(r);
|
||||
}).Error(e => rt.TriggerError(e));
|
||||
else
|
||||
rt.Trigger(store);
|
||||
}).Error(e => {
|
||||
}).Error(e =>
|
||||
{
|
||||
rt.TriggerError(e);
|
||||
Warehouse.Remove(store);
|
||||
});
|
||||
@ -472,11 +481,55 @@ namespace Esyur.Resource
|
||||
|
||||
}
|
||||
|
||||
public static T New<T>(string name, IStore store = null, IResource parent = null, IPermissionsManager manager = null, Structure attributes = null)
|
||||
where T:IResource
|
||||
public static T New<T>(string name, IStore store = null, IResource parent = null, IPermissionsManager manager = null, Structure attributes = null, Structure arguments = null, Structure properties = null)
|
||||
where T : IResource
|
||||
{
|
||||
var type = ResourceProxy.GetProxy<T>();
|
||||
|
||||
|
||||
/*
|
||||
if (arguments != null)
|
||||
{
|
||||
var constructors = type.GetConstructors(System.Reflection.BindingFlags.Public);
|
||||
|
||||
foreach(var constructor in constructors)
|
||||
{
|
||||
var pi = constructor.GetParameters();
|
||||
if (pi.Length == constructor.le)
|
||||
}
|
||||
|
||||
// cast arguments
|
||||
ParameterInfo[] pi = fi.GetParameters();
|
||||
|
||||
object[] args = new object[pi.Length];
|
||||
|
||||
for (var i = 0; i < pi.Length; i++)
|
||||
{
|
||||
if (pi[i].ParameterType == typeof(DistributedConnection))
|
||||
{
|
||||
args[i] = this;
|
||||
}
|
||||
else if (namedArgs.ContainsKey(pi[i].Name))
|
||||
{
|
||||
args[i] = DC.CastConvert(namedArgs[pi[i].Name], pi[i].ParameterType);
|
||||
}
|
||||
}
|
||||
|
||||
constructors[0].
|
||||
}
|
||||
*/
|
||||
var res = Activator.CreateInstance(type) as IResource;
|
||||
|
||||
if (properties != null)
|
||||
{
|
||||
foreach (var p in properties)
|
||||
{
|
||||
var pi = typeof(T).GetProperty(p.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly);
|
||||
if (pi != null)
|
||||
pi.SetValue(res, p.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Put(res, name, store, parent, null, 0, manager, attributes);
|
||||
return (T)res;
|
||||
}
|
||||
@ -552,7 +605,8 @@ namespace Esyur.Resource
|
||||
stores.Remove(resource as IStore);
|
||||
|
||||
// remove all objects associated with the store
|
||||
var toBeRemoved = resources.Values.Where(x => {
|
||||
var toBeRemoved = resources.Values.Where(x =>
|
||||
{
|
||||
IResource r;
|
||||
return x.TryGetTarget(out r) && r.Instance.Store == resource;
|
||||
}).ToArray();
|
||||
|
Loading…
x
Reference in New Issue
Block a user