mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
1.4.5
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user