2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-26 04:53:12 +00:00
This commit is contained in:
2019-07-07 02:49:34 +03:00
parent 08e95bd4dc
commit 8763ac805e
4 changed files with 56 additions and 15 deletions

View File

@ -22,6 +22,8 @@ namespace Esiur.Stores.MongoDB
MongoClient client; MongoClient client;
IMongoDatabase database; IMongoDatabase database;
IMongoCollection<BsonDocument> resourcesCollection; IMongoCollection<BsonDocument> resourcesCollection;
string collectionName;
string dbName;
Dictionary<string, IResource> resources = new Dictionary<string, IResource>(); Dictionary<string, IResource> resources = new Dictionary<string, IResource>();
@ -49,7 +51,7 @@ namespace Esiur.Stores.MongoDB
{"property", propertyName}, {"age", BsonValue.Create(age) }, {"date", date}, {"value", Compose(value) } {"property", propertyName}, {"age", BsonValue.Create(age) }, {"date", date}, {"value", Compose(value) }
}); });
var col = this.database.GetCollection<BsonDocument>("resources"); var col = this.database.GetCollection<BsonDocument>(collectionName);
@ -64,19 +66,19 @@ namespace Esiur.Stores.MongoDB
return true; return true;
} }
public MongoDBStore() public MongoDBStore() : this("mongodb://localhost", "esiur", "resources")
{ {
client = new MongoClient();
this.database = client.GetDatabase("esiur");
this.resourcesCollection = this.database.GetCollection<BsonDocument>("resources");
} }
public MongoDBStore(string connectionString, string database) public MongoDBStore(string connectionString, string database, string collection)
{ {
collectionName = collection;
dbName = database;
client = new MongoClient(connectionString); client = new MongoClient(connectionString);
this.database = client.GetDatabase(database); this.database = client.GetDatabase(database);
this.resourcesCollection = this.database.GetCollection<BsonDocument>("resources"); this.resourcesCollection = this.database.GetCollection<BsonDocument>(collection);
} }
public bool Remove(IResource resource) public bool Remove(IResource resource)
@ -274,6 +276,20 @@ namespace Esiur.Stores.MongoDB
return true; return true;
} }
// insert the document
var document = new BsonDocument
{
{ "classname", resource.GetType().FullName + "," + resource.GetType().GetTypeInfo().Assembly.GetName().Name },
{ "name", resource.Instance.Name },
};
resourcesCollection.InsertOne(document);
resource.Instance.Attributes["objectId"] = document["_id"].ToString();
// now update the document
// * insert first to get the object id, update values, attributes, children and parents after in case the same resource has a property references self
var parents = new BsonArray(); var parents = new BsonArray();
var children = new BsonArray(); var children = new BsonArray();
@ -314,6 +330,7 @@ namespace Esiur.Stores.MongoDB
// col.UpdateOne(filter, update); // col.UpdateOne(filter, update);
/*
var document = new BsonDocument var document = new BsonDocument
{ {
{ "parents", parents }, { "parents", parents },
@ -323,11 +340,15 @@ namespace Esiur.Stores.MongoDB
{ "name", resource.Instance.Name }, { "name", resource.Instance.Name },
{ "values", values } { "values", values }
}; };
*/
var filter = Builders<BsonDocument>.Filter.Eq("_id", document["_id"]);
var update = Builders<BsonDocument>.Update
.Set("values", values).Set("parents", parents).Set("children", children).Set("attributes", attrsDoc);
resourcesCollection.UpdateOne(filter, update);
resourcesCollection.InsertOne(document); //resource.Instance.Attributes["objectId"] = document["_id"].ToString();
resource.Instance.Attributes["objectId"] = document["_id"].ToString();
return true; return true;
} }
@ -398,6 +419,7 @@ namespace Esiur.Stores.MongoDB
case DataType.Resource: case DataType.Resource:
case DataType.DistributedResource: case DataType.DistributedResource:
return new BsonDocument { { "type", 0 }, { "link", (value as IResource).Instance.Link } }; return new BsonDocument { { "type", 0 }, { "link", (value as IResource).Instance.Link } };
//return new BsonObjectId(new ObjectId((string)(value as IResource).Instance.Attributes["objectId"])); //return new BsonObjectId(new ObjectId((string)(value as IResource).Instance.Attributes["objectId"]));

View File

@ -36,12 +36,20 @@ namespace Esiur.Resource
public virtual void Destroy() public virtual void Destroy()
{ {
} }
public virtual AsyncReply<bool> Trigger(ResourceTrigger trigger) public virtual AsyncReply<bool> Trigger(ResourceTrigger trigger)
{ {
return new AsyncReply<bool>(true); if (trigger == ResourceTrigger.Initialize)
return new AsyncReply<bool>(this.Create());
else
return new AsyncReply<bool>(true);
}
public virtual bool Create()
{
return true;
} }
} }
} }

View File

@ -96,8 +96,7 @@ namespace Esiur.Security.Permissions
if ((string)userPermissions["_rename"] != "yes") if ((string)userPermissions["_rename"] != "yes")
return Ruling.Denied; return Ruling.Denied;
} }
else if (userPermissions.ContainsKey(member?.Name))
if (userPermissions.ContainsKey(member.Name))
{ {
Structure methodPermissions = userPermissions[member.Name] as Structure; Structure methodPermissions = userPermissions[member.Name] as Structure;
if ((string)methodPermissions[action.ToString()] != "yes") if ((string)methodPermissions[action.ToString()] != "yes")

View File

@ -1,6 +1,7 @@
using Esiur.Data; using Esiur.Data;
using Esiur.Engine; using Esiur.Engine;
using Esiur.Resource; using Esiur.Resource;
using Esiur.Security.Authority;
using Esiur.Security.Membership; using Esiur.Security.Membership;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -25,12 +26,23 @@ namespace Test
return new AsyncReply<byte[]>(DC.ToBytes("1234")); return new AsyncReply<byte[]>(DC.ToBytes("1234"));
} }
public AsyncReply<bool> Login(Session session)
{
return new AsyncReply<bool>(true);
}
public AsyncReply<bool> Logout(Session session)
{
return new AsyncReply<bool>(true);
}
public AsyncReply<bool> Trigger(ResourceTrigger trigger) public AsyncReply<bool> Trigger(ResourceTrigger trigger)
{ {
return new AsyncReply<bool>(true); return new AsyncReply<bool>(true);
} }
public AsyncReply<bool> UserExists(string username)
public AsyncReply<bool> UserExists(string username, string domain)
{ {
return new AsyncReply<bool>(username == "demo"); return new AsyncReply<bool>(username == "demo");
} }