mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-26 04:53:12 +00:00
Bugfix
This commit is contained in:
@ -22,6 +22,8 @@ namespace Esiur.Stores.MongoDB
|
||||
MongoClient client;
|
||||
IMongoDatabase database;
|
||||
IMongoCollection<BsonDocument> resourcesCollection;
|
||||
string collectionName;
|
||||
string dbName;
|
||||
|
||||
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) }
|
||||
});
|
||||
|
||||
var col = this.database.GetCollection<BsonDocument>("resources");
|
||||
var col = this.database.GetCollection<BsonDocument>(collectionName);
|
||||
|
||||
|
||||
|
||||
@ -64,19 +66,19 @@ namespace Esiur.Stores.MongoDB
|
||||
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);
|
||||
this.database = client.GetDatabase(database);
|
||||
this.resourcesCollection = this.database.GetCollection<BsonDocument>("resources");
|
||||
this.resourcesCollection = this.database.GetCollection<BsonDocument>(collection);
|
||||
}
|
||||
|
||||
public bool Remove(IResource resource)
|
||||
@ -274,6 +276,20 @@ namespace Esiur.Stores.MongoDB
|
||||
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 children = new BsonArray();
|
||||
|
||||
@ -314,6 +330,7 @@ namespace Esiur.Stores.MongoDB
|
||||
// col.UpdateOne(filter, update);
|
||||
|
||||
|
||||
/*
|
||||
var document = new BsonDocument
|
||||
{
|
||||
{ "parents", parents },
|
||||
@ -323,11 +340,15 @@ namespace Esiur.Stores.MongoDB
|
||||
{ "name", resource.Instance.Name },
|
||||
{ "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;
|
||||
}
|
||||
@ -398,6 +419,7 @@ namespace Esiur.Stores.MongoDB
|
||||
|
||||
case DataType.Resource:
|
||||
case DataType.DistributedResource:
|
||||
|
||||
return new BsonDocument { { "type", 0 }, { "link", (value as IResource).Instance.Link } };
|
||||
|
||||
//return new BsonObjectId(new ObjectId((string)(value as IResource).Instance.Attributes["objectId"]));
|
||||
|
@ -41,7 +41,15 @@ namespace Esiur.Resource
|
||||
|
||||
public virtual AsyncReply<bool> Trigger(ResourceTrigger trigger)
|
||||
{
|
||||
if (trigger == ResourceTrigger.Initialize)
|
||||
return new AsyncReply<bool>(this.Create());
|
||||
else
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
public virtual bool Create()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,8 +96,7 @@ namespace Esiur.Security.Permissions
|
||||
if ((string)userPermissions["_rename"] != "yes")
|
||||
return Ruling.Denied;
|
||||
}
|
||||
|
||||
if (userPermissions.ContainsKey(member.Name))
|
||||
else if (userPermissions.ContainsKey(member?.Name))
|
||||
{
|
||||
Structure methodPermissions = userPermissions[member.Name] as Structure;
|
||||
if ((string)methodPermissions[action.ToString()] != "yes")
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Esiur.Data;
|
||||
using Esiur.Engine;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Authority;
|
||||
using Esiur.Security.Membership;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -25,12 +26,23 @@ namespace Test
|
||||
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)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user