mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
async put
This commit is contained in:
parent
7c707637de
commit
4cfad2a242
@ -48,7 +48,7 @@ namespace Esiur.Stores.MongoDB
|
||||
IMongoDatabase database;
|
||||
IMongoCollection<BsonDocument> resourcesCollection;
|
||||
|
||||
Dictionary<string, WeakReference> resources = new Dictionary<string, WeakReference>();
|
||||
KeyList<string, WeakReference> resources = new KeyList<string, WeakReference>();
|
||||
|
||||
|
||||
[Public]
|
||||
@ -158,7 +158,8 @@ namespace Esiur.Stores.MongoDB
|
||||
else
|
||||
resources.Add(id, new WeakReference(resource));
|
||||
|
||||
Warehouse.Put(resource, document["name"].AsString, this);
|
||||
//@TODO this causes store.put to be invoked, need fix
|
||||
await Warehouse.Put(resource, document["name"].AsString, this);
|
||||
|
||||
|
||||
var parents = document["parents"].AsBsonArray;
|
||||
|
@ -36,9 +36,9 @@ namespace Esiur.Stores.MongoDB
|
||||
public class MongoDBStore<T> : MongoDBStore where T:IResource
|
||||
{
|
||||
[Public]
|
||||
public T New(string name = null, object properties = null)
|
||||
public async AsyncReply<T> New(string name = null, object properties = null)
|
||||
{
|
||||
var resource = Warehouse.New<T>(name, this, null, null, null, properties);
|
||||
var resource = await Warehouse.New<T>(name, this, null, null, null, properties);
|
||||
resource.Instance.Managers.AddRange(this.Instance.Managers.ToArray());
|
||||
return resource;
|
||||
}
|
||||
|
@ -36,5 +36,6 @@ namespace Esiur.Core
|
||||
SetPropertyDenied,
|
||||
ReadOnlyProperty,
|
||||
GeneralFailure,
|
||||
AddToStoreFailed
|
||||
}
|
||||
}
|
||||
|
@ -759,13 +759,19 @@ namespace Esiur.Net.IIP
|
||||
.Done();
|
||||
|
||||
ready = true;
|
||||
Warehouse.Put(this, this.LocalUsername, null, Server);
|
||||
|
||||
Warehouse.Put(this, this.LocalUsername, null, Server).Then(x =>
|
||||
{
|
||||
openReply?.Trigger(true);
|
||||
OnReady?.Invoke(this);
|
||||
|
||||
Server?.Membership.Login(session);
|
||||
|
||||
}).Error(x=>
|
||||
{
|
||||
openReply?.TriggerError(x);
|
||||
});
|
||||
|
||||
|
||||
//Global.Log("auth", LogType.Warning, "U:" + RemoteUsername + " IP:" + Socket.RemoteEndPoint.Address.ToString() + " S:AUTH");
|
||||
|
||||
}
|
||||
@ -835,11 +841,13 @@ namespace Esiur.Net.IIP
|
||||
|
||||
ready = true;
|
||||
// put it in the warehouse
|
||||
Warehouse.Put(this, this.LocalUsername, null, Server);
|
||||
|
||||
Warehouse.Put(this, this.LocalUsername, null, Server).Then(x =>
|
||||
{
|
||||
openReply?.Trigger(true);
|
||||
OnReady?.Invoke(this);
|
||||
|
||||
}).Error(x=> openReply?.TriggerError(x));
|
||||
|
||||
}
|
||||
}
|
||||
else if (authPacket.Command == IIPAuthPacket.IIPAuthPacketCommand.Error)
|
||||
@ -945,7 +953,7 @@ namespace Esiur.Net.IIP
|
||||
}
|
||||
}
|
||||
|
||||
return new AsyncReply<bool>();
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -770,12 +770,17 @@ namespace Esiur.Net.IIP
|
||||
// create the resource
|
||||
var resource = Activator.CreateInstance(type, args) as IResource;
|
||||
|
||||
Warehouse.Put(resource, name, store as IStore, parent);
|
||||
|
||||
Warehouse.Put(resource, name, store as IStore, parent).Then(ok =>
|
||||
{
|
||||
SendReply(IIPPacket.IIPPacketAction.CreateResource, callback)
|
||||
.AddUInt32(resource.Instance.Id)
|
||||
.Done();
|
||||
|
||||
}).Error(x =>
|
||||
{
|
||||
SendError(ErrorType.Exception, callback, (ushort)ExceptionCode.AddToStoreFailed);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1959,14 +1964,27 @@ namespace Esiur.Net.IIP
|
||||
{
|
||||
// ClassId, ResourceAge, ResourceLink, Content
|
||||
if (resource == null)
|
||||
Warehouse.Put(dr, id.ToString(), this, null, tmp);
|
||||
|
||||
{
|
||||
Warehouse.Put(dr, id.ToString(), this, null, tmp).Then((ok) =>
|
||||
{
|
||||
Codec.ParsePropertyValueArray((byte[])rt[3], this).Then((ar) =>
|
||||
{
|
||||
dr._Attach(ar);
|
||||
resourceRequests.Remove(id);
|
||||
reply.Trigger(dr);
|
||||
});
|
||||
}).Error(ex=>reply.TriggerError(ex));
|
||||
}
|
||||
else
|
||||
{
|
||||
Codec.ParsePropertyValueArray((byte[])rt[3], this).Then((ar) =>
|
||||
{
|
||||
dr._Attach(ar);
|
||||
resourceRequests.Remove(id);
|
||||
reply.Trigger(dr);
|
||||
}).Error(ex=>reply.TriggerError(ex));
|
||||
}
|
||||
|
||||
}).Error((ex) =>
|
||||
{
|
||||
reply.TriggerError(ex);
|
||||
|
@ -535,24 +535,10 @@ namespace Esiur.Resource
|
||||
parent = null;
|
||||
|
||||
|
||||
/*
|
||||
if (parent == null)
|
||||
{
|
||||
if (!(resource is IStore))
|
||||
store.Instance.Children.Add(resource);
|
||||
}
|
||||
else
|
||||
parent.Instance.Children.Add(resource);
|
||||
*/
|
||||
|
||||
|
||||
if (resource is IStore)
|
||||
{
|
||||
|
||||
stores.TryAdd(resource as IStore, new List<WeakReference<IResource>>());
|
||||
StoreConnected?.Invoke(resource as IStore, name);
|
||||
}
|
||||
//else
|
||||
|
||||
|
||||
if (!await store.Put(resource))
|
||||
@ -563,16 +549,12 @@ namespace Esiur.Resource
|
||||
{
|
||||
await parent.Instance.Store.AddChild(parent, resource);
|
||||
await store.AddParent(resource, parent);
|
||||
//store.AddChild(parent, resource);
|
||||
|
||||
}
|
||||
|
||||
var t = resource.GetType();
|
||||
Global.Counters["T-" + t.Namespace + "." + t.Name]++;
|
||||
|
||||
//var wr = new WeakReference<IResource>(resource);
|
||||
|
||||
//lock (resourcesLock)
|
||||
resources.TryAdd(resource.Instance.Id, resourceReference);
|
||||
|
||||
if (warehouseIsOpen)
|
||||
@ -580,10 +562,11 @@ namespace Esiur.Resource
|
||||
await resource.Trigger(ResourceTrigger.Initialize);
|
||||
if (resource is IStore)
|
||||
await resource.Trigger(ResourceTrigger.Open);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
if (resource is IStore)
|
||||
StoreConnected?.Invoke(resource as IStore, name);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user