2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2019-12-23 11:57:16 +03:00
parent 128972bb74
commit a96ddf602f
12 changed files with 183 additions and 57 deletions

View File

@ -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();